+
{/* Hidden widgets button - toggles panel in Dashboard */}
{hiddenCount > 0 && (
a.jsxs("button",{onClick:()=>d(E),className:`px-2 py-1 text-xs rounded transition-colors ${u===E?"bg-bambu-green text-white":"bg-bambu-dark-tertiary text-bambu-gray hover:bg-bambu-dark-tertiary/80"}`,children:[E,"x"]},E))})]})]})]})]})]}),y&&r&&a.jsx(hqe,{archiveId:r,timelapseSrc:t,onClose:()=>v(!1),onSave:s})]})}function mqe({archiveIds:t,onClose:e}){_.useEffect(()=>{const s=o=>{o.key==="Escape"&&e()};return window.addEventListener("keydown",s),()=>window.removeEventListener("keydown",s)},[e]);const{data:n,isLoading:r,error:i}=ct({queryKey:["archive-comparison",t],queryFn:()=>ce.compareArchives(t)});return a.jsx("div",{className:"fixed inset-0 bg-black/80 flex items-center justify-center z-50 p-4",onClick:e,children:a.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg max-w-4xl w-full max-h-[90vh] flex flex-col border border-bambu-dark-tertiary",onClick:s=>s.stopPropagation(),children:[a.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[a.jsxs("h3",{className:"text-lg font-semibold text-white",children:["Compare Archives (",t.length,")"]}),a.jsx("button",{onClick:e,className:"text-bambu-gray hover:text-white p-1",children:a.jsx(Lt,{className:"w-5 h-5"})})]}),a.jsx("div",{className:"flex-1 overflow-auto p-4 bg-bambu-dark-secondary",children:r?a.jsx("div",{className:"flex items-center justify-center py-12",children:a.jsx(pt,{className:"w-8 h-8 text-bambu-green animate-spin"})}):i?a.jsxs("div",{className:"text-center py-12 text-red-400",children:[a.jsx(Sn,{className:"w-12 h-12 mx-auto mb-4 opacity-50"}),a.jsx("p",{children:"Failed to load comparison"}),a.jsx("p",{className:"text-sm text-bambu-gray mt-2",children:i instanceof Error?i.message:"Unknown error"})]}):n?a.jsx(pqe,{comparison:n}):null}),a.jsx("div",{className:"p-4 border-t border-bambu-dark-tertiary",children:a.jsx(Te,{variant:"secondary",onClick:e,className:"w-full",children:"Close"})})]})})}function pqe({comparison:t}){return a.jsxs("div",{className:"space-y-6",children:[a.jsx("div",{className:"overflow-x-auto",children:a.jsxs("table",{className:"w-full",children:[a.jsx("thead",{children:a.jsxs("tr",{children:[a.jsx("th",{className:"text-left text-sm text-bambu-gray font-medium pb-2 pr-4 min-w-[150px]",children:"Setting"}),t.archives.map(e=>a.jsxs("th",{className:"text-left text-sm font-medium pb-2 px-2 min-w-[120px]",children:[a.jsx("div",{className:"text-white truncate max-w-[150px]",title:e.print_name,children:e.print_name}),a.jsx("div",{className:`text-xs ${e.status==="completed"?"text-status-ok":e.status==="failed"?"text-status-error":"text-bambu-gray"}`,children:e.status})]},e.id))]})}),a.jsx("tbody",{className:"divide-y divide-bambu-gray/20",children:t.comparison.map(e=>a.jsxs("tr",{className:e.has_difference?"bg-yellow-500/5":"",children:[a.jsx("td",{className:"py-2 pr-4 text-sm",children:a.jsxs("div",{className:"flex items-center gap-2",children:[e.has_difference&&a.jsx(Sn,{className:"w-3 h-3 text-yellow-400 flex-shrink-0"}),a.jsx("span",{className:e.has_difference?"text-yellow-400":"text-bambu-gray",children:e.label})]})}),e.values.map((n,r)=>a.jsxs("td",{className:"py-2 px-2 text-sm text-white",children:[n??a.jsx("span",{className:"text-bambu-gray/50",children:"-"}),e.unit&&n!==null&&a.jsx("span",{className:"text-bambu-gray ml-1",children:e.unit})]},r))]},e.field))})]})}),t.differences.length>0&&a.jsxs("div",{className:"p-4 bg-yellow-500/10 border border-yellow-500/30 rounded-lg",children:[a.jsxs("h4",{className:"text-sm font-medium text-yellow-400 mb-2 flex items-center gap-2",children:[a.jsx(Sn,{className:"w-4 h-4"}),t.differences.length," Difference",t.differences.length>1?"s":""," Found"]}),a.jsxs("ul",{className:"text-sm text-white/80 space-y-1",children:[t.differences.slice(0,5).map(e=>a.jsxs("li",{children:[a.jsx("span",{className:"text-yellow-400",children:e.label}),": ",e.values.join(" vs ")," ",e.unit||""]},e.field)),t.differences.length>5&&a.jsxs("li",{className:"text-bambu-gray",children:["...and ",t.differences.length-5," more"]})]})]}),t.success_correlation.has_both_outcomes?a.jsxs("div",{className:"p-4 bg-bambu-dark rounded-lg",children:[a.jsxs("h4",{className:"text-sm font-medium text-white mb-3 flex items-center gap-2",children:[a.jsx(Wi,{className:"w-4 h-4 text-bambu-green"}),"Success/Failure Analysis"]}),a.jsxs("div",{className:"flex items-center gap-4 text-sm mb-3",children:[a.jsxs("span",{className:"text-bambu-green",children:[t.success_correlation.successful_count," successful"]}),a.jsxs("span",{className:"text-red-400",children:[t.success_correlation.failed_count," failed"]})]}),t.success_correlation.insights&&t.success_correlation.insights.length>0?a.jsx("div",{className:"space-y-2",children:t.success_correlation.insights.map(e=>a.jsxs("div",{className:"text-sm p-2 bg-bambu-dark-secondary rounded",children:[a.jsxs("span",{className:"text-white font-medium",children:[e.label,":"]})," ",a.jsx("span",{className:"text-white/80",children:e.insight})]},e.field))}):a.jsx("p",{className:"text-sm text-bambu-gray",children:"No clear correlations found between settings and outcomes."})]}):a.jsx("div",{className:"p-4 bg-bambu-dark rounded-lg text-sm text-bambu-gray",children:a.jsx("p",{children:t.success_correlation.message||"Need both successful and failed prints for correlation analysis."})})]})}function gqe(t){return t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:`${(t/(1024*1024)).toFixed(1)} MB`}function xqe(t){const e=new Date(t),r=new Date().getTime()-e.getTime(),i=Math.floor(r/6e4);if(i<1)return"Just now";if(i<60)return`${i}m ago`;const s=Math.floor(i/60);return s<24?`${s}h ago`:`${Math.floor(s/24)}d ago`}function bqe({upload:t,projects:e,onArchive:n,onDiscard:r,isArchiving:i,isDiscarding:s}){const[o,l]=_.useState(!1),[c,u]=_.useState(t.tags||""),[d,h]=_.useState(t.notes||""),[p,m]=_.useState(t.project_id),[x,y]=_.useState(!1);return a.jsx(St,{children:a.jsxs(Nt,{className:"py-3",children:[a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{className:"flex items-center gap-3",children:[a.jsx(Hf,{className:"w-8 h-8 text-bambu-green flex-shrink-0"}),a.jsxs("div",{children:[a.jsx("p",{className:"text-white font-medium",children:t.filename}),a.jsxs("div",{className:"flex items-center gap-2 text-xs text-bambu-gray",children:[a.jsx("span",{children:gqe(t.file_size)}),a.jsx("span",{children:"·"}),a.jsxs("span",{className:"flex items-center gap-1",children:[a.jsx(tr,{className:"w-3 h-3"}),xqe(t.uploaded_at)]}),t.source_ip&&a.jsxs(a.Fragment,{children:[a.jsx("span",{children:"·"}),a.jsxs("span",{children:["from ",t.source_ip]})]})]})]})]}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("button",{onClick:()=>l(!o),className:"p-1 text-bambu-gray hover:text-white transition-colors",children:o?a.jsx(yh,{className:"w-5 h-5"}):a.jsx(Kr,{className:"w-5 h-5"})}),a.jsx(Te,{variant:"primary",size:"sm",onClick:()=>n(t.id,{tags:c,notes:d,project_id:p||void 0}),disabled:i,children:i?a.jsx(pt,{className:"w-4 h-4 animate-spin"}):a.jsxs(a.Fragment,{children:[a.jsx(go,{className:"w-4 h-4"}),"Archive"]})}),a.jsx(Te,{variant:"secondary",size:"sm",onClick:()=>y(!0),disabled:s,children:s?a.jsx(pt,{className:"w-4 h-4 animate-spin"}):a.jsx(an,{className:"w-4 h-4 text-red-400"})})]})]}),x&&a.jsx(Zn,{title:"Discard Upload",message:`Are you sure you want to discard "${t.filename}"? This cannot be undone.`,confirmText:"Discard",variant:"danger",onConfirm:()=>{r(t.id),y(!1)},onCancel:()=>y(!1)}),o&&a.jsxs("div",{className:"mt-4 pt-4 border-t border-bambu-dark-tertiary space-y-3",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Tags"}),a.jsx("input",{type:"text",value:c,onChange:v=>u(v.target.value),placeholder:"e.g., functional, prototype, gift",className:"w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-2 text-white placeholder-bambu-gray text-sm"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Notes"}),a.jsx("textarea",{value:d,onChange:v=>h(v.target.value),placeholder:"Add notes about this print...",rows:2,className:"w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-2 text-white placeholder-bambu-gray text-sm resize-none"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Project"}),a.jsxs("select",{value:p||"",onChange:v=>m(v.target.value?Number(v.target.value):null),className:"w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-2 text-white text-sm",children:[a.jsx("option",{value:"",children:"No project"}),e.map(v=>a.jsx("option",{value:v.id,children:v.name},v.id))]})]})]})]})})}function yqe(){const t=sn(),{showToast:e}=Hn(),[n,r]=_.useState(!1),[i,s]=_.useState(!1),[o,l]=_.useState(new Set),[c,u]=_.useState(new Set),{data:d,isLoading:h}=ct({queryKey:["pending-uploads"],queryFn:sg.list,refetchInterval:1e4}),{data:p}=ct({queryKey:["projects"],queryFn:()=>ce.getProjects()}),m=gt({mutationFn:({id:b,data:S})=>sg.archive(b,S),onMutate:({id:b})=>{l(S=>new Set(S).add(b))},onSettled:(b,S,{id:N})=>{l(T=>{const k=new Set(T);return k.delete(N),k})},onSuccess:b=>{t.invalidateQueries({queryKey:["pending-uploads"]}),t.invalidateQueries({queryKey:["archives"]}),e(`Archived: ${b.print_name}`)},onError:b=>{e(b.message||"Failed to archive","error")}}),x=gt({mutationFn:b=>sg.discard(b),onMutate:b=>{u(S=>new Set(S).add(b))},onSettled:(b,S,N)=>{u(T=>{const k=new Set(T);return k.delete(N),k})},onSuccess:()=>{t.invalidateQueries({queryKey:["pending-uploads"]}),e("Upload discarded")},onError:b=>{e(b.message||"Failed to discard","error")}}),y=gt({mutationFn:sg.archiveAll,onSuccess:b=>{t.invalidateQueries({queryKey:["pending-uploads"]}),t.invalidateQueries({queryKey:["archives"]}),e(`Archived ${b.archived} files${b.failed>0?`, ${b.failed} failed`:""}`)},onError:b=>{e(b.message||"Failed to archive all","error")}}),v=gt({mutationFn:sg.discardAll,onSuccess:b=>{t.invalidateQueries({queryKey:["pending-uploads"]}),e(`Discarded ${b.discarded} files`)},onError:b=>{e(b.message||"Failed to discard all","error")}});return h?a.jsx(St,{children:a.jsx(Nt,{className:"py-8 flex justify-center",children:a.jsx(pt,{className:"w-6 h-6 animate-spin text-bambu-green"})})}):!d||d.length===0?null:a.jsxs("div",{className:"mb-6",children:[a.jsxs(St,{className:"border-l-4 border-l-yellow-500",children:[a.jsx(Kn,{children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(Ba,{className:"w-5 h-5 text-yellow-500"}),a.jsxs("h2",{className:"text-lg font-semibold text-white",children:["Pending Uploads (",d.length,")"]})]}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(Te,{variant:"primary",size:"sm",onClick:()=>r(!0),disabled:y.isPending,children:y.isPending?a.jsx(pt,{className:"w-4 h-4 animate-spin"}):a.jsxs(a.Fragment,{children:[a.jsx(go,{className:"w-4 h-4"}),"Archive All"]})}),a.jsx(Te,{variant:"secondary",size:"sm",onClick:()=>s(!0),disabled:v.isPending,children:v.isPending?a.jsx(pt,{className:"w-4 h-4 animate-spin"}):a.jsxs(a.Fragment,{children:[a.jsx(an,{className:"w-4 h-4"}),"Discard All"]})})]})]})}),a.jsxs(Nt,{children:[a.jsx("p",{className:"text-sm text-bambu-gray mb-4",children:"These files were uploaded via the virtual printer. Review and archive them to add to your collection."}),a.jsx("div",{className:"space-y-3",children:d.map(b=>a.jsx(bqe,{upload:b,projects:p||[],onArchive:(S,N)=>m.mutate({id:S,data:N}),onDiscard:S=>x.mutate(S),isArchiving:o.has(b.id),isDiscarding:c.has(b.id)},b.id))})]})]}),n&&a.jsx(Zn,{title:"Archive All Uploads",message:`Are you sure you want to archive all ${d.length} pending uploads?`,confirmText:"Archive All",onConfirm:()=>{y.mutate(),r(!1)},onCancel:()=>r(!1)}),i&&a.jsx(Zn,{title:"Discard All Uploads",message:`Are you sure you want to discard all ${d.length} pending uploads? This cannot be undone.`,confirmText:"Discard All",variant:"danger",onConfirm:()=>{v.mutate(),s(!1)},onCancel:()=>s(!1)})]})}function vqe({onClose:t}){const e=sn(),{showToast:n}=Hn(),[r,i]=_.useState(""),[s,o]=_.useState(null),[l,c]=_.useState(""),[u,d]=_.useState(null),[h,p]=_.useState("count");_.useEffect(()=>{const A=D=>{D.key==="Escape"&&(s?o(null):u?d(null):t())};return window.addEventListener("keydown",A),()=>window.removeEventListener("keydown",A)},[t,s,u]);const{data:m,isLoading:x}=ct({queryKey:["tags"],queryFn:ce.getTags}),y=gt({mutationFn:({oldName:A,newName:D})=>ce.renameTag(A,D),onSuccess:(A,{oldName:D,newName:I})=>{e.invalidateQueries({queryKey:["tags"]}),e.invalidateQueries({queryKey:["archives"]}),n(`Renamed "${D}" to "${I}" in ${A.affected} archive${A.affected!==1?"s":""}`),o(null)},onError:A=>{n(A.message||"Failed to rename tag","error")}}),v=gt({mutationFn:A=>ce.deleteTag(A),onSuccess:(A,D)=>{e.invalidateQueries({queryKey:["tags"]}),e.invalidateQueries({queryKey:["archives"]}),n(`Deleted "${D}" from ${A.affected} archive${A.affected!==1?"s":""}`),d(null)},onError:A=>{n(A.message||"Failed to delete tag","error")}}),b=A=>{o(A.name),c(A.name),d(null)},S=()=>{o(null),c("")},N=()=>{if(!s||!l.trim())return;const A=l.trim();if(A===s){S();return}y.mutate({oldName:s,newName:A})},T=A=>{A.key==="Enter"?(A.preventDefault(),N()):A.key==="Escape"&&(A.preventDefault(),S())},k=A=>{d(A),o(null)},C=()=>{u&&v.mutate(u)},E=m?.filter(A=>A.name.toLowerCase().includes(r.toLowerCase())).sort((A,D)=>h==="count"&&D.count-A.count||A.name.localeCompare(D.name)),P=m?.reduce((A,D)=>A+D.count,0)||0;return a.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",children:a.jsx(St,{className:"w-full max-w-lg max-h-[80vh] flex flex-col",children:a.jsxs(Nt,{className:"p-0 flex flex-col min-h-0",children:[a.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary flex-shrink-0",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(wh,{className:"w-5 h-5 text-bambu-green"}),a.jsx("h2",{className:"text-xl font-semibold text-white",children:"Manage Tags"})]}),a.jsx("button",{onClick:t,className:"text-bambu-gray hover:text-white transition-colors",children:a.jsx(Lt,{className:"w-5 h-5"})})]}),a.jsxs("div",{className:"p-4 border-b border-bambu-dark-tertiary flex-shrink-0",children:[a.jsxs("div",{className:"flex gap-2",children:[a.jsxs("div",{className:"relative flex-1",children:[a.jsx(wa,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray"}),a.jsx("input",{type:"text",placeholder:"Search tags...",className:"w-full pl-9 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none",value:r,onChange:A=>i(A.target.value)})]}),a.jsxs("select",{className:"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",value:h,onChange:A=>p(A.target.value),children:[a.jsx("option",{value:"count",children:"Sort by Count"}),a.jsx("option",{value:"name",children:"Sort by Name"})]})]}),m&&a.jsxs("p",{className:"text-xs text-bambu-gray mt-2",children:[m.length," tag",m.length!==1?"s":""," across ",P," usage",P!==1?"s":""]})]}),a.jsx("div",{className:"flex-1 overflow-y-auto min-h-0 p-4",children:x?a.jsx("div",{className:"flex items-center justify-center py-8",children:a.jsx(pt,{className:"w-6 h-6 animate-spin text-bambu-gray"})}):E?.length?a.jsx("div",{className:"space-y-2",children:E.map(A=>a.jsx("div",{className:"flex items-center gap-2 p-2 rounded-lg bg-bambu-dark hover:bg-bambu-dark-tertiary transition-colors group",children:s===A.name?a.jsxs("div",{className:"flex-1 flex items-center gap-2",children:[a.jsx("input",{type:"text",className:"flex-1 px-2 py-1 bg-bambu-dark-tertiary border border-bambu-green rounded text-white text-sm focus:outline-none",value:l,onChange:D=>c(D.target.value),onKeyDown:T,autoFocus:!0}),a.jsx(Te,{size:"sm",variant:"primary",onClick:N,disabled:!l.trim()||y.isPending,className:"p-1.5",children:y.isPending?a.jsx(pt,{className:"w-4 h-4 animate-spin"}):a.jsx(Wi,{className:"w-4 h-4"})}),a.jsx(Te,{size:"sm",variant:"ghost",onClick:S,className:"p-1.5",children:a.jsx(Lt,{className:"w-4 h-4"})})]}):u===A.name?a.jsxs("div",{className:"flex-1 flex items-center gap-2",children:[a.jsx(Sn,{className:"w-4 h-4 text-yellow-400 flex-shrink-0"}),a.jsxs("span",{className:"text-sm text-bambu-gray-light flex-1",children:['Delete "',A.name,'" from ',A.count," archive",A.count!==1?"s":"","?"]}),a.jsx(Te,{size:"sm",variant:"danger",onClick:C,disabled:v.isPending,className:"p-1.5",children:v.isPending?a.jsx(pt,{className:"w-4 h-4 animate-spin"}):a.jsx(an,{className:"w-4 h-4"})}),a.jsx(Te,{size:"sm",variant:"ghost",onClick:()=>d(null),className:"p-1.5",children:a.jsx(Lt,{className:"w-4 h-4"})})]}):a.jsxs(a.Fragment,{children:[a.jsx(wh,{className:"w-4 h-4 text-bambu-gray flex-shrink-0"}),a.jsx("span",{className:"text-white flex-1 truncate",children:A.name}),a.jsx("span",{className:"px-2 py-0.5 rounded-full bg-bambu-dark-tertiary text-bambu-gray text-xs",children:A.count}),a.jsxs("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity",children:[a.jsx("button",{onClick:()=>b(A),className:"p-1.5 rounded hover:bg-bambu-dark text-bambu-gray hover:text-white transition-colors",title:"Rename tag",children:a.jsx(ea,{className:"w-4 h-4"})}),a.jsx("button",{onClick:()=>k(A.name),className:"p-1.5 rounded hover:bg-bambu-dark text-bambu-gray hover:text-red-400 transition-colors",title:"Delete tag",children:a.jsx(an,{className:"w-4 h-4"})})]})]})},A.name))}):a.jsx("div",{className:"text-center py-8 text-bambu-gray",children:r?"No tags match your search":"No tags found"})}),a.jsx("div",{className:"flex gap-3 p-4 border-t border-bambu-dark-tertiary flex-shrink-0",children:a.jsx(Te,{variant:"secondary",onClick:t,className:"flex-1",children:"Close"})})]})})})}function QN(t){return t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:`${(t/(1024*1024)).toFixed(1)} MB`}function r0(t){const e=Math.floor(t/3600),n=Math.floor(t%3600/60);return e>0?`${e}h ${n}m`:`${n}m`}function Pf(t){if(!t)return!1;const e=t.toLowerCase();return e.endsWith(".gcode")||e.includes(".gcode.")}function xre(t){if(!t)return;const e=t.toLowerCase();return e.endsWith(".3mf")?"3mf":e.endsWith(".stl")?"stl":e.endsWith(".gcode")||e.includes(".gcode.")?"gcode":e.split(".").pop()}function wqe({archive:t,printerName:e,isSelected:n,onSelect:r,selectionMode:i,projects:s,isHighlighted:o,timeFormat:l="system",t:c}){o&&console.log("ArchiveCard isHighlighted=true for archive:",t.id);const u=sn(),{showToast:d}=Hn(),{hasPermission:h,canModify:p}=Ci(),m=BR(),[x,y]=_.useState(!1),[v,b]=_.useState(!1),[S,N]=_.useState(!1),[T,k]=_.useState(!1),[C,E]=_.useState(!1),[P,A]=_.useState(!1),[D,I]=_.useState([]),[L,U]=_.useState(!1),[j,$]=_.useState(!1),[K,B]=_.useState(!1),[X,Y]=_.useState(!1),[ne,H]=_.useState(!1),[W,re]=_.useState(!1),[ie,pe]=_.useState(null),[me,de]=_.useState(null),[Ee,se]=_.useState(!1),Ae=_.useRef(null),Fe=_.useRef(null),{data:ge}=ct({queryKey:["archive-plates",t.id],queryFn:()=>ce.getArchivePlates(t.id),enabled:Ee,staleTime:300*1e3}),Ze=ge?.plates??[],G=ge?.is_multi_plate??!1,Q=me??0,he=gt({mutationFn:ae=>ce.uploadSource3mf(t.id,ae),onSuccess:ae=>{u.invalidateQueries({queryKey:["archives"]}),d(c("archives.toast.source3mfAttached",{filename:ae.filename}))},onError:ae=>{d(ae.message||c("archives.toast.failedUploadSource3mf"),"error")}}),q=gt({mutationFn:()=>ce.deleteSource3mf(t.id),onSuccess:()=>{u.invalidateQueries({queryKey:["archives"]}),d(c("archives.toast.source3mfRemoved"))},onError:ae=>{d(ae.message||c("archives.toast.failedRemoveSource3mf"),"error")}}),ee=gt({mutationFn:ae=>ce.uploadF3d(t.id,ae),onSuccess:ae=>{u.invalidateQueries({queryKey:["archives"]}),d(c("archives.toast.f3dAttached",{filename:ae.filename}))},onError:ae=>{d(ae.message||c("archives.toast.failedUploadF3d"),"error")}}),V=gt({mutationFn:()=>ce.deleteF3d(t.id),onSuccess:()=>{u.invalidateQueries({queryKey:["archives"]}),d(c("archives.toast.f3dRemoved"))},onError:ae=>{d(ae.message||c("archives.toast.failedRemoveF3d"),"error")}}),ye=gt({mutationFn:()=>ce.scanArchiveTimelapse(t.id),onSuccess:ae=>{ae.status==="attached"?(u.invalidateQueries({queryKey:["archives"]}),d(c("archives.toast.timelapseAttached",{filename:ae.filename}))):ae.status==="exists"?d(c("archives.toast.timelapseAlreadyAttached")):ae.status==="not_found"&&ae.available_files&&ae.available_files.length>0?(I(ae.available_files),A(!0)):d(ae.message||c("archives.toast.noMatchingTimelapse"),"warning")},onError:ae=>{d(ae.message||c("archives.toast.failedScanTimelapse"),"error")}}),je=gt({mutationFn:ae=>ce.selectArchiveTimelapse(t.id,ae),onSuccess:ae=>{u.invalidateQueries({queryKey:["archives"]}),d(c("archives.toast.timelapseAttached",{filename:ae.filename})),A(!1),I([])},onError:ae=>{d(ae.message||c("archives.toast.failedAttachTimelapse"),"error")}}),te=gt({mutationFn:()=>ce.deleteArchive(t.id),onSuccess:()=>{u.invalidateQueries({queryKey:["archives"]}),d(c("archives.toast.archiveDeleted"))},onError:()=>{d(c("archives.toast.failedDeleteArchive"),"error")}}),z=gt({mutationFn:()=>ce.toggleFavorite(t.id),onSuccess:ae=>{u.invalidateQueries({queryKey:["archives"]}),d(ae.is_favorite?c("archives.toast.addedToFavorites"):c("archives.toast.removedFromFavorites"))}}),{data:O}=ct({queryKey:["archive-folders",t.id],queryFn:()=>ce.getLibraryFoldersByArchive(t.id)}),Z=gt({mutationFn:ae=>ce.updateArchive(t.id,{project_id:ae}),onSuccess:()=>{u.invalidateQueries({queryKey:["archives"]}),u.invalidateQueries({queryKey:["projects"]}),d(c("archives.toast.projectUpdated"))},onError:()=>{d(c("archives.toast.failedUpdateProject"),"error")}}),oe=ae=>{ae.preventDefault(),pe({x:ae.clientX,y:ae.clientY})},_e=[...Pf(t.filename)?[{label:c("archives.menu.print"),icon:a.jsx(Ur,{className:"w-4 h-4"}),onClick:()=>b(!0),disabled:!p("archives","reprint",t.created_by_id),title:p("archives","reprint",t.created_by_id)?void 0:c("archives.permission.noReprint")},{label:c("archives.menu.schedule"),icon:a.jsx(ti,{className:"w-4 h-4"}),onClick:()=>Y(!0),disabled:!h("queue:create"),title:h("queue:create")?void 0:c("archives.permission.noAddToQueue")},{label:c("archives.menu.openInBambuStudio"),icon:a.jsx(Xr,{className:"w-4 h-4"}),onClick:()=>{const ae=t.print_name||t.filename||"model",Le=`${window.location.origin}${ce.getArchiveForSlicer(t.id,ae)}`;lc(Le)}}]:[{label:c("archives.menu.slice"),icon:a.jsx(Xr,{className:"w-4 h-4"}),onClick:()=>{const ae=t.print_name||t.filename||"model",Le=`${window.location.origin}${ce.getArchiveForSlicer(t.id,ae)}`;lc(Le)}}],{label:t.external_url?c("archives.menu.externalLink"):c("archives.menu.viewOnMakerWorld"),icon:a.jsx(oh,{className:"w-4 h-4"}),onClick:()=>{const ae=t.external_url||t.makerworld_url;ae&&window.open(ae,"_blank")},disabled:!t.external_url&&!t.makerworld_url},{label:"",divider:!0,onClick:()=>{}},{label:c("archives.menu.preview3d"),icon:a.jsx(Ui,{className:"w-4 h-4"}),onClick:()=>y(!0)},{label:c("archives.menu.viewTimelapse"),icon:a.jsx(sh,{className:"w-4 h-4"}),onClick:()=>E(!0),disabled:!t.timelapse_path},{label:c("archives.menu.scanForTimelapse"),icon:a.jsx(Y1,{className:"w-4 h-4"}),onClick:()=>ye.mutate(),disabled:!t.printer_id||!!t.timelapse_path||ye.isPending||!p("archives","update",t.created_by_id),title:p("archives","update",t.created_by_id)?void 0:c("archives.permission.noUpdateArchives")},{label:"",divider:!0,onClick:()=>{}},{label:t.source_3mf_path?c("archives.menu.downloadSource3mf"):c("archives.menu.uploadSource3mf"),icon:a.jsx(W1,{className:"w-4 h-4"}),onClick:()=>{t.source_3mf_path?ce.downloadSource3mf(t.id).catch(ae=>{console.error("Source 3MF download failed:",ae)}):Ae.current?.click()},disabled:!t.source_3mf_path&&!p("archives","update",t.created_by_id),title:!t.source_3mf_path&&!p("archives","update",t.created_by_id)?c("archives.permission.noUploadFiles"):void 0},...t.source_3mf_path?[{label:c("archives.menu.replaceSource3mf"),icon:a.jsx(Ba,{className:"w-4 h-4"}),onClick:()=>Ae.current?.click(),disabled:!p("archives","update",t.created_by_id),title:p("archives","update",t.created_by_id)?void 0:c("archives.permission.noUpdateArchives")},{label:c("archives.menu.removeSource3mf"),icon:a.jsx(an,{className:"w-4 h-4"}),onClick:()=>H(!0),danger:!0,disabled:!p("archives","update",t.created_by_id),title:p("archives","update",t.created_by_id)?void 0:c("archives.permission.noUpdateArchives")}]:[],{label:t.f3d_path?c("archives.menu.replaceF3d"):c("archives.menu.uploadF3d"),icon:a.jsx(Ui,{className:"w-4 h-4"}),onClick:()=>Fe.current?.click(),disabled:!p("archives","update",t.created_by_id),title:p("archives","update",t.created_by_id)?void 0:c("archives.permission.noUpdateArchives")},...t.f3d_path?[{label:c("archives.menu.downloadF3d"),icon:a.jsx(wi,{className:"w-4 h-4"}),onClick:()=>{ce.downloadF3d(t.id).catch(ae=>{console.error("F3D download failed:",ae)})}},{label:c("archives.menu.removeF3d"),icon:a.jsx(an,{className:"w-4 h-4"}),onClick:()=>re(!0),danger:!0,disabled:!p("archives","update",t.created_by_id),title:p("archives","update",t.created_by_id)?void 0:c("archives.permission.noUpdateArchives")}]:[],{label:"",divider:!0,onClick:()=>{}},{label:c("archives.menu.download"),icon:a.jsx(wi,{className:"w-4 h-4"}),onClick:()=>{ce.downloadArchive(t.id,`${t.print_name||t.filename}.3mf`).catch(ae=>{console.error("Archive download failed:",ae)})},disabled:!h("archives:read"),title:h("archives:read")?void 0:c("archives.permission.noDownload")},{label:c("archives.menu.copyDownloadLink"),icon:a.jsx(Ul,{className:"w-4 h-4"}),onClick:()=>{const ae=`${window.location.origin}${ce.getArchiveDownload(t.id)}`;navigator.clipboard.writeText(ae).then(()=>{d(c("archives.toast.linkCopied"))}).catch(()=>{d(c("archives.toast.failedCopyLink"),"error")})},disabled:!h("archives:read"),title:h("archives:read")?void 0:c("archives.permission.noCopyLink")},{label:c("archives.menu.qrCode"),icon:a.jsx(DW,{className:"w-4 h-4"}),onClick:()=>U(!0)},{label:t.photos?.length?c("archives.menu.viewPhotosCount",{count:t.photos.length}):c("archives.menu.viewPhotos"),icon:a.jsx(Bg,{className:"w-4 h-4"}),onClick:()=>$(!0),disabled:!t.photos?.length},{label:c("archives.menu.projectPage"),icon:a.jsx(fs,{className:"w-4 h-4"}),onClick:()=>B(!0)},{label:"",divider:!0,onClick:()=>{}},{label:t.is_favorite?c("archives.menu.removeFromFavorites"):c("archives.menu.addToFavorites"),icon:a.jsx(sm,{className:`w-4 h-4 ${t.is_favorite?"fill-yellow-400 text-yellow-400":""}`}),onClick:()=>z.mutate(),disabled:!p("archives","update",t.created_by_id),title:p("archives","update",t.created_by_id)?void 0:c("archives.permission.noUpdateArchives")},{label:c("archives.menu.edit"),icon:a.jsx(ea,{className:"w-4 h-4"}),onClick:()=>k(!0),disabled:!p("archives","update",t.created_by_id),title:p("archives","update",t.created_by_id)?void 0:c("archives.permission.noUpdateArchives")},...t.project_id&&t.project_name?[{label:c("archives.menu.goToProject",{name:t.project_name}),icon:a.jsx(es,{className:"w-4 h-4 text-bambu-green"}),onClick:()=>window.location.href="/projects"}]:[],{label:c("archives.menu.addToProject"),icon:a.jsx(es,{className:"w-4 h-4"}),onClick:()=>{},disabled:!p("archives","update",t.created_by_id),title:p("archives","update",t.created_by_id)?void 0:c("archives.permission.noUpdateArchives"),submenu:(()=>{const ae=[];if(t.project_id&&ae.push({label:c("archives.menu.removeFromProject"),icon:a.jsx(Lt,{className:"w-4 h-4"}),onClick:()=>Z.mutate(null),disabled:!p("archives","update",t.created_by_id)}),!s)ae.push({label:c("archives.menu.loading"),icon:a.jsx(pt,{className:"w-4 h-4 animate-spin"}),onClick:()=>{},disabled:!0});else{const Le=s.filter(Be=>Be.status==="active");Le.length===0?ae.push({label:c("archives.menu.noProjectsAvailable"),icon:a.jsx(es,{className:"w-4 h-4 opacity-50"}),onClick:()=>{},disabled:!0}):Le.forEach(Be=>{ae.push({label:Be.name,icon:a.jsx("div",{className:"w-3 h-3 rounded-full flex-shrink-0",style:{backgroundColor:Be.color||"#888"}}),onClick:()=>Z.mutate(Be.id),disabled:t.project_id===Be.id||!p("archives","update",t.created_by_id)})})}return ae})()},{label:c(n?"archives.menu.deselect":"archives.menu.select"),icon:n?a.jsx(Gs,{className:"w-4 h-4"}):a.jsx(cl,{className:"w-4 h-4"}),onClick:()=>r(t.id)},{label:"",divider:!0,onClick:()=>{}},{label:c("archives.menu.delete"),icon:a.jsx(an,{className:"w-4 h-4"}),onClick:()=>N(!0),danger:!0,disabled:!p("archives","delete",t.created_by_id),title:p("archives","delete",t.created_by_id)?void 0:c("archives.permission.noDelete")}];return a.jsxs(St,{"data-archive-id":t.id,className:`relative flex flex-col group ${n?"ring-2 ring-bambu-green":""} ${i?"cursor-pointer":""}`,style:o?{outline:"4px solid #facc15",outlineOffset:"2px"}:void 0,onContextMenu:oe,onClick:i?()=>r(t.id):void 0,children:[i&&a.jsx("button",{className:"absolute top-2 left-2 z-10 p-1 rounded bg-black/50 hover:bg-black/70 transition-colors",onClick:ae=>{ae.stopPropagation(),r(t.id)},children:n?a.jsx(Gs,{className:"w-5 h-5 text-bambu-green"}):a.jsx(cl,{className:"w-5 h-5 text-white"})}),a.jsxs("div",{className:"aspect-video bg-bambu-dark relative flex-shrink-0 overflow-hidden rounded-t-xl",onMouseEnter:()=>se(!0),onMouseLeave:()=>se(!1),children:[t.thumbnail_path?a.jsx("img",{src:me!==null&&Ze.length>0?ce.getArchivePlateThumbnail(t.id,Ze[Q]?.index??0):ce.getArchiveThumbnail(t.id),alt:t.print_name||t.filename,className:"w-full h-full object-cover"}):a.jsx("div",{className:"w-full h-full flex items-center justify-center",children:a.jsx(Lu,{className:"w-12 h-12 text-bambu-dark-tertiary"})}),G&&Ze.length>1&&a.jsxs(a.Fragment,{children:[a.jsx("button",{className:`absolute left-1 top-1/2 -translate-y-1/2 p-1 rounded-full bg-black/60 hover:bg-black/80 transition-all ${m?"opacity-100":"opacity-0 group-hover:opacity-100"}`,onClick:ae=>{ae.stopPropagation(),de(Le=>{const Be=Le??0;return Be>0?Be-1:Ze.length-1})},title:c("archives.card.previousPlate"),children:a.jsx(bh,{className:"w-4 h-4 text-white"})}),a.jsx("button",{className:`absolute right-1 top-1/2 -translate-y-1/2 p-1 rounded-full bg-black/60 hover:bg-black/80 transition-all ${m?"opacity-100":"opacity-0 group-hover:opacity-100"}`,onClick:ae=>{ae.stopPropagation(),de(Le=>{const Be=Le??0;return Bea.jsx("button",{className:`w-2 h-2 rounded-full transition-colors ${Le===Q?"bg-bambu-green":"bg-white/50 hover:bg-white/80"}`,onClick:Be=>{Be.stopPropagation(),de(Le)},title:ae.name||c("archives.card.plateNumber",{index:ae.index})},ae.index))})]}),a.jsx("button",{className:`absolute top-2 left-2 p-1.5 rounded bg-black/50 hover:bg-black/70 transition-all ${m?"opacity-100":"opacity-0 group-hover:opacity-100"} ${i?"left-10":""}`,onClick:ae=>{ae.stopPropagation();const Le=ae.currentTarget.getBoundingClientRect();pe({x:Le.left,y:Le.bottom+4})},title:c("archives.card.moreOptions"),children:a.jsx(ah,{className:"w-5 h-5 text-white"})}),a.jsx("button",{className:`absolute top-2 right-2 p-1 rounded transition-colors ${p("archives","update",t.created_by_id)?"bg-black/50 hover:bg-black/70":"bg-black/30 cursor-not-allowed"}`,onClick:ae=>{ae.stopPropagation(),p("archives","update",t.created_by_id)&&z.mutate()},disabled:!p("archives","update",t.created_by_id),title:p("archives","update",t.created_by_id)?t.is_favorite?c("archives.card.removeFromFavorites"):c("archives.card.addToFavorites"):c("archives.permission.noUpdateArchives"),children:a.jsx(sm,{className:`w-5 h-5 ${t.is_favorite?"text-yellow-400 fill-yellow-400":"text-white"} ${p("archives","update",t.created_by_id)?"":"opacity-50"}`})}),(t.status==="failed"||t.status==="aborted")&&a.jsx("div",{className:"absolute top-2 left-12 px-2 py-1 rounded text-xs bg-status-error/80 text-white",children:t.status==="aborted"?c("archives.card.cancelled"):c("archives.card.failed")}),t.duplicate_count>0&&a.jsxs("div",{className:"absolute top-2 right-2 px-2 py-1 rounded text-xs bg-purple-500/80 text-white flex items-center gap-1",title:c("archives.card.duplicateTitle"),children:[a.jsx(Ul,{className:"w-3 h-3"}),c("archives.card.duplicate")]}),t.source_3mf_path&&a.jsx("button",{className:"absolute bottom-2 left-2 p-1.5 rounded bg-black/60 hover:bg-black/80 transition-colors",onClick:ae=>{ae.stopPropagation();const Le=(t.print_name||t.filename||"source").replace(/\.gcode\.3mf$/i,"")+"_source",Be=`${window.location.origin}${ce.getSource3mfForSlicer(t.id,Le)}`;lc(Be)},title:c("archives.card.openSource3mf"),children:a.jsx(W1,{className:"w-4 h-4 text-orange-400"})}),t.f3d_path&&a.jsx("button",{className:`absolute bottom-2 ${t.source_3mf_path?"left-12":"left-2"} p-1.5 rounded bg-black/60 hover:bg-black/80 transition-colors`,onClick:ae=>{ae.stopPropagation(),ce.downloadF3d(t.id).catch(Le=>{console.error("F3D download failed:",Le)})},title:c("archives.card.downloadF3d"),children:a.jsx(Ui,{className:"w-4 h-4 text-cyan-400"})}),t.timelapse_path&&a.jsx("button",{className:"absolute bottom-2 right-2 p-1.5 rounded bg-black/60 hover:bg-black/80 transition-colors",onClick:ae=>{ae.stopPropagation(),E(!0)},title:c("archives.card.viewTimelapse"),children:a.jsx(sh,{className:"w-4 h-4 text-bambu-green"})}),t.photos&&t.photos.length>0&&a.jsxs("button",{className:`absolute bottom-2 ${t.timelapse_path?"right-12":"right-2"} p-1.5 rounded bg-black/60 hover:bg-black/80 transition-colors`,onClick:ae=>{ae.stopPropagation(),$(!0)},title:t.photos.length===1?c("archives.card.viewPhoto"):c("archives.card.viewPhotos",{count:t.photos.length}),children:[a.jsx(Bg,{className:"w-4 h-4 text-blue-400"}),t.photos.length>1&&a.jsx("span",{className:"absolute -top-1 -right-1 w-4 h-4 bg-blue-500 rounded-full text-[10px] text-white flex items-center justify-center",children:t.photos.length})]}),O&&O.length>0&&a.jsx(Fs,{to:`/files?folder=${O[0].id}`,className:"absolute bottom-2 p-1.5 rounded bg-black/60 hover:bg-black/80 transition-colors",onClick:ae=>ae.stopPropagation(),title:c("archives.card.openFolder",{name:O[0].name}),style:{left:t.source_3mf_path?t.f3d_path?"5.5rem":"3rem":t.f3d_path?"3rem":"0.5rem"},children:a.jsx(zl,{className:"w-4 h-4 text-yellow-400"})})]}),a.jsxs(Nt,{className:"p-4 flex-1 flex flex-col",children:[a.jsx("h3",{className:"font-medium text-white mb-1 truncate",children:t.print_name||t.filename}),a.jsxs("div",{className:"flex items-center gap-2 mb-3 flex-wrap",children:[a.jsx("p",{className:"text-xs text-bambu-gray",children:e}),a.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded font-medium ${Pf(t.filename)?"bg-bambu-green/20 text-bambu-green":"bg-orange-500/20 text-orange-400"}`,title:Pf(t.filename)?c("archives.card.slicedFile"):c("archives.card.sourceFile"),children:Pf(t.filename)?c("archives.card.gcode"):c("archives.card.source")}),t.project_name&&a.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded-full truncate max-w-[120px]",style:{backgroundColor:`${s?.find(ae=>ae.id===t.project_id)?.color||"#6b7280"}20`,color:s?.find(ae=>ae.id===t.project_id)?.color||"#6b7280"},title:c("archives.card.project",{name:t.project_name}),children:t.project_name})]}),a.jsxs("div",{className:"grid grid-cols-2 gap-2 text-xs mb-4 min-h-[48px]",children:[(t.print_time_seconds||t.actual_time_seconds)&&a.jsxs("div",{className:"flex items-center gap-1.5 text-bambu-gray",title:t.time_accuracy?`Estimated: ${r0(t.print_time_seconds||0)}
Actual: ${r0(t.actual_time_seconds||0)}
-Accuracy: ${t.time_accuracy.toFixed(0)}%`:t.actual_time_seconds?`Actual: ${r0(t.actual_time_seconds)}`:`Estimated: ${r0(t.print_time_seconds||0)}`,children:[a.jsx(tr,{className:"w-3 h-3"}),r0(t.actual_time_seconds||t.print_time_seconds||0),t.time_accuracy&&a.jsxs("span",{className:`text-[10px] px-1 rounded ${t.time_accuracy>=95&&t.time_accuracy<=105?"bg-bambu-green/20 text-bambu-green":t.time_accuracy>105?"bg-blue-500/20 text-blue-400":"bg-orange-500/20 text-orange-400"}`,children:[t.time_accuracy>100?"+":"",(t.time_accuracy-100).toFixed(0),"%"]})]}),t.filament_used_grams&&a.jsxs("div",{className:"flex items-center gap-1.5 text-bambu-gray",children:[a.jsx(bc,{className:"w-3 h-3"}),t.filament_used_grams.toFixed(1),"g"]}),(t.layer_height||t.total_layers)&&a.jsxs("div",{className:"flex items-center gap-1.5 text-bambu-gray",children:[a.jsx(xs,{className:"w-3 h-3"}),t.total_layers&&a.jsx("span",{children:t.total_layers===1?c("archives.card.layer",{count:t.total_layers}):c("archives.card.layers",{count:t.total_layers})}),t.total_layers&&t.layer_height&&a.jsx("span",{className:"text-bambu-gray/50",children:"·"}),t.layer_height&&a.jsxs("span",{children:[t.layer_height,"mm"]})]}),t.object_count!=null&&t.object_count>0&&a.jsxs("div",{className:"flex items-center gap-1.5 text-bambu-gray",title:t.object_count===1?c("archives.card.object",{count:t.object_count}):c("archives.card.objects",{count:t.object_count}),children:[a.jsx(Ui,{className:"w-3 h-3"}),t.object_count===1?c("archives.card.object",{count:t.object_count}):c("archives.card.objects",{count:t.object_count})]}),t.sliced_for_model&&a.jsxs("div",{className:"flex items-center gap-1.5 text-bambu-gray",title:c("archives.card.slicedFor",{model:t.sliced_for_model}),children:[a.jsx(Ur,{className:"w-3 h-3"}),t.sliced_for_model]}),t.filament_type&&a.jsxs("div",{className:"flex items-center gap-1.5 col-span-2",children:[a.jsx("span",{className:"text-bambu-gray text-xs",children:t.filament_type}),t.filament_color&&a.jsx("div",{className:"flex items-center gap-0.5 flex-wrap",children:t.filament_color.split(",").map((ae,Le)=>a.jsx("div",{className:"w-3 h-3 rounded-full border border-white/20",style:{backgroundColor:ae},title:ae},Le))})]})]}),(t.tags||t.notes)&&a.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 mb-3",children:[t.notes&&a.jsx("div",{className:"flex items-center gap-1 px-1.5 py-0.5 bg-blue-500/20 text-blue-400 rounded text-xs",title:t.notes,children:a.jsx(OW,{className:"w-3 h-3"})}),t.tags?.split(",").map((ae,Le)=>a.jsx("span",{className:"px-1.5 py-0.5 bg-bambu-dark-tertiary text-bambu-gray-light rounded text-xs",children:ae.trim()},Le))]}),a.jsx("div",{className:"flex-1"}),a.jsxs("div",{className:"flex items-center justify-between text-xs text-bambu-gray border-t border-bambu-dark-tertiary pt-3",children:[a.jsx("span",{children:Vg(t.created_at,l)}),a.jsxs("div",{className:"flex items-center gap-2",children:[t.created_by_username&&a.jsxs("span",{className:"flex items-center gap-1",title:c("archives.card.uploadedBy",{name:t.created_by_username}),children:[a.jsx(om,{className:"w-3 h-3"}),t.created_by_username]}),a.jsx("span",{children:QN(t.file_size)})]})]}),a.jsxs("div",{className:"flex gap-1 mt-3",children:[Pf(t.filename)?a.jsxs(a.Fragment,{children:[a.jsxs(Te,{variant:"primary",size:"sm",className:"flex-1 min-w-0",onClick:()=>b(!0),disabled:!p("archives","reprint",t.created_by_id),title:p("archives","reprint",t.created_by_id)?void 0:c("archives.card.noPermissionReprint"),children:[a.jsx(Ur,{className:"w-3 h-3 flex-shrink-0"}),a.jsx("span",{className:"hidden sm:inline",children:c("archives.card.reprint")})]}),a.jsxs(Te,{variant:"secondary",size:"sm",className:"flex-1 min-w-0",onClick:()=>Y(!0),disabled:!h("queue:create"),title:h("queue:create")?c("archives.card.schedulePrint"):c("archives.permission.noAddToQueue"),children:[a.jsx(ti,{className:"w-3 h-3 flex-shrink-0"}),a.jsx("span",{className:"hidden sm:inline",children:c("archives.card.schedule")})]}),a.jsx(Te,{variant:"secondary",size:"sm",className:"min-w-0 p-1 sm:p-1.5",onClick:()=>{const ae=t.print_name||t.filename||"model",Le=`${window.location.origin}${ce.getArchiveForSlicer(t.id,ae)}`;lc(Le)},title:c("archives.card.openInBambuStudio"),children:a.jsx(Xr,{className:"w-3 h-3 sm:w-4 sm:h-4"})})]}):a.jsxs(Te,{variant:"primary",size:"sm",className:"flex-1 min-w-0",onClick:()=>{const ae=t.print_name||t.filename||"model",Le=`${window.location.origin}${ce.getArchiveForSlicer(t.id,ae)}`;lc(Le)},title:c("archives.card.openInBambuStudioToSlice"),children:[a.jsx(Xr,{className:"w-3 h-3 flex-shrink-0"}),a.jsx("span",{className:"hidden sm:inline",children:c("archives.card.slice")})]}),a.jsx(Te,{variant:"secondary",size:"sm",className:"min-w-0 p-1 sm:p-1.5",onClick:()=>{const ae=t.external_url||t.makerworld_url;ae&&window.open(ae,"_blank")},disabled:!t.external_url&&!t.makerworld_url,title:t.external_url?c("archives.card.externalLink"):t.makerworld_url?c("archives.card.makerWorld",{designer:t.designer||c("archives.card.viewProject")}):c("archives.card.noExternalLink"),children:a.jsx(oh,{className:`w-3 h-3 sm:w-4 sm:h-4 ${!t.external_url&&!t.makerworld_url?"opacity-20":""}`})}),a.jsx(Te,{variant:"secondary",size:"sm",className:"min-w-0 p-1 sm:p-1.5",onClick:()=>y(!0),title:c("archives.card.preview3d"),children:a.jsx(Ui,{className:"w-3 h-3 sm:w-4 sm:h-4"})}),a.jsx(Te,{variant:"secondary",size:"sm",className:"min-w-0 p-1 sm:p-1.5",onClick:()=>{ce.downloadArchive(t.id,`${t.print_name||t.filename}.3mf`).catch(ae=>{console.error("Archive download failed:",ae)})},title:c("archives.card.download"),children:a.jsx(wi,{className:"w-3 h-3 sm:w-4 sm:h-4"})}),a.jsx(Te,{variant:"ghost",size:"sm",className:"min-w-0 p-1 sm:p-1.5",onClick:()=>k(!0),disabled:!p("archives","update",t.created_by_id),title:p("archives","update",t.created_by_id)?c("archives.card.edit"):c("archives.card.noPermissionEdit"),children:a.jsx(ea,{className:"w-3 h-3 sm:w-4 sm:h-4"})}),a.jsx(Te,{variant:"ghost",size:"sm",className:"min-w-0 p-1 sm:p-1.5",onClick:()=>N(!0),disabled:!p("archives","delete",t.created_by_id),title:p("archives","delete",t.created_by_id)?c("archives.card.delete"):c("archives.card.noPermissionDelete"),children:a.jsx(an,{className:"w-3 h-3 sm:w-4 sm:h-4 text-red-400"})})]})]}),T&&a.jsx(Cee,{archive:t,onClose:()=>k(!1)}),x&&a.jsx(bL,{archiveId:t.id,title:t.print_name||t.filename,fileType:xre(t.filename),onClose:()=>y(!1)}),v&&a.jsx(Dh,{mode:"reprint",archiveId:t.id,archiveName:t.print_name||t.filename,onClose:()=>b(!1)}),S&&a.jsx(Zn,{title:c("archives.modal.deleteArchive"),message:c("archives.modal.deleteConfirm",{name:t.print_name||t.filename}),confirmText:c("archives.modal.deleteButton"),variant:"danger",onConfirm:()=>{te.mutate(),N(!1)},onCancel:()=>N(!1)}),ne&&a.jsx(Zn,{title:c("archives.modal.removeSource3mf"),message:c("archives.modal.removeSource3mfConfirm",{name:t.print_name||t.filename}),confirmText:c("archives.modal.removeButton"),variant:"danger",onConfirm:()=>{q.mutate(),H(!1)},onCancel:()=>H(!1)}),W&&a.jsx(Zn,{title:c("archives.modal.removeF3d"),message:c("archives.modal.removeF3dConfirm",{name:t.print_name||t.filename}),confirmText:c("archives.modal.removeButton"),variant:"danger",onConfirm:()=>{V.mutate(),re(!1)},onCancel:()=>re(!1)}),ie&&a.jsx(jee,{x:ie.x,y:ie.y,items:_e,onClose:()=>pe(null)}),C&&t.timelapse_path&&a.jsx(gre,{src:ce.getArchiveTimelapse(t.id),title:c("archives.modal.timelapse",{name:t.print_name||t.filename}),downloadFilename:`${t.print_name||t.filename}_timelapse.mp4`,archiveId:t.id,onClose:()=>E(!1),onEdit:()=>{u.invalidateQueries({queryKey:["archives"]}),E(!1)}}),P&&D.length>0&&a.jsx("div",{className:"fixed inset-0 bg-black/80 flex items-center justify-center z-50 p-4",children:a.jsxs("div",{className:"bg-card-dark rounded-lg max-w-lg w-full max-h-[80vh] flex flex-col",children:[a.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-gray-700",children:[a.jsxs("div",{children:[a.jsx("h3",{className:"text-lg font-semibold text-white",children:"Select Timelapse"}),a.jsx("p",{className:"text-sm text-gray-400 mt-1",children:"No auto-match found. Select the timelapse for this print:"})]}),a.jsx("button",{onClick:()=>{A(!1),I([])},className:"text-gray-400 hover:text-white p-1",children:a.jsx(Lt,{className:"w-5 h-5"})})]}),a.jsx("div",{className:"overflow-y-auto flex-1 p-2",children:D.map(ae=>a.jsxs("button",{onClick:()=>je.mutate(ae.name),disabled:je.isPending,className:"w-full text-left p-3 rounded-lg hover:bg-gray-700 transition-colors flex items-center gap-3 disabled:opacity-50",children:[a.jsx(sh,{className:"w-8 h-8 text-bambu-green flex-shrink-0"}),a.jsxs("div",{className:"flex-1 min-w-0",children:[a.jsx("p",{className:"text-white font-medium truncate",children:ae.name}),a.jsxs("p",{className:"text-sm text-gray-400",children:[QN(ae.size),ae.mtime&&` • ${Vg(ae.mtime,l)}`]})]})]},ae.name))}),a.jsx("div",{className:"p-4 border-t border-gray-700",children:a.jsx(Te,{variant:"secondary",onClick:()=>{A(!1),I([])},className:"w-full",children:"Cancel"})})]})}),L&&a.jsx(Pee,{archiveId:t.id,archiveName:t.print_name||t.filename,onClose:()=>U(!1)}),j&&t.photos&&t.photos.length>0&&a.jsx(Dee,{archiveId:t.id,archiveName:t.print_name||t.filename,photos:t.photos,onClose:()=>$(!1),onDelete:async ae=>{try{await ce.deleteArchivePhoto(t.id,ae),u.invalidateQueries({queryKey:["archives"]}),d(c("archives.toast.photoDeleted"))}catch{d(c("archives.toast.failedDeletePhoto"),"error")}}}),K&&a.jsx(pre,{archiveId:t.id,archiveName:t.print_name||t.filename,onClose:()=>B(!1)}),X&&a.jsx(Dh,{mode:"add-to-queue",archiveId:t.id,archiveName:t.print_name||t.filename,onClose:()=>Y(!1)}),a.jsx("input",{ref:Ae,type:"file",accept:".3mf",className:"hidden",onChange:ae=>{const Le=ae.target.files?.[0];Le&&he.mutate(Le),ae.target.value=""}}),a.jsx("input",{ref:Fe,type:"file",accept:".f3d",className:"hidden",onChange:ae=>{const Le=ae.target.files?.[0];Le&&ee.mutate(Le),ae.target.value=""}})]})}function _qe({archive:t,printerName:e,isSelected:n,onSelect:r,selectionMode:i,projects:s,isHighlighted:o,t:l}){const c=sn(),{showToast:u}=Hn(),{hasPermission:d,canModify:h}=Ci(),[p,m]=_.useState(!1),[x,y]=_.useState(!1),[v,b]=_.useState(!1),[S,N]=_.useState(!1),[T,k]=_.useState(!1),[C,E]=_.useState(!1),[P,A]=_.useState(!1),[D,I]=_.useState([]),[L,U]=_.useState(!1),[j,$]=_.useState(!1),[K,B]=_.useState(!1),[X,Y]=_.useState(!1),[ne,H]=_.useState(!1),[W,re]=_.useState(null),ie=_.useRef(null),pe=_.useRef(null),me=gt({mutationFn:V=>ce.uploadSource3mf(t.id,V),onSuccess:V=>{c.invalidateQueries({queryKey:["archives"]}),u(l("archives.toast.source3mfAttached",{filename:V.filename}))},onError:V=>{u(V.message||l("archives.toast.failedUploadSource3mf"),"error")}}),de=gt({mutationFn:()=>ce.deleteSource3mf(t.id),onSuccess:()=>{c.invalidateQueries({queryKey:["archives"]}),u(l("archives.toast.source3mfRemoved"))},onError:V=>{u(V.message||l("archives.toast.failedRemoveSource3mf"),"error")}}),Ee=gt({mutationFn:V=>ce.uploadF3d(t.id,V),onSuccess:V=>{c.invalidateQueries({queryKey:["archives"]}),u(l("archives.toast.f3dAttached",{filename:V.filename}))},onError:V=>{u(V.message||l("archives.toast.failedUploadF3d"),"error")}}),se=gt({mutationFn:()=>ce.deleteF3d(t.id),onSuccess:()=>{c.invalidateQueries({queryKey:["archives"]}),u(l("archives.toast.f3dRemoved"))},onError:V=>{u(V.message||l("archives.toast.failedRemoveF3d"),"error")}}),Ae=gt({mutationFn:()=>ce.scanArchiveTimelapse(t.id),onSuccess:V=>{V.status==="attached"?(c.invalidateQueries({queryKey:["archives"]}),u(l("archives.toast.timelapseAttached",{filename:V.filename}))):V.status==="exists"?u(l("archives.toast.timelapseAlreadyAttached")):V.status==="not_found"&&V.available_files&&V.available_files.length>0?(I(V.available_files),A(!0)):u(V.message||l("archives.toast.noMatchingTimelapse"),"warning")},onError:V=>{u(V.message||l("archives.toast.failedScanTimelapse"),"error")}}),Fe=gt({mutationFn:V=>ce.selectArchiveTimelapse(t.id,V),onSuccess:V=>{c.invalidateQueries({queryKey:["archives"]}),u(l("archives.toast.timelapseAttached",{filename:V.filename})),A(!1),I([])},onError:V=>{u(V.message||l("archives.toast.failedAttachTimelapse"),"error")}}),ge=gt({mutationFn:()=>ce.deleteArchive(t.id),onSuccess:()=>{c.invalidateQueries({queryKey:["archives"]}),u(l("archives.toast.archiveDeleted"))},onError:()=>{u(l("archives.toast.failedDeleteArchive"),"error")}}),Ze=gt({mutationFn:()=>ce.toggleFavorite(t.id),onSuccess:V=>{c.invalidateQueries({queryKey:["archives"]}),u(V.is_favorite?l("archives.toast.addedToFavorites"):l("archives.toast.removedFromFavorites"))}}),{data:G}=ct({queryKey:["archive-folders",t.id],queryFn:()=>ce.getLibraryFoldersByArchive(t.id)}),Q=gt({mutationFn:V=>ce.updateArchive(t.id,{project_id:V}),onSuccess:()=>{c.invalidateQueries({queryKey:["archives"]}),c.invalidateQueries({queryKey:["projects"]}),u(l("archives.toast.projectUpdated"))},onError:()=>{u(l("archives.toast.failedUpdateProject"),"error")}}),he=V=>{V.preventDefault(),re({x:V.clientX,y:V.clientY})},ee=[...Pf(t.filename)?[{label:l("archives.menu.print"),icon:a.jsx(Ur,{className:"w-4 h-4"}),onClick:()=>b(!0),disabled:!h("archives","reprint",t.created_by_id),title:h("archives","reprint",t.created_by_id)?void 0:l("archives.permission.noReprint")},{label:l("archives.menu.schedule"),icon:a.jsx(ti,{className:"w-4 h-4"}),onClick:()=>N(!0),disabled:!d("queue:create"),title:d("queue:create")?void 0:l("archives.permission.noAddToQueue")},{label:l("archives.menu.openInBambuStudio"),icon:a.jsx(Xr,{className:"w-4 h-4"}),onClick:()=>{const V=t.print_name||t.filename||"model",ye=`${window.location.origin}${ce.getArchiveForSlicer(t.id,V)}`;lc(ye)}}]:[{label:l("archives.menu.slice"),icon:a.jsx(Xr,{className:"w-4 h-4"}),onClick:()=>{const V=t.print_name||t.filename||"model",ye=`${window.location.origin}${ce.getArchiveForSlicer(t.id,V)}`;lc(ye)}}],{label:t.external_url?l("archives.menu.externalLink"):l("archives.menu.viewOnMakerWorld"),icon:a.jsx(oh,{className:"w-4 h-4"}),onClick:()=>{const V=t.external_url||t.makerworld_url;V&&window.open(V,"_blank")},disabled:!t.external_url&&!t.makerworld_url},{label:"",divider:!0,onClick:()=>{}},{label:l("archives.menu.preview3d"),icon:a.jsx(Ui,{className:"w-4 h-4"}),onClick:()=>k(!0)},{label:l("archives.menu.viewTimelapse"),icon:a.jsx(sh,{className:"w-4 h-4"}),onClick:()=>E(!0),disabled:!t.timelapse_path},{label:l("archives.menu.scanForTimelapse"),icon:a.jsx(Y1,{className:"w-4 h-4"}),onClick:()=>Ae.mutate(),disabled:!t.printer_id||!!t.timelapse_path||Ae.isPending||!h("archives","update",t.created_by_id),title:h("archives","update",t.created_by_id)?void 0:l("archives.permission.noUpdateArchives")},{label:"",divider:!0,onClick:()=>{}},{label:t.source_3mf_path?l("archives.menu.downloadSource3mf"):l("archives.menu.uploadSource3mf"),icon:a.jsx(W1,{className:"w-4 h-4"}),onClick:()=>{t.source_3mf_path?ce.downloadSource3mf(t.id).catch(V=>{console.error("Source 3MF download failed:",V)}):ie.current?.click()},disabled:!t.source_3mf_path&&!h("archives","update",t.created_by_id),title:!t.source_3mf_path&&!h("archives","update",t.created_by_id)?l("archives.permission.noUploadFiles"):void 0},...t.source_3mf_path?[{label:l("archives.menu.replaceSource3mf"),icon:a.jsx(Ba,{className:"w-4 h-4"}),onClick:()=>ie.current?.click(),disabled:!h("archives","update",t.created_by_id),title:h("archives","update",t.created_by_id)?void 0:l("archives.permission.noUpdateArchives")},{label:l("archives.menu.removeSource3mf"),icon:a.jsx(an,{className:"w-4 h-4"}),onClick:()=>Y(!0),danger:!0,disabled:!h("archives","update",t.created_by_id),title:h("archives","update",t.created_by_id)?void 0:l("archives.permission.noUpdateArchives")}]:[],{label:t.f3d_path?l("archives.menu.replaceF3d"):l("archives.menu.uploadF3d"),icon:a.jsx(Ui,{className:"w-4 h-4"}),onClick:()=>pe.current?.click(),disabled:!h("archives","update",t.created_by_id),title:h("archives","update",t.created_by_id)?void 0:l("archives.permission.noUpdateArchives")},...t.f3d_path?[{label:l("archives.menu.downloadF3d"),icon:a.jsx(wi,{className:"w-4 h-4"}),onClick:()=>{ce.downloadF3d(t.id).catch(V=>{console.error("F3D download failed:",V)})}},{label:l("archives.menu.removeF3d"),icon:a.jsx(an,{className:"w-4 h-4"}),onClick:()=>H(!0),danger:!0,disabled:!h("archives","update",t.created_by_id),title:h("archives","update",t.created_by_id)?void 0:l("archives.permission.noUpdateArchives")}]:[],{label:"",divider:!0,onClick:()=>{}},{label:l("archives.menu.download"),icon:a.jsx(wi,{className:"w-4 h-4"}),onClick:()=>{ce.downloadArchive(t.id,`${t.print_name||t.filename}.3mf`).catch(V=>{console.error("Archive download failed:",V)})},disabled:!d("archives:read"),title:d("archives:read")?void 0:l("archives.permission.noDownload")},{label:l("archives.menu.copyDownloadLink"),icon:a.jsx(Ul,{className:"w-4 h-4"}),onClick:()=>{const V=`${window.location.origin}${ce.getArchiveDownload(t.id)}`;navigator.clipboard.writeText(V).then(()=>{u(l("archives.toast.linkCopied"))}).catch(()=>{u(l("archives.toast.failedCopyLink"),"error")})},disabled:!d("archives:read"),title:d("archives:read")?void 0:l("archives.permission.noCopyLink")},{label:l("archives.menu.qrCode"),icon:a.jsx(DW,{className:"w-4 h-4"}),onClick:()=>U(!0)},{label:t.photos?.length?l("archives.menu.viewPhotosCount",{count:t.photos.length}):l("archives.menu.viewPhotos"),icon:a.jsx(Bg,{className:"w-4 h-4"}),onClick:()=>$(!0),disabled:!t.photos?.length},{label:l("archives.menu.projectPage"),icon:a.jsx(fs,{className:"w-4 h-4"}),onClick:()=>B(!0)},{label:"",divider:!0,onClick:()=>{}},{label:t.is_favorite?l("archives.menu.removeFromFavorites"):l("archives.menu.addToFavorites"),icon:a.jsx(sm,{className:`w-4 h-4 ${t.is_favorite?"fill-yellow-400 text-yellow-400":""}`}),onClick:()=>Ze.mutate(),disabled:!h("archives","update",t.created_by_id),title:h("archives","update",t.created_by_id)?void 0:l("archives.permission.noUpdateArchives")},{label:l("archives.menu.edit"),icon:a.jsx(ea,{className:"w-4 h-4"}),onClick:()=>m(!0),disabled:!h("archives","update",t.created_by_id),title:h("archives","update",t.created_by_id)?void 0:l("archives.permission.noUpdateArchives")},...t.project_id&&t.project_name?[{label:l("archives.menu.goToProject",{name:t.project_name}),icon:a.jsx(es,{className:"w-4 h-4 text-bambu-green"}),onClick:()=>window.location.href="/projects"}]:[],{label:l("archives.menu.addToProject"),icon:a.jsx(es,{className:"w-4 h-4"}),onClick:()=>{},submenu:(()=>{const V=[];if(t.project_id&&V.push({label:l("archives.menu.removeFromProject"),icon:a.jsx(Lt,{className:"w-4 h-4"}),onClick:()=>Q.mutate(null)}),!s)V.push({label:l("archives.menu.loading"),icon:a.jsx(pt,{className:"w-4 h-4 animate-spin"}),onClick:()=>{},disabled:!0});else{const ye=s.filter(je=>je.status==="active");ye.length===0?V.push({label:l("archives.menu.noProjectsAvailable"),icon:a.jsx(es,{className:"w-4 h-4 opacity-50"}),onClick:()=>{},disabled:!0}):ye.forEach(je=>{V.push({label:je.name,icon:a.jsx("div",{className:"w-3 h-3 rounded-full flex-shrink-0",style:{backgroundColor:je.color||"#888"}}),onClick:()=>Q.mutate(je.id),disabled:t.project_id===je.id})})}return V})()},{label:l(n?"archives.menu.deselect":"archives.menu.select"),icon:n?a.jsx(Gs,{className:"w-4 h-4"}):a.jsx(cl,{className:"w-4 h-4"}),onClick:()=>r(t.id)},{label:"",divider:!0,onClick:()=>{}},{label:l("archives.menu.delete"),icon:a.jsx(an,{className:"w-4 h-4"}),onClick:()=>y(!0),danger:!0,disabled:!h("archives","delete",t.created_by_id),title:h("archives","delete",t.created_by_id)?void 0:l("archives.permission.noDelete")}];return a.jsxs(a.Fragment,{children:[a.jsxs("div",{"data-archive-id":t.id,className:`grid grid-cols-12 gap-4 px-4 py-3 items-center hover:bg-bambu-dark-tertiary/30 ${n?"bg-bambu-green/10":""}`,style:o?{outline:"4px solid #facc15",outlineOffset:"-4px"}:void 0,onContextMenu:he,children:[a.jsxs("div",{className:"col-span-1 flex items-center gap-2",children:[i&&a.jsx("button",{onClick:()=>r(t.id),children:n?a.jsx(Gs,{className:"w-4 h-4 text-bambu-green"}):a.jsx(cl,{className:"w-4 h-4 text-bambu-gray"})}),t.thumbnail_path?a.jsx("img",{src:ce.getArchiveThumbnail(t.id),alt:"",className:"w-10 h-10 object-cover rounded"}):a.jsx("div",{className:"w-10 h-10 bg-bambu-dark rounded flex items-center justify-center",children:a.jsx(Lu,{className:"w-5 h-5 text-bambu-dark-tertiary"})})]}),a.jsxs("div",{className:"col-span-4",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("p",{className:"text-white text-sm truncate",children:t.print_name||t.filename}),t.timelapse_path&&a.jsx("span",{title:l("archives.list.hasTimelapse"),children:a.jsx(sh,{className:"w-3.5 h-3.5 text-bambu-green flex-shrink-0"})}),G&&G.length>0&&a.jsx(Fs,{to:`/files?folder=${G[0].id}`,className:"flex-shrink-0",title:l("archives.card.openFolder",{name:G[0].name}),onClick:V=>V.stopPropagation(),children:a.jsx(zl,{className:"w-3.5 h-3.5 text-yellow-400"})})]}),(t.filament_type||t.sliced_for_model)&&a.jsxs("div",{className:"flex items-center gap-1.5 mt-0.5",children:[t.sliced_for_model&&a.jsxs("span",{className:"text-xs text-bambu-gray flex items-center gap-1",title:l("archives.card.slicedFor",{model:t.sliced_for_model}),children:[a.jsx(Ur,{className:"w-2.5 h-2.5"}),t.sliced_for_model]}),t.sliced_for_model&&t.filament_type&&a.jsx("span",{className:"text-bambu-gray/50",children:"·"}),t.filament_type&&a.jsx("span",{className:"text-xs text-bambu-gray",children:t.filament_type}),t.filament_color&&a.jsx("div",{className:"flex items-center gap-0.5 flex-wrap",children:t.filament_color.split(",").map((V,ye)=>a.jsx("div",{className:"w-2.5 h-2.5 rounded-full border border-white/20",style:{backgroundColor:V},title:V},ye))})]})]}),a.jsx("div",{className:"col-span-2 text-sm text-bambu-gray truncate",children:e}),a.jsxs("div",{className:"col-span-2 text-sm text-bambu-gray",children:[a.jsx("div",{children:$g(t.created_at)}),t.created_by_username&&a.jsxs("div",{className:"flex items-center gap-1 text-xs opacity-75",title:l("archives.card.uploadedBy",{name:t.created_by_username}),children:[a.jsx(om,{className:"w-3 h-3"}),t.created_by_username]})]}),a.jsx("div",{className:"col-span-1 text-sm text-bambu-gray",children:QN(t.file_size)}),a.jsxs("div",{className:"col-span-2 flex justify-end gap-1",children:[a.jsx(Te,{variant:"ghost",size:"sm",onClick:()=>{const V=t.print_name||t.filename||"model",ye=`${window.location.origin}${ce.getArchiveForSlicer(t.id,V)}`;lc(ye)},title:l("archives.card.openInBambuStudio"),children:a.jsx(Xr,{className:"w-4 h-4"})}),(t.external_url||t.makerworld_url)&&a.jsx(Te,{variant:"ghost",size:"sm",onClick:()=>window.open(t.external_url||t.makerworld_url,"_blank"),title:t.external_url?l("archives.card.externalLink"):"MakerWorld",children:a.jsx(oh,{className:"w-4 h-4"})}),a.jsx(Te,{variant:"ghost",size:"sm",onClick:()=>{ce.downloadArchive(t.id,`${t.print_name||t.filename}.3mf`).catch(V=>{console.error("Archive download failed:",V)})},title:l("archives.card.download"),children:a.jsx(wi,{className:"w-4 h-4"})}),a.jsx(Te,{variant:"ghost",size:"sm",onClick:()=>m(!0),disabled:!h("archives","update",t.created_by_id),title:h("archives","update",t.created_by_id)?l("archives.card.edit"):l("archives.card.noPermissionEdit"),children:a.jsx(ea,{className:"w-4 h-4"})}),a.jsx(Te,{variant:"ghost",size:"sm",onClick:()=>y(!0),disabled:!h("archives","delete",t.created_by_id),title:h("archives","delete",t.created_by_id)?l("archives.card.delete"):l("archives.card.noPermissionDelete"),children:a.jsx(an,{className:"w-4 h-4 text-red-400"})}),a.jsx(Te,{variant:"ghost",size:"sm",onClick:V=>{const ye=V.currentTarget.getBoundingClientRect();re({x:ye.left,y:ye.bottom+4})},title:l("archives.card.moreOptions"),children:a.jsx(ah,{className:"w-4 h-4"})})]})]}),p&&a.jsx(Cee,{archive:t,onClose:()=>m(!1)}),T&&a.jsx(bL,{archiveId:t.id,title:t.print_name||t.filename,fileType:xre(t.filename),onClose:()=>k(!1)}),v&&a.jsx(Dh,{mode:"reprint",archiveId:t.id,archiveName:t.print_name||t.filename,onClose:()=>b(!1)}),x&&a.jsx(Zn,{title:l("archives.modal.deleteArchive"),message:l("archives.modal.deleteConfirm",{name:t.print_name||t.filename}),confirmText:l("archives.modal.deleteButton"),variant:"danger",onConfirm:()=>{ge.mutate(),y(!1)},onCancel:()=>y(!1)}),X&&a.jsx(Zn,{title:l("archives.modal.removeSource3mf"),message:l("archives.modal.removeSource3mfConfirm",{name:t.print_name||t.filename}),confirmText:l("archives.modal.removeButton"),variant:"danger",onConfirm:()=>{de.mutate(),Y(!1)},onCancel:()=>Y(!1)}),ne&&a.jsx(Zn,{title:l("archives.modal.removeF3d"),message:l("archives.modal.removeF3dConfirm",{name:t.print_name||t.filename}),confirmText:l("archives.modal.removeButton"),variant:"danger",onConfirm:()=>{se.mutate(),H(!1)},onCancel:()=>H(!1)}),W&&a.jsx(jee,{x:W.x,y:W.y,items:ee,onClose:()=>re(null)}),C&&t.timelapse_path&&a.jsx(gre,{src:ce.getArchiveTimelapse(t.id),title:l("archives.modal.timelapse",{name:t.print_name||t.filename}),downloadFilename:`${t.print_name||t.filename}_timelapse.mp4`,archiveId:t.id,onClose:()=>E(!1),onEdit:()=>{c.invalidateQueries({queryKey:["archives"]}),E(!1)}}),P&&D.length>0&&a.jsx("div",{className:"fixed inset-0 bg-black/80 flex items-center justify-center z-50 p-4",children:a.jsxs("div",{className:"bg-card-dark rounded-lg max-w-lg w-full max-h-[80vh] flex flex-col",children:[a.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-gray-700",children:[a.jsxs("div",{children:[a.jsx("h3",{className:"text-lg font-semibold text-white",children:"Select Timelapse"}),a.jsx("p",{className:"text-sm text-gray-400 mt-1",children:"No auto-match found. Select the timelapse for this print:"})]}),a.jsx("button",{onClick:()=>{A(!1),I([])},className:"text-gray-400 hover:text-white p-1",children:a.jsx(Lt,{className:"w-5 h-5"})})]}),a.jsx("div",{className:"overflow-y-auto flex-1 p-2",children:D.map(V=>a.jsxs("button",{onClick:()=>Fe.mutate(V.name),disabled:Fe.isPending,className:"w-full text-left p-3 rounded-lg hover:bg-gray-700 transition-colors mb-1",children:[a.jsx("div",{className:"font-medium text-white",children:V.name}),a.jsxs("div",{className:"text-sm text-gray-400 flex gap-3",children:[a.jsx("span",{children:QN(V.size)}),V.mtime&&a.jsx("span",{children:$g(V.mtime)})]})]},V.name))})]})}),L&&a.jsx(Pee,{archiveId:t.id,archiveName:t.print_name||t.filename,onClose:()=>U(!1)}),j&&t.photos&&a.jsx(Dee,{archiveId:t.id,archiveName:t.print_name||t.filename,photos:t.photos,onClose:()=>$(!1),onDelete:async V=>{try{await ce.deleteArchivePhoto(t.id,V),c.invalidateQueries({queryKey:["archives"]}),u(l("archives.toast.photoDeleted"))}catch{u(l("archives.toast.failedDeletePhoto"),"error")}}}),K&&a.jsx(pre,{archiveId:t.id,archiveName:t.print_name||t.filename,onClose:()=>B(!1)}),S&&a.jsx(Dh,{mode:"add-to-queue",archiveId:t.id,archiveName:t.print_name||t.filename,onClose:()=>N(!1)}),a.jsx("input",{ref:ie,type:"file",accept:".3mf",className:"hidden",onChange:V=>{const ye=V.target.files?.[0];ye&&me.mutate(ye),V.target.value=""}}),a.jsx("input",{ref:pe,type:"file",accept:".f3d",className:"hidden",onChange:V=>{const ye=V.target.files?.[0];ye&&Ee.mutate(ye),V.target.value=""}})]})}const Sqe=[{id:"all",label:"All Archives",icon:a.jsx(zl,{className:"w-4 h-4"})},{id:"recent",label:"Last 24 Hours",icon:a.jsx(tr,{className:"w-4 h-4"})},{id:"this-week",label:"This Week",icon:a.jsx(ti,{className:"w-4 h-4"})},{id:"this-month",label:"This Month",icon:a.jsx(ti,{className:"w-4 h-4"})},{id:"favorites",label:"Favorites",icon:a.jsx(sm,{className:"w-4 h-4"})},{id:"failed",label:"Failed Prints",icon:a.jsx(Vi,{className:"w-4 h-4"})},{id:"duplicates",label:"Duplicates",icon:a.jsx(Ul,{className:"w-4 h-4"})}];function Nqe(){const{t}=On(),e=sn(),{showToast:n}=Hn(),{hasPermission:r,hasAnyPermission:i}=Ci(),s=_.useRef(null),[o,l]=_.useState(""),[c,u]=_.useState(()=>{const ue=localStorage.getItem("archiveFilterPrinter");return ue?Number(ue):null}),[d,h]=_.useState(()=>localStorage.getItem("archiveFilterMaterial")),[p,m]=_.useState(()=>{const ue=localStorage.getItem("archiveFilterColors");return ue?new Set(JSON.parse(ue)):new Set}),[x,y]=_.useState(()=>localStorage.getItem("archiveColorFilterMode")||"or"),[v,b]=_.useState(()=>localStorage.getItem("archiveFilterFavorites")==="true"),[S,N]=_.useState(()=>localStorage.getItem("archiveHideFailed")==="true"),[T,k]=_.useState(()=>localStorage.getItem("archiveFilterTag")),[C,E]=_.useState(()=>localStorage.getItem("archiveFilterFileType")||"all"),[P,A]=_.useState(!1),[D,I]=_.useState([]),[L,U]=_.useState(!1),[j,$]=_.useState(new Set),[K,B]=_.useState(!1),[X,Y]=_.useState(!1),[ne,H]=_.useState(!1),[W,re]=_.useState(!1),[ie,pe]=_.useState(()=>localStorage.getItem("archiveViewMode")||"grid"),[me,de]=_.useState(()=>localStorage.getItem("archiveSortBy")||"date-desc"),[Ee,se]=_.useState(()=>localStorage.getItem("archiveCollection")||"all"),[Ae,Fe]=_.useState(!1),[ge,Ze]=_.useState(!1),[G,Q]=_.useState(!1),[he,q]=_.useState(!1),[ee,V]=_.useState(null);_.useEffect(()=>{if(ee){const ue=setTimeout(()=>{const be=document.querySelector(`[data-archive-id="${ee}"]`);be&&be.scrollIntoView({behavior:"smooth",block:"center"})},100),$e=setTimeout(()=>V(null),5e3);return()=>{clearTimeout(ue),clearTimeout($e)}}},[ee]);const{data:ye,isLoading:je}=ct({queryKey:["archives",c],queryFn:()=>ce.getArchives(c||void 0)}),{data:te}=ct({queryKey:["printers"],queryFn:ce.getPrinters}),{data:z}=ct({queryKey:["projects"],queryFn:()=>ce.getProjects()}),{data:O}=ct({queryKey:["settings"],queryFn:ce.getSettings}),Z=O?.time_format||"system",oe=gt({mutationFn:async ue=>(await Promise.all(ue.map($e=>ce.deleteArchive($e))),ue.length),onSuccess:ue=>{e.invalidateQueries({queryKey:["archives"]}),$(new Set),n(`${ue} archive${ue!==1?"s":""} deleted`)},onError:()=>{n(t("archives.toast.failedDeleteArchives"),"error")}});_.useEffect(()=>{c!==null?localStorage.setItem("archiveFilterPrinter",c.toString()):localStorage.removeItem("archiveFilterPrinter")},[c]),_.useEffect(()=>{d?localStorage.setItem("archiveFilterMaterial",d):localStorage.removeItem("archiveFilterMaterial")},[d]),_.useEffect(()=>{localStorage.setItem("archiveFilterColors",JSON.stringify([...p]))},[p]),_.useEffect(()=>{localStorage.setItem("archiveColorFilterMode",x)},[x]),_.useEffect(()=>{localStorage.setItem("archiveFilterFavorites",v.toString())},[v]),_.useEffect(()=>{localStorage.setItem("archiveHideFailed",S.toString())},[S]),_.useEffect(()=>{T?localStorage.setItem("archiveFilterTag",T):localStorage.removeItem("archiveFilterTag")},[T]),_.useEffect(()=>{localStorage.setItem("archiveFilterFileType",C)},[C]),_.useEffect(()=>{localStorage.setItem("archiveViewMode",ie)},[ie]),_.useEffect(()=>{localStorage.setItem("archiveSortBy",me)},[me]),_.useEffect(()=>{localStorage.setItem("archiveCollection",Ee)},[Ee]);const we=new Map(te?.map(ue=>[ue.id,ue.name])||[]),_e=[...new Set(ye?.flatMap(ue=>ue.filament_type?.split(", ")||[]).filter(Boolean)||[])].sort(),ae=[...new Set(ye?.flatMap(ue=>ue.filament_color?.split(",")||[]).filter(Boolean)||[])],Le=[...new Set(ye?.flatMap(ue=>ue.tags?.split(",").map($e=>$e.trim())||[]).filter(Boolean)||[])].sort(),Be=ye?.filter(ue=>{const $e=new Date,be=zi(ue.created_at)||new Date(0);let Je=!0;switch(Ee){case"recent":Je=$e.getTime()-be.getTime()<1440*60*1e3;break;case"this-week":Je=$e.getTime()-be.getTime()<10080*60*1e3;break;case"this-month":Je=be.getMonth()===$e.getMonth()&&be.getFullYear()===$e.getFullYear();break;case"favorites":Je=ue.is_favorite===!0;break;case"failed":Je=ue.status==="failed"||ue.status==="aborted";break;case"duplicates":Je=ue.duplicate_count>0;break}const at=(ue.print_name||ue.filename).toLowerCase().includes(o.toLowerCase()),jt=!d||ue.filament_type?.split(", ").includes(d),Dt=ue.filament_color?.split(",")||[],yn=p.size===0||(x==="or"?Dt.some(Gn=>p.has(Gn)):[...p].every(Gn=>Dt.includes(Gn))),cn=Ee==="favorites"||!v||ue.is_favorite,rr=Ee==="failed"||!S||ue.status!=="failed"&&ue.status!=="aborted",Vn=ue.tags?.split(",").map(Gn=>Gn.trim())||[],Jn=!T||Vn.includes(T),xn=Pf(ue.filename);return Je&&at&&jt&&yn&&cn&&rr&&Jn&&(C==="all"||C==="gcode"&&xn||C==="source"&&!xn)}).sort((ue,$e)=>{switch(me){case"date-desc":return(zi($e.created_at)?.getTime()||0)-(zi(ue.created_at)?.getTime()||0);case"date-asc":return(zi(ue.created_at)?.getTime()||0)-(zi($e.created_at)?.getTime()||0);case"name-asc":return(ue.print_name||ue.filename).localeCompare($e.print_name||$e.filename);case"name-desc":return($e.print_name||$e.filename).localeCompare(ue.print_name||ue.filename);case"size-desc":return $e.file_size-ue.file_size;case"size-asc":return ue.file_size-$e.file_size;default:return 0}}),Ve=K||j.size>0,He=ue=>{$($e=>{const be=new Set($e);return be.has(ue)?be.delete(ue):be.add(ue),be})},xe=()=>{Be&&$(new Set(Be.map(ue=>ue.id)))},Pe=()=>{$(new Set),B(!1)},Ie=ue=>{m($e=>{const be=new Set($e);return be.has(ue)?be.delete(ue):be.add(ue),be})},Se=()=>{m(new Set)},Ke=()=>{l(""),u(null),h(null),b(!1),N(!1),k(null),E("all")},Me=o||c||d||v||S||T||C!=="all",it=_.useCallback(ue=>{ue.preventDefault(),ue.dataTransfer.types.includes("Files")&&U(!0)},[]),ke=_.useCallback(ue=>{ue.preventDefault(),ue.currentTarget===ue.target&&U(!1)},[]),Xe=_.useCallback(ue=>{ue.preventDefault(),U(!1);const $e=Array.from(ue.dataTransfer.files).filter(be=>be.name.endsWith(".3mf"));$e.length>0?(I($e),A(!0)):ue.dataTransfer.files.length>0&&n(t("archives.page.only3mfSupported"),"warning")},[n,t]),ze=_.useCallback(ue=>{const $e=ue.target;if($e.tagName==="INPUT"||$e.tagName==="TEXTAREA"||$e.isContentEditable){ue.key==="Escape"&&$e.blur();return}switch(ue.key){case"/":ue.preventDefault(),s.current?.focus();break;case"u":case"U":!ue.metaKey&&!ue.ctrlKey&&(ue.preventDefault(),A(!0));break;case"Escape":Ve&&Pe();break}},[Ve]);return _.useEffect(()=>(document.addEventListener("keydown",ze),()=>document.removeEventListener("keydown",ze)),[ze]),a.jsxs("div",{className:"p-4 md:p-8 relative min-h-full",onDragOver:it,onDragLeave:ke,onDrop:Xe,children:[L&&a.jsx("div",{className:"fixed inset-0 z-50 bg-bambu-dark/90 flex items-center justify-center pointer-events-none",children:a.jsxs("div",{className:"border-4 border-dashed border-bambu-green rounded-xl p-12 text-center",children:[a.jsx(Ba,{className:"w-16 h-16 mx-auto mb-4 text-bambu-green"}),a.jsx("p",{className:"text-2xl font-semibold text-white mb-2",children:"Drop .3mf files here"}),a.jsx("p",{className:"text-bambu-gray",children:t("archives.releaseToUpload")})]})}),Ve&&a.jsxs("div",{className:"fixed bottom-6 left-1/2 -translate-x-1/2 z-40 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl px-4 py-3 flex items-center gap-4",children:[a.jsxs(Te,{variant:"secondary",size:"sm",onClick:Pe,children:[a.jsx(Lt,{className:"w-4 h-4"}),"Close"]}),a.jsx("div",{className:"w-px h-6 bg-bambu-dark-tertiary"}),a.jsxs("span",{className:"text-white font-medium",children:[j.size," selected"]}),a.jsx("div",{className:"w-px h-6 bg-bambu-dark-tertiary"}),a.jsx(Te,{variant:"secondary",size:"sm",onClick:xe,children:"Select All"}),a.jsx("div",{className:"w-px h-6 bg-bambu-dark-tertiary"}),a.jsxs(Te,{variant:"secondary",size:"sm",onClick:()=>H(!0),disabled:!i("archives:update_own","archives:update_all"),title:i("archives:update_own","archives:update_all")?void 0:t("archives.permission.noUpdateArchives"),children:[a.jsx(wh,{className:"w-4 h-4"}),"Tags"]}),a.jsxs(Te,{variant:"secondary",size:"sm",onClick:()=>re(!0),disabled:!i("archives:update_own","archives:update_all"),title:i("archives:update_own","archives:update_all")?void 0:t("archives.permission.noUpdateArchives"),children:[a.jsx(es,{className:"w-4 h-4"}),"Project"]}),a.jsxs(Te,{variant:"secondary",size:"sm",disabled:!i("archives:update_own","archives:update_all"),title:i("archives:update_own","archives:update_all")?void 0:t("archives.permission.noUpdateArchives"),onClick:()=>{const ue=Array.from(j);Promise.all(ue.map($e=>ce.toggleFavorite($e))).then(()=>{e.invalidateQueries({queryKey:["archives"]}),n(`Toggled favorites for ${ue.length} archive${ue.length!==1?"s":""}`)}).catch(()=>{n(t("archives.toast.failedUpdateFavorites"),"error")})},children:[a.jsx(sm,{className:"w-4 h-4"}),"Favorite"]}),a.jsxs(Te,{size:"sm",className:"bg-red-500 hover:bg-red-600",onClick:()=>Y(!0),disabled:!i("archives:delete_own","archives:delete_all"),title:i("archives:delete_own","archives:delete_all")?void 0:t("archives.permission.noDelete"),children:[a.jsx(an,{className:"w-4 h-4"}),"Delete"]})]}),a.jsxs("div",{className:"flex items-center justify-between mb-8",children:[a.jsxs("div",{children:[a.jsxs("div",{className:"flex items-center gap-3",children:[a.jsx("h1",{className:"text-2xl font-bold text-white",children:"Archives"}),a.jsx("select",{className:"px-3 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray-light text-sm focus:border-bambu-green focus:outline-none",value:Ee,onChange:ue=>se(ue.target.value),children:Sqe.map(ue=>a.jsx("option",{value:ue.id,children:ue.label},ue.id))})]}),a.jsxs("p",{className:"text-bambu-gray",children:[Be?.length||0," of ",ye?.length||0," prints"]})]}),a.jsxs("div",{className:"flex items-center gap-3",children:[a.jsxs("div",{className:"relative",children:[a.jsxs(Te,{variant:"secondary",onClick:()=>Fe(!Ae),disabled:ge,children:[ge?a.jsx(pt,{className:"w-4 h-4 animate-spin"}):a.jsx(K1,{className:"w-4 h-4"}),"Export"]}),Ae&&a.jsxs("div",{className:"absolute right-0 top-full mt-1 w-48 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl z-20",children:[a.jsxs("button",{className:"w-full px-4 py-2 text-left text-white hover:bg-bambu-dark-tertiary transition-colors flex items-center gap-2 rounded-t-lg",onClick:async()=>{Fe(!1),Ze(!0);try{const{blob:ue,filename:$e}=await ce.exportArchives({format:"csv",printerId:c||void 0,status:Ee==="failed"?"failed":void 0,search:o||void 0}),be=URL.createObjectURL(ue),Je=document.createElement("a");Je.href=be,Je.download=$e,Je.click(),URL.revokeObjectURL(be),n(t("archives.toast.exportDownloaded"))}catch{n(t("archives.toast.exportFailed"),"error")}finally{Ze(!1)}},children:[a.jsx(fs,{className:"w-4 h-4"}),"Export as CSV"]}),a.jsxs("button",{className:"w-full px-4 py-2 text-left text-white hover:bg-bambu-dark-tertiary transition-colors flex items-center gap-2 rounded-b-lg",onClick:async()=>{Fe(!1),Ze(!0);try{const{blob:ue,filename:$e}=await ce.exportArchives({format:"xlsx",printerId:c||void 0,status:Ee==="failed"?"failed":void 0,search:o||void 0}),be=URL.createObjectURL(ue),Je=document.createElement("a");Je.href=be,Je.download=$e,Je.click(),URL.revokeObjectURL(be),n(t("archives.toast.exportDownloaded"))}catch{n(t("archives.toast.exportFailed"),"error")}finally{Ze(!1)}},children:[a.jsx(K1,{className:"w-4 h-4"}),"Export as Excel"]})]})]}),j.size>=2&&j.size<=5&&a.jsxs(Te,{variant:"secondary",onClick:()=>Q(!0),children:[a.jsx(Ng,{className:"w-4 h-4"}),"Compare (",j.size,")"]}),!Ve&&a.jsxs(Te,{variant:"secondary",onClick:()=>B(!0),children:[a.jsx(Gs,{className:"w-4 h-4"}),"Select"]}),a.jsxs(Te,{onClick:()=>A(!0),disabled:!r("archives:create"),title:r("archives:create")?void 0:t("archives.permission.noCreate"),children:[a.jsx(Ba,{className:"w-4 h-4"}),"Upload 3MF"]})]})]}),a.jsx(St,{className:"mb-6",children:a.jsxs(Nt,{className:"py-4",children:[a.jsxs("div",{className:"flex flex-col md:flex-row gap-3 md:gap-4 md:items-center md:flex-wrap",children:[a.jsxs("div",{className:"w-full md:flex-1 relative md:min-w-[200px]",children:[a.jsx(wa,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray"}),a.jsx("input",{ref:s,type:"text",placeholder:t("archives.searchPlaceholder"),className:"w-full pl-10 pr-4 py-3 md:py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",value:o,onChange:ue=>l(ue.target.value)})]}),a.jsxs("div",{className:"flex gap-2 md:gap-4 overflow-x-auto pb-1 md:pb-0 -mx-4 px-4 md:mx-0 md:px-0 md:flex-wrap scrollbar-hide",children:[a.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[a.jsx(hM,{className:"w-4 h-4 text-bambu-gray hidden md:block"}),a.jsxs("select",{className:"px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",value:c||"",onChange:ue=>u(ue.target.value?Number(ue.target.value):null),children:[a.jsx("option",{value:"",children:"All Printers"}),te?.map(ue=>a.jsx("option",{value:ue.id,children:ue.name},ue.id))]})]}),a.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[a.jsx(bc,{className:"w-4 h-4 text-bambu-gray hidden md:block"}),a.jsxs("select",{className:"px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",value:d||"",onChange:ue=>h(ue.target.value||null),children:[a.jsx("option",{value:"",children:"All Materials"}),_e.map(ue=>a.jsx("option",{value:ue,children:ue},ue))]})]}),a.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[a.jsx(W1,{className:"w-4 h-4 text-bambu-gray hidden md:block"}),a.jsxs("select",{className:"px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",value:C,onChange:ue=>E(ue.target.value),children:[a.jsx("option",{value:"all",children:"All Files"}),a.jsx("option",{value:"gcode",children:"Sliced (GCODE)"}),a.jsx("option",{value:"source",children:"Source Only"})]})]}),a.jsxs("button",{onClick:()=>b(!v),className:`flex items-center gap-2 px-3 py-2 rounded-lg border transition-colors flex-shrink-0 ${v?"bg-yellow-500/20 border-yellow-500 text-yellow-400":"bg-bambu-dark border-bambu-dark-tertiary text-bambu-gray hover:text-white"}`,title:t(v?"archives.showAll":"archives.showFavoritesOnly"),children:[a.jsx(sm,{className:`w-4 h-4 ${v?"fill-yellow-400":""}`}),a.jsx("span",{className:"text-sm hidden md:inline",children:"Favorites"})]}),a.jsxs("button",{onClick:()=>N(!S),className:`flex items-center gap-2 px-3 py-2 rounded-lg border transition-colors flex-shrink-0 ${S?"bg-red-500/20 border-red-500 text-red-400":"bg-bambu-dark border-bambu-dark-tertiary text-bambu-gray hover:text-white"}`,title:t(S?"archives.showFailedPrints":"archives.hideFailedPrints"),children:[a.jsx(Vi,{className:"w-4 h-4 "}),a.jsx("span",{className:"text-sm hidden md:inline",children:"Hide Failed"})]}),Le.length>0&&a.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[a.jsx(wh,{className:"w-4 h-4 text-bambu-gray hidden md:block"}),a.jsxs("select",{className:"px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",value:T||"",onChange:ue=>k(ue.target.value||null),children:[a.jsx("option",{value:"",children:"All Tags"}),Le.map(ue=>a.jsx("option",{value:ue,children:ue},ue))]}),a.jsx("button",{onClick:()=>q(!0),className:"p-2 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary text-bambu-gray hover:text-white hover:border-bambu-green transition-colors",title:t("archives.manageTags"),children:a.jsx(yM,{className:"w-4 h-4"})})]}),a.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[a.jsx(_W,{className:"w-4 h-4 text-bambu-gray hidden md:block"}),a.jsxs("select",{className:"px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",value:me,onChange:ue=>de(ue.target.value),children:[a.jsx("option",{value:"date-desc",children:t("archives.sortNewest")}),a.jsx("option",{value:"date-asc",children:t("archives.sortOldest")}),a.jsxs("option",{value:"name-asc",children:[t("archives.sortName")," A-Z"]}),a.jsxs("option",{value:"name-desc",children:[t("archives.sortName")," Z-A"]}),a.jsx("option",{value:"size-desc",children:t("archives.sortLargest")}),a.jsx("option",{value:"size-asc",children:t("archives.sortSmallest")})]})]}),a.jsxs("div",{className:"flex items-center border border-bambu-dark-tertiary rounded-lg overflow-hidden flex-shrink-0",children:[a.jsx("button",{className:`p-2 ${ie==="grid"?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white"}`,onClick:()=>pe("grid"),title:t("archives.gridView"),children:a.jsx(pM,{className:"w-4 h-4"})}),a.jsx("button",{className:`p-2 ${ie==="list"?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white"}`,onClick:()=>pe("list"),title:t("archives.listView"),children:a.jsx(gM,{className:"w-4 h-4"})}),a.jsx("button",{className:`p-2 ${ie==="calendar"?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white"}`,onClick:()=>pe("calendar"),title:t("archives.calendarView"),children:a.jsx($ce,{className:"w-4 h-4"})})]})]}),Me&&a.jsxs(Te,{variant:"ghost",size:"sm",onClick:Ke,className:"text-bambu-gray hover:text-white",children:[a.jsx(Lt,{className:"w-4 h-4"}),"Reset"]})]}),ae.length>0&&a.jsxs("div",{className:"flex items-center gap-3 mt-4 pt-4 border-t border-bambu-dark-tertiary",children:[a.jsx("span",{className:"text-xs text-bambu-gray",children:"Colors:"}),p.size>1&&a.jsx("button",{onClick:()=>y(ue=>ue==="or"?"and":"or"),className:`px-2 py-0.5 text-xs rounded transition-colors ${x==="and"?"bg-bambu-green text-white":"bg-bambu-dark-tertiary text-bambu-gray hover:text-white"}`,title:x==="or"?"Match ANY selected color":"Match ALL selected colors",children:x.toUpperCase()}),a.jsx("div",{className:"flex items-center gap-1.5 flex-wrap",children:ae.map(ue=>a.jsx("button",{onClick:()=>Ie(ue),className:`w-6 h-6 rounded-full border-2 transition-all ${p.has(ue)?"border-bambu-green scale-110":"border-white/20 hover:border-white/40"}`,style:{backgroundColor:ue},title:ue},ue))}),p.size>0&&a.jsxs("button",{onClick:Se,className:"text-xs text-bambu-gray hover:text-white flex items-center gap-1",children:[a.jsx(Lt,{className:"w-3 h-3"}),"Clear"]})]})]})}),a.jsx(yqe,{}),je?a.jsx("div",{className:"text-center py-12 text-bambu-gray",children:t("archives.loadingArchives")}):Be?.length===0?a.jsx(St,{children:a.jsxs(Nt,{className:"text-center py-12",children:[a.jsx("p",{className:"text-bambu-gray",children:t(o?"archives.noArchivesSearch":"archives.noArchivesYet")}),a.jsx("p",{className:"text-sm text-bambu-gray mt-2",children:"Archives are created automatically when prints complete"})]})}):ie==="calendar"?a.jsx(St,{className:"p-6",children:a.jsx(Y8e,{archives:Be||[],onArchiveClick:ue=>{l(""),pe("grid"),V(ue.id)},highlightedArchiveId:ee})}):ie==="grid"?a.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-6",children:Be?.map(ue=>a.jsx(wqe,{archive:ue,printerName:ue.printer_id?we.get(ue.printer_id)||"Unknown":ue.sliced_for_model?`Sliced for ${ue.sliced_for_model}`:"No Printer",isSelected:j.has(ue.id),onSelect:He,selectionMode:Ve,projects:z,isHighlighted:ue.id===ee,timeFormat:Z,t},ue.id))}):ie==="list"?a.jsx(St,{children:a.jsxs("div",{className:"divide-y divide-bambu-dark-tertiary",children:[a.jsxs("div",{className:"grid grid-cols-12 gap-4 px-4 py-3 text-xs text-bambu-gray font-medium",children:[a.jsx("div",{className:"col-span-1"}),a.jsx("div",{className:"col-span-4",children:"Name"}),a.jsx("div",{className:"col-span-2",children:"Printer"}),a.jsx("div",{className:"col-span-2",children:"Date"}),a.jsx("div",{className:"col-span-1",children:"Size"}),a.jsx("div",{className:"col-span-2 text-right",children:"Actions"})]}),Be?.map(ue=>a.jsx(_qe,{archive:ue,printerName:ue.printer_id?we.get(ue.printer_id)||"Unknown":ue.sliced_for_model?`Sliced for ${ue.sliced_for_model}`:"No Printer",isSelected:j.has(ue.id),onSelect:He,selectionMode:Ve,projects:z,isHighlighted:ue.id===ee,t},ue.id))]})}):null,P&&a.jsx(B8e,{onClose:()=>{A(!1),I([])},initialFiles:D}),X&&a.jsx(Zn,{title:t("archives.modal.deleteArchives"),message:t("archives.modal.deleteArchivesConfirm",{count:j.size}),confirmText:t("archives.modal.deleteCount",{count:j.size}),variant:"danger",onConfirm:()=>{oe.mutate(Array.from(j)),Y(!1)},onCancel:()=>Y(!1)}),ne&&a.jsx(V8e,{selectedIds:Array.from(j),existingTags:Le,onClose:()=>H(!1)}),W&&a.jsx(G8e,{selectedIds:Array.from(j),onClose:()=>re(!1)}),G&&j.size>=2&&j.size<=5&&a.jsx(mqe,{archiveIds:Array.from(j),onClose:()=>{Q(!1),$(new Set),B(!1)}}),he&&a.jsx(vqe,{onClose:()=>q(!1)})]})}function Mqe(){for(var t=arguments.length,e=new Array(t),n=0;nr=>{e.forEach(i=>i(r))},e)}const z2=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u";function Ix(t){const e=Object.prototype.toString.call(t);return e==="[object Window]"||e==="[object global]"}function oF(t){return"nodeType"in t}function Xs(t){var e,n;return t?Ix(t)?t:oF(t)&&(e=(n=t.ownerDocument)==null?void 0:n.defaultView)!=null?e:window:window}function lF(t){const{Document:e}=Xs(t);return t instanceof e}function _v(t){return Ix(t)?!1:t instanceof Xs(t).HTMLElement}function bre(t){return t instanceof Xs(t).SVGElement}function Ux(t){return t?Ix(t)?t.document:oF(t)?lF(t)?t:_v(t)||bre(t)?t.ownerDocument:document:document:document}const kc=z2?_.useLayoutEffect:_.useEffect;function cF(t){const e=_.useRef(t);return kc(()=>{e.current=t}),_.useCallback(function(){for(var n=arguments.length,r=new Array(n),i=0;i{t.current=setInterval(r,i)},[]),n=_.useCallback(()=>{t.current!==null&&(clearInterval(t.current),t.current=null)},[]);return[e,n]}function Py(t,e){e===void 0&&(e=[t]);const n=_.useRef(t);return kc(()=>{n.current!==t&&(n.current=t)},e),n}function Sv(t,e){const n=_.useRef();return _.useMemo(()=>{const r=t(n.current);return n.current=r,r},[...e])}function ZN(t){const e=cF(t),n=_.useRef(null),r=_.useCallback(i=>{i!==n.current&&e?.(i,n.current),n.current=i},[]);return[n,r]}function lR(t){const e=_.useRef();return _.useEffect(()=>{e.current=t},[t]),e.current}let zj={};function Nv(t,e){return _.useMemo(()=>{if(e)return e;const n=zj[t]==null?0:zj[t]+1;return zj[t]=n,t+"-"+n},[t,e])}function yre(t){return function(e){for(var n=arguments.length,r=new Array(n>1?n-1:0),i=1;i{const l=Object.entries(o);for(const[c,u]of l){const d=s[c];d!=null&&(s[c]=d+t*u)}return s},{...e})}}const Ig=yre(1),Dy=yre(-1);function Eqe(t){return"clientX"in t&&"clientY"in t}function uF(t){if(!t)return!1;const{KeyboardEvent:e}=Xs(t.target);return e&&t instanceof e}function Tqe(t){if(!t)return!1;const{TouchEvent:e}=Xs(t.target);return e&&t instanceof e}function cR(t){if(Tqe(t)){if(t.touches&&t.touches.length){const{clientX:e,clientY:n}=t.touches[0];return{x:e,y:n}}else if(t.changedTouches&&t.changedTouches.length){const{clientX:e,clientY:n}=t.changedTouches[0];return{x:e,y:n}}}return Eqe(t)?{x:t.clientX,y:t.clientY}:null}const gx=Object.freeze({Translate:{toString(t){if(!t)return;const{x:e,y:n}=t;return"translate3d("+(e?Math.round(e):0)+"px, "+(n?Math.round(n):0)+"px, 0)"}},Scale:{toString(t){if(!t)return;const{scaleX:e,scaleY:n}=t;return"scaleX("+e+") scaleY("+n+")"}},Transform:{toString(t){if(t)return[gx.Translate.toString(t),gx.Scale.toString(t)].join(" ")}},Transition:{toString(t){let{property:e,duration:n,easing:r}=t;return e+" "+n+"ms "+r}}}),cq="a,frame,iframe,input:not([type=hidden]):not(:disabled),select:not(:disabled),textarea:not(:disabled),button:not(:disabled),*[tabindex]";function Aqe(t){return t.matches(cq)?t:t.querySelector(cq)}const Cqe={display:"none"};function jqe(t){let{id:e,value:n}=t;return ei.createElement("div",{id:e,style:Cqe},n)}function Pqe(t){let{id:e,announcement:n,ariaLiveType:r="assertive"}=t;const i={position:"fixed",top:0,left:0,width:1,height:1,margin:-1,border:0,padding:0,overflow:"hidden",clip:"rect(0 0 0 0)",clipPath:"inset(100%)",whiteSpace:"nowrap"};return ei.createElement("div",{id:e,style:i,role:"status","aria-live":r,"aria-atomic":!0},n)}function Dqe(){const[t,e]=_.useState("");return{announce:_.useCallback(r=>{r!=null&&e(r)},[]),announcement:t}}const vre=_.createContext(null);function Rqe(t){const e=_.useContext(vre);_.useEffect(()=>{if(!e)throw new Error("useDndMonitor must be used within a children of ");return e(t)},[t,e])}function Oqe(){const[t]=_.useState(()=>new Set),e=_.useCallback(r=>(t.add(r),()=>t.delete(r)),[t]);return[_.useCallback(r=>{let{type:i,event:s}=r;t.forEach(o=>{var l;return(l=o[i])==null?void 0:l.call(o,s)})},[t]),e]}const Lqe={draggable:`
+Accuracy: ${t.time_accuracy.toFixed(0)}%`:t.actual_time_seconds?`Actual: ${r0(t.actual_time_seconds)}`:`Estimated: ${r0(t.print_time_seconds||0)}`,children:[a.jsx(tr,{className:"w-3 h-3"}),r0(t.actual_time_seconds||t.print_time_seconds||0),t.time_accuracy&&a.jsxs("span",{className:`text-[10px] px-1 rounded ${t.time_accuracy>=95&&t.time_accuracy<=105?"bg-bambu-green/20 text-bambu-green":t.time_accuracy>105?"bg-blue-500/20 text-blue-400":"bg-orange-500/20 text-orange-400"}`,children:[t.time_accuracy>100?"+":"",(t.time_accuracy-100).toFixed(0),"%"]})]}),t.filament_used_grams&&a.jsxs("div",{className:"flex items-center gap-1.5 text-bambu-gray",children:[a.jsx(bc,{className:"w-3 h-3"}),t.filament_used_grams.toFixed(1),"g"]}),(t.layer_height||t.total_layers)&&a.jsxs("div",{className:"flex items-center gap-1.5 text-bambu-gray",children:[a.jsx(xs,{className:"w-3 h-3"}),t.total_layers&&a.jsx("span",{children:t.total_layers===1?c("archives.card.layer",{count:t.total_layers}):c("archives.card.layers",{count:t.total_layers})}),t.total_layers&&t.layer_height&&a.jsx("span",{className:"text-bambu-gray/50",children:"·"}),t.layer_height&&a.jsxs("span",{children:[t.layer_height,"mm"]})]}),t.object_count!=null&&t.object_count>0&&a.jsxs("div",{className:"flex items-center gap-1.5 text-bambu-gray",title:t.object_count===1?c("archives.card.object",{count:t.object_count}):c("archives.card.objects",{count:t.object_count}),children:[a.jsx(Ui,{className:"w-3 h-3"}),t.object_count===1?c("archives.card.object",{count:t.object_count}):c("archives.card.objects",{count:t.object_count})]}),t.sliced_for_model&&a.jsxs("div",{className:"flex items-center gap-1.5 text-bambu-gray",title:c("archives.card.slicedFor",{model:t.sliced_for_model}),children:[a.jsx(Ur,{className:"w-3 h-3"}),t.sliced_for_model]}),t.filament_type&&a.jsxs("div",{className:"flex items-center gap-1.5 col-span-2",children:[a.jsx("span",{className:"text-bambu-gray text-xs",children:t.filament_type}),t.filament_color&&a.jsx("div",{className:"flex items-center gap-0.5 flex-wrap",children:t.filament_color.split(",").map((ae,Le)=>a.jsx("div",{className:"w-3 h-3 rounded-full border border-white/20",style:{backgroundColor:ae},title:ae},Le))})]})]}),(t.tags||t.notes)&&a.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 mb-3",children:[t.notes&&a.jsx("div",{className:"flex items-center gap-1 px-1.5 py-0.5 bg-blue-500/20 text-blue-400 rounded text-xs",title:t.notes,children:a.jsx(OW,{className:"w-3 h-3"})}),t.tags?.split(",").map((ae,Le)=>a.jsx("span",{className:"px-1.5 py-0.5 bg-bambu-dark-tertiary text-bambu-gray-light rounded text-xs",children:ae.trim()},Le))]}),a.jsx("div",{className:"flex-1"}),a.jsxs("div",{className:"flex items-center justify-between text-xs text-bambu-gray border-t border-bambu-dark-tertiary pt-3",children:[a.jsx("span",{children:Vg(t.created_at,l)}),a.jsxs("div",{className:"flex items-center gap-2",children:[t.created_by_username&&a.jsxs("span",{className:"flex items-center gap-1",title:c("archives.card.uploadedBy",{name:t.created_by_username}),children:[a.jsx(om,{className:"w-3 h-3"}),t.created_by_username]}),a.jsx("span",{children:QN(t.file_size)})]})]}),a.jsxs("div",{className:"flex gap-1 mt-3",children:[Pf(t.filename)?a.jsxs(a.Fragment,{children:[a.jsxs(Te,{variant:"primary",size:"sm",className:"flex-1 min-w-0",onClick:()=>b(!0),disabled:!p("archives","reprint",t.created_by_id),title:p("archives","reprint",t.created_by_id)?void 0:c("archives.card.noPermissionReprint"),children:[a.jsx(Ur,{className:"w-3 h-3 flex-shrink-0"}),a.jsx("span",{className:"hidden sm:inline",children:c("archives.card.reprint")})]}),a.jsxs(Te,{variant:"secondary",size:"sm",className:"flex-1 min-w-0",onClick:()=>Y(!0),disabled:!h("queue:create"),title:h("queue:create")?c("archives.card.schedulePrint"):c("archives.permission.noAddToQueue"),children:[a.jsx(ti,{className:"w-3 h-3 flex-shrink-0"}),a.jsx("span",{className:"hidden sm:inline",children:c("archives.card.schedule")})]}),a.jsx(Te,{variant:"secondary",size:"sm",className:"min-w-0 p-1 sm:p-1.5",onClick:()=>{const ae=t.print_name||t.filename||"model",Le=`${window.location.origin}${ce.getArchiveForSlicer(t.id,ae)}`;lc(Le)},title:c("archives.card.openInBambuStudio"),children:a.jsx(Xr,{className:"w-3 h-3 sm:w-4 sm:h-4"})})]}):a.jsxs(Te,{variant:"primary",size:"sm",className:"flex-1 min-w-0",onClick:()=>{const ae=t.print_name||t.filename||"model",Le=`${window.location.origin}${ce.getArchiveForSlicer(t.id,ae)}`;lc(Le)},title:c("archives.card.openInBambuStudioToSlice"),children:[a.jsx(Xr,{className:"w-3 h-3 flex-shrink-0"}),a.jsx("span",{className:"hidden sm:inline",children:c("archives.card.slice")})]}),a.jsx(Te,{variant:"secondary",size:"sm",className:"min-w-0 p-1 sm:p-1.5",onClick:()=>{const ae=t.external_url||t.makerworld_url;ae&&window.open(ae,"_blank")},disabled:!t.external_url&&!t.makerworld_url,title:t.external_url?c("archives.card.externalLink"):t.makerworld_url?c("archives.card.makerWorld",{designer:t.designer||c("archives.card.viewProject")}):c("archives.card.noExternalLink"),children:a.jsx(oh,{className:`w-3 h-3 sm:w-4 sm:h-4 ${!t.external_url&&!t.makerworld_url?"opacity-20":""}`})}),a.jsx(Te,{variant:"secondary",size:"sm",className:"min-w-0 p-1 sm:p-1.5",onClick:()=>y(!0),title:c("archives.card.preview3d"),children:a.jsx(Ui,{className:"w-3 h-3 sm:w-4 sm:h-4"})}),a.jsx(Te,{variant:"secondary",size:"sm",className:"min-w-0 p-1 sm:p-1.5",onClick:()=>{ce.downloadArchive(t.id,`${t.print_name||t.filename}.3mf`).catch(ae=>{console.error("Archive download failed:",ae)})},title:c("archives.card.download"),children:a.jsx(wi,{className:"w-3 h-3 sm:w-4 sm:h-4"})}),a.jsx(Te,{variant:"ghost",size:"sm",className:"min-w-0 p-1 sm:p-1.5",onClick:()=>k(!0),disabled:!p("archives","update",t.created_by_id),title:p("archives","update",t.created_by_id)?c("archives.card.edit"):c("archives.card.noPermissionEdit"),children:a.jsx(ea,{className:"w-3 h-3 sm:w-4 sm:h-4"})}),a.jsx(Te,{variant:"ghost",size:"sm",className:"min-w-0 p-1 sm:p-1.5",onClick:()=>N(!0),disabled:!p("archives","delete",t.created_by_id),title:p("archives","delete",t.created_by_id)?c("archives.card.delete"):c("archives.card.noPermissionDelete"),children:a.jsx(an,{className:"w-3 h-3 sm:w-4 sm:h-4 text-red-400"})})]})]}),T&&a.jsx(Cee,{archive:t,onClose:()=>k(!1)}),x&&a.jsx(bL,{archiveId:t.id,title:t.print_name||t.filename,fileType:xre(t.filename),onClose:()=>y(!1)}),v&&a.jsx(Dh,{mode:"reprint",archiveId:t.id,archiveName:t.print_name||t.filename,onClose:()=>b(!1)}),S&&a.jsx(Zn,{title:c("archives.modal.deleteArchive"),message:c("archives.modal.deleteConfirm",{name:t.print_name||t.filename}),confirmText:c("archives.modal.deleteButton"),variant:"danger",onConfirm:()=>{te.mutate(),N(!1)},onCancel:()=>N(!1)}),ne&&a.jsx(Zn,{title:c("archives.modal.removeSource3mf"),message:c("archives.modal.removeSource3mfConfirm",{name:t.print_name||t.filename}),confirmText:c("archives.modal.removeButton"),variant:"danger",onConfirm:()=>{q.mutate(),H(!1)},onCancel:()=>H(!1)}),W&&a.jsx(Zn,{title:c("archives.modal.removeF3d"),message:c("archives.modal.removeF3dConfirm",{name:t.print_name||t.filename}),confirmText:c("archives.modal.removeButton"),variant:"danger",onConfirm:()=>{V.mutate(),re(!1)},onCancel:()=>re(!1)}),ie&&a.jsx(jee,{x:ie.x,y:ie.y,items:_e,onClose:()=>pe(null)}),C&&t.timelapse_path&&a.jsx(gre,{src:ce.getArchiveTimelapse(t.id),title:c("archives.modal.timelapse",{name:t.print_name||t.filename}),downloadFilename:`${t.print_name||t.filename}_timelapse.mp4`,archiveId:t.id,onClose:()=>E(!1),onEdit:()=>{u.invalidateQueries({queryKey:["archives"]}),E(!1)}}),P&&D.length>0&&a.jsx("div",{className:"fixed inset-0 bg-black/80 flex items-center justify-center z-50 p-4",children:a.jsxs("div",{className:"bg-card-dark rounded-lg max-w-lg w-full max-h-[80vh] flex flex-col",children:[a.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-gray-700",children:[a.jsxs("div",{children:[a.jsx("h3",{className:"text-lg font-semibold text-white",children:"Select Timelapse"}),a.jsx("p",{className:"text-sm text-gray-400 mt-1",children:"No auto-match found. Select the timelapse for this print:"})]}),a.jsx("button",{onClick:()=>{A(!1),I([])},className:"text-gray-400 hover:text-white p-1",children:a.jsx(Lt,{className:"w-5 h-5"})})]}),a.jsx("div",{className:"overflow-y-auto flex-1 p-2",children:D.map(ae=>a.jsxs("button",{onClick:()=>je.mutate(ae.name),disabled:je.isPending,className:"w-full text-left p-3 rounded-lg hover:bg-gray-700 transition-colors flex items-center gap-3 disabled:opacity-50",children:[a.jsx(sh,{className:"w-8 h-8 text-bambu-green flex-shrink-0"}),a.jsxs("div",{className:"flex-1 min-w-0",children:[a.jsx("p",{className:"text-white font-medium truncate",children:ae.name}),a.jsxs("p",{className:"text-sm text-gray-400",children:[QN(ae.size),ae.mtime&&` • ${Vg(ae.mtime,l)}`]})]})]},ae.name))}),a.jsx("div",{className:"p-4 border-t border-gray-700",children:a.jsx(Te,{variant:"secondary",onClick:()=>{A(!1),I([])},className:"w-full",children:"Cancel"})})]})}),L&&a.jsx(Pee,{archiveId:t.id,archiveName:t.print_name||t.filename,onClose:()=>U(!1)}),j&&t.photos&&t.photos.length>0&&a.jsx(Dee,{archiveId:t.id,archiveName:t.print_name||t.filename,photos:t.photos,onClose:()=>$(!1),onDelete:async ae=>{try{await ce.deleteArchivePhoto(t.id,ae),u.invalidateQueries({queryKey:["archives"]}),d(c("archives.toast.photoDeleted"))}catch{d(c("archives.toast.failedDeletePhoto"),"error")}}}),K&&a.jsx(pre,{archiveId:t.id,archiveName:t.print_name||t.filename,onClose:()=>B(!1)}),X&&a.jsx(Dh,{mode:"add-to-queue",archiveId:t.id,archiveName:t.print_name||t.filename,onClose:()=>Y(!1)}),a.jsx("input",{ref:Ae,type:"file",accept:".3mf",className:"hidden",onChange:ae=>{const Le=ae.target.files?.[0];Le&&he.mutate(Le),ae.target.value=""}}),a.jsx("input",{ref:Fe,type:"file",accept:".f3d",className:"hidden",onChange:ae=>{const Le=ae.target.files?.[0];Le&&ee.mutate(Le),ae.target.value=""}})]})}function _qe({archive:t,printerName:e,isSelected:n,onSelect:r,selectionMode:i,projects:s,isHighlighted:o,t:l}){const c=sn(),{showToast:u}=Hn(),{hasPermission:d,canModify:h}=Ci(),[p,m]=_.useState(!1),[x,y]=_.useState(!1),[v,b]=_.useState(!1),[S,N]=_.useState(!1),[T,k]=_.useState(!1),[C,E]=_.useState(!1),[P,A]=_.useState(!1),[D,I]=_.useState([]),[L,U]=_.useState(!1),[j,$]=_.useState(!1),[K,B]=_.useState(!1),[X,Y]=_.useState(!1),[ne,H]=_.useState(!1),[W,re]=_.useState(null),ie=_.useRef(null),pe=_.useRef(null),me=gt({mutationFn:V=>ce.uploadSource3mf(t.id,V),onSuccess:V=>{c.invalidateQueries({queryKey:["archives"]}),u(l("archives.toast.source3mfAttached",{filename:V.filename}))},onError:V=>{u(V.message||l("archives.toast.failedUploadSource3mf"),"error")}}),de=gt({mutationFn:()=>ce.deleteSource3mf(t.id),onSuccess:()=>{c.invalidateQueries({queryKey:["archives"]}),u(l("archives.toast.source3mfRemoved"))},onError:V=>{u(V.message||l("archives.toast.failedRemoveSource3mf"),"error")}}),Ee=gt({mutationFn:V=>ce.uploadF3d(t.id,V),onSuccess:V=>{c.invalidateQueries({queryKey:["archives"]}),u(l("archives.toast.f3dAttached",{filename:V.filename}))},onError:V=>{u(V.message||l("archives.toast.failedUploadF3d"),"error")}}),se=gt({mutationFn:()=>ce.deleteF3d(t.id),onSuccess:()=>{c.invalidateQueries({queryKey:["archives"]}),u(l("archives.toast.f3dRemoved"))},onError:V=>{u(V.message||l("archives.toast.failedRemoveF3d"),"error")}}),Ae=gt({mutationFn:()=>ce.scanArchiveTimelapse(t.id),onSuccess:V=>{V.status==="attached"?(c.invalidateQueries({queryKey:["archives"]}),u(l("archives.toast.timelapseAttached",{filename:V.filename}))):V.status==="exists"?u(l("archives.toast.timelapseAlreadyAttached")):V.status==="not_found"&&V.available_files&&V.available_files.length>0?(I(V.available_files),A(!0)):u(V.message||l("archives.toast.noMatchingTimelapse"),"warning")},onError:V=>{u(V.message||l("archives.toast.failedScanTimelapse"),"error")}}),Fe=gt({mutationFn:V=>ce.selectArchiveTimelapse(t.id,V),onSuccess:V=>{c.invalidateQueries({queryKey:["archives"]}),u(l("archives.toast.timelapseAttached",{filename:V.filename})),A(!1),I([])},onError:V=>{u(V.message||l("archives.toast.failedAttachTimelapse"),"error")}}),ge=gt({mutationFn:()=>ce.deleteArchive(t.id),onSuccess:()=>{c.invalidateQueries({queryKey:["archives"]}),u(l("archives.toast.archiveDeleted"))},onError:()=>{u(l("archives.toast.failedDeleteArchive"),"error")}}),Ze=gt({mutationFn:()=>ce.toggleFavorite(t.id),onSuccess:V=>{c.invalidateQueries({queryKey:["archives"]}),u(V.is_favorite?l("archives.toast.addedToFavorites"):l("archives.toast.removedFromFavorites"))}}),{data:G}=ct({queryKey:["archive-folders",t.id],queryFn:()=>ce.getLibraryFoldersByArchive(t.id)}),Q=gt({mutationFn:V=>ce.updateArchive(t.id,{project_id:V}),onSuccess:()=>{c.invalidateQueries({queryKey:["archives"]}),c.invalidateQueries({queryKey:["projects"]}),u(l("archives.toast.projectUpdated"))},onError:()=>{u(l("archives.toast.failedUpdateProject"),"error")}}),he=V=>{V.preventDefault(),re({x:V.clientX,y:V.clientY})},ee=[...Pf(t.filename)?[{label:l("archives.menu.print"),icon:a.jsx(Ur,{className:"w-4 h-4"}),onClick:()=>b(!0),disabled:!h("archives","reprint",t.created_by_id),title:h("archives","reprint",t.created_by_id)?void 0:l("archives.permission.noReprint")},{label:l("archives.menu.schedule"),icon:a.jsx(ti,{className:"w-4 h-4"}),onClick:()=>N(!0),disabled:!d("queue:create"),title:d("queue:create")?void 0:l("archives.permission.noAddToQueue")},{label:l("archives.menu.openInBambuStudio"),icon:a.jsx(Xr,{className:"w-4 h-4"}),onClick:()=>{const V=t.print_name||t.filename||"model",ye=`${window.location.origin}${ce.getArchiveForSlicer(t.id,V)}`;lc(ye)}}]:[{label:l("archives.menu.slice"),icon:a.jsx(Xr,{className:"w-4 h-4"}),onClick:()=>{const V=t.print_name||t.filename||"model",ye=`${window.location.origin}${ce.getArchiveForSlicer(t.id,V)}`;lc(ye)}}],{label:t.external_url?l("archives.menu.externalLink"):l("archives.menu.viewOnMakerWorld"),icon:a.jsx(oh,{className:"w-4 h-4"}),onClick:()=>{const V=t.external_url||t.makerworld_url;V&&window.open(V,"_blank")},disabled:!t.external_url&&!t.makerworld_url},{label:"",divider:!0,onClick:()=>{}},{label:l("archives.menu.preview3d"),icon:a.jsx(Ui,{className:"w-4 h-4"}),onClick:()=>k(!0)},{label:l("archives.menu.viewTimelapse"),icon:a.jsx(sh,{className:"w-4 h-4"}),onClick:()=>E(!0),disabled:!t.timelapse_path},{label:l("archives.menu.scanForTimelapse"),icon:a.jsx(Y1,{className:"w-4 h-4"}),onClick:()=>Ae.mutate(),disabled:!t.printer_id||!!t.timelapse_path||Ae.isPending||!h("archives","update",t.created_by_id),title:h("archives","update",t.created_by_id)?void 0:l("archives.permission.noUpdateArchives")},{label:"",divider:!0,onClick:()=>{}},{label:t.source_3mf_path?l("archives.menu.downloadSource3mf"):l("archives.menu.uploadSource3mf"),icon:a.jsx(W1,{className:"w-4 h-4"}),onClick:()=>{t.source_3mf_path?ce.downloadSource3mf(t.id).catch(V=>{console.error("Source 3MF download failed:",V)}):ie.current?.click()},disabled:!t.source_3mf_path&&!h("archives","update",t.created_by_id),title:!t.source_3mf_path&&!h("archives","update",t.created_by_id)?l("archives.permission.noUploadFiles"):void 0},...t.source_3mf_path?[{label:l("archives.menu.replaceSource3mf"),icon:a.jsx(Ba,{className:"w-4 h-4"}),onClick:()=>ie.current?.click(),disabled:!h("archives","update",t.created_by_id),title:h("archives","update",t.created_by_id)?void 0:l("archives.permission.noUpdateArchives")},{label:l("archives.menu.removeSource3mf"),icon:a.jsx(an,{className:"w-4 h-4"}),onClick:()=>Y(!0),danger:!0,disabled:!h("archives","update",t.created_by_id),title:h("archives","update",t.created_by_id)?void 0:l("archives.permission.noUpdateArchives")}]:[],{label:t.f3d_path?l("archives.menu.replaceF3d"):l("archives.menu.uploadF3d"),icon:a.jsx(Ui,{className:"w-4 h-4"}),onClick:()=>pe.current?.click(),disabled:!h("archives","update",t.created_by_id),title:h("archives","update",t.created_by_id)?void 0:l("archives.permission.noUpdateArchives")},...t.f3d_path?[{label:l("archives.menu.downloadF3d"),icon:a.jsx(wi,{className:"w-4 h-4"}),onClick:()=>{ce.downloadF3d(t.id).catch(V=>{console.error("F3D download failed:",V)})}},{label:l("archives.menu.removeF3d"),icon:a.jsx(an,{className:"w-4 h-4"}),onClick:()=>H(!0),danger:!0,disabled:!h("archives","update",t.created_by_id),title:h("archives","update",t.created_by_id)?void 0:l("archives.permission.noUpdateArchives")}]:[],{label:"",divider:!0,onClick:()=>{}},{label:l("archives.menu.download"),icon:a.jsx(wi,{className:"w-4 h-4"}),onClick:()=>{ce.downloadArchive(t.id,`${t.print_name||t.filename}.3mf`).catch(V=>{console.error("Archive download failed:",V)})},disabled:!d("archives:read"),title:d("archives:read")?void 0:l("archives.permission.noDownload")},{label:l("archives.menu.copyDownloadLink"),icon:a.jsx(Ul,{className:"w-4 h-4"}),onClick:()=>{const V=`${window.location.origin}${ce.getArchiveDownload(t.id)}`;navigator.clipboard.writeText(V).then(()=>{u(l("archives.toast.linkCopied"))}).catch(()=>{u(l("archives.toast.failedCopyLink"),"error")})},disabled:!d("archives:read"),title:d("archives:read")?void 0:l("archives.permission.noCopyLink")},{label:l("archives.menu.qrCode"),icon:a.jsx(DW,{className:"w-4 h-4"}),onClick:()=>U(!0)},{label:t.photos?.length?l("archives.menu.viewPhotosCount",{count:t.photos.length}):l("archives.menu.viewPhotos"),icon:a.jsx(Bg,{className:"w-4 h-4"}),onClick:()=>$(!0),disabled:!t.photos?.length},{label:l("archives.menu.projectPage"),icon:a.jsx(fs,{className:"w-4 h-4"}),onClick:()=>B(!0)},{label:"",divider:!0,onClick:()=>{}},{label:t.is_favorite?l("archives.menu.removeFromFavorites"):l("archives.menu.addToFavorites"),icon:a.jsx(sm,{className:`w-4 h-4 ${t.is_favorite?"fill-yellow-400 text-yellow-400":""}`}),onClick:()=>Ze.mutate(),disabled:!h("archives","update",t.created_by_id),title:h("archives","update",t.created_by_id)?void 0:l("archives.permission.noUpdateArchives")},{label:l("archives.menu.edit"),icon:a.jsx(ea,{className:"w-4 h-4"}),onClick:()=>m(!0),disabled:!h("archives","update",t.created_by_id),title:h("archives","update",t.created_by_id)?void 0:l("archives.permission.noUpdateArchives")},...t.project_id&&t.project_name?[{label:l("archives.menu.goToProject",{name:t.project_name}),icon:a.jsx(es,{className:"w-4 h-4 text-bambu-green"}),onClick:()=>window.location.href="/projects"}]:[],{label:l("archives.menu.addToProject"),icon:a.jsx(es,{className:"w-4 h-4"}),onClick:()=>{},submenu:(()=>{const V=[];if(t.project_id&&V.push({label:l("archives.menu.removeFromProject"),icon:a.jsx(Lt,{className:"w-4 h-4"}),onClick:()=>Q.mutate(null)}),!s)V.push({label:l("archives.menu.loading"),icon:a.jsx(pt,{className:"w-4 h-4 animate-spin"}),onClick:()=>{},disabled:!0});else{const ye=s.filter(je=>je.status==="active");ye.length===0?V.push({label:l("archives.menu.noProjectsAvailable"),icon:a.jsx(es,{className:"w-4 h-4 opacity-50"}),onClick:()=>{},disabled:!0}):ye.forEach(je=>{V.push({label:je.name,icon:a.jsx("div",{className:"w-3 h-3 rounded-full flex-shrink-0",style:{backgroundColor:je.color||"#888"}}),onClick:()=>Q.mutate(je.id),disabled:t.project_id===je.id})})}return V})()},{label:l(n?"archives.menu.deselect":"archives.menu.select"),icon:n?a.jsx(Gs,{className:"w-4 h-4"}):a.jsx(cl,{className:"w-4 h-4"}),onClick:()=>r(t.id)},{label:"",divider:!0,onClick:()=>{}},{label:l("archives.menu.delete"),icon:a.jsx(an,{className:"w-4 h-4"}),onClick:()=>y(!0),danger:!0,disabled:!h("archives","delete",t.created_by_id),title:h("archives","delete",t.created_by_id)?void 0:l("archives.permission.noDelete")}];return a.jsxs(a.Fragment,{children:[a.jsxs("div",{"data-archive-id":t.id,className:`grid grid-cols-12 gap-4 px-4 py-3 items-center hover:bg-bambu-dark-tertiary/30 ${n?"bg-bambu-green/10":""}`,style:o?{outline:"4px solid #facc15",outlineOffset:"-4px"}:void 0,onContextMenu:he,children:[a.jsxs("div",{className:"col-span-1 flex items-center gap-2",children:[i&&a.jsx("button",{onClick:()=>r(t.id),children:n?a.jsx(Gs,{className:"w-4 h-4 text-bambu-green"}):a.jsx(cl,{className:"w-4 h-4 text-bambu-gray"})}),t.thumbnail_path?a.jsx("img",{src:ce.getArchiveThumbnail(t.id),alt:"",className:"w-10 h-10 object-cover rounded"}):a.jsx("div",{className:"w-10 h-10 bg-bambu-dark rounded flex items-center justify-center",children:a.jsx(Lu,{className:"w-5 h-5 text-bambu-dark-tertiary"})})]}),a.jsxs("div",{className:"col-span-4",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("p",{className:"text-white text-sm truncate",children:t.print_name||t.filename}),t.timelapse_path&&a.jsx("span",{title:l("archives.list.hasTimelapse"),children:a.jsx(sh,{className:"w-3.5 h-3.5 text-bambu-green flex-shrink-0"})}),G&&G.length>0&&a.jsx(Fs,{to:`/files?folder=${G[0].id}`,className:"flex-shrink-0",title:l("archives.card.openFolder",{name:G[0].name}),onClick:V=>V.stopPropagation(),children:a.jsx(zl,{className:"w-3.5 h-3.5 text-yellow-400"})})]}),(t.filament_type||t.sliced_for_model)&&a.jsxs("div",{className:"flex items-center gap-1.5 mt-0.5",children:[t.sliced_for_model&&a.jsxs("span",{className:"text-xs text-bambu-gray flex items-center gap-1",title:l("archives.card.slicedFor",{model:t.sliced_for_model}),children:[a.jsx(Ur,{className:"w-2.5 h-2.5"}),t.sliced_for_model]}),t.sliced_for_model&&t.filament_type&&a.jsx("span",{className:"text-bambu-gray/50",children:"·"}),t.filament_type&&a.jsx("span",{className:"text-xs text-bambu-gray",children:t.filament_type}),t.filament_color&&a.jsx("div",{className:"flex items-center gap-0.5 flex-wrap",children:t.filament_color.split(",").map((V,ye)=>a.jsx("div",{className:"w-2.5 h-2.5 rounded-full border border-white/20",style:{backgroundColor:V},title:V},ye))})]})]}),a.jsx("div",{className:"col-span-2 text-sm text-bambu-gray truncate",children:e}),a.jsxs("div",{className:"col-span-2 text-sm text-bambu-gray",children:[a.jsx("div",{children:$g(t.created_at)}),t.created_by_username&&a.jsxs("div",{className:"flex items-center gap-1 text-xs opacity-75",title:l("archives.card.uploadedBy",{name:t.created_by_username}),children:[a.jsx(om,{className:"w-3 h-3"}),t.created_by_username]})]}),a.jsx("div",{className:"col-span-1 text-sm text-bambu-gray",children:QN(t.file_size)}),a.jsxs("div",{className:"col-span-2 flex justify-end gap-1",children:[a.jsx(Te,{variant:"ghost",size:"sm",onClick:()=>{const V=t.print_name||t.filename||"model",ye=`${window.location.origin}${ce.getArchiveForSlicer(t.id,V)}`;lc(ye)},title:l("archives.card.openInBambuStudio"),children:a.jsx(Xr,{className:"w-4 h-4"})}),(t.external_url||t.makerworld_url)&&a.jsx(Te,{variant:"ghost",size:"sm",onClick:()=>window.open(t.external_url||t.makerworld_url,"_blank"),title:t.external_url?l("archives.card.externalLink"):"MakerWorld",children:a.jsx(oh,{className:"w-4 h-4"})}),a.jsx(Te,{variant:"ghost",size:"sm",onClick:()=>{ce.downloadArchive(t.id,`${t.print_name||t.filename}.3mf`).catch(V=>{console.error("Archive download failed:",V)})},title:l("archives.card.download"),children:a.jsx(wi,{className:"w-4 h-4"})}),a.jsx(Te,{variant:"ghost",size:"sm",onClick:()=>m(!0),disabled:!h("archives","update",t.created_by_id),title:h("archives","update",t.created_by_id)?l("archives.card.edit"):l("archives.card.noPermissionEdit"),children:a.jsx(ea,{className:"w-4 h-4"})}),a.jsx(Te,{variant:"ghost",size:"sm",onClick:()=>y(!0),disabled:!h("archives","delete",t.created_by_id),title:h("archives","delete",t.created_by_id)?l("archives.card.delete"):l("archives.card.noPermissionDelete"),children:a.jsx(an,{className:"w-4 h-4 text-red-400"})}),a.jsx(Te,{variant:"ghost",size:"sm",onClick:V=>{const ye=V.currentTarget.getBoundingClientRect();re({x:ye.left,y:ye.bottom+4})},title:l("archives.card.moreOptions"),children:a.jsx(ah,{className:"w-4 h-4"})})]})]}),p&&a.jsx(Cee,{archive:t,onClose:()=>m(!1)}),T&&a.jsx(bL,{archiveId:t.id,title:t.print_name||t.filename,fileType:xre(t.filename),onClose:()=>k(!1)}),v&&a.jsx(Dh,{mode:"reprint",archiveId:t.id,archiveName:t.print_name||t.filename,onClose:()=>b(!1)}),x&&a.jsx(Zn,{title:l("archives.modal.deleteArchive"),message:l("archives.modal.deleteConfirm",{name:t.print_name||t.filename}),confirmText:l("archives.modal.deleteButton"),variant:"danger",onConfirm:()=>{ge.mutate(),y(!1)},onCancel:()=>y(!1)}),X&&a.jsx(Zn,{title:l("archives.modal.removeSource3mf"),message:l("archives.modal.removeSource3mfConfirm",{name:t.print_name||t.filename}),confirmText:l("archives.modal.removeButton"),variant:"danger",onConfirm:()=>{de.mutate(),Y(!1)},onCancel:()=>Y(!1)}),ne&&a.jsx(Zn,{title:l("archives.modal.removeF3d"),message:l("archives.modal.removeF3dConfirm",{name:t.print_name||t.filename}),confirmText:l("archives.modal.removeButton"),variant:"danger",onConfirm:()=>{se.mutate(),H(!1)},onCancel:()=>H(!1)}),W&&a.jsx(jee,{x:W.x,y:W.y,items:ee,onClose:()=>re(null)}),C&&t.timelapse_path&&a.jsx(gre,{src:ce.getArchiveTimelapse(t.id),title:l("archives.modal.timelapse",{name:t.print_name||t.filename}),downloadFilename:`${t.print_name||t.filename}_timelapse.mp4`,archiveId:t.id,onClose:()=>E(!1),onEdit:()=>{c.invalidateQueries({queryKey:["archives"]}),E(!1)}}),P&&D.length>0&&a.jsx("div",{className:"fixed inset-0 bg-black/80 flex items-center justify-center z-50 p-4",children:a.jsxs("div",{className:"bg-card-dark rounded-lg max-w-lg w-full max-h-[80vh] flex flex-col",children:[a.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-gray-700",children:[a.jsxs("div",{children:[a.jsx("h3",{className:"text-lg font-semibold text-white",children:"Select Timelapse"}),a.jsx("p",{className:"text-sm text-gray-400 mt-1",children:"No auto-match found. Select the timelapse for this print:"})]}),a.jsx("button",{onClick:()=>{A(!1),I([])},className:"text-gray-400 hover:text-white p-1",children:a.jsx(Lt,{className:"w-5 h-5"})})]}),a.jsx("div",{className:"overflow-y-auto flex-1 p-2",children:D.map(V=>a.jsxs("button",{onClick:()=>Fe.mutate(V.name),disabled:Fe.isPending,className:"w-full text-left p-3 rounded-lg hover:bg-gray-700 transition-colors mb-1",children:[a.jsx("div",{className:"font-medium text-white",children:V.name}),a.jsxs("div",{className:"text-sm text-gray-400 flex gap-3",children:[a.jsx("span",{children:QN(V.size)}),V.mtime&&a.jsx("span",{children:$g(V.mtime)})]})]},V.name))})]})}),L&&a.jsx(Pee,{archiveId:t.id,archiveName:t.print_name||t.filename,onClose:()=>U(!1)}),j&&t.photos&&a.jsx(Dee,{archiveId:t.id,archiveName:t.print_name||t.filename,photos:t.photos,onClose:()=>$(!1),onDelete:async V=>{try{await ce.deleteArchivePhoto(t.id,V),c.invalidateQueries({queryKey:["archives"]}),u(l("archives.toast.photoDeleted"))}catch{u(l("archives.toast.failedDeletePhoto"),"error")}}}),K&&a.jsx(pre,{archiveId:t.id,archiveName:t.print_name||t.filename,onClose:()=>B(!1)}),S&&a.jsx(Dh,{mode:"add-to-queue",archiveId:t.id,archiveName:t.print_name||t.filename,onClose:()=>N(!1)}),a.jsx("input",{ref:ie,type:"file",accept:".3mf",className:"hidden",onChange:V=>{const ye=V.target.files?.[0];ye&&me.mutate(ye),V.target.value=""}}),a.jsx("input",{ref:pe,type:"file",accept:".f3d",className:"hidden",onChange:V=>{const ye=V.target.files?.[0];ye&&Ee.mutate(ye),V.target.value=""}})]})}const Sqe=[{id:"all",label:"All Archives",icon:a.jsx(zl,{className:"w-4 h-4"})},{id:"recent",label:"Last 24 Hours",icon:a.jsx(tr,{className:"w-4 h-4"})},{id:"this-week",label:"This Week",icon:a.jsx(ti,{className:"w-4 h-4"})},{id:"this-month",label:"This Month",icon:a.jsx(ti,{className:"w-4 h-4"})},{id:"favorites",label:"Favorites",icon:a.jsx(sm,{className:"w-4 h-4"})},{id:"failed",label:"Failed Prints",icon:a.jsx(Vi,{className:"w-4 h-4"})},{id:"duplicates",label:"Duplicates",icon:a.jsx(Ul,{className:"w-4 h-4"})}];function Nqe(){const{t}=On(),e=sn(),{showToast:n}=Hn(),{hasPermission:r,hasAnyPermission:i}=Ci(),s=_.useRef(null),[o,l]=_.useState(""),[c,u]=_.useState(()=>{const ue=localStorage.getItem("archiveFilterPrinter");return ue?Number(ue):null}),[d,h]=_.useState(()=>localStorage.getItem("archiveFilterMaterial")),[p,m]=_.useState(()=>{const ue=localStorage.getItem("archiveFilterColors");return ue?new Set(JSON.parse(ue)):new Set}),[x,y]=_.useState(()=>localStorage.getItem("archiveColorFilterMode")||"or"),[v,b]=_.useState(()=>localStorage.getItem("archiveFilterFavorites")==="true"),[S,N]=_.useState(()=>localStorage.getItem("archiveHideFailed")==="true"),[T,k]=_.useState(()=>localStorage.getItem("archiveFilterTag")),[C,E]=_.useState(()=>localStorage.getItem("archiveFilterFileType")||"all"),[P,A]=_.useState(!1),[D,I]=_.useState([]),[L,U]=_.useState(!1),[j,$]=_.useState(new Set),[K,B]=_.useState(!1),[X,Y]=_.useState(!1),[ne,H]=_.useState(!1),[W,re]=_.useState(!1),[ie,pe]=_.useState(()=>localStorage.getItem("archiveViewMode")||"grid"),[me,de]=_.useState(()=>localStorage.getItem("archiveSortBy")||"date-desc"),[Ee,se]=_.useState(()=>localStorage.getItem("archiveCollection")||"all"),[Ae,Fe]=_.useState(!1),[ge,Ze]=_.useState(!1),[G,Q]=_.useState(!1),[he,q]=_.useState(!1),[ee,V]=_.useState(null);_.useEffect(()=>{if(ee){const ue=setTimeout(()=>{const be=document.querySelector(`[data-archive-id="${ee}"]`);be&&be.scrollIntoView({behavior:"smooth",block:"center"})},100),$e=setTimeout(()=>V(null),5e3);return()=>{clearTimeout(ue),clearTimeout($e)}}},[ee]);const{data:ye,isLoading:je}=ct({queryKey:["archives",c],queryFn:()=>ce.getArchives(c||void 0)}),{data:te}=ct({queryKey:["printers"],queryFn:ce.getPrinters}),{data:z}=ct({queryKey:["projects"],queryFn:()=>ce.getProjects()}),{data:O}=ct({queryKey:["settings"],queryFn:ce.getSettings}),Z=O?.time_format||"system",oe=gt({mutationFn:async ue=>(await Promise.all(ue.map($e=>ce.deleteArchive($e))),ue.length),onSuccess:ue=>{e.invalidateQueries({queryKey:["archives"]}),$(new Set),n(`${ue} archive${ue!==1?"s":""} deleted`)},onError:()=>{n(t("archives.toast.failedDeleteArchives"),"error")}});_.useEffect(()=>{c!==null?localStorage.setItem("archiveFilterPrinter",c.toString()):localStorage.removeItem("archiveFilterPrinter")},[c]),_.useEffect(()=>{d?localStorage.setItem("archiveFilterMaterial",d):localStorage.removeItem("archiveFilterMaterial")},[d]),_.useEffect(()=>{localStorage.setItem("archiveFilterColors",JSON.stringify([...p]))},[p]),_.useEffect(()=>{localStorage.setItem("archiveColorFilterMode",x)},[x]),_.useEffect(()=>{localStorage.setItem("archiveFilterFavorites",v.toString())},[v]),_.useEffect(()=>{localStorage.setItem("archiveHideFailed",S.toString())},[S]),_.useEffect(()=>{T?localStorage.setItem("archiveFilterTag",T):localStorage.removeItem("archiveFilterTag")},[T]),_.useEffect(()=>{localStorage.setItem("archiveFilterFileType",C)},[C]),_.useEffect(()=>{localStorage.setItem("archiveViewMode",ie)},[ie]),_.useEffect(()=>{localStorage.setItem("archiveSortBy",me)},[me]),_.useEffect(()=>{localStorage.setItem("archiveCollection",Ee)},[Ee]);const we=new Map(te?.map(ue=>[ue.id,ue.name])||[]),_e=[...new Set(ye?.flatMap(ue=>ue.filament_type?.split(", ")||[]).filter(Boolean)||[])].sort(),ae=[...new Set(ye?.flatMap(ue=>ue.filament_color?.split(",")||[]).filter(Boolean)||[])],Le=[...new Set(ye?.flatMap(ue=>ue.tags?.split(",").map($e=>$e.trim())||[]).filter(Boolean)||[])].sort(),Be=ye?.filter(ue=>{const $e=new Date,be=zi(ue.created_at)||new Date(0);let Je=!0;switch(Ee){case"recent":Je=$e.getTime()-be.getTime()<1440*60*1e3;break;case"this-week":Je=$e.getTime()-be.getTime()<10080*60*1e3;break;case"this-month":Je=be.getMonth()===$e.getMonth()&&be.getFullYear()===$e.getFullYear();break;case"favorites":Je=ue.is_favorite===!0;break;case"failed":Je=ue.status==="failed"||ue.status==="aborted";break;case"duplicates":Je=ue.duplicate_count>0;break}const at=(ue.print_name||ue.filename).toLowerCase().includes(o.toLowerCase()),jt=!d||ue.filament_type?.split(", ").includes(d),Dt=ue.filament_color?.split(",")||[],yn=p.size===0||(x==="or"?Dt.some(Gn=>p.has(Gn)):[...p].every(Gn=>Dt.includes(Gn))),cn=Ee==="favorites"||!v||ue.is_favorite,rr=Ee==="failed"||!S||ue.status!=="failed"&&ue.status!=="aborted",Vn=ue.tags?.split(",").map(Gn=>Gn.trim())||[],Jn=!T||Vn.includes(T),xn=Pf(ue.filename);return Je&&at&&jt&&yn&&cn&&rr&&Jn&&(C==="all"||C==="gcode"&&xn||C==="source"&&!xn)}).sort((ue,$e)=>{switch(me){case"date-desc":return(zi($e.created_at)?.getTime()||0)-(zi(ue.created_at)?.getTime()||0);case"date-asc":return(zi(ue.created_at)?.getTime()||0)-(zi($e.created_at)?.getTime()||0);case"name-asc":return(ue.print_name||ue.filename).localeCompare($e.print_name||$e.filename);case"name-desc":return($e.print_name||$e.filename).localeCompare(ue.print_name||ue.filename);case"size-desc":return $e.file_size-ue.file_size;case"size-asc":return ue.file_size-$e.file_size;default:return 0}}),Ve=K||j.size>0,He=ue=>{$($e=>{const be=new Set($e);return be.has(ue)?be.delete(ue):be.add(ue),be})},xe=()=>{Be&&$(new Set(Be.map(ue=>ue.id)))},Pe=()=>{$(new Set),B(!1)},Ie=ue=>{m($e=>{const be=new Set($e);return be.has(ue)?be.delete(ue):be.add(ue),be})},Se=()=>{m(new Set)},Ke=()=>{l(""),u(null),h(null),b(!1),N(!1),k(null),E("all")},Me=o||c||d||v||S||T||C!=="all",it=_.useCallback(ue=>{ue.preventDefault(),ue.dataTransfer.types.includes("Files")&&U(!0)},[]),ke=_.useCallback(ue=>{ue.preventDefault(),ue.currentTarget===ue.target&&U(!1)},[]),Xe=_.useCallback(ue=>{ue.preventDefault(),U(!1);const $e=Array.from(ue.dataTransfer.files).filter(be=>be.name.endsWith(".3mf"));$e.length>0?(I($e),A(!0)):ue.dataTransfer.files.length>0&&n(t("archives.page.only3mfSupported"),"warning")},[n,t]),ze=_.useCallback(ue=>{const $e=ue.target;if($e.tagName==="INPUT"||$e.tagName==="TEXTAREA"||$e.isContentEditable){ue.key==="Escape"&&$e.blur();return}switch(ue.key){case"/":ue.preventDefault(),s.current?.focus();break;case"u":case"U":!ue.metaKey&&!ue.ctrlKey&&(ue.preventDefault(),A(!0));break;case"Escape":Ve&&Pe();break}},[Ve]);return _.useEffect(()=>(document.addEventListener("keydown",ze),()=>document.removeEventListener("keydown",ze)),[ze]),a.jsxs("div",{className:"p-4 md:p-8 relative min-h-full",onDragOver:it,onDragLeave:ke,onDrop:Xe,children:[L&&a.jsx("div",{className:"fixed inset-0 z-50 bg-bambu-dark/90 flex items-center justify-center pointer-events-none",children:a.jsxs("div",{className:"border-4 border-dashed border-bambu-green rounded-xl p-12 text-center",children:[a.jsx(Ba,{className:"w-16 h-16 mx-auto mb-4 text-bambu-green"}),a.jsx("p",{className:"text-2xl font-semibold text-white mb-2",children:"Drop .3mf files here"}),a.jsx("p",{className:"text-bambu-gray",children:t("archives.releaseToUpload")})]})}),Ve&&a.jsxs("div",{className:"fixed bottom-6 left-1/2 -translate-x-1/2 z-40 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl px-4 py-3 flex items-center gap-4",children:[a.jsxs(Te,{variant:"secondary",size:"sm",onClick:Pe,children:[a.jsx(Lt,{className:"w-4 h-4"}),"Close"]}),a.jsx("div",{className:"w-px h-6 bg-bambu-dark-tertiary"}),a.jsxs("span",{className:"text-white font-medium",children:[j.size," selected"]}),a.jsx("div",{className:"w-px h-6 bg-bambu-dark-tertiary"}),a.jsx(Te,{variant:"secondary",size:"sm",onClick:xe,children:"Select All"}),a.jsx("div",{className:"w-px h-6 bg-bambu-dark-tertiary"}),a.jsxs(Te,{variant:"secondary",size:"sm",onClick:()=>H(!0),disabled:!i("archives:update_own","archives:update_all"),title:i("archives:update_own","archives:update_all")?void 0:t("archives.permission.noUpdateArchives"),children:[a.jsx(wh,{className:"w-4 h-4"}),"Tags"]}),a.jsxs(Te,{variant:"secondary",size:"sm",onClick:()=>re(!0),disabled:!i("archives:update_own","archives:update_all"),title:i("archives:update_own","archives:update_all")?void 0:t("archives.permission.noUpdateArchives"),children:[a.jsx(es,{className:"w-4 h-4"}),"Project"]}),a.jsxs(Te,{variant:"secondary",size:"sm",disabled:!i("archives:update_own","archives:update_all"),title:i("archives:update_own","archives:update_all")?void 0:t("archives.permission.noUpdateArchives"),onClick:()=>{const ue=Array.from(j);Promise.all(ue.map($e=>ce.toggleFavorite($e))).then(()=>{e.invalidateQueries({queryKey:["archives"]}),n(`Toggled favorites for ${ue.length} archive${ue.length!==1?"s":""}`)}).catch(()=>{n(t("archives.toast.failedUpdateFavorites"),"error")})},children:[a.jsx(sm,{className:"w-4 h-4"}),"Favorite"]}),a.jsxs(Te,{size:"sm",className:"bg-red-500 hover:bg-red-600",onClick:()=>Y(!0),disabled:!i("archives:delete_own","archives:delete_all"),title:i("archives:delete_own","archives:delete_all")?void 0:t("archives.permission.noDelete"),children:[a.jsx(an,{className:"w-4 h-4"}),"Delete"]})]}),a.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4 mb-8",children:[a.jsxs("div",{children:[a.jsxs("div",{className:"flex items-center gap-3",children:[a.jsx("h1",{className:"text-2xl font-bold text-white",children:"Archives"}),a.jsx("select",{className:"px-3 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray-light text-sm focus:border-bambu-green focus:outline-none",value:Ee,onChange:ue=>se(ue.target.value),children:Sqe.map(ue=>a.jsx("option",{value:ue.id,children:ue.label},ue.id))})]}),a.jsxs("p",{className:"text-bambu-gray",children:[Be?.length||0," of ",ye?.length||0," prints"]})]}),a.jsxs("div",{className:"flex items-center gap-2 sm:gap-3 flex-wrap",children:[a.jsxs("div",{className:"relative",children:[a.jsxs(Te,{variant:"secondary",onClick:()=>Fe(!Ae),disabled:ge,children:[ge?a.jsx(pt,{className:"w-4 h-4 animate-spin"}):a.jsx(K1,{className:"w-4 h-4"}),"Export"]}),Ae&&a.jsxs("div",{className:"absolute right-0 top-full mt-1 w-48 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl z-20",children:[a.jsxs("button",{className:"w-full px-4 py-2 text-left text-white hover:bg-bambu-dark-tertiary transition-colors flex items-center gap-2 rounded-t-lg",onClick:async()=>{Fe(!1),Ze(!0);try{const{blob:ue,filename:$e}=await ce.exportArchives({format:"csv",printerId:c||void 0,status:Ee==="failed"?"failed":void 0,search:o||void 0}),be=URL.createObjectURL(ue),Je=document.createElement("a");Je.href=be,Je.download=$e,Je.click(),URL.revokeObjectURL(be),n(t("archives.toast.exportDownloaded"))}catch{n(t("archives.toast.exportFailed"),"error")}finally{Ze(!1)}},children:[a.jsx(fs,{className:"w-4 h-4"}),"Export as CSV"]}),a.jsxs("button",{className:"w-full px-4 py-2 text-left text-white hover:bg-bambu-dark-tertiary transition-colors flex items-center gap-2 rounded-b-lg",onClick:async()=>{Fe(!1),Ze(!0);try{const{blob:ue,filename:$e}=await ce.exportArchives({format:"xlsx",printerId:c||void 0,status:Ee==="failed"?"failed":void 0,search:o||void 0}),be=URL.createObjectURL(ue),Je=document.createElement("a");Je.href=be,Je.download=$e,Je.click(),URL.revokeObjectURL(be),n(t("archives.toast.exportDownloaded"))}catch{n(t("archives.toast.exportFailed"),"error")}finally{Ze(!1)}},children:[a.jsx(K1,{className:"w-4 h-4"}),"Export as Excel"]})]})]}),j.size>=2&&j.size<=5&&a.jsxs(Te,{variant:"secondary",onClick:()=>Q(!0),children:[a.jsx(Ng,{className:"w-4 h-4"}),"Compare (",j.size,")"]}),!Ve&&a.jsxs(Te,{variant:"secondary",onClick:()=>B(!0),children:[a.jsx(Gs,{className:"w-4 h-4"}),"Select"]}),a.jsxs(Te,{onClick:()=>A(!0),disabled:!r("archives:create"),title:r("archives:create")?void 0:t("archives.permission.noCreate"),children:[a.jsx(Ba,{className:"w-4 h-4"}),"Upload 3MF"]})]})]}),a.jsx(St,{className:"mb-6",children:a.jsxs(Nt,{className:"py-4",children:[a.jsxs("div",{className:"flex flex-col md:flex-row gap-3 md:gap-4 md:items-center md:flex-wrap",children:[a.jsxs("div",{className:"w-full md:flex-1 relative md:min-w-[200px]",children:[a.jsx(wa,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray"}),a.jsx("input",{ref:s,type:"text",placeholder:t("archives.searchPlaceholder"),className:"w-full pl-10 pr-4 py-3 md:py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",value:o,onChange:ue=>l(ue.target.value)})]}),a.jsxs("div",{className:"flex gap-2 md:gap-4 overflow-x-auto pb-1 md:pb-0 -mx-4 px-4 md:mx-0 md:px-0 md:flex-wrap scrollbar-hide",children:[a.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[a.jsx(hM,{className:"w-4 h-4 text-bambu-gray hidden md:block"}),a.jsxs("select",{className:"px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",value:c||"",onChange:ue=>u(ue.target.value?Number(ue.target.value):null),children:[a.jsx("option",{value:"",children:"All Printers"}),te?.map(ue=>a.jsx("option",{value:ue.id,children:ue.name},ue.id))]})]}),a.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[a.jsx(bc,{className:"w-4 h-4 text-bambu-gray hidden md:block"}),a.jsxs("select",{className:"px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",value:d||"",onChange:ue=>h(ue.target.value||null),children:[a.jsx("option",{value:"",children:"All Materials"}),_e.map(ue=>a.jsx("option",{value:ue,children:ue},ue))]})]}),a.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[a.jsx(W1,{className:"w-4 h-4 text-bambu-gray hidden md:block"}),a.jsxs("select",{className:"px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",value:C,onChange:ue=>E(ue.target.value),children:[a.jsx("option",{value:"all",children:"All Files"}),a.jsx("option",{value:"gcode",children:"Sliced (GCODE)"}),a.jsx("option",{value:"source",children:"Source Only"})]})]}),a.jsxs("button",{onClick:()=>b(!v),className:`flex items-center gap-2 px-3 py-2 rounded-lg border transition-colors flex-shrink-0 ${v?"bg-yellow-500/20 border-yellow-500 text-yellow-400":"bg-bambu-dark border-bambu-dark-tertiary text-bambu-gray hover:text-white"}`,title:t(v?"archives.showAll":"archives.showFavoritesOnly"),children:[a.jsx(sm,{className:`w-4 h-4 ${v?"fill-yellow-400":""}`}),a.jsx("span",{className:"text-sm hidden md:inline",children:"Favorites"})]}),a.jsxs("button",{onClick:()=>N(!S),className:`flex items-center gap-2 px-3 py-2 rounded-lg border transition-colors flex-shrink-0 ${S?"bg-red-500/20 border-red-500 text-red-400":"bg-bambu-dark border-bambu-dark-tertiary text-bambu-gray hover:text-white"}`,title:t(S?"archives.showFailedPrints":"archives.hideFailedPrints"),children:[a.jsx(Vi,{className:"w-4 h-4 "}),a.jsx("span",{className:"text-sm hidden md:inline",children:"Hide Failed"})]}),Le.length>0&&a.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[a.jsx(wh,{className:"w-4 h-4 text-bambu-gray hidden md:block"}),a.jsxs("select",{className:"px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",value:T||"",onChange:ue=>k(ue.target.value||null),children:[a.jsx("option",{value:"",children:"All Tags"}),Le.map(ue=>a.jsx("option",{value:ue,children:ue},ue))]}),a.jsx("button",{onClick:()=>q(!0),className:"p-2 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary text-bambu-gray hover:text-white hover:border-bambu-green transition-colors",title:t("archives.manageTags"),children:a.jsx(yM,{className:"w-4 h-4"})})]}),a.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[a.jsx(_W,{className:"w-4 h-4 text-bambu-gray hidden md:block"}),a.jsxs("select",{className:"px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",value:me,onChange:ue=>de(ue.target.value),children:[a.jsx("option",{value:"date-desc",children:t("archives.sortNewest")}),a.jsx("option",{value:"date-asc",children:t("archives.sortOldest")}),a.jsxs("option",{value:"name-asc",children:[t("archives.sortName")," A-Z"]}),a.jsxs("option",{value:"name-desc",children:[t("archives.sortName")," Z-A"]}),a.jsx("option",{value:"size-desc",children:t("archives.sortLargest")}),a.jsx("option",{value:"size-asc",children:t("archives.sortSmallest")})]})]}),a.jsxs("div",{className:"flex items-center border border-bambu-dark-tertiary rounded-lg overflow-hidden flex-shrink-0",children:[a.jsx("button",{className:`p-2 ${ie==="grid"?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white"}`,onClick:()=>pe("grid"),title:t("archives.gridView"),children:a.jsx(pM,{className:"w-4 h-4"})}),a.jsx("button",{className:`p-2 ${ie==="list"?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white"}`,onClick:()=>pe("list"),title:t("archives.listView"),children:a.jsx(gM,{className:"w-4 h-4"})}),a.jsx("button",{className:`p-2 ${ie==="calendar"?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white"}`,onClick:()=>pe("calendar"),title:t("archives.calendarView"),children:a.jsx($ce,{className:"w-4 h-4"})})]})]}),Me&&a.jsxs(Te,{variant:"ghost",size:"sm",onClick:Ke,className:"text-bambu-gray hover:text-white",children:[a.jsx(Lt,{className:"w-4 h-4"}),"Reset"]})]}),ae.length>0&&a.jsxs("div",{className:"flex items-center gap-3 mt-4 pt-4 border-t border-bambu-dark-tertiary",children:[a.jsx("span",{className:"text-xs text-bambu-gray",children:"Colors:"}),p.size>1&&a.jsx("button",{onClick:()=>y(ue=>ue==="or"?"and":"or"),className:`px-2 py-0.5 text-xs rounded transition-colors ${x==="and"?"bg-bambu-green text-white":"bg-bambu-dark-tertiary text-bambu-gray hover:text-white"}`,title:x==="or"?"Match ANY selected color":"Match ALL selected colors",children:x.toUpperCase()}),a.jsx("div",{className:"flex items-center gap-1.5 flex-wrap",children:ae.map(ue=>a.jsx("button",{onClick:()=>Ie(ue),className:`w-6 h-6 rounded-full border-2 transition-all ${p.has(ue)?"border-bambu-green scale-110":"border-white/20 hover:border-white/40"}`,style:{backgroundColor:ue},title:ue},ue))}),p.size>0&&a.jsxs("button",{onClick:Se,className:"text-xs text-bambu-gray hover:text-white flex items-center gap-1",children:[a.jsx(Lt,{className:"w-3 h-3"}),"Clear"]})]})]})}),a.jsx(yqe,{}),je?a.jsx("div",{className:"text-center py-12 text-bambu-gray",children:t("archives.loadingArchives")}):Be?.length===0?a.jsx(St,{children:a.jsxs(Nt,{className:"text-center py-12",children:[a.jsx("p",{className:"text-bambu-gray",children:t(o?"archives.noArchivesSearch":"archives.noArchivesYet")}),a.jsx("p",{className:"text-sm text-bambu-gray mt-2",children:"Archives are created automatically when prints complete"})]})}):ie==="calendar"?a.jsx(St,{className:"p-6",children:a.jsx(Y8e,{archives:Be||[],onArchiveClick:ue=>{l(""),pe("grid"),V(ue.id)},highlightedArchiveId:ee})}):ie==="grid"?a.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-6",children:Be?.map(ue=>a.jsx(wqe,{archive:ue,printerName:ue.printer_id?we.get(ue.printer_id)||"Unknown":ue.sliced_for_model?`Sliced for ${ue.sliced_for_model}`:"No Printer",isSelected:j.has(ue.id),onSelect:He,selectionMode:Ve,projects:z,isHighlighted:ue.id===ee,timeFormat:Z,t},ue.id))}):ie==="list"?a.jsx(St,{children:a.jsxs("div",{className:"divide-y divide-bambu-dark-tertiary",children:[a.jsxs("div",{className:"grid grid-cols-12 gap-4 px-4 py-3 text-xs text-bambu-gray font-medium",children:[a.jsx("div",{className:"col-span-1"}),a.jsx("div",{className:"col-span-4",children:"Name"}),a.jsx("div",{className:"col-span-2",children:"Printer"}),a.jsx("div",{className:"col-span-2",children:"Date"}),a.jsx("div",{className:"col-span-1",children:"Size"}),a.jsx("div",{className:"col-span-2 text-right",children:"Actions"})]}),Be?.map(ue=>a.jsx(_qe,{archive:ue,printerName:ue.printer_id?we.get(ue.printer_id)||"Unknown":ue.sliced_for_model?`Sliced for ${ue.sliced_for_model}`:"No Printer",isSelected:j.has(ue.id),onSelect:He,selectionMode:Ve,projects:z,isHighlighted:ue.id===ee,t},ue.id))]})}):null,P&&a.jsx(B8e,{onClose:()=>{A(!1),I([])},initialFiles:D}),X&&a.jsx(Zn,{title:t("archives.modal.deleteArchives"),message:t("archives.modal.deleteArchivesConfirm",{count:j.size}),confirmText:t("archives.modal.deleteCount",{count:j.size}),variant:"danger",onConfirm:()=>{oe.mutate(Array.from(j)),Y(!1)},onCancel:()=>Y(!1)}),ne&&a.jsx(V8e,{selectedIds:Array.from(j),existingTags:Le,onClose:()=>H(!1)}),W&&a.jsx(G8e,{selectedIds:Array.from(j),onClose:()=>re(!1)}),G&&j.size>=2&&j.size<=5&&a.jsx(mqe,{archiveIds:Array.from(j),onClose:()=>{Q(!1),$(new Set),B(!1)}}),he&&a.jsx(vqe,{onClose:()=>q(!1)})]})}function Mqe(){for(var t=arguments.length,e=new Array(t),n=0;nr=>{e.forEach(i=>i(r))},e)}const z2=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u";function Ix(t){const e=Object.prototype.toString.call(t);return e==="[object Window]"||e==="[object global]"}function oF(t){return"nodeType"in t}function Xs(t){var e,n;return t?Ix(t)?t:oF(t)&&(e=(n=t.ownerDocument)==null?void 0:n.defaultView)!=null?e:window:window}function lF(t){const{Document:e}=Xs(t);return t instanceof e}function _v(t){return Ix(t)?!1:t instanceof Xs(t).HTMLElement}function bre(t){return t instanceof Xs(t).SVGElement}function Ux(t){return t?Ix(t)?t.document:oF(t)?lF(t)?t:_v(t)||bre(t)?t.ownerDocument:document:document:document}const kc=z2?_.useLayoutEffect:_.useEffect;function cF(t){const e=_.useRef(t);return kc(()=>{e.current=t}),_.useCallback(function(){for(var n=arguments.length,r=new Array(n),i=0;i{t.current=setInterval(r,i)},[]),n=_.useCallback(()=>{t.current!==null&&(clearInterval(t.current),t.current=null)},[]);return[e,n]}function Py(t,e){e===void 0&&(e=[t]);const n=_.useRef(t);return kc(()=>{n.current!==t&&(n.current=t)},e),n}function Sv(t,e){const n=_.useRef();return _.useMemo(()=>{const r=t(n.current);return n.current=r,r},[...e])}function ZN(t){const e=cF(t),n=_.useRef(null),r=_.useCallback(i=>{i!==n.current&&e?.(i,n.current),n.current=i},[]);return[n,r]}function lR(t){const e=_.useRef();return _.useEffect(()=>{e.current=t},[t]),e.current}let zj={};function Nv(t,e){return _.useMemo(()=>{if(e)return e;const n=zj[t]==null?0:zj[t]+1;return zj[t]=n,t+"-"+n},[t,e])}function yre(t){return function(e){for(var n=arguments.length,r=new Array(n>1?n-1:0),i=1;i{const l=Object.entries(o);for(const[c,u]of l){const d=s[c];d!=null&&(s[c]=d+t*u)}return s},{...e})}}const Ig=yre(1),Dy=yre(-1);function Eqe(t){return"clientX"in t&&"clientY"in t}function uF(t){if(!t)return!1;const{KeyboardEvent:e}=Xs(t.target);return e&&t instanceof e}function Tqe(t){if(!t)return!1;const{TouchEvent:e}=Xs(t.target);return e&&t instanceof e}function cR(t){if(Tqe(t)){if(t.touches&&t.touches.length){const{clientX:e,clientY:n}=t.touches[0];return{x:e,y:n}}else if(t.changedTouches&&t.changedTouches.length){const{clientX:e,clientY:n}=t.changedTouches[0];return{x:e,y:n}}}return Eqe(t)?{x:t.clientX,y:t.clientY}:null}const gx=Object.freeze({Translate:{toString(t){if(!t)return;const{x:e,y:n}=t;return"translate3d("+(e?Math.round(e):0)+"px, "+(n?Math.round(n):0)+"px, 0)"}},Scale:{toString(t){if(!t)return;const{scaleX:e,scaleY:n}=t;return"scaleX("+e+") scaleY("+n+")"}},Transform:{toString(t){if(t)return[gx.Translate.toString(t),gx.Scale.toString(t)].join(" ")}},Transition:{toString(t){let{property:e,duration:n,easing:r}=t;return e+" "+n+"ms "+r}}}),cq="a,frame,iframe,input:not([type=hidden]):not(:disabled),select:not(:disabled),textarea:not(:disabled),button:not(:disabled),*[tabindex]";function Aqe(t){return t.matches(cq)?t:t.querySelector(cq)}const Cqe={display:"none"};function jqe(t){let{id:e,value:n}=t;return ei.createElement("div",{id:e,style:Cqe},n)}function Pqe(t){let{id:e,announcement:n,ariaLiveType:r="assertive"}=t;const i={position:"fixed",top:0,left:0,width:1,height:1,margin:-1,border:0,padding:0,overflow:"hidden",clip:"rect(0 0 0 0)",clipPath:"inset(100%)",whiteSpace:"nowrap"};return ei.createElement("div",{id:e,style:i,role:"status","aria-live":r,"aria-atomic":!0},n)}function Dqe(){const[t,e]=_.useState("");return{announce:_.useCallback(r=>{r!=null&&e(r)},[]),announcement:t}}const vre=_.createContext(null);function Rqe(t){const e=_.useContext(vre);_.useEffect(()=>{if(!e)throw new Error("useDndMonitor must be used within a children of ");return e(t)},[t,e])}function Oqe(){const[t]=_.useState(()=>new Set),e=_.useCallback(r=>(t.add(r),()=>t.delete(r)),[t]);return[_.useCallback(r=>{let{type:i,event:s}=r;t.forEach(o=>{var l;return(l=o[i])==null?void 0:l.call(o,s)})},[t]),e]}const Lqe={draggable:`
To pick up a draggable item, press the space bar.
While dragging, use the arrow keys to move the item.
Press space again to drop the item in its new position, or press escape to cancel.
@@ -8648,7 +8648,7 @@ Accuracy: ${t.time_accuracy.toFixed(0)}%`:t.actual_time_seconds?`Actual: ${r0(t.
transition-all duration-200 hover:border-bambu-dark-tertiary/80
${k?"opacity-50 scale-[1.02] shadow-xl z-50":""}
${E?"border-blue-500/30 bg-gradient-to-r from-blue-500/5 to-transparent":""}
- `,children:a.jsxs("div",{className:"flex items-center gap-4 p-4",children:[P&&d&&a.jsx("button",{onClick:D=>{D.stopPropagation(),d()},className:`flex items-center justify-center w-6 h-6 rounded border transition-colors ${u?"bg-bambu-green border-bambu-green text-white":"border-white/30 bg-black/30 hover:border-bambu-green/50"}`,children:u&&a.jsx(Wi,{className:"w-4 h-4"})}),P?a.jsx("div",{...v,...b,className:"flex items-center justify-center w-10 h-10 md:w-8 md:h-8 rounded-lg bg-bambu-dark cursor-grab active:cursor-grabbing hover:bg-bambu-dark-tertiary transition-colors touch-manipulation",children:a.jsx(Hg,{className:"w-6 h-6 md:w-4 md:h-4 text-bambu-gray"})}):e!==void 0?a.jsxs("div",{className:"flex items-center justify-center w-8 h-8 rounded-lg bg-bambu-dark text-bambu-gray text-sm font-medium",children:["#",e]}):a.jsx("div",{className:"w-8"}),a.jsx("div",{className:"w-14 h-14 flex-shrink-0 bg-bambu-dark rounded-lg overflow-hidden",children:t.archive_thumbnail?a.jsx("img",{src:t.plate_id!=null?ce.getArchivePlateThumbnail(t.archive_id,t.plate_id):ce.getArchiveThumbnail(t.archive_id),alt:"",className:"w-full h-full object-cover"}):t.library_file_thumbnail?a.jsx("img",{src:t.plate_id!=null?ce.getLibraryFilePlateThumbnail(t.library_file_id,t.plate_id):ce.getLibraryFileThumbnailUrl(t.library_file_id),alt:"",className:"w-full h-full object-cover"}):a.jsx("div",{className:"w-full h-full flex items-center justify-center text-bambu-gray",children:a.jsx(xs,{className:"w-6 h-6"})})}),a.jsxs("div",{className:"flex-1 min-w-0",children:[a.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[a.jsx("p",{className:"text-white font-medium truncate",children:t.archive_name||t.library_file_name||`File #${t.archive_id||t.library_file_id}`}),t.archive_id?a.jsx(Fs,{to:`/archives?highlight=${t.archive_id}`,className:"text-bambu-gray hover:text-bambu-green transition-colors flex-shrink-0",title:x("queue.viewArchive"),children:a.jsx(Xr,{className:"w-3.5 h-3.5"})}):t.library_file_id?a.jsx(Fs,{to:`/library?highlight=${t.library_file_id}`,className:"text-bambu-gray hover:text-bambu-green transition-colors flex-shrink-0",title:x("queue.viewInFileManager"),children:a.jsx(Xr,{className:"w-3.5 h-3.5"})}):null]}),a.jsxs("div",{className:"flex items-center gap-3 text-sm text-bambu-gray",children:[a.jsxs("span",{className:`flex items-center gap-1.5 ${t.printer_id===null&&!t.target_model?"text-orange-400":""} ${t.target_model?"text-blue-400":""}`,children:[a.jsx(Ur,{className:"w-3.5 h-3.5"}),t.target_model?`${x("queue.filter.any")} ${t.target_model}${t.target_location?` @ ${t.target_location}`:""}${t.required_filament_types?.length?` (${t.required_filament_types.join(", ")})`:""}`:t.printer_id===null?x("queue.filter.unassigned"):t.printer_name||`${x("common.printer")} #${t.printer_id}`]}),t.print_time_seconds&&a.jsxs("span",{className:"flex items-center gap-1.5",children:[a.jsx(yu,{className:"w-3.5 h-3.5"}),qre(t.print_time_seconds)]}),t.created_by_username&&a.jsxs("span",{className:"flex items-center gap-1.5",title:x("queue.addedBy",{name:t.created_by_username}),children:[a.jsx(om,{className:"w-3.5 h-3.5"}),t.created_by_username]}),P&&!t.manual_start&&a.jsxs("span",{className:"flex items-center gap-1.5",children:[a.jsx(tr,{className:"w-3.5 h-3.5"}),sKe(t.scheduled_time,c,x)]})]}),a.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[t.manual_start&&a.jsxs("span",{className:"text-xs px-2 py-0.5 bg-purple-500/10 text-purple-400 rounded-full border border-purple-500/20 flex items-center gap-1",children:[a.jsx(EW,{className:"w-3 h-3"}),x("queue.badges.staged")]}),t.require_previous_success&&a.jsx("span",{className:"text-xs px-2 py-0.5 bg-orange-500/10 text-orange-400 rounded-full border border-orange-500/20",children:x("queue.badges.requiresPrevious")}),t.auto_off_after&&a.jsxs("span",{className:"text-xs px-2 py-0.5 bg-blue-500/10 text-blue-400 rounded-full border border-blue-500/20 flex items-center gap-1",children:[a.jsx(qu,{className:"w-3 h-3"}),x("queue.badges.autoPowerOff")]})]}),E&&a.jsxs("div",{className:"mt-3",children:[a.jsx("div",{className:"h-2 bg-bambu-dark rounded-full overflow-hidden",children:a.jsx("div",{className:"h-full bg-gradient-to-r from-blue-500 to-blue-400 animate-pulse w-full opacity-50"})}),a.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:x("queue.printingInProgress")})]}),t.waiting_reason&&t.status==="pending"&&a.jsxs("p",{className:"text-xs text-purple-400 mt-2 flex items-start gap-1",children:[a.jsx(Vi,{className:"w-3 h-3 mt-0.5 flex-shrink-0"}),a.jsx("span",{children:t.waiting_reason})]}),t.error_message&&a.jsxs("p",{className:"text-xs text-red-400 mt-2 flex items-center gap-1",children:[a.jsx(Vi,{className:"w-3 h-3"}),t.error_message]})]}),a.jsx(oKe,{status:t.status,waitingReason:t.waiting_reason,printerState:m,t:x}),a.jsxs("div",{className:"flex items-center gap-1",children:[E&&a.jsx(Te,{variant:"ghost",size:"sm",onClick:s,disabled:!h("printers:control"),title:h("printers:control")?x("queue.actions.stopPrint"):x("queue.permissions.noStopPrint"),className:"text-red-400 hover:text-red-300 hover:bg-red-500/10",children:a.jsx(lue,{className:"w-4 h-4"})}),P&&a.jsxs(a.Fragment,{children:[t.manual_start&&a.jsx(Te,{variant:"ghost",size:"sm",onClick:l,disabled:!h("printers:control"),title:h("printers:control")?x("queue.actions.startPrint"):x("queue.permissions.noStartPrint"),className:"text-bambu-green hover:text-bambu-green-light hover:bg-bambu-green/10",children:a.jsx(So,{className:"w-4 h-4"})}),a.jsx(Te,{variant:"ghost",size:"sm",onClick:n,disabled:!p("queue","update",t.created_by_id),title:p("queue","update",t.created_by_id)?x("common.edit"):x("queue.permissions.noEdit"),children:a.jsx(ea,{className:"w-4 h-4"})}),a.jsx(Te,{variant:"ghost",size:"sm",onClick:r,disabled:!p("queue","delete",t.created_by_id),title:p("queue","delete",t.created_by_id)?x("common.cancel"):x("queue.permissions.noCancel"),className:"text-red-400 hover:text-red-300 hover:bg-red-500/10",children:a.jsx(Lt,{className:"w-4 h-4"})})]}),A&&a.jsxs(a.Fragment,{children:[a.jsx(Te,{variant:"ghost",size:"sm",onClick:o,disabled:!h("queue:create"),title:h("queue:create")?x("queue.actions.requeue"):x("queue.permissions.noRequeue"),className:"text-bambu-green hover:text-bambu-green/80 hover:bg-bambu-green/10",children:a.jsx(Dr,{className:"w-4 h-4"})}),a.jsx(Te,{variant:"ghost",size:"sm",onClick:i,disabled:!p("queue","delete",t.created_by_id),title:p("queue","delete",t.created_by_id)?x("common.remove"):x("queue.permissions.noRemove"),children:a.jsx(an,{className:"w-4 h-4"})})]})]})]})})}function cKe(){const{t}=On(),e=sn(),{showToast:n}=Hn(),{hasPermission:r,hasAnyPermission:i,canModify:s}=Ci(),[o,l]=_.useState(null),[c,u]=_.useState(""),[d,h]=_.useState(""),[p,m]=_.useState(!1),[x,y]=_.useState(null),[v,b]=_.useState(null),[S,N]=_.useState(null),[T,k]=_.useState([]),[C,E]=_.useState(!1),[P,A]=_.useState(()=>localStorage.getItem("queue.historySortBy")||"date"),[D,I]=_.useState(()=>{const te=localStorage.getItem("queue.historySortAsc");return te!==null?te==="true":!1}),[L,U]=_.useState(()=>localStorage.getItem("queue.pendingSortBy")||"position"),[j,$]=_.useState(()=>{const te=localStorage.getItem("queue.pendingSortAsc");return te!==null?te==="true":!0});_.useEffect(()=>{localStorage.setItem("queue.historySortBy",P)},[P]),_.useEffect(()=>{localStorage.setItem("queue.historySortAsc",String(D))},[D]),_.useEffect(()=>{localStorage.setItem("queue.pendingSortBy",L)},[L]),_.useEffect(()=>{localStorage.setItem("queue.pendingSortAsc",String(j))},[j]);const K=wre(eM($2,{activationConstraint:{distance:8}}),eM(H2,{coordinateGetter:Vre})),{data:B}=ct({queryKey:["settings"],queryFn:ce.getSettings}),X=B?.time_format||"system",{data:Y,isLoading:ne}=ct({queryKey:["queue",o,c],queryFn:()=>ce.getQueue(o||void 0,c||void 0),refetchInterval:5e3}),{data:H}=ct({queryKey:["printers"],queryFn:()=>ce.getPrinters()}),W=gt({mutationFn:te=>ce.cancelQueueItem(te),onSuccess:()=>{e.invalidateQueries({queryKey:["queue"]}),n(t("queue.toast.cancelled"))},onError:()=>n(t("queue.toast.cancelFailed"),"error")}),re=gt({mutationFn:te=>ce.removeFromQueue(te),onSuccess:()=>{e.invalidateQueries({queryKey:["queue"]}),n(t("queue.toast.removed"))},onError:()=>n(t("queue.toast.removeFailed"),"error")}),ie=gt({mutationFn:te=>ce.stopQueueItem(te),onSuccess:()=>{e.invalidateQueries({queryKey:["queue"]}),n(t("queue.toast.stopped"))},onError:()=>n(t("queue.toast.stopFailed"),"error")}),pe=gt({mutationFn:te=>ce.startQueueItem(te),onSuccess:()=>{e.invalidateQueries({queryKey:["queue"]}),n(t("queue.toast.released"))},onError:()=>n(t("queue.toast.startFailed"),"error")}),me=gt({mutationFn:te=>ce.reorderQueue(te),onSuccess:()=>{e.invalidateQueries({queryKey:["queue"]})},onError:()=>n(t("queue.toast.reorderFailed"),"error")}),de=gt({mutationFn:async()=>{const te=Y?.filter(z=>["completed","failed","skipped","cancelled"].includes(z.status))||[];for(const z of te)await ce.removeFromQueue(z.id);return te.length},onSuccess:te=>{e.invalidateQueries({queryKey:["queue"]}),n(t("queue.toast.historyCleared",{count:te}))},onError:()=>n(t("queue.toast.clearHistoryFailed"),"error")}),Ee=gt({mutationFn:te=>ce.bulkUpdateQueue(te),onSuccess:te=>{e.invalidateQueries({queryKey:["queue"]}),k([]),E(!1),n(te.message)},onError:()=>n(t("queue.toast.updateFailed"),"error")}),se=gt({mutationFn:async te=>{for(const z of te)await ce.cancelQueueItem(z);return te.length},onSuccess:te=>{e.invalidateQueries({queryKey:["queue"]}),k([]),n(t("queue.toast.bulkCancelled",{count:te}))},onError:()=>n(t("queue.toast.bulkCancelFailed"),"error")}),Ae=te=>{k(z=>z.includes(te)?z.filter(O=>O!==te):[...z,te])},Fe=_.useMemo(()=>{const te=new Set;return H?.forEach(z=>{z.location&&te.add(z.location)}),Y?.forEach(z=>{z.target_location&&te.add(z.target_location)}),Array.from(te).sort()},[H,Y]),ge=_.useCallback(te=>d?te.target_location?te.target_location===d:te.printer_id?H?.find(O=>O.id===te.printer_id)?.location===d:!1:!0,[d,H]),Ze=_.useMemo(()=>{let te=Y?.filter(O=>O.status==="pending")||[];d&&(te=te.filter(ge));const z=O=>{if(!O.scheduled_time)return 0;const Z=new Date(O.scheduled_time).getTime(),oe=Date.now()+4320*60*60*1e3;return Z>oe?0:Z};return[...te].sort((O,Z)=>{let oe;if(L==="name"){const we=O.archive_name||O.library_file_name||"",_e=Z.archive_name||Z.library_file_name||"";oe=we.localeCompare(_e)}else L==="printer"?oe=(O.printer_name||"").localeCompare(Z.printer_name||""):L==="time"?oe=z(O)-z(Z):oe=O.position-Z.position;return j?oe:-oe})},[Y,L,j,ge,d]),G=()=>{const te=Ze.map(z=>z.id);T.length===te.length?k([]):k(te)},Q=_.useMemo(()=>{let te=Y?.filter(z=>z.status==="printing")||[];return d&&(te=te.filter(ge)),te},[Y,d,ge]),he=_.useMemo(()=>{const te=new Set;return Q.forEach(z=>{z.printer_id&&te.add(z.printer_id)}),Array.from(te)},[Q]),q=jR({queries:he.map(te=>({queryKey:["printerStatus",te],queryFn:()=>ce.getPrinterStatus(te),refetchInterval:5e3}))}),ee=_.useMemo(()=>{const te={};return he.forEach((z,O)=>{const Z=q[O];Z?.data?.state&&(te[z]=Z.data.state)}),te},[he,q]),V=_.useMemo(()=>{let te=Y?.filter(z=>["completed","failed","skipped","cancelled"].includes(z.status))||[];return d&&(te=te.filter(ge)),[...te].sort((z,O)=>{let Z;if(P==="name"){const oe=z.archive_name||z.library_file_name||"",we=O.archive_name||O.library_file_name||"";Z=oe.localeCompare(we)}else P==="printer"?Z=(z.printer_name||"").localeCompare(O.printer_name||""):Z=new Date(O.completed_at||O.created_at).getTime()-new Date(z.completed_at||z.created_at).getTime();return D?-Z:Z})},[Y,P,D,ge,d]),ye=_.useMemo(()=>Ze.reduce((te,z)=>te+(z.print_time_seconds||0),0),[Ze]),je=te=>{const{active:z,over:O}=te;if(!O||z.id===O.id)return;const Z=Ze.findIndex(we=>we.id===z.id),oe=Ze.findIndex(we=>we.id===O.id);if(Z!==-1&&oe!==-1){const _e=q2(Ze,Z,oe).map((ae,Le)=>({id:ae.id,position:Le+1}));me.mutate(_e)}};return a.jsxs("div",{className:"p-4 md:p-8",children:[a.jsx("div",{className:"flex items-center justify-between mb-8",children:a.jsxs("div",{children:[a.jsxs("h1",{className:"text-2xl font-bold text-white flex items-center gap-3",children:[a.jsx(TW,{className:"w-7 h-7 text-bambu-green"}),t("queue.title")]}),a.jsx("p",{className:"text-bambu-gray mt-1",children:t("queue.subtitle")})]})}),a.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-4 gap-4 mb-8",children:[a.jsx(St,{className:"bg-gradient-to-br from-blue-500/10 to-transparent border-blue-500/20",children:a.jsx(Nt,{className:"p-4",children:a.jsxs("div",{className:"flex items-center gap-3",children:[a.jsx("div",{className:"w-10 h-10 rounded-lg bg-blue-500/20 flex items-center justify-center",children:a.jsx(So,{className:"w-5 h-5 text-blue-400"})}),a.jsxs("div",{children:[a.jsx("p",{className:"text-2xl font-bold text-white",children:Q.length}),a.jsx("p",{className:"text-sm text-bambu-gray",children:t("queue.summary.printing")})]})]})})}),a.jsx(St,{className:"bg-gradient-to-br from-yellow-500/10 to-transparent border-yellow-500/20",children:a.jsx(Nt,{className:"p-4",children:a.jsxs("div",{className:"flex items-center gap-3",children:[a.jsx("div",{className:"w-10 h-10 rounded-lg bg-yellow-500/20 flex items-center justify-center",children:a.jsx(tr,{className:"w-5 h-5 text-yellow-400"})}),a.jsxs("div",{children:[a.jsx("p",{className:"text-2xl font-bold text-white",children:Ze.length}),a.jsx("p",{className:"text-sm text-bambu-gray",children:t("queue.summary.queued")})]})]})})}),a.jsx(St,{className:"bg-gradient-to-br from-bambu-green/10 to-transparent border-bambu-green/20",children:a.jsx(Nt,{className:"p-4",children:a.jsxs("div",{className:"flex items-center gap-3",children:[a.jsx("div",{className:"w-10 h-10 rounded-lg bg-bambu-green/20 flex items-center justify-center",children:a.jsx(yu,{className:"w-5 h-5 text-bambu-green"})}),a.jsxs("div",{children:[a.jsx("p",{className:"text-2xl font-bold text-white",children:qre(ye)}),a.jsx("p",{className:"text-sm text-bambu-gray",children:t("queue.summary.totalTime")})]})]})})}),a.jsx(St,{className:"bg-gradient-to-br from-gray-500/10 to-transparent border-gray-500/20",children:a.jsx(Nt,{className:"p-4",children:a.jsxs("div",{className:"flex items-center gap-3",children:[a.jsx("div",{className:"w-10 h-10 rounded-lg bg-gray-500/20 flex items-center justify-center",children:a.jsx(Ar,{className:"w-5 h-5 text-gray-400"})}),a.jsxs("div",{children:[a.jsx("p",{className:"text-2xl font-bold text-white",children:V.length}),a.jsx("p",{className:"text-sm text-bambu-gray",children:t("queue.summary.history")})]})]})})})]}),a.jsxs("div",{className:"flex items-center gap-4 mb-6",children:[a.jsxs("select",{className:"px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",value:o===-1?"unassigned":o||"",onChange:te=>{const z=te.target.value;l(z==="unassigned"?-1:z===""?null:Number(z))},children:[a.jsx("option",{value:"",children:t("queue.filter.allPrinters")}),a.jsx("option",{value:"unassigned",children:t("queue.filter.unassigned")}),H?.map(te=>a.jsx("option",{value:te.id,children:te.name},te.id))]}),a.jsxs("select",{className:"px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",value:c,onChange:te=>u(te.target.value),children:[a.jsx("option",{value:"",children:t("queue.filter.allStatus")}),a.jsx("option",{value:"pending",children:t("queue.status.pending")}),a.jsx("option",{value:"printing",children:t("queue.status.printing")}),a.jsx("option",{value:"completed",children:t("queue.status.completed")}),a.jsx("option",{value:"failed",children:t("queue.status.failed")}),a.jsx("option",{value:"skipped",children:t("queue.status.skipped")}),a.jsx("option",{value:"cancelled",children:t("queue.status.cancelled")})]}),Fe.length>0&&a.jsxs("select",{className:"px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",value:d,onChange:te=>h(te.target.value),children:[a.jsx("option",{value:"",children:t("queue.filter.allLocations")}),Fe.map(te=>a.jsx("option",{value:te,children:te},te))]}),a.jsx("div",{className:"flex-1"}),V.length>0&&a.jsxs(Te,{variant:"secondary",size:"sm",onClick:()=>m(!0),disabled:!r("queue:delete_all"),title:r("queue:delete_all")?void 0:t("queue.permissions.noClearHistory"),children:[a.jsx(an,{className:"w-4 h-4"}),t("queue.clearHistory")]})]}),ne?a.jsx("div",{className:"text-center py-12 text-bambu-gray",children:t("common.loading")}):Y?.length===0?a.jsxs(St,{className:"p-12 text-center border-dashed",children:[a.jsx(ti,{className:"w-16 h-16 text-bambu-gray mx-auto mb-4 opacity-50"}),a.jsx("h3",{className:"text-xl font-medium text-white mb-2",children:t("queue.empty.title")}),a.jsx("p",{className:"text-bambu-gray max-w-md mx-auto",children:t("queue.empty.description")})]}):a.jsxs("div",{className:"space-y-8",children:[Q.length>0&&a.jsxs("div",{children:[a.jsxs("h2",{className:"text-lg font-semibold text-white mb-4 flex items-center gap-2",children:[a.jsx("div",{className:"w-2 h-2 rounded-full bg-blue-400 animate-pulse"}),t("queue.sections.currentlyPrinting")]}),a.jsx("div",{className:"space-y-3",children:Q.map(te=>a.jsx(Vj,{item:te,onEdit:()=>{},onCancel:()=>{},onRemove:()=>{},onStop:()=>N({type:"stop",item:te}),onRequeue:()=>{},onStart:()=>{},timeFormat:X,hasPermission:r,canModify:s,printerState:te.printer_id?ee[te.printer_id]:null,t},te.id))})]}),Ze.length>0&&a.jsxs("div",{children:[a.jsxs("div",{className:"flex items-center justify-between mb-4",children:[a.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[a.jsx(tr,{className:"w-5 h-5 text-yellow-400"}),t("queue.sections.queued"),a.jsxs("span",{className:"text-sm font-normal text-bambu-gray",children:["(",t("queue.itemCount",{count:Ze.length}),")"]}),a.jsx("span",{className:"text-xs text-bambu-gray ml-2",title:t("queue.reorderHint"),children:t("queue.dragToReorder")})]}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsxs("select",{className:"px-3 py-1.5 text-sm bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",value:L,onChange:te=>U(te.target.value),children:[a.jsx("option",{value:"position",children:t("queue.sort.byPosition")}),a.jsx("option",{value:"name",children:t("queue.sort.byName")}),a.jsx("option",{value:"printer",children:t("queue.sort.byPrinter")}),a.jsx("option",{value:"time",children:t("queue.sort.bySchedule")})]}),a.jsx(Te,{variant:"ghost",size:"sm",onClick:()=>$(!j),title:t(j?"common.ascending":"common.descending"),className:"px-2",children:j?a.jsx(zg,{className:"w-4 h-4"}):a.jsx(q0,{className:"w-4 h-4"})})]})]}),a.jsxs("div",{className:"flex items-center gap-3 mb-4 p-3 bg-bambu-dark rounded-lg",children:[a.jsxs(Te,{variant:"ghost",size:"sm",onClick:G,className:"flex items-center gap-2",children:[T.length===Ze.length&&Ze.length>0?a.jsx(Gs,{className:"w-4 h-4 text-bambu-green"}):a.jsx(cl,{className:"w-4 h-4"}),T.length===Ze.length&&Ze.length>0?t("queue.bulkEdit.deselectAll"):t("queue.bulkEdit.selectAll")]}),T.length>0&&a.jsxs(a.Fragment,{children:[a.jsx("span",{className:"text-sm text-bambu-gray",children:t("queue.bulkEdit.selected",{count:T.length})}),a.jsx("div",{className:"h-4 w-px bg-bambu-dark-tertiary"}),a.jsxs(Te,{variant:"ghost",size:"sm",onClick:()=>E(!0),className:"flex items-center gap-2 text-bambu-green hover:text-bambu-green-light",disabled:!i("queue:update_own","queue:update_all"),title:i("queue:update_own","queue:update_all")?void 0:t("queue.permissions.noEditItems"),children:[a.jsx(ea,{className:"w-4 h-4"}),t("queue.bulkEdit.editSelected")]}),a.jsxs(Te,{variant:"ghost",size:"sm",onClick:()=>se.mutate(T),className:"flex items-center gap-2 text-red-400 hover:text-red-300",disabled:se.isPending||!i("queue:delete_own","queue:delete_all"),title:i("queue:delete_own","queue:delete_all")?void 0:t("queue.permissions.noCancelItems"),children:[a.jsx(Lt,{className:"w-4 h-4"}),t("queue.bulkEdit.cancelSelected")]})]})]}),a.jsx(Ire,{sensors:K,collisionDetection:Mre,onDragEnd:je,children:a.jsx(Bre,{items:Ze.map(te=>te.id),strategy:XWe,children:a.jsx("div",{className:"space-y-3",children:Ze.map((te,z)=>a.jsx(Vj,{item:te,position:z+1,onEdit:()=>y(te),onCancel:()=>N({type:"cancel",item:te}),onRemove:()=>{},onStop:()=>{},onRequeue:()=>{},onStart:()=>pe.mutate(te.id),timeFormat:X,isSelected:T.includes(te.id),onToggleSelect:()=>Ae(te.id),hasPermission:r,canModify:s,t},te.id))})})})]}),V.length>0&&a.jsxs("div",{children:[a.jsxs("div",{className:"flex items-center justify-between mb-4",children:[a.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[a.jsx(Ar,{className:"w-5 h-5 text-bambu-gray"}),t("queue.sections.history"),a.jsxs("span",{className:"text-sm font-normal text-bambu-gray",children:["(",t("queue.itemCount",{count:V.length}),")"]})]}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsxs("select",{className:"px-3 py-1.5 text-sm bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",value:P,onChange:te=>A(te.target.value),children:[a.jsx("option",{value:"date",children:t("queue.sort.byDate")}),a.jsx("option",{value:"name",children:t("queue.sort.byName")}),a.jsx("option",{value:"printer",children:t("queue.sort.byPrinter")})]}),a.jsx(Te,{variant:"ghost",size:"sm",onClick:()=>I(!D),title:t(D?"queue.sort.ascendingOldest":"queue.sort.descendingNewest"),className:"px-2",children:D?a.jsx(zg,{className:"w-4 h-4"}):a.jsx(q0,{className:"w-4 h-4"})})]})]}),a.jsx("div",{className:"space-y-3",children:V.slice(0,20).map((te,z)=>a.jsx(Vj,{item:te,position:z+1,onEdit:()=>{},onCancel:()=>{},onRemove:()=>N({type:"remove",item:te}),onStop:()=>{},onRequeue:()=>b(te),onStart:()=>{},timeFormat:X,hasPermission:r,canModify:s,t},te.id))})]})]}),x&&a.jsx(Dh,{mode:"edit-queue-item",archiveId:x.archive_id??void 0,libraryFileId:x.library_file_id??void 0,archiveName:x.archive_name||x.library_file_name||`File #${x.archive_id||x.library_file_id}`,queueItem:x,onClose:()=>y(null)}),v&&a.jsx(Dh,{mode:"add-to-queue",archiveId:v.archive_id??void 0,libraryFileId:v.library_file_id??void 0,archiveName:v.archive_name||v.library_file_name||`File #${v.archive_id||v.library_file_id}`,onClose:()=>b(null)}),S&&a.jsx(Zn,{title:S.type==="cancel"?t("queue.confirm.cancelTitle"):S.type==="stop"?t("queue.confirm.stopTitle"):t("queue.confirm.removeTitle"),message:S.type==="cancel"?t("queue.confirm.cancelMessage",{name:S.item.archive_name||S.item.library_file_name||t("queue.confirm.thisPrint")}):S.type==="stop"?t("queue.confirm.stopMessage",{name:S.item.archive_name||S.item.library_file_name||t("queue.confirm.thisPrint")}):t("queue.confirm.removeMessage",{name:S.item.archive_name||S.item.library_file_name||t("queue.confirm.thisItem")}),confirmText:S.type==="cancel"?t("queue.confirm.cancelButton"):S.type==="stop"?t("queue.confirm.stopButton"):t("common.remove"),variant:"danger",onConfirm:()=>{S.type==="cancel"?W.mutate(S.item.id):S.type==="stop"?ie.mutate(S.item.id):re.mutate(S.item.id),N(null)},onCancel:()=>N(null)}),p&&a.jsx(Zn,{title:t("queue.confirm.clearHistoryTitle"),message:t("queue.confirm.clearHistoryMessage",{count:V.length}),confirmText:t("queue.clearHistory"),variant:"danger",onConfirm:()=>{de.mutate(),m(!1)},onCancel:()=>m(!1)}),C&&a.jsx(lKe,{selectedCount:T.length,printers:H?.map(te=>({id:te.id,name:te.name}))||[],onSave:te=>{Object.keys(te).length>0&&Ee.mutate({item_ids:T,...te})},onClose:()=>E(!1),isSaving:Ee.isPending,t})]})}function uKe({printDates:t,months:e=3}){const n=_.useRef(null),[r,i]=_.useState(0);_.useEffect(()=>{const S=n.current;if(!S)return;const N=new ResizeObserver(T=>{const k=T[0]?.contentRect.width||0;i(k)});return N.observe(S),()=>N.disconnect()},[]);const{weeks:s,monthLabels:o,printCounts:l}=_.useMemo(()=>{const S={};t.forEach(I=>{const L=I.split("T")[0];S[L]=(S[L]||0)+1});const N=new Date,T=new Date(N);T.setMonth(T.getMonth()-e),T.setDate(T.getDate()-T.getDay());const k=[],C=[];let E=[],P=-1;const A=new Date(T);let D=0;for(;A<=N;)A.getDay()===0&&E.length>0&&(k.push(E),E=[],D++),A.getMonth()!==P&&(C.push({month:A.toLocaleDateString("en-US",{month:"short"}),weekIndex:D}),P=A.getMonth()),E.push(new Date(A)),A.setDate(A.getDate()+1);return E.length>0&&k.push(E),{weeks:k,monthLabels:C,printCounts:S}},[t,e]),c=Math.max(1,...Object.values(l)),u=S=>{if(S===0)return"bg-bambu-dark";const N=S/c;return N<=.25?"bg-bambu-green/30":N<=.5?"bg-bambu-green/50":N<=.75?"bg-bambu-green/75":"bg-bambu-green"},d=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],h=s.length,p=32,m=2,x=r-p-16,y=h>0?Math.floor((x-(h-1)*m)/h):12,v=Math.max(8,Math.min(20,y)),b=v<=10?10:12;return a.jsx("div",{ref:n,className:"w-full flex justify-center",children:r>0&&a.jsxs("div",{children:[a.jsx("div",{className:"flex mb-1",style:{marginLeft:p+4},children:o.map(({month:S,weekIndex:N},T)=>a.jsx("div",{className:"text-bambu-gray",style:{fontSize:b,marginLeft:T===0?0:`${(N-(o[T-1]?.weekIndex||0))*(v+m)-24}px`},children:S},T))}),a.jsxs("div",{className:"flex",style:{gap:m},children:[a.jsx("div",{className:"flex flex-col",style:{gap:m,marginRight:4,width:p},children:d.map((S,N)=>a.jsx("div",{className:"text-bambu-gray flex items-center",style:{width:p,height:v,fontSize:b,visibility:N%2===1?"visible":"hidden"},children:S},S))}),s.map((S,N)=>a.jsx("div",{className:"flex flex-col",style:{gap:m},children:[0,1,2,3,4,5,6].map(T=>{const k=S.find(A=>A.getDay()===T);if(!k)return a.jsx("div",{style:{width:v,height:v}},T);const C=k.toISOString().split("T")[0],E=l[C]||0,P=C===new Date().toISOString().split("T")[0];return a.jsx("div",{className:`rounded-sm ${u(E)} ${P?"ring-1 ring-white":""}`,style:{width:v,height:v},title:`${k.toLocaleDateString()}: ${E} print${E!==1?"s":""}`},T)})},N))]}),a.jsxs("div",{className:"flex items-center gap-2 mt-3 text-bambu-gray",style:{fontSize:b},children:[a.jsx("span",{children:"Less"}),a.jsxs("div",{className:"flex",style:{gap:m},children:[a.jsx("div",{className:"rounded-sm bg-bambu-dark",style:{width:v,height:v}}),a.jsx("div",{className:"rounded-sm bg-bambu-green/30",style:{width:v,height:v}}),a.jsx("div",{className:"rounded-sm bg-bambu-green/50",style:{width:v,height:v}}),a.jsx("div",{className:"rounded-sm bg-bambu-green/75",style:{width:v,height:v}}),a.jsx("div",{className:"rounded-sm bg-bambu-green",style:{width:v,height:v}})]}),a.jsx("span",{children:"More"})]})]})})}const f1=["#00ae42","#3b82f6","#f59e0b","#ef4444","#8b5cf6","#ec4899","#14b8a6","#f97316"];function dKe(t){const e=new Date;switch(t){case"7d":return new Date(e.getTime()-10080*60*1e3);case"30d":return new Date(e.getTime()-720*60*60*1e3);case"90d":return new Date(e.getTime()-2160*60*60*1e3);case"365d":return new Date(e.getTime()-365*24*60*60*1e3);case"all":return new Date(0)}}function hKe({archives:t,currency:e="$"}){const[n,r]=_.useState("30d"),i=_.useMemo(()=>{const m=dKe(n);return t.filter(x=>(zi(x.completed_at||x.created_at)||new Date(0))>=m)},[t,n]),s=_.useMemo(()=>{const m=new Map;return i.forEach(x=>{const y=zi(x.completed_at||x.created_at)||new Date,v=`${y.getFullYear()}-${String(y.getMonth()+1).padStart(2,"0")}-${String(y.getDate()).padStart(2,"0")}`,b=m.get(v)||{date:v,filament:0,cost:0,prints:0},S=x.quantity||1;b.filament+=(x.filament_used_grams||0)*S,b.cost+=x.cost||0,b.prints+=S,m.set(v,b)}),Array.from(m.values()).sort((x,y)=>x.date.localeCompare(y.date)).map(x=>({...x,dateLabel:new Date(x.date).toLocaleDateString("en-US",{month:"short",day:"numeric"})}))},[i]),o=_.useMemo(()=>{if(n==="7d"||n==="30d")return s;const m=new Map;return i.forEach(x=>{const y=zi(x.completed_at||x.created_at)||new Date,v=new Date(y);v.setDate(y.getDate()-y.getDay());const b=`${v.getFullYear()}-${String(v.getMonth()+1).padStart(2,"0")}-${String(v.getDate()).padStart(2,"0")}`,S=m.get(b)||{week:b,filament:0,cost:0,prints:0},N=x.quantity||1;S.filament+=(x.filament_used_grams||0)*N,S.cost+=x.cost||0,S.prints+=N,m.set(b,S)}),Array.from(m.values()).sort((x,y)=>x.week.localeCompare(y.week)).map(x=>({date:x.week,dateLabel:`Week of ${new Date(x.week).toLocaleDateString("en-US",{month:"short",day:"numeric"})}`,...x}))},[i,s,n]),l=_.useMemo(()=>{const m=new Map;return i.forEach(x=>{const y=x.filament_type||"Unknown",v=x.quantity||1,b=y.split(", ");b.forEach(S=>{const N=(x.filament_used_grams||0)*v/b.length;m.set(S,(m.get(S)||0)+N)})}),Array.from(m.entries()).map(([x,y])=>({name:x,value:Math.round(y)})).sort((x,y)=>y.value-x.value)},[i]),c=_.useMemo(()=>{const m=new Date,x=[];for(let y=5;y>=0;y--){const v=new Date(m.getFullYear(),m.getMonth()-y,1),b=new Date(m.getFullYear(),m.getMonth()-y+1,0),S=v.toLocaleDateString("en-US",{month:"short",year:"2-digit"}),N=t.filter(T=>{const k=zi(T.completed_at||T.created_at)||new Date(0);return k>=v&&k<=b});x.push({month:S,filament:Math.round(N.reduce((T,k)=>T+(k.filament_used_grams||0),0)),cost:N.reduce((T,k)=>T+(k.cost||0),0),prints:N.reduce((T,k)=>T+(k.quantity||1),0)})}return x},[t]),u=n==="7d"||n==="30d"?s:o,d=i.reduce((m,x)=>m+(x.filament_used_grams||0),0),h=i.reduce((m,x)=>m+(x.cost||0),0),p=i.reduce((m,x)=>m+(x.quantity||1),0);return a.jsxs("div",{className:"space-y-6",children:[a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx("h3",{className:"text-lg font-semibold text-white",children:"Filament Usage Trends"}),a.jsx("div",{className:"flex gap-1 bg-bambu-dark rounded-lg p-1",children:["7d","30d","90d","365d","all"].map(m=>a.jsx("button",{onClick:()=>r(m),className:`px-3 py-1 text-sm rounded-md transition-colors ${n===m?"bg-bambu-green text-white":"text-bambu-gray hover:text-white"}`,children:m==="all"?"All":m.replace("d","D")},m))})]}),a.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[a.jsxs("div",{className:"bg-bambu-dark rounded-lg p-4",children:[a.jsx("p",{className:"text-sm text-bambu-gray",children:"Period Filament"}),a.jsxs("p",{className:"text-2xl font-bold text-white",children:[(d/1e3).toFixed(2),"kg"]}),a.jsxs("p",{className:"text-xs text-bambu-gray",children:[d.toFixed(0),"g total"]})]}),a.jsxs("div",{className:"bg-bambu-dark rounded-lg p-4",children:[a.jsx("p",{className:"text-sm text-bambu-gray",children:"Period Cost"}),a.jsxs("p",{className:"text-2xl font-bold text-white",children:[e,h.toFixed(2)]}),a.jsxs("p",{className:"text-xs text-bambu-gray",children:[p," prints"]})]}),a.jsxs("div",{className:"bg-bambu-dark rounded-lg p-4",children:[a.jsx("p",{className:"text-sm text-bambu-gray",children:"Avg per Print"}),a.jsxs("p",{className:"text-2xl font-bold text-white",children:[p>0?(d/p).toFixed(0):0,"g"]}),a.jsxs("p",{className:"text-xs text-bambu-gray",children:[e,p>0?(h/p).toFixed(2):"0.00"," avg"]})]})]}),u.length>0?a.jsxs("div",{className:"bg-bambu-dark rounded-lg p-4",children:[a.jsx("h4",{className:"text-sm font-medium text-bambu-gray mb-4",children:"Usage Over Time"}),a.jsx(j1,{width:"100%",height:250,children:a.jsxs(YBe,{data:u,children:[a.jsx("defs",{children:a.jsxs("linearGradient",{id:"colorFilament",x1:"0",y1:"0",x2:"0",y2:"1",children:[a.jsx("stop",{offset:"5%",stopColor:"#00ae42",stopOpacity:.3}),a.jsx("stop",{offset:"95%",stopColor:"#00ae42",stopOpacity:0})]})}),a.jsx(nN,{strokeDasharray:"3 3",stroke:"#3d3d3d"}),a.jsx(iN,{dataKey:"dateLabel",stroke:"#9ca3af",tick:{fontSize:12},interval:"preserveStartEnd"}),a.jsx(aN,{stroke:"#9ca3af",tick:{fontSize:12},tickFormatter:m=>`${m}g`}),a.jsx(D1,{contentStyle:{backgroundColor:"#2d2d2d",border:"1px solid #3d3d3d",borderRadius:"8px"},labelStyle:{color:"#fff"},formatter:m=>[`${Number(m??0).toFixed(0)}g`,"Filament"]}),a.jsx(uee,{type:"monotone",dataKey:"filament",stroke:"#00ae42",strokeWidth:2,fillOpacity:1,fill:"url(#colorFilament)"})]})})]}):a.jsx("div",{className:"bg-bambu-dark rounded-lg p-8 text-center text-bambu-gray",children:"No data for selected time range"}),a.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[a.jsxs("div",{className:"bg-bambu-dark rounded-lg p-4",children:[a.jsx("h4",{className:"text-sm font-medium text-bambu-gray mb-4",children:"By Filament Type"}),l.length>0?a.jsxs("div",{className:"flex items-center gap-4",children:[a.jsx(j1,{width:160,height:160,children:a.jsxs(KBe,{children:[a.jsx(RJ,{data:l,cx:"50%",cy:"50%",innerRadius:40,outerRadius:70,paddingAngle:2,dataKey:"value",children:l.map((m,x)=>a.jsx(pv,{fill:f1[x%f1.length]},`cell-${x}`))}),a.jsx(D1,{contentStyle:{backgroundColor:"#2d2d2d",border:"1px solid #3d3d3d",borderRadius:"8px"},formatter:m=>[`${m??0}g`,"Usage"]})]})}),a.jsx("div",{className:"flex-1 space-y-2 overflow-hidden",children:l.map((m,x)=>{const y=l.reduce((b,S)=>b+S.value,0),v=y>0?(m.value/y*100).toFixed(0):0;return a.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[a.jsx("div",{className:"w-3 h-3 rounded-sm flex-shrink-0",style:{backgroundColor:f1[x%f1.length]}}),a.jsx("span",{className:"text-white truncate flex-1",children:m.name}),a.jsxs("span",{className:"text-bambu-gray flex-shrink-0",children:[v,"%"]})]},m.name)})})]}):a.jsx("div",{className:"h-[160px] flex items-center justify-center text-bambu-gray",children:"No filament data"})]}),a.jsxs("div",{className:"bg-bambu-dark rounded-lg p-4",children:[a.jsx("h4",{className:"text-sm font-medium text-bambu-gray mb-4",children:"Monthly Comparison"}),a.jsx(j1,{width:"100%",height:200,children:a.jsxs(LBe,{data:c,children:[a.jsx(nN,{strokeDasharray:"3 3",stroke:"#3d3d3d"}),a.jsx(iN,{dataKey:"month",stroke:"#9ca3af",tick:{fontSize:12}}),a.jsx(aN,{stroke:"#9ca3af",tick:{fontSize:12},tickFormatter:m=>`${m}g`}),a.jsx(D1,{contentStyle:{backgroundColor:"#2d2d2d",border:"1px solid #3d3d3d",borderRadius:"8px"},formatter:(m,x)=>[x==="filament"?`${m??0}g`:x==="cost"?`${e}${Number(m??0).toFixed(2)}`:m??0,x==="filament"?"Filament":x==="cost"?"Cost":"Prints"]}),a.jsx(HO,{}),a.jsx(zJ,{dataKey:"filament",name:"Filament (g)",fill:"#00ae42",radius:[4,4,0,0]})]})})]})]})]})}function fKe({id:t,title:e,component:n,isHidden:r,size:i,onToggleVisibility:s,onToggleSize:o}){const{attributes:l,listeners:c,setNodeRef:u,transform:d,transition:h,isDragging:p}=$re({id:t}),m={transform:gx.Transform.toString(d),transition:h,opacity:p?.5:1};return r?null:a.jsxs("div",{ref:u,style:{...m,gridColumn:`span ${i}`},className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary overflow-hidden ${p?"ring-2 ring-bambu-green shadow-lg":""}`,children:[a.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-bambu-dark-tertiary bg-bambu-dark/30",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("button",{...l,...c,className:"cursor-grab active:cursor-grabbing p-1 hover:bg-bambu-dark-tertiary rounded transition-colors",title:"Drag to reorder",children:a.jsx(Hg,{className:"w-6 h-6 md:w-4 md:h-4 text-bambu-gray"})}),a.jsx("h3",{className:"text-sm font-medium text-white",children:e})]}),a.jsxs("div",{className:"flex items-center gap-1",children:[a.jsx("button",{onClick:o,className:"p-1 hover:bg-bambu-dark-tertiary rounded transition-colors",title:`Size: ${i===1?"1/4":i===2?"1/2":"Full"} - Click to cycle`,children:i===4?a.jsx(CW,{className:"w-4 h-4 text-bambu-gray hover:text-white"}):a.jsx(AW,{className:"w-4 h-4 text-bambu-gray hover:text-white"})}),a.jsx("button",{onClick:s,className:"p-1 hover:bg-bambu-dark-tertiary rounded transition-colors",title:"Hide widget",children:a.jsx(uM,{className:"w-4 h-4 text-bambu-gray hover:text-white"})})]})]}),a.jsx("div",{className:"p-4",children:typeof n=="function"?n(i):n})]})}function mKe({widgets:t,storageKey:e,columns:n=4,hideControls:r=!1,onResetLayout:i,renderControls:s}){const o=()=>{const T={};return t.forEach(k=>{T[k.id]=k.defaultSize||4}),T},[l,c]=_.useState(()=>{const T=localStorage.getItem(e);if(T)try{const k=JSON.parse(T);return k.sizes||(k.sizes=o()),k}catch{}return{order:t.map(k=>k.id),hidden:t.filter(k=>k.defaultVisible===!1).map(k=>k.id),sizes:o()}}),[u,d]=_.useState(!1);_.useEffect(()=>{const T=()=>d(k=>!k);return window.addEventListener("toggle-hidden-panel",T),()=>window.removeEventListener("toggle-hidden-panel",T)},[]),_.useEffect(()=>{localStorage.setItem(e,JSON.stringify(l))},[l,e]),_.useEffect(()=>{const k=t.map(C=>C.id).filter(C=>!l.order.includes(C));k.length>0&&c(C=>({...C,order:[...C.order,...k]}))},[t,l.order]);const h=wre(eM($2,{activationConstraint:{distance:8}}),eM(H2,{coordinateGetter:Vre})),p=T=>{const{active:k,over:C}=T;C&&k.id!==C.id&&c(E=>{const P=E.order.indexOf(k.id),A=E.order.indexOf(C.id);return{...E,order:q2(E.order,P,A)}})},m=T=>{c(k=>({...k,hidden:k.hidden.includes(T)?k.hidden.filter(C=>C!==T):[...k.hidden,T]}))},x=T=>{c(k=>{const C=k.sizes[T]||4,E=C===1?2:C===2?4:1;return{...k,sizes:{...k.sizes,[T]:E}}})},y=()=>{const T={order:t.map(k=>k.id),hidden:t.filter(k=>k.defaultVisible===!1).map(k=>k.id),sizes:o()};c(T),i?.()},v=l.order.map(T=>t.find(k=>k.id===T)).filter(Boolean),b=v.filter(T=>!l.hidden.includes(T.id)),S=v.filter(T=>l.hidden.includes(T.id)),N=s?.({hiddenCount:S.length,showHiddenPanel:u,setShowHiddenPanel:d,resetLayout:y});return a.jsxs("div",{className:"space-y-4",children:[N,!r&&!s&&a.jsxs("div",{className:"flex items-center justify-end gap-2",children:[a.jsxs(Te,{variant:"secondary",size:"sm",onClick:y,children:[a.jsx(Lh,{className:"w-4 h-4"}),"Reset Layout"]}),S.length>0&&a.jsxs(Te,{variant:"secondary",size:"sm",onClick:()=>d(!u),children:[a.jsx(xc,{className:"w-4 h-4"}),S.length," Hidden"]})]}),u&&S.length>0&&a.jsxs("div",{className:"p-4 bg-bambu-dark rounded-xl border border-bambu-dark-tertiary",children:[a.jsx("p",{className:"text-sm text-bambu-gray mb-3",children:"Hidden widgets (click to show):"}),a.jsx("div",{className:"flex flex-wrap gap-2",children:S.map(T=>a.jsxs("button",{onClick:()=>m(T.id),className:"px-3 py-1.5 bg-bambu-dark-tertiary hover:bg-bambu-green/20 rounded-lg text-sm text-white transition-colors flex items-center gap-2",children:[a.jsx(xc,{className:"w-3 h-3"}),T.title]},T.id))})]}),a.jsx(Ire,{sensors:h,collisionDetection:Mre,onDragEnd:p,children:a.jsx(Bre,{items:b.map(T=>T.id),strategy:fF,children:a.jsx("div",{className:"grid gap-6",style:{gridTemplateColumns:`repeat(${n}, minmax(0, 1fr))`},children:b.map(T=>a.jsx(fKe,{id:T.id,title:T.title,component:T.component,isHidden:l.hidden.includes(T.id),size:l.sizes[T.id]||2,onToggleVisibility:()=>m(T.id),onToggleSize:()=>x(T.id)},T.id))})})}),b.length===0&&a.jsxs("div",{className:"text-center py-12 text-bambu-gray",children:[a.jsx("p",{children:"All widgets are hidden."}),a.jsx(Te,{className:"mt-4",onClick:y,children:"Reset Layout"})]})]})}function pKe({stats:t,currency:e,t:n}){return a.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-3 gap-4",children:[a.jsxs("div",{className:"flex items-start gap-3",children:[a.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark text-bambu-green",children:a.jsx(bc,{className:"w-5 h-5"})}),a.jsxs("div",{children:[a.jsx("p",{className:"text-xs text-bambu-gray",children:n("stats.totalPrints")}),a.jsx("p",{className:"text-xl font-bold text-white",children:t?.total_prints||0})]})]}),a.jsxs("div",{className:"flex items-start gap-3",children:[a.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark text-blue-400",children:a.jsx(tr,{className:"w-5 h-5"})}),a.jsxs("div",{children:[a.jsx("p",{className:"text-xs text-bambu-gray",children:n("stats.printTime")}),a.jsxs("p",{className:"text-xl font-bold text-white",children:[t?.total_print_time_hours.toFixed(1)||0,"h"]})]})]}),a.jsxs("div",{className:"flex items-start gap-3",children:[a.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark text-orange-400",children:a.jsx(bc,{className:"w-5 h-5"})}),a.jsxs("div",{children:[a.jsx("p",{className:"text-xs text-bambu-gray",children:n("stats.filamentUsed")}),a.jsxs("p",{className:"text-xl font-bold text-white",children:[((t?.total_filament_grams||0)/1e3).toFixed(2),"kg"]})]})]}),a.jsxs("div",{className:"flex items-start gap-3",children:[a.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark text-green-400",children:a.jsx(mP,{className:"w-5 h-5"})}),a.jsxs("div",{children:[a.jsx("p",{className:"text-xs text-bambu-gray",children:n("stats.filamentCost")}),a.jsxs("p",{className:"text-xl font-bold text-white",children:[e," ",t?.total_cost.toFixed(2)||"0.00"]})]})]}),a.jsxs("div",{className:"flex items-start gap-3",children:[a.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark text-yellow-400",children:a.jsx(_h,{className:"w-5 h-5"})}),a.jsxs("div",{children:[a.jsx("p",{className:"text-xs text-bambu-gray",children:n("stats.energyUsed")}),a.jsxs("p",{className:"text-xl font-bold text-white",children:[t?.total_energy_kwh.toFixed(2)||"0.00"," kWh"]})]})]}),a.jsxs("div",{className:"flex items-start gap-3",children:[a.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark text-yellow-500",children:a.jsx(mP,{className:"w-5 h-5"})}),a.jsxs("div",{children:[a.jsx("p",{className:"text-xs text-bambu-gray",children:n("stats.energyCost")}),a.jsxs("p",{className:"text-xl font-bold text-white",children:[e," ",t?.total_energy_cost.toFixed(2)||"0.00"]})]})]})]})}function gKe({stats:t,printerMap:e,size:n=1,t:r}){const i=t?.total_prints?Math.round(t.successful_prints/t.total_prints*100):0,s=n===1?112:n===2?128:144,o=s/2-8,l=o*2*Math.PI;return a.jsxs("div",{className:"flex items-center gap-6",children:[a.jsxs("div",{className:"relative flex-shrink-0",style:{width:s,height:s},children:[a.jsxs("svg",{className:"w-full h-full -rotate-90",children:[a.jsx("circle",{cx:s/2,cy:s/2,r:o,fill:"none",stroke:"#3d3d3d",strokeWidth:"10"}),a.jsx("circle",{cx:s/2,cy:s/2,r:o,fill:"none",stroke:"#00ae42",strokeWidth:"10",strokeLinecap:"round",strokeDasharray:`${i/100*l} ${l}`})]}),a.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:a.jsxs("span",{className:`font-bold text-white ${n>=2?"text-2xl":"text-xl"}`,children:[i,"%"]})})]}),a.jsxs("div",{className:"flex-1 min-w-0",children:[a.jsxs("div",{className:"space-y-2",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(Ar,{className:"w-4 h-4 text-status-ok flex-shrink-0"}),a.jsx("span",{className:"text-sm text-bambu-gray",children:r("stats.successful")}),a.jsx("span",{className:"text-sm text-white font-medium",children:t?.successful_prints||0})]}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(Ji,{className:"w-4 h-4 text-status-error flex-shrink-0"}),a.jsx("span",{className:"text-sm text-bambu-gray",children:r("stats.failed")}),a.jsx("span",{className:"text-sm text-white font-medium",children:t?.failed_prints||0})]})]}),n>=2&&t?.prints_by_printer&&Object.keys(t.prints_by_printer).length>0&&a.jsxs("div",{className:"mt-4 pt-4 border-t border-bambu-dark-tertiary",children:[a.jsx("p",{className:"text-xs text-bambu-gray font-medium mb-2",children:r("stats.printsByPrinter")}),a.jsx("div",{className:`grid gap-x-6 gap-y-1 ${n===4?"grid-cols-3":"grid-cols-2"}`,style:{width:"fit-content"},children:Object.entries(t.prints_by_printer).map(([c,u])=>a.jsxs("div",{className:"flex items-center gap-3 text-sm",children:[a.jsx("span",{className:"text-bambu-gray truncate max-w-[120px]",children:e.get(c)||`${r("common.printer")} ${c}`}),a.jsx("span",{className:"text-white font-medium",children:u})]},c))})]})]})]})}function xKe({stats:t,printerMap:e,size:n=1,t:r}){const i=t?.average_time_accuracy;if(i==null)return a.jsx("div",{className:"flex items-center justify-center h-full",children:a.jsx("p",{className:"text-bambu-gray text-center py-4",children:r("stats.noTimeAccuracyData")})});const o=(Math.min(150,Math.max(50,i))-50)/100*100,c=(y=>y>=95&&y<=105?"#00ae42":y>105?"#3b82f6":"#f97316")(i),u=i-100,d=n===1?112:n===2?128:144,h=d/2-8,p=h*2*Math.PI,m=n===1?3:n===2?6:999,x=t?.time_accuracy_by_printer?Object.entries(t.time_accuracy_by_printer).slice(0,m):[];return a.jsxs("div",{className:"flex items-center gap-6",children:[a.jsxs("div",{className:"relative flex-shrink-0",style:{width:d,height:d},children:[a.jsxs("svg",{className:"w-full h-full -rotate-90",children:[a.jsx("circle",{cx:d/2,cy:d/2,r:h,fill:"none",stroke:"#3d3d3d",strokeWidth:"10"}),a.jsx("circle",{cx:d/2,cy:d/2,r:h,fill:"none",stroke:c,strokeWidth:"10",strokeLinecap:"round",strokeDasharray:`${o/100*p} ${p}`})]}),a.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center",children:[a.jsxs("span",{className:`font-bold text-white ${n>=2?"text-2xl":"text-xl"}`,children:[i.toFixed(0),"%"]}),a.jsxs("span",{className:`text-xs ${u>=0?"text-blue-400":"text-orange-400"}`,children:[u>=0?"+":"",u.toFixed(0),"%"]})]})]}),a.jsxs("div",{className:"flex-1 min-w-0",children:[a.jsxs("div",{className:"flex items-center gap-2 text-xs text-bambu-gray",children:[a.jsx(LW,{className:"w-3 h-3 flex-shrink-0"}),a.jsx("span",{children:r("stats.perfectEstimate")})]}),x.length>0&&a.jsx("div",{className:`mt-2 ${n===4?"grid grid-cols-3 gap-x-6 gap-y-1":n===2?"grid grid-cols-2 gap-x-6 gap-y-1":"space-y-1"}`,style:{width:"fit-content"},children:x.map(([y,v])=>a.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[a.jsx("span",{className:"text-bambu-gray truncate max-w-[100px]",children:e.get(y)||`${r("common.printer")} ${y}`}),a.jsxs("span",{className:`font-medium ${v>=95&&v<=105?"text-status-ok":v>105?"text-blue-400":"text-status-warning"}`,children:[v.toFixed(0),"%"]})]},y))})]})]})}function bKe({stats:t,size:e=1,t:n}){if(!t?.prints_by_filament_type||Object.keys(t.prints_by_filament_type).length===0)return a.jsx("p",{className:"text-bambu-gray text-center py-4",children:n("stats.noFilamentData")});const r=Object.entries(t.prints_by_filament_type).sort(([,l],[,c])=>c-l),i=e===1?5:e===2?8:999,s=r.slice(0,i),o=r.length>i;return e===4&&s.length>4?a.jsx("div",{className:"grid grid-cols-2 lg:grid-cols-3 gap-4",children:s.map(([l,c])=>{const u=Math.round(c/(t.total_prints||1)*100);return a.jsxs("div",{children:[a.jsxs("div",{className:"flex justify-between text-sm mb-1",children:[a.jsx("span",{className:"text-white truncate max-w-[120px]",children:l}),a.jsx("span",{className:"text-bambu-gray",children:c})]}),a.jsx("div",{className:"h-2 bg-bambu-dark rounded-full",children:a.jsx("div",{className:"h-full bg-bambu-green rounded-full transition-all",style:{width:`${u}%`}})})]},l)})}):a.jsxs("div",{className:"space-y-3",children:[s.map(([l,c])=>{const u=Math.round(c/(t.total_prints||1)*100);return a.jsxs("div",{children:[a.jsxs("div",{className:"flex justify-between text-sm mb-1",children:[a.jsx("span",{className:"text-white",children:l}),a.jsxs("span",{className:"text-bambu-gray",children:[c," ",n("common.prints")]})]}),a.jsx("div",{className:"h-2 bg-bambu-dark rounded-full",children:a.jsx("div",{className:"h-full bg-bambu-green rounded-full transition-all",style:{width:`${u}%`}})})]},l)}),o&&a.jsx("p",{className:"text-xs text-bambu-gray text-center pt-1",children:n("common.more",{count:r.length-i})})]})}function yKe({printDates:t,size:e=2}){const n=e===1?3:e===2?6:12;return a.jsx(uKe,{printDates:t,months:n})}function vKe({stats:t,printerMap:e,t:n}){return!t?.prints_by_printer||Object.keys(t.prints_by_printer).length===0?a.jsx("p",{className:"text-bambu-gray text-center py-4",children:n("stats.noPrinterData")}):a.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:Object.entries(t.prints_by_printer).map(([r,i])=>a.jsxs("div",{className:"flex items-center gap-3 p-3 bg-bambu-dark rounded-lg",children:[a.jsx("div",{className:"p-2 bg-bambu-dark-tertiary rounded-lg",children:a.jsx(Ur,{className:"w-4 h-4 text-bambu-green"})}),a.jsxs("div",{children:[a.jsx("p",{className:"text-white font-medium text-sm",children:e.get(r)||`${n("common.printer")} ${r}`}),a.jsxs("p",{className:"text-xs text-bambu-gray",children:[i," ",n("common.prints")]})]})]},r))})}function wKe({archives:t,currency:e,t:n}){return!t||t.length===0?a.jsx("p",{className:"text-bambu-gray text-center py-4",children:n("stats.noPrintData")}):a.jsx(hKe,{archives:t,currency:e})}function _Ke({size:t=1,t:e}){const{data:n,isLoading:r}=ct({queryKey:["failureAnalysis"],queryFn:()=>ce.getFailureAnalysis({days:30})});if(r)return a.jsx("div",{className:"flex justify-center py-4",children:a.jsx(pt,{className:"w-6 h-6 text-bambu-green animate-spin"})});if(!n||n.total_prints===0)return a.jsx("p",{className:"text-bambu-gray text-center py-4",children:e("stats.noPrintDataLast30Days")});const i=t===1?5:t===2?8:999,s=Object.entries(n.failures_by_reason).sort(([,c],[,u])=>u-c),o=s.slice(0,i),l=s.length>i;return a.jsxs("div",{className:`${t>=2?"flex gap-8":"space-y-4"}`,children:[a.jsxs("div",{className:t>=2?"flex-shrink-0":"",children:[a.jsx("div",{className:"flex items-center gap-4",children:a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(Sn,{className:`w-5 h-5 ${n.failure_rate>20?"text-status-error":n.failure_rate>10?"text-status-warning":"text-status-ok"}`}),a.jsxs("span",{className:`font-bold text-white ${t>=2?"text-3xl":"text-2xl"}`,children:[n.failure_rate.toFixed(1),"%"]})]})}),a.jsx("div",{className:"text-sm text-bambu-gray mt-1",children:e("stats.failedPrintsCount",{failed:n.failed_prints,total:n.total_prints})}),n.trend&&n.trend.length>=2&&a.jsx("div",{className:`${t>=2?"mt-4":"mt-2 pt-2 border-t border-bambu-dark-tertiary"}`,children:a.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[a.jsx(IW,{className:`w-4 h-4 ${n.trend[n.trend.length-1].failure_rate0&&a.jsxs("div",{className:`flex-1 ${t>=2?"border-l border-bambu-dark-tertiary pl-8":"pt-2"}`,children:[a.jsx("p",{className:"text-xs text-bambu-gray font-medium mb-2",children:t>=2?e("stats.failureReasons"):e("stats.topFailureReasons")}),a.jsx("div",{className:`${t===4?"grid grid-cols-2 gap-x-6 gap-y-1":"space-y-1"}`,children:o.map(([c,u])=>a.jsxs("div",{className:"flex items-center justify-between text-sm",children:[a.jsx("span",{className:`text-white truncate ${t===4?"max-w-[200px]":"max-w-[160px]"}`,children:c||e("common.unknown")}),a.jsx("span",{className:"text-bambu-gray ml-2",children:u})]},c))}),l&&a.jsx("p",{className:"text-xs text-bambu-gray mt-2",children:e("common.more",{count:s.length-i})})]})]})}function SKe(){const{t}=On(),{showToast:e}=Hn(),{hasPermission:n}=Ci(),[r,i]=_.useState(!1),[s,o]=_.useState(!1),[l,c]=_.useState(0),[u,d]=_.useState(0),[h,p]=_.useState(!1);_.useEffect(()=>{const A=()=>{try{const I=localStorage.getItem("bambusy-dashboard-layout");if(I){const L=JSON.parse(I);d(L.hidden?.length||0)}}catch{d(0)}};A(),window.addEventListener("storage",A);const D=setInterval(A,500);return()=>{window.removeEventListener("storage",A),clearInterval(D)}},[l]);const{data:m,isLoading:x,refetch:y}=ct({queryKey:["archiveStats"],queryFn:ce.getArchiveStats}),{data:v}=ct({queryKey:["printers"],queryFn:ce.getPrinters}),{data:b}=ct({queryKey:["archives"],queryFn:()=>ce.getArchives(void 0,void 0,1e3,0)}),{data:S}=ct({queryKey:["settings"],queryFn:ce.getSettings}),N=async A=>{o(!1),i(!0);try{const{blob:D,filename:I}=await ce.exportStats({format:A,days:90}),L=URL.createObjectURL(D),U=document.createElement("a");U.href=L,U.download=I,U.click(),URL.revokeObjectURL(L),e(t("stats.exportDownloaded"))}catch{e(t("stats.exportFailed"),"error")}finally{i(!1)}},T=async()=>{p(!0);try{const A=await ce.recalculateCosts();await y(),e(t("stats.recalculatedCosts",{count:A.updated}))}catch{e(t("stats.recalculateFailed"),"error")}finally{p(!1)}},k=S?.currency||"$",C=new Map(v?.map(A=>[String(A.id),A.name])||[]),E=b?.map(A=>A.created_at)||[];if(x)return a.jsx("div",{className:"p-4 md:p-8",children:a.jsx("div",{className:"text-center py-12 text-bambu-gray",children:t("stats.loadingStats")})});const P=[{id:"quick-stats",title:t("stats.quickStats"),component:a.jsx(pKe,{stats:m,currency:k,t}),defaultSize:2},{id:"success-rate",title:t("stats.successRate"),component:A=>a.jsx(gKe,{stats:m,printerMap:C,size:A,t}),defaultSize:1},{id:"time-accuracy",title:t("stats.timeAccuracy"),component:A=>a.jsx(xKe,{stats:m,printerMap:C,size:A,t}),defaultSize:1},{id:"filament-types",title:t("stats.filamentTypes"),component:A=>a.jsx(bKe,{stats:m,size:A,t}),defaultSize:1},{id:"failure-analysis",title:t("stats.failureAnalysis"),component:A=>a.jsx(_Ke,{size:A,t}),defaultSize:1},{id:"print-activity",title:t("stats.printActivity"),component:A=>a.jsx(yKe,{printDates:E,size:A}),defaultSize:2},{id:"prints-by-printer",title:t("stats.printsByPrinter"),component:a.jsx(vKe,{stats:m,printerMap:C,t}),defaultSize:2},{id:"filament-trends",title:t("stats.filamentTrends"),component:a.jsx(wKe,{archives:b||[],currency:k,t}),defaultSize:4}];return a.jsxs("div",{className:"p-4 md:p-8",children:[a.jsxs("div",{className:"flex items-center justify-between mb-6",children:[a.jsxs("div",{children:[a.jsx("h1",{className:"text-2xl font-bold text-white",children:t("stats.title")}),a.jsx("p",{className:"text-bambu-gray",children:t("stats.subtitle")})]}),a.jsxs("div",{className:"flex items-center gap-2",children:[u>0&&a.jsxs(Te,{variant:"secondary",onClick:()=>{window.dispatchEvent(new CustomEvent("toggle-hidden-panel"))},children:[a.jsx(xc,{className:"w-4 h-4"}),t("stats.hiddenCount",{count:u})]}),a.jsxs(Te,{variant:"secondary",onClick:()=>{localStorage.removeItem("bambusy-dashboard-layout"),c(A=>A+1),e(t("stats.layoutReset"))},disabled:!n("settings:update"),title:n("settings:update")?void 0:t("stats.noPermissionResetLayout"),children:[a.jsx(Lh,{className:"w-4 h-4"}),t("stats.resetLayout")]}),a.jsxs(Te,{variant:"secondary",onClick:T,disabled:h||!n("archives:update_all"),title:n("archives:update_all")?t("stats.recalculateCostsHint"):t("stats.noPermissionRecalculate"),children:[h?a.jsx(pt,{className:"w-4 h-4 animate-spin"}):a.jsx(Bce,{className:"w-4 h-4"}),t("stats.recalculateCosts")]}),a.jsxs("div",{className:"relative",children:[a.jsxs(Te,{variant:"secondary",onClick:()=>o(!s),disabled:r,children:[r?a.jsx(pt,{className:"w-4 h-4 animate-spin"}):a.jsx(K1,{className:"w-4 h-4"}),t("stats.exportStats")]}),s&&a.jsxs("div",{className:"absolute right-0 top-full mt-1 w-48 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl z-20",children:[a.jsxs("button",{className:"w-full px-4 py-2 text-left text-white hover:bg-bambu-dark-tertiary transition-colors flex items-center gap-2 rounded-t-lg",onClick:()=>N("csv"),children:[a.jsx(fs,{className:"w-4 h-4"}),t("stats.exportAsCsv")]}),a.jsxs("button",{className:"w-full px-4 py-2 text-left text-white hover:bg-bambu-dark-tertiary transition-colors flex items-center gap-2 rounded-b-lg",onClick:()=>N("xlsx"),children:[a.jsx(K1,{className:"w-4 h-4"}),t("stats.exportAsExcel")]})]})]})]})]}),a.jsx(mKe,{widgets:P,storageKey:"bambusy-dashboard-layout",hideControls:!0},l)]})}function NKe({plug:t,onEdit:e}){const n=sn(),{showToast:r}=Hn(),[i,s]=_.useState(!1),[o,l]=_.useState(!1),[c,u]=_.useState(!1),[d,h]=_.useState(!1),{data:p,isLoading:m}=ct({queryKey:["smart-plug-status",t.id],queryFn:()=>ce.getSmartPlugStatus(t.id),refetchInterval:3e4}),{data:x}=ct({queryKey:["printers"],queryFn:ce.getPrinters}),y=x?.find(A=>A.id===t.printer_id),v=gt({mutationFn:A=>ce.controlSmartPlug(t.id,A),onMutate:async A=>{await n.cancelQueries({queryKey:["smart-plug-status",t.id]});const D=n.getQueryData(["smart-plug-status",t.id]),I=A==="on"?"ON":A==="off"||p?.state==="ON"?"OFF":"ON";return n.setQueryData(["smart-plug-status",t.id],L=>({...L,state:I})),{previousStatus:D}},onError:(A,D,I)=>{I?.previousStatus&&n.setQueryData(["smart-plug-status",t.id],I.previousStatus),r(`Failed to turn ${D} "${t.name}"`,"error")},onSettled:()=>{setTimeout(()=>{n.invalidateQueries({queryKey:["smart-plug-status",t.id]}),n.invalidateQueries({queryKey:["smart-plugs"]})},1e3)}}),b=gt({mutationFn:A=>ce.updateSmartPlug(t.id,A),onSuccess:()=>{n.invalidateQueries({queryKey:["smart-plugs"]}),t.printer_id&&(n.invalidateQueries({queryKey:["smartPlugByPrinter",t.printer_id]}),n.invalidateQueries({queryKey:["scriptPlugsByPrinter",t.printer_id]}))}}),S=gt({mutationFn:()=>ce.deleteSmartPlug(t.id),onSuccess:()=>{n.invalidateQueries({queryKey:["smart-plugs"]}),t.printer_id&&n.invalidateQueries({queryKey:["scriptPlugsByPrinter",t.printer_id]})}}),N=p?.state==="ON",T=t.plug_type==="mqtt"&&p?.energy?.power!==null&&p?.energy?.power!==void 0,k=(p?.reachable??!1)||T,C=v.isPending,P=(()=>{if(t.plug_type!=="tasmota"||!t.ip_address)return null;const A=t.ip_address;return t.username&&t.password?`http://${encodeURIComponent(t.username)}:${encodeURIComponent(t.password)}@${A}/`:`http://${A}/`})();return a.jsxs(a.Fragment,{children:[a.jsx(St,{className:"relative",children:a.jsxs(Nt,{className:"p-4",children:[a.jsxs("div",{className:"flex items-start justify-between gap-2 mb-3",children:[a.jsxs("div",{className:"flex items-center gap-3 min-w-0 flex-1",children:[a.jsx("div",{className:`p-2 rounded-lg flex-shrink-0 ${t.plug_type==="mqtt"?k?"bg-teal-500/20":"bg-red-500/20":k?N?"bg-bambu-green/20":"bg-bambu-dark":"bg-red-500/20"}`,children:t.plug_type==="mqtt"?a.jsx(RR,{className:`w-5 h-5 ${k?"text-teal-400":"text-red-400"}`}):t.plug_type==="homeassistant"?a.jsx(Iy,{className:`w-5 h-5 ${k?N?"text-bambu-green":"text-bambu-gray":"text-red-400"}`}):a.jsx(al,{className:`w-5 h-5 ${k?N?"text-bambu-green":"text-bambu-gray":"text-red-400"}`})}),a.jsxs("div",{className:"min-w-0",children:[a.jsx("h3",{className:"font-medium text-white truncate",children:t.name}),a.jsx("p",{className:"text-sm text-bambu-gray truncate",title:t.plug_type==="mqtt"?t.mqtt_topic??void 0:t.plug_type==="homeassistant"?t.ha_entity_id??void 0:t.ip_address??void 0,children:t.plug_type==="mqtt"?t.mqtt_topic:t.plug_type==="homeassistant"?t.ha_entity_id:t.ip_address})]})]}),a.jsxs("div",{className:"flex flex-col items-end gap-1 flex-shrink-0",children:[m?a.jsx(pt,{className:"w-4 h-4 text-bambu-gray animate-spin"}):t.plug_type==="mqtt"?a.jsxs("div",{className:"flex items-center gap-1.5 text-sm whitespace-nowrap",children:[a.jsx("span",{className:"px-1.5 py-0.5 bg-teal-500/20 text-teal-400 text-[10px] font-medium rounded flex-shrink-0",children:"MQTT"}),k&&a.jsx("span",{className:"text-status-ok",children:"✓"})]}):t.plug_type==="homeassistant"?a.jsxs("div",{className:"flex items-center gap-1 text-sm",children:[a.jsx("span",{className:"px-1 py-0.5 bg-blue-500/20 text-blue-400 text-[10px] font-medium rounded",children:"HA"}),a.jsx("span",{className:k?N?"text-status-ok":"text-bambu-gray":"text-status-error",children:k?p?.state||"?":"Offline"})]}):k?a.jsxs("div",{className:"flex items-center gap-1 text-sm",children:[a.jsx(Mg,{className:"w-4 h-4 text-status-ok"}),a.jsx("span",{className:N?"text-status-ok":"text-bambu-gray",children:p?.state||"Unknown"})]}):a.jsxs("div",{className:"flex items-center gap-1 text-sm text-status-error",children:[a.jsx(lm,{className:"w-4 h-4"}),a.jsx("span",{children:"Offline"})]}),P&&a.jsxs("a",{href:P,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1 px-2 py-0.5 bg-bambu-dark hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white text-xs rounded-full transition-colors",title:"Open plug admin page",children:[a.jsx(Xr,{className:"w-3 h-3"}),"Admin"]})]})]}),y&&a.jsxs("div",{className:"mb-3 px-2 py-1.5 bg-bambu-dark rounded-lg",children:[a.jsx("span",{className:"text-xs text-bambu-gray",children:"Linked to: "}),a.jsx("span",{className:"text-sm text-white",children:y.name})]}),(t.power_alert_enabled||t.schedule_enabled||t.plug_type==="mqtt")&&a.jsxs("div",{className:"flex flex-wrap gap-1.5 mb-3",children:[t.plug_type==="mqtt"&&a.jsxs("span",{className:"flex items-center gap-1 px-2 py-0.5 bg-teal-500/20 text-teal-400 text-xs rounded-full",children:[a.jsx(xc,{className:"w-3 h-3"}),"Monitor Only"]}),t.power_alert_enabled&&a.jsxs("span",{className:"flex items-center gap-1 px-2 py-0.5 bg-yellow-500/20 text-yellow-400 text-xs rounded-full",children:[a.jsx(Sg,{className:"w-3 h-3"}),"Alerts"]}),t.schedule_enabled&&a.jsxs("span",{className:"flex items-center gap-1 px-2 py-0.5 bg-blue-500/20 text-blue-400 text-xs rounded-full",children:[a.jsx(ti,{className:"w-3 h-3"}),t.schedule_on_time&&t.schedule_off_time?`${t.schedule_on_time} - ${t.schedule_off_time}`:t.schedule_on_time?`On ${t.schedule_on_time}`:`Off ${t.schedule_off_time}`]})]}),t.plug_type!=="mqtt"&&a.jsxs("div",{className:"flex gap-2 mb-3",children:[a.jsxs(Te,{size:"sm",variant:N?"primary":"secondary",disabled:!k||C,onClick:()=>l(!0),className:"flex-1",children:[C?a.jsx(pt,{className:"w-4 h-4 animate-spin"}):a.jsx(qu,{className:"w-4 h-4"}),"On"]}),a.jsxs(Te,{size:"sm",variant:N?"secondary":"primary",disabled:!k||C,onClick:()=>u(!0),className:"flex-1",children:[C?a.jsx(pt,{className:"w-4 h-4 animate-spin"}):a.jsx(bM,{className:"w-4 h-4"}),"Off"]})]}),t.plug_type==="mqtt"&&p?.energy&&a.jsxs("div",{className:"flex gap-2 mb-3 px-3 py-2 bg-bambu-dark rounded-lg",children:[p.energy.power!==null&&p.energy.power!==void 0&&a.jsxs("div",{className:"flex-1 text-center",children:[a.jsxs("p",{className:"text-lg font-semibold text-white",children:[Math.round(p.energy.power),"W"]}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Power"})]}),p.energy.today!==null&&p.energy.today!==void 0&&a.jsxs("div",{className:"flex-1 text-center border-l border-bambu-dark-tertiary",children:[a.jsx("p",{className:"text-lg font-semibold text-white",children:p.energy.today.toFixed(2)}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"kWh Today"})]})]}),a.jsxs("button",{onClick:()=>h(!d),className:"w-full flex items-center justify-between py-2 text-sm text-bambu-gray hover:text-white transition-colors",children:[a.jsxs("span",{className:"flex items-center gap-2",children:[a.jsx(vh,{className:"w-4 h-4"}),t.plug_type==="mqtt"?"Settings":"Automation Settings"]}),a.jsx("span",{children:d?"-":"+"})]}),d&&a.jsxs("div",{className:"pt-3 border-t border-bambu-dark-tertiary space-y-4",children:[a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(pM,{className:"w-4 h-4 text-bambu-green"}),a.jsxs("div",{children:[a.jsx("p",{className:"text-sm text-white",children:"Show in Switchbar"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Quick access from sidebar"})]})]}),a.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:t.show_in_switchbar,onChange:A=>b.mutate({show_in_switchbar:A.target.checked}),className:"sr-only peer"}),a.jsx("div",{className:"w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green"})]})]}),t.plug_type!=="mqtt"&&a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-sm text-white",children:"Enabled"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Enable automation for this plug"})]}),a.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:t.enabled,onChange:A=>b.mutate({enabled:A.target.checked}),className:"sr-only peer"}),a.jsx("div",{className:"w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green"})]})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-sm text-white",children:"Auto On"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Turn on when print starts"})]}),a.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:t.auto_on,onChange:A=>b.mutate({auto_on:A.target.checked}),className:"sr-only peer"}),a.jsx("div",{className:"w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green"})]})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-sm text-white",children:"Auto Off"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Turn off when print completes (one-shot)"})]}),a.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:t.auto_off,onChange:A=>b.mutate({auto_off:A.target.checked}),className:"sr-only peer"}),a.jsx("div",{className:"w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green"})]})]}),t.auto_off&&a.jsxs("div",{className:"space-y-3 pl-4 border-l-2 border-bambu-dark-tertiary",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-sm text-white mb-2",children:"Turn Off Delay Mode"}),a.jsxs("div",{className:"flex gap-2",children:[a.jsxs("button",{onClick:()=>b.mutate({off_delay_mode:"time"}),className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 rounded-lg text-sm transition-colors ${t.off_delay_mode==="time"?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white"}`,children:[a.jsx(tr,{className:"w-4 h-4"}),"Time"]}),a.jsxs("button",{onClick:()=>b.mutate({off_delay_mode:"temperature"}),className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 rounded-lg text-sm transition-colors ${t.off_delay_mode==="temperature"?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white"}`,children:[a.jsx(vM,{className:"w-4 h-4"}),"Temp"]})]})]}),t.off_delay_mode==="time"?a.jsxs("div",{children:[a.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Delay (minutes)"}),a.jsx("input",{type:"number",min:"1",max:"60",value:t.off_delay_minutes,onChange:A=>b.mutate({off_delay_minutes:parseInt(A.target.value)||5}),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"})]}):a.jsxs("div",{children:[a.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Temperature threshold (C)"}),a.jsx("input",{type:"number",min:"30",max:"100",value:t.off_temp_threshold,onChange:A=>b.mutate({off_temp_threshold:parseInt(A.target.value)||70}),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"}),a.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Turns off when nozzle cools below this temperature"})]})]})]}),a.jsxs("div",{className:"flex gap-2 pt-2",children:[a.jsxs(Te,{size:"sm",variant:"secondary",onClick:()=>e(t),className:"flex-1",children:[a.jsx(mg,{className:"w-4 h-4"}),"Edit"]}),a.jsx(Te,{size:"sm",variant:"secondary",onClick:()=>s(!0),className:"text-red-400 hover:text-red-300",children:a.jsx(an,{className:"w-4 h-4"})})]})]})]})}),i&&a.jsx(Zn,{title:"Delete Smart Plug",message:`Are you sure you want to delete "${t.name}"? This cannot be undone.`,confirmText:"Delete",variant:"danger",onConfirm:()=>{S.mutate(),s(!1)},onCancel:()=>s(!1)}),o&&a.jsx(Zn,{title:"Turn On Smart Plug",message:`Are you sure you want to turn on "${t.name}"?`,confirmText:"Turn On",variant:"default",onConfirm:()=>{v.mutate("on"),l(!1)},onCancel:()=>l(!1)}),c&&a.jsx(Zn,{title:"Turn Off Smart Plug",message:`Are you sure you want to turn off "${t.name}"? This will cut power to the connected device.`,confirmText:"Turn Off",variant:"danger",onConfirm:()=>{v.mutate("off"),u(!1)},onCancel:()=>u(!1)})]})}function MKe({plug:t,onClose:e}){const n=sn(),r=!!t,[i,s]=_.useState(t?.plug_type||"tasmota"),[o,l]=_.useState(t?.name||""),[c,u]=_.useState(t?.ip_address||""),[d,h]=_.useState(t?.username||""),[p,m]=_.useState(t?.password||""),[x,y]=_.useState(t?.ha_entity_id||""),[v,b]=_.useState(t?.mqtt_power_topic||t?.mqtt_topic||""),[S,N]=_.useState(t?.mqtt_power_path||""),[T,k]=_.useState((t?.mqtt_power_multiplier??t?.mqtt_multiplier??1).toString()),[C,E]=_.useState(t?.mqtt_energy_topic||""),[P,A]=_.useState(t?.mqtt_energy_path||""),[D,I]=_.useState((t?.mqtt_energy_multiplier??1).toString()),[L,U]=_.useState(t?.mqtt_state_topic||""),[j,$]=_.useState(t?.mqtt_state_path||""),[K,B]=_.useState(t?.mqtt_state_on_value||""),[X,Y]=_.useState(t?.ha_power_entity||""),[ne,H]=_.useState(t?.ha_energy_today_entity||""),[W,re]=_.useState(t?.ha_energy_total_entity||""),[ie,pe]=_.useState(""),[me,de]=_.useState(""),[Ee,se]=_.useState(!1),Ae=_.useRef(null),[Fe,ge]=_.useState(""),[Ze,G]=_.useState(!1),Q=_.useRef(null),[he,q]=_.useState(""),[ee,V]=_.useState(!1),ye=_.useRef(null),[je,te]=_.useState(""),[z,O]=_.useState(!1),Z=_.useRef(null),[oe,we]=_.useState(t?.printer_id||null),[_e,ae]=_.useState(null),[Le,Be]=_.useState(null),[Ve,He]=_.useState(t?.power_alert_enabled||!1),[xe,Pe]=_.useState(t?.power_alert_high?.toString()||""),[Ie,Se]=_.useState(t?.power_alert_low?.toString()||""),[Ke,Me]=_.useState(t?.schedule_enabled||!1),[it,ke]=_.useState(t?.schedule_on_time||""),[Xe,ze]=_.useState(t?.schedule_off_time||""),[ue,$e]=_.useState(t?.show_in_switchbar||!1),[be,Je]=_.useState(t?.show_on_printer_card??!0),[at,jt]=_.useState(!1),[Dt,yn]=_.useState({scanned:0,total:0}),[cn,rr]=_.useState([]),Vn=_.useRef(null),{data:Jn}=ct({queryKey:["printers"],queryFn:ce.getPrinters}),{data:xn}=ct({queryKey:["smart-plugs"],queryFn:ce.getSmartPlugs}),{data:sr}=ct({queryKey:["settings"],queryFn:ce.getSettings}),Gn=!!(sr?.ha_enabled&&sr?.ha_url&&sr?.ha_token);_.useEffect(()=>{const Ne=setTimeout(()=>{de(ie)},300);return()=>clearTimeout(Ne)},[ie]),_.useEffect(()=>{const Ne=Oe=>{Ae.current&&!Ae.current.contains(Oe.target)&&se(!1),Q.current&&!Q.current.contains(Oe.target)&&G(!1),ye.current&&!ye.current.contains(Oe.target)&&V(!1),Z.current&&!Z.current.contains(Oe.target)&&O(!1)};return document.addEventListener("mousedown",Ne),()=>document.removeEventListener("mousedown",Ne)},[]);const{data:Xn,isLoading:Nn,error:hi}=ct({queryKey:["ha-entities",me],queryFn:()=>ce.getHAEntities(me||void 0),enabled:i==="homeassistant"&&Gn,retry:!1,staleTime:0}),{data:ai}=ct({queryKey:["ha-sensor-entities"],queryFn:ce.getHASensorEntities,enabled:i==="homeassistant"&&Gn,retry:!1,staleTime:0});_.useEffect(()=>{const Ne=Oe=>{Oe.key==="Escape"&&e()};return window.addEventListener("keydown",Ne),()=>{window.removeEventListener("keydown",Ne),Vn.current&&clearInterval(Vn.current)}},[e]);const Ce=async()=>{jt(!0),rr([]),yn({scanned:0,total:0}),Be(null);try{await ce.startTasmotaScan();const Ne=async()=>{try{const Oe=await ce.getTasmotaScanStatus();yn({scanned:Oe.scanned,total:Oe.total});const nt=await ce.getDiscoveredTasmotaDevices();rr(nt),Oe.running||(jt(!1),Vn.current&&(clearInterval(Vn.current),Vn.current=null))}catch(Oe){console.error("Polling error:",Oe)}};await Ne(),Vn.current=setInterval(Ne,500)}catch(Ne){jt(!1);const Oe=Ne instanceof Error?Ne.message:typeof Ne=="string"?Ne:JSON.stringify(Ne);Be(Oe||"Failed to start scan")}},tt=async()=>{try{await ce.stopTasmotaScan()}catch{}jt(!1),Vn.current&&(clearInterval(Vn.current),Vn.current=null)},dt=Ne=>{u(Ne.ip_address),l(Ne.name),ae(null)},ht=gt({mutationFn:()=>ce.testSmartPlugConnection(c,d||null,p||null),onSuccess:Ne=>{ae(Ne),Be(null),!o&&Ne.device_name&&l(Ne.device_name)},onError:Ne=>{ae(null),Be(Ne.message)}}),ut=gt({mutationFn:Ne=>ce.createSmartPlug(Ne),onSuccess:()=>{n.invalidateQueries({queryKey:["smart-plugs"]}),n.invalidateQueries({queryKey:["scriptPlugsByPrinter"]}),e()},onError:Ne=>{Be(Ne.message)}}),Et=gt({mutationFn:Ne=>ce.updateSmartPlug(t.id,Ne),onSuccess:()=>{n.invalidateQueries({queryKey:["smart-plugs"]}),n.invalidateQueries({queryKey:["scriptPlugsByPrinter"]}),e()},onError:Ne=>{Be(Ne.message)}}),fe=Jn?.filter(Ne=>i==="tasmota"?!xn?.some(nt=>nt.printer_id===Ne.id&&nt.id!==t?.id&&nt.plug_type==="tasmota"):!0),Re=Ne=>{if(Ne.preventDefault(),Be(null),!o.trim()){Be("Name is required");return}if(i==="tasmota"&&!c.trim()){Be("IP address is required for Tasmota plugs");return}if(i==="homeassistant"&&!x){Be("Entity is required for Home Assistant plugs");return}if(i==="mqtt"){const nt=v.trim(),Ye=C.trim(),Tt=L.trim();if(!nt&&!Ye&&!Tt){Be("At least one MQTT topic must be configured for power, energy, or state monitoring");return}}const Oe={name:o.trim(),plug_type:i,ip_address:i==="tasmota"?c.trim():null,ha_entity_id:i==="homeassistant"?x:null,ha_power_entity:i==="homeassistant"&&X||null,ha_energy_today_entity:i==="homeassistant"&&ne||null,ha_energy_total_entity:i==="homeassistant"&&W||null,mqtt_power_topic:i==="mqtt"&&v.trim()||null,mqtt_power_path:i==="mqtt"&&S.trim()||null,mqtt_power_multiplier:i==="mqtt"&&parseFloat(T)||1,mqtt_energy_topic:i==="mqtt"&&C.trim()||null,mqtt_energy_path:i==="mqtt"&&P.trim()||null,mqtt_energy_multiplier:i==="mqtt"&&parseFloat(D)||1,mqtt_state_topic:i==="mqtt"&&L.trim()||null,mqtt_state_path:i==="mqtt"&&j.trim()||null,mqtt_state_on_value:i==="mqtt"&&K.trim()||null,username:i==="tasmota"&&d.trim()||null,password:i==="tasmota"&&p.trim()||null,printer_id:oe,power_alert_enabled:Ve,power_alert_high:xe?parseFloat(xe):null,power_alert_low:Ie?parseFloat(Ie):null,schedule_enabled:Ke,schedule_on_time:it||null,schedule_off_time:Xe||null,show_in_switchbar:ue,show_on_printer_card:be};r?Et.mutate(Oe):ut.mutate(Oe)},Ge=ut.isPending||Et.isPending;return a.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",onClick:e,children:a.jsxs("div",{className:"bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-md max-h-[90vh] flex flex-col",onClick:Ne=>Ne.stopPropagation(),children:[a.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary flex-shrink-0",children:[a.jsx("h2",{className:"text-lg font-semibold text-white",children:r?"Edit Smart Plug":"Add Smart Plug"}),a.jsx("button",{onClick:e,className:"text-bambu-gray hover:text-white transition-colors",children:a.jsx(Lt,{className:"w-5 h-5"})})]}),a.jsxs("form",{onSubmit:Re,className:"p-6 space-y-4 overflow-y-auto",children:[Le&&a.jsx("div",{className:"p-3 bg-red-500/20 border border-red-500/50 rounded-lg text-sm text-red-400",children:Le}),!r&&a.jsxs("div",{className:"flex gap-2 mb-2",children:[a.jsxs("button",{type:"button",onClick:()=>{s("tasmota"),ae(null),Be(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2.5 rounded-lg font-medium transition-colors ${i==="tasmota"?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white border border-bambu-dark-tertiary"}`,children:[a.jsx(al,{className:"w-4 h-4"}),"Tasmota"]}),a.jsxs("button",{type:"button",onClick:()=>{s("homeassistant"),ae(null),Be(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2.5 rounded-lg font-medium transition-colors ${i==="homeassistant"?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white border border-bambu-dark-tertiary"}`,children:[a.jsx(Iy,{className:"w-4 h-4"}),"HA"]}),a.jsxs("button",{type:"button",onClick:()=>{s("mqtt"),ae(null),Be(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2.5 rounded-lg font-medium transition-colors ${i==="mqtt"?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white border border-bambu-dark-tertiary"}`,children:[a.jsx(RR,{className:"w-4 h-4"}),"MQTT"]})]}),!r&&i==="tasmota"&&a.jsxs("div",{className:"space-y-3",children:[at?a.jsxs(Te,{type:"button",variant:"secondary",onClick:tt,className:"w-full",children:[a.jsx(Lt,{className:"w-4 h-4"}),"Stop Scanning"]}):a.jsxs(Te,{type:"button",variant:"primary",onClick:Ce,className:"w-full",children:[a.jsx(wa,{className:"w-4 h-4"}),"Discover Tasmota Devices"]}),at&&Dt.total>0&&a.jsxs("div",{className:"space-y-1",children:[a.jsxs("div",{className:"flex justify-between text-xs text-bambu-gray",children:[a.jsx("span",{children:"Scanning network..."}),a.jsxs("span",{children:[Dt.scanned," / ",Dt.total]})]}),a.jsx("div",{className:"w-full bg-bambu-dark-tertiary rounded-full h-2",children:a.jsx("div",{className:"bg-bambu-green h-2 rounded-full transition-all duration-300",style:{width:`${Dt.scanned/Dt.total*100}%`}})})]}),cn.length>0&&a.jsxs("div",{className:"space-y-2",children:[a.jsxs("p",{className:"text-xs text-bambu-gray",children:["Found ",cn.length," device(s) - click to select:"]}),a.jsx("div",{className:"max-h-40 overflow-y-auto space-y-1",children:cn.map(Ne=>a.jsxs("button",{type:"button",onClick:()=>dt(Ne),className:"w-full flex items-center justify-between p-2 bg-bambu-dark hover:bg-bambu-dark-tertiary rounded-lg transition-colors text-left border border-bambu-dark-tertiary",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(al,{className:"w-4 h-4 text-bambu-green"}),a.jsxs("div",{children:[a.jsx("p",{className:"text-sm text-white",children:Ne.name}),a.jsx("p",{className:"text-xs text-bambu-gray",children:Ne.ip_address})]})]}),Ne.state&&a.jsxs("span",{className:`flex items-center gap-1 text-xs ${Ne.state==="ON"?"text-bambu-green":"text-bambu-gray"}`,children:[a.jsx(qu,{className:"w-3 h-3"}),Ne.state]})]},Ne.ip_address))})]}),!at&&cn.length===0&&Dt.total>0&&a.jsx("p",{className:"text-xs text-bambu-gray text-center py-2",children:"No Tasmota devices found on your network"})]}),i==="homeassistant"&&a.jsxs("div",{className:"space-y-3",children:[!Gn&&a.jsxs("div",{className:"space-y-3",children:[a.jsxs("div",{className:"p-3 bg-yellow-500/20 border border-yellow-500/50 rounded-lg text-sm text-yellow-400",children:["Home Assistant is not configured. Set it up in"," ",a.jsx("span",{className:"font-medium",children:"Settings → Network → Home Assistant"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1 opacity-50",children:"Select Entity *"}),a.jsx("select",{disabled:!0,className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray cursor-not-allowed opacity-50",children:a.jsx("option",{children:"Choose an entity..."})})]})]}),Gn&&a.jsxs(a.Fragment,{children:[Nn&&a.jsxs("div",{className:"flex items-center justify-center py-4 text-bambu-gray",children:[a.jsx(pt,{className:"w-5 h-5 animate-spin mr-2"}),"Loading entities..."]}),hi&&a.jsxs("div",{className:"p-3 bg-red-500/20 border border-red-500/50 rounded-lg text-sm text-red-400",children:["Failed to load entities: ",hi.message]}),(()=>{const Ne=xn?.filter(Ye=>Ye.ha_entity_id&&Ye.id!==t?.id).map(Ye=>Ye.ha_entity_id)||[],Oe=(Xn||[]).filter(Ye=>!Ne.includes(Ye.entity_id)),nt=Xn?.find(Ye=>Ye.entity_id===x);return a.jsxs("div",{ref:Ae,className:"relative",children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Select Entity *"}),a.jsxs("div",{className:"relative",children:[a.jsx(wa,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"}),a.jsx("input",{type:"text",value:Ee?ie:nt?`${nt.friendly_name} (${nt.entity_id})`:"",onChange:Ye=>{pe(Ye.target.value),Ee||se(!0)},onFocus:()=>{se(!0),pe("")},placeholder:"Search entities...",className:"w-full pl-9 pr-8 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none"}),x&&!Ee&&a.jsx("button",{type:"button",onClick:()=>{y(""),pe("")},className:"absolute right-2 top-1/2 -translate-y-1/2 p-1 hover:bg-bambu-dark-tertiary rounded",children:a.jsx(Lt,{className:"w-4 h-4 text-bambu-gray hover:text-white"})}),Nn&&a.jsx(pt,{className:"absolute right-2 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray animate-spin"})]}),Ee&&a.jsxs("div",{className:"absolute z-50 w-full mt-1 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-60 overflow-y-auto",children:[Nn&&a.jsxs("div",{className:"px-3 py-2 text-sm text-bambu-gray flex items-center gap-2",children:[a.jsx(pt,{className:"w-4 h-4 animate-spin"}),"Loading..."]}),!Nn&&Oe.length===0&&a.jsx("div",{className:"px-3 py-2 text-sm text-bambu-gray",children:me?`No entities found matching "${me}"`:"No entities available"}),!Nn&&Oe.map(Ye=>a.jsxs("button",{type:"button",onClick:()=>{y(Ye.entity_id),se(!1),pe(""),o||l(Ye.friendly_name)},className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary transition-colors ${Ye.entity_id===x?"bg-bambu-green/20 text-bambu-green":"text-white"}`,children:[a.jsx("div",{className:"font-medium",children:Ye.friendly_name}),a.jsxs("div",{className:"text-xs text-bambu-gray flex items-center justify-between",children:[a.jsx("span",{children:Ye.entity_id}),a.jsx("span",{className:Ye.state==="on"?"text-bambu-green":"",children:Ye.state})]})]},Ye.entity_id))]}),a.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:me?`Searching all entities (${Oe.length} found)`:`Showing switch, light, input_boolean (${Oe.length} available)`})]})})(),x&&ai&&ai.length>0&&a.jsxs("div",{className:"border-t border-bambu-dark-tertiary pt-4 mt-4 space-y-3",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-white font-medium mb-1",children:"Energy Monitoring (Optional)"}),a.jsx("p",{className:"text-xs text-bambu-gray mb-3",children:"Search and select sensors that provide power/energy data."})]}),(()=>{const Ne=ai.filter(Ye=>Ye.unit_of_measurement==="W"||Ye.unit_of_measurement==="kW"||Ye.unit_of_measurement==="mW"),Oe=Fe?Ne.filter(Ye=>Ye.entity_id.toLowerCase().includes(Fe.toLowerCase())||Ye.friendly_name.toLowerCase().includes(Fe.toLowerCase())):Ne,nt=ai.find(Ye=>Ye.entity_id===X);return a.jsxs("div",{ref:Q,className:"relative",children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Power Sensor (W)"}),a.jsxs("div",{className:"relative",children:[a.jsx(wa,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"}),a.jsx("input",{type:"text",value:Ze?Fe:nt?`${nt.friendly_name} (${nt.state} ${nt.unit_of_measurement})`:"",onChange:Ye=>{ge(Ye.target.value),Ze||G(!0)},onFocus:()=>{G(!0),ge("")},placeholder:"Search power sensors...",className:"w-full pl-9 pr-8 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none"}),X&&!Ze&&a.jsx("button",{type:"button",onClick:()=>{Y(""),ge("")},className:"absolute right-2 top-1/2 -translate-y-1/2 p-1 hover:bg-bambu-dark-tertiary rounded",children:a.jsx(Lt,{className:"w-4 h-4 text-bambu-gray hover:text-white"})})]}),Ze&&a.jsxs("div",{className:"absolute z-50 w-full mt-1 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-48 overflow-y-auto",children:[a.jsx("button",{type:"button",onClick:()=>{Y(""),G(!1),ge("")},className:"w-full px-3 py-2 text-left text-sm text-bambu-gray hover:bg-bambu-dark-tertiary",children:"None"}),Oe.map(Ye=>a.jsxs("button",{type:"button",onClick:()=>{Y(Ye.entity_id),G(!1),ge("")},className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary ${Ye.entity_id===X?"bg-bambu-green/20 text-bambu-green":"text-white"}`,children:[a.jsx("div",{className:"font-medium",children:Ye.friendly_name}),a.jsxs("div",{className:"text-xs text-bambu-gray",children:[Ye.entity_id," • ",Ye.state," ",Ye.unit_of_measurement]})]},Ye.entity_id)),Oe.length===0&&a.jsx("div",{className:"px-3 py-2 text-sm text-bambu-gray",children:"No matching sensors"})]})]})})(),(()=>{const Ne=ai.filter(Ye=>Ye.unit_of_measurement==="kWh"||Ye.unit_of_measurement==="Wh"||Ye.unit_of_measurement==="MWh"),Oe=he?Ne.filter(Ye=>Ye.entity_id.toLowerCase().includes(he.toLowerCase())||Ye.friendly_name.toLowerCase().includes(he.toLowerCase())):Ne,nt=ai.find(Ye=>Ye.entity_id===ne);return a.jsxs("div",{ref:ye,className:"relative",children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Energy Today (kWh)"}),a.jsxs("div",{className:"relative",children:[a.jsx(wa,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"}),a.jsx("input",{type:"text",value:ee?he:nt?`${nt.friendly_name} (${nt.state} ${nt.unit_of_measurement})`:"",onChange:Ye=>{q(Ye.target.value),ee||V(!0)},onFocus:()=>{V(!0),q("")},placeholder:"Search energy sensors...",className:"w-full pl-9 pr-8 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none"}),ne&&!ee&&a.jsx("button",{type:"button",onClick:()=>{H(""),q("")},className:"absolute right-2 top-1/2 -translate-y-1/2 p-1 hover:bg-bambu-dark-tertiary rounded",children:a.jsx(Lt,{className:"w-4 h-4 text-bambu-gray hover:text-white"})})]}),ee&&a.jsxs("div",{className:"absolute z-50 w-full mt-1 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-48 overflow-y-auto",children:[a.jsx("button",{type:"button",onClick:()=>{H(""),V(!1),q("")},className:"w-full px-3 py-2 text-left text-sm text-bambu-gray hover:bg-bambu-dark-tertiary",children:"None"}),Oe.map(Ye=>a.jsxs("button",{type:"button",onClick:()=>{H(Ye.entity_id),V(!1),q("")},className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary ${Ye.entity_id===ne?"bg-bambu-green/20 text-bambu-green":"text-white"}`,children:[a.jsx("div",{className:"font-medium",children:Ye.friendly_name}),a.jsxs("div",{className:"text-xs text-bambu-gray",children:[Ye.entity_id," • ",Ye.state," ",Ye.unit_of_measurement]})]},Ye.entity_id)),Oe.length===0&&a.jsx("div",{className:"px-3 py-2 text-sm text-bambu-gray",children:"No matching sensors"})]})]})})(),(()=>{const Ne=ai.filter(Ye=>Ye.unit_of_measurement==="kWh"||Ye.unit_of_measurement==="Wh"||Ye.unit_of_measurement==="MWh"),Oe=je?Ne.filter(Ye=>Ye.entity_id.toLowerCase().includes(je.toLowerCase())||Ye.friendly_name.toLowerCase().includes(je.toLowerCase())):Ne,nt=ai.find(Ye=>Ye.entity_id===W);return a.jsxs("div",{ref:Z,className:"relative",children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Total Energy (kWh)"}),a.jsxs("div",{className:"relative",children:[a.jsx(wa,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"}),a.jsx("input",{type:"text",value:z?je:nt?`${nt.friendly_name} (${nt.state} ${nt.unit_of_measurement})`:"",onChange:Ye=>{te(Ye.target.value),z||O(!0)},onFocus:()=>{O(!0),te("")},placeholder:"Search energy sensors...",className:"w-full pl-9 pr-8 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none"}),W&&!z&&a.jsx("button",{type:"button",onClick:()=>{re(""),te("")},className:"absolute right-2 top-1/2 -translate-y-1/2 p-1 hover:bg-bambu-dark-tertiary rounded",children:a.jsx(Lt,{className:"w-4 h-4 text-bambu-gray hover:text-white"})})]}),z&&a.jsxs("div",{className:"absolute z-50 w-full mt-1 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-48 overflow-y-auto",children:[a.jsx("button",{type:"button",onClick:()=>{re(""),O(!1),te("")},className:"w-full px-3 py-2 text-left text-sm text-bambu-gray hover:bg-bambu-dark-tertiary",children:"None"}),Oe.map(Ye=>a.jsxs("button",{type:"button",onClick:()=>{re(Ye.entity_id),O(!1),te("")},className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary ${Ye.entity_id===W?"bg-bambu-green/20 text-bambu-green":"text-white"}`,children:[a.jsx("div",{className:"font-medium",children:Ye.friendly_name}),a.jsxs("div",{className:"text-xs text-bambu-gray",children:[Ye.entity_id," • ",Ye.state," ",Ye.unit_of_measurement]})]},Ye.entity_id)),Oe.length===0&&a.jsx("div",{className:"px-3 py-2 text-sm text-bambu-gray",children:"No matching sensors"})]})]})})()]})]})]}),i==="mqtt"&&a.jsxs("div",{className:"space-y-3",children:[!sr?.mqtt_broker&&a.jsxs("div",{className:"p-3 bg-yellow-500/20 border border-yellow-500/50 rounded-lg text-sm text-yellow-400",children:["MQTT broker not configured. Set broker address in"," ",a.jsx("span",{className:"font-medium",children:"Settings → Network → MQTT Publishing"})," ","(you don't need to enable publishing, just fill in the broker details)."]}),sr?.mqtt_broker&&a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:"p-3 bg-blue-500/10 border border-blue-500/30 rounded-lg text-sm text-blue-300",children:[a.jsx("p",{className:"font-medium mb-1",children:"Monitor Only"}),a.jsx("p",{className:"text-xs opacity-80",children:"MQTT plugs receive power/energy data via MQTT subscription. On/off control is not available - use your MQTT broker or home automation system."})]}),a.jsxs("div",{className:"space-y-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary",children:[a.jsx("p",{className:"text-white font-medium text-sm",children:"Power Monitoring"}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Topic"}),a.jsx("input",{type:"text",value:v,onChange:Ne=>b(Ne.target.value),placeholder:"zigbee2mqtt/shelly-working-room",className:"w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none"})]}),a.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"JSON Path"}),a.jsx("input",{type:"text",value:S,onChange:Ne=>N(Ne.target.value),placeholder:"power_l1",className:"w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Multiplier"}),a.jsx("input",{type:"text",value:T,onChange:Ne=>k(Ne.target.value),placeholder:"1",className:"w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none"})]})]}),a.jsxs("p",{className:"text-xs text-bambu-gray",children:['JSON path extracts value from JSON payload (e.g., "power_l1"). Leave empty if topic publishes raw numeric values.',a.jsx("br",{}),"Use multiplier 0.001 for mW→W, 1000 for kW→W."]})]}),a.jsxs("div",{className:"space-y-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary",children:[a.jsxs("p",{className:"text-white font-medium text-sm",children:["Energy Monitoring ",a.jsx("span",{className:"text-bambu-gray font-normal",children:"(optional)"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Topic"}),a.jsx("input",{type:"text",value:C,onChange:Ne=>E(Ne.target.value),placeholder:"Same as power topic, or different",className:"w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none"})]}),a.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"JSON Path"}),a.jsx("input",{type:"text",value:P,onChange:Ne=>A(Ne.target.value),placeholder:"energy_l1",className:"w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Multiplier"}),a.jsx("input",{type:"text",value:D,onChange:Ne=>I(Ne.target.value),placeholder:"1",className:"w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none"})]})]}),a.jsxs("p",{className:"text-xs text-bambu-gray",children:["JSON path extracts value from JSON payload. Leave empty for raw values.",a.jsx("br",{}),"Use multiplier 0.001 for Wh→kWh, 1000 for MWh→kWh."]})]}),a.jsxs("div",{className:"space-y-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary",children:[a.jsxs("p",{className:"text-white font-medium text-sm",children:["State Monitoring ",a.jsx("span",{className:"text-bambu-gray font-normal",children:"(optional)"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Topic"}),a.jsx("input",{type:"text",value:L,onChange:Ne=>U(Ne.target.value),placeholder:"Same as power topic, or different",className:"w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none"})]}),a.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"JSON Path"}),a.jsx("input",{type:"text",value:j,onChange:Ne=>$(Ne.target.value),placeholder:"state_l1",className:"w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"ON Value"}),a.jsx("input",{type:"text",value:K,onChange:Ne=>B(Ne.target.value),placeholder:"ON, true, 1",className:"w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none"})]})]}),a.jsxs("p",{className:"text-xs text-bambu-gray",children:["JSON path extracts value from JSON payload. Leave empty for raw values.",a.jsx("br",{}),'ON value: the exact string that means "ON". Leave empty for auto-detect (ON, true, 1).']})]})]})]}),i==="tasmota"&&a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"IP Address *"}),a.jsxs("div",{className:"flex gap-2",children:[a.jsx("input",{type:"text",value:c,onChange:Ne=>{u(Ne.target.value),ae(null)},placeholder:"192.168.1.100",className:"flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"}),a.jsxs(Te,{type:"button",variant:"secondary",onClick:()=>ht.mutate(),disabled:!c.trim()||ht.isPending,children:[ht.isPending?a.jsx(pt,{className:"w-4 h-4 animate-spin"}):a.jsx(Mg,{className:"w-4 h-4"}),"Test"]})]})]}),i==="tasmota"&&_e&&a.jsx("div",{className:`p-3 rounded-lg flex items-center gap-2 ${_e.success?"bg-bambu-green/20 border border-bambu-green/50 text-bambu-green":"bg-red-500/20 border border-red-500/50 text-red-400"}`,children:_e.success?a.jsxs(a.Fragment,{children:[a.jsx(Ar,{className:"w-5 h-5"}),a.jsxs("div",{children:[a.jsx("p",{className:"font-medium",children:"Connected!"}),a.jsxs("p",{className:"text-sm opacity-80",children:[_e.device_name&&`Device: ${_e.device_name} - `,"State: ",_e.state]})]})]}):a.jsxs(a.Fragment,{children:[a.jsx(lm,{className:"w-5 h-5"}),a.jsx("span",{children:"Connection failed"})]})}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Name *"}),a.jsx("input",{type:"text",value:o,onChange:Ne=>l(Ne.target.value),placeholder:"Living Room Plug",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"})]}),i==="tasmota"&&a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Username"}),a.jsx("input",{type:"text",value:d,onChange:Ne=>h(Ne.target.value),placeholder:"admin",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"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Password"}),a.jsx("input",{type:"password",value:p,onChange:Ne=>m(Ne.target.value),placeholder:"********",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"})]})]}),a.jsx("p",{className:"text-xs text-bambu-gray -mt-2",children:"Leave empty if your Tasmota device doesn't require authentication"})]}),i!=="mqtt"&&a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Link to Printer"}),a.jsxs("select",{value:oe??"",onChange:Ne=>we(Ne.target.value?Number(Ne.target.value):null),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[a.jsx("option",{value:"",children:"No printer (manual control only)"}),fe?.map(Ne=>a.jsx("option",{value:Ne.id,children:Ne.name},Ne.id))]}),a.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Linking enables automatic on/off when prints start/complete"})]}),a.jsxs("div",{className:"border-t border-bambu-dark-tertiary pt-4",children:[a.jsxs("div",{className:"flex items-center justify-between mb-3",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(Sg,{className:"w-4 h-4 text-bambu-green"}),a.jsx("span",{className:"text-white font-medium",children:"Power Alerts"})]}),a.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:Ve,onChange:Ne=>He(Ne.target.checked),className:"sr-only peer"}),a.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]}),Ve&&a.jsxs("div",{className:"space-y-3",children:[a.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Alert if above (W)"}),a.jsx("input",{type:"number",value:xe,onChange:Ne=>Pe(Ne.target.value),placeholder:"e.g. 200",min:"0",max:"5000",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"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Alert if below (W)"}),a.jsx("input",{type:"number",value:Ie,onChange:Ne=>Se(Ne.target.value),placeholder:"e.g. 10",min:"0",max:"5000",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"})]})]}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Get notified when power consumption crosses these thresholds. Leave empty to disable that direction."})]})]}),i!=="mqtt"&&a.jsxs("div",{className:"border-t border-bambu-dark-tertiary pt-4",children:[a.jsxs("div",{className:"flex items-center justify-between mb-3",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(tr,{className:"w-4 h-4 text-bambu-green"}),a.jsx("span",{className:"text-white font-medium",children:"Daily Schedule"})]}),a.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:Ke,onChange:Ne=>Me(Ne.target.checked),className:"sr-only peer"}),a.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]}),Ke&&a.jsxs("div",{className:"space-y-3",children:[a.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Turn On at"}),a.jsx("input",{type:"time",value:it,onChange:Ne=>ke(Ne.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"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Turn Off at"}),a.jsx("input",{type:"time",value:Xe,onChange:Ne=>ze(Ne.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"})]})]}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Automatically turn the plug on/off at these times daily. Leave empty to skip that action."})]})]}),a.jsx("div",{className:"border-t border-bambu-dark-tertiary pt-4",children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(pM,{className:"w-4 h-4 text-bambu-green"}),a.jsxs("div",{children:[a.jsx("span",{className:"text-white font-medium",children:"Show in Switchbar"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Quick access from sidebar"})]})]}),a.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:ue,onChange:Ne=>$e(Ne.target.checked),className:"sr-only peer"}),a.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]})}),i==="homeassistant"&&a.jsx("div",{className:"border-t border-bambu-dark-tertiary pt-4",children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(xc,{className:"w-4 h-4 text-bambu-green"}),a.jsxs("div",{children:[a.jsx("span",{className:"text-white font-medium",children:"Show on Printer Card"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Display button on printer card"})]})]}),a.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:be,onChange:Ne=>Je(Ne.target.checked),className:"sr-only peer"}),a.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]})}),a.jsxs("div",{className:"flex gap-3 pt-2",children:[a.jsx(Te,{type:"button",variant:"secondary",onClick:e,className:"flex-1",children:"Cancel"}),a.jsxs(Te,{type:"submit",disabled:Ge,className:"flex-1",children:[Ge?a.jsx(pt,{className:"w-4 h-4 animate-spin"}):a.jsx(ms,{className:"w-4 h-4"}),r?"Save":"Add"]})]})]})]})})}function Fn({checked:t,onChange:e,disabled:n}){const r=i=>{i.preventDefault(),i.stopPropagation(),n||e(!t)};return a.jsx("button",{type:"button",role:"switch","aria-checked":t,disabled:n,onClick:r,className:`relative inline-flex w-11 h-7 md:w-9 md:h-5 rounded-full transition-colors flex-shrink-0 focus:outline-none focus:ring-2 focus:ring-bambu-green focus:ring-offset-2 focus:ring-offset-bambu-dark ${n?"bg-bambu-dark-tertiary/50 cursor-not-allowed opacity-50":t?"bg-bambu-green cursor-pointer":"bg-bambu-dark-tertiary cursor-pointer hover:bg-bambu-dark-tertiary/80"}`,children:a.jsx("span",{className:`pointer-events-none absolute top-[3px] md:top-[2px] left-[3px] md:left-[2px] w-5 h-5 md:w-4 md:h-4 bg-white rounded-full shadow transition-transform duration-200 ease-in-out ${t?"translate-x-4":"translate-x-0"}`})})}const kKe={callmebot:"CallMeBot/WhatsApp",ntfy:"ntfy",pushover:"Pushover",telegram:"Telegram",email:"Email",discord:"Discord",webhook:"Webhook"};function EKe({provider:t,onEdit:e}){const n=sn(),[r,i]=_.useState(!1),[s,o]=_.useState(!1),[l,c]=_.useState(null),{data:u}=ct({queryKey:["printers"],queryFn:ce.getPrinters}),d=u?.find(y=>y.id===t.printer_id),h=gt({mutationFn:y=>ce.updateNotificationProvider(t.id,y),onSuccess:()=>{n.invalidateQueries({queryKey:["notification-providers"]})}}),p=gt({mutationFn:()=>ce.deleteNotificationProvider(t.id),onSuccess:()=>{n.invalidateQueries({queryKey:["notification-providers"]})}}),m=gt({mutationFn:()=>ce.testNotificationProvider(t.id),onSuccess:y=>{c(y),n.invalidateQueries({queryKey:["notification-providers"]})},onError:y=>{c({success:!1,message:y.message})}}),x=y=>y||"";return a.jsxs(a.Fragment,{children:[a.jsx(St,{className:"relative",children:a.jsxs(Nt,{className:"p-4",children:[a.jsxs("div",{className:"flex items-start justify-between mb-3",children:[a.jsxs("div",{className:"flex items-center gap-3",children:[a.jsx("div",{className:`p-2 rounded-lg ${t.enabled?"bg-bambu-green/20":"bg-bambu-dark"}`,children:a.jsx(Sg,{className:`w-5 h-5 ${t.enabled?"text-bambu-green":"text-bambu-gray"}`})}),a.jsxs("div",{children:[a.jsx("h3",{className:"font-medium text-white",children:t.name}),a.jsx("p",{className:"text-sm text-bambu-gray",children:kKe[t.provider_type]||t.provider_type})]})]}),a.jsxs("div",{className:"flex items-center gap-3",children:[t.last_success&&a.jsxs("span",{className:"text-xs text-status-ok hidden sm:inline",children:["Last: ",$g(t.last_success)]}),t.last_error&&t.last_error_at&&(!t.last_success||(zi(t.last_error_at)?.getTime()||0)>(zi(t.last_success)?.getTime()||0))&&a.jsx("span",{className:"text-xs text-status-error",title:t.last_error,children:"Error"}),a.jsx(Fn,{checked:t.enabled,onChange:y=>h.mutate({enabled:y})})]})]}),d&&a.jsxs("div",{className:"mb-3 px-2 py-1.5 bg-bambu-dark rounded-lg",children:[a.jsx("span",{className:"text-xs text-bambu-gray",children:"Printer: "}),a.jsx("span",{className:"text-sm text-white",children:d.name})]}),!d&&!t.printer_id&&a.jsx("div",{className:"mb-3 px-2 py-1.5 bg-bambu-dark rounded-lg",children:a.jsx("span",{className:"text-xs text-bambu-gray",children:"All printers"})}),a.jsxs("div",{className:"mb-3 flex flex-wrap gap-1",children:[t.on_print_start&&a.jsx("span",{className:"px-2 py-0.5 bg-blue-500/20 text-blue-400 text-xs rounded",children:"Start"}),t.on_plate_not_empty&&a.jsx("span",{className:"px-2 py-0.5 bg-rose-600/20 text-rose-300 text-xs rounded",children:"Plate Check"}),t.on_print_complete&&a.jsx("span",{className:"px-2 py-0.5 bg-bambu-green/20 text-bambu-green text-xs rounded",children:"Complete"}),t.on_print_failed&&a.jsx("span",{className:"px-2 py-0.5 bg-red-500/20 text-red-400 text-xs rounded",children:"Failed"}),t.on_print_stopped&&a.jsx("span",{className:"px-2 py-0.5 bg-orange-500/20 text-orange-400 text-xs rounded",children:"Stopped"}),t.on_print_progress&&a.jsx("span",{className:"px-2 py-0.5 bg-yellow-500/20 text-yellow-400 text-xs rounded",children:"Progress"}),t.on_printer_offline&&a.jsx("span",{className:"px-2 py-0.5 bg-gray-500/20 text-gray-400 text-xs rounded",children:"Offline"}),t.on_printer_error&&a.jsx("span",{className:"px-2 py-0.5 bg-rose-500/20 text-rose-400 text-xs rounded",children:"Error"}),t.on_filament_low&&a.jsx("span",{className:"px-2 py-0.5 bg-cyan-500/20 text-cyan-400 text-xs rounded",children:"Low Filament"}),t.on_maintenance_due&&a.jsx("span",{className:"px-2 py-0.5 bg-purple-500/20 text-purple-400 text-xs rounded",children:"Maintenance"}),t.on_ams_humidity_high&&a.jsx("span",{className:"px-2 py-0.5 bg-blue-600/20 text-blue-300 text-xs rounded",children:"AMS Humidity"}),t.on_ams_temperature_high&&a.jsx("span",{className:"px-2 py-0.5 bg-orange-600/20 text-orange-300 text-xs rounded",children:"AMS Temp"}),t.on_ams_ht_humidity_high&&a.jsx("span",{className:"px-2 py-0.5 bg-cyan-600/20 text-cyan-300 text-xs rounded",children:"AMS-HT Humidity"}),t.on_ams_ht_temperature_high&&a.jsx("span",{className:"px-2 py-0.5 bg-amber-600/20 text-amber-300 text-xs rounded",children:"AMS-HT Temp"}),t.quiet_hours_enabled&&a.jsxs("span",{className:"px-2 py-0.5 bg-indigo-500/20 text-indigo-400 text-xs rounded flex items-center gap-1",children:[a.jsx(X1,{className:"w-3 h-3"}),"Quiet"]}),t.daily_digest_enabled&&a.jsxs("span",{className:"px-2 py-0.5 bg-emerald-500/20 text-emerald-400 text-xs rounded flex items-center gap-1",children:[a.jsx(ti,{className:"w-3 h-3"}),"Digest ",t.daily_digest_time]})]}),a.jsx("div",{className:"mb-3",children:a.jsxs(Te,{size:"sm",variant:"secondary",disabled:m.isPending,onClick:()=>{c(null),m.mutate()},className:"w-full",children:[m.isPending?a.jsx(pt,{className:"w-4 h-4 animate-spin"}):a.jsx(OR,{className:"w-4 h-4"}),"Send Test Notification"]})}),l&&a.jsxs("div",{className:`mb-3 p-2 rounded-lg flex items-center gap-2 text-sm ${l.success?"bg-bambu-green/20 text-bambu-green":"bg-red-500/20 text-red-400"}`,children:[l.success?a.jsx(Ar,{className:"w-4 h-4"}):a.jsx(Ji,{className:"w-4 h-4"}),a.jsx("span",{children:l.message})]}),a.jsxs("button",{onClick:()=>o(!s),className:"w-full flex items-center justify-between py-2 text-sm text-bambu-gray hover:text-white transition-colors border-t border-bambu-dark-tertiary",children:[a.jsxs("span",{className:"flex items-center gap-2",children:[a.jsx(vh,{className:"w-4 h-4"}),"Event Settings"]}),s?a.jsx(yh,{className:"w-4 h-4"}):a.jsx(Kr,{className:"w-4 h-4"})]}),s&&a.jsxs("div",{className:"pt-3 border-t border-bambu-dark-tertiary space-y-4",children:[a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-sm text-white",children:"Enabled"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Send notifications from this provider"})]}),a.jsx(Fn,{checked:t.enabled,onChange:y=>h.mutate({enabled:y})})]}),a.jsxs("div",{className:"space-y-2",children:[a.jsx("p",{className:"text-xs text-bambu-gray uppercase tracking-wide",children:"Print Events"}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx("p",{className:"text-sm text-white",children:"Print Started"}),a.jsx(Fn,{checked:t.on_print_start,onChange:y=>h.mutate({on_print_start:y})})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-sm text-white",children:"Plate Not Empty"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Objects detected before print"})]}),a.jsx(Fn,{checked:t.on_plate_not_empty??!0,onChange:y=>h.mutate({on_plate_not_empty:y})})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx("p",{className:"text-sm text-white",children:"Print Completed"}),a.jsx(Fn,{checked:t.on_print_complete,onChange:y=>h.mutate({on_print_complete:y})})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx("p",{className:"text-sm text-white",children:"Print Failed"}),a.jsx(Fn,{checked:t.on_print_failed,onChange:y=>h.mutate({on_print_failed:y})})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx("p",{className:"text-sm text-white",children:"Print Stopped"}),a.jsx(Fn,{checked:t.on_print_stopped,onChange:y=>h.mutate({on_print_stopped:y})})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-sm text-white",children:"Progress Milestones"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Notify at 25%, 50%, 75%"})]}),a.jsx(Fn,{checked:t.on_print_progress,onChange:y=>h.mutate({on_print_progress:y})})]})]}),a.jsxs("div",{className:"space-y-2",children:[a.jsx("p",{className:"text-xs text-bambu-gray uppercase tracking-wide",children:"Printer Status"}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx("p",{className:"text-sm text-white",children:"Printer Offline"}),a.jsx(Fn,{checked:t.on_printer_offline,onChange:y=>h.mutate({on_printer_offline:y})})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx("p",{className:"text-sm text-white",children:"Printer Error"}),a.jsx(Fn,{checked:t.on_printer_error,onChange:y=>h.mutate({on_printer_error:y})})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx("p",{className:"text-sm text-white",children:"Low Filament"}),a.jsx(Fn,{checked:t.on_filament_low,onChange:y=>h.mutate({on_filament_low:y})})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-sm text-white",children:"Maintenance Due"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Notify when maintenance is needed"})]}),a.jsx(Fn,{checked:t.on_maintenance_due??!1,onChange:y=>h.mutate({on_maintenance_due:y})})]})]}),a.jsxs("div",{className:"space-y-2",children:[a.jsx("p",{className:"text-xs text-bambu-gray uppercase tracking-wide",children:"AMS Alarms"}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-sm text-white",children:"AMS Humidity High"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Regular AMS humidity exceeds threshold"})]}),a.jsx(Fn,{checked:t.on_ams_humidity_high??!1,onChange:y=>h.mutate({on_ams_humidity_high:y})})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-sm text-white",children:"AMS Temperature High"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Regular AMS temperature exceeds threshold"})]}),a.jsx(Fn,{checked:t.on_ams_temperature_high??!1,onChange:y=>h.mutate({on_ams_temperature_high:y})})]})]}),a.jsxs("div",{className:"space-y-2",children:[a.jsx("p",{className:"text-xs text-bambu-gray uppercase tracking-wide",children:"AMS-HT Alarms"}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-sm text-white",children:"AMS-HT Humidity High"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"AMS-HT humidity exceeds threshold"})]}),a.jsx(Fn,{checked:t.on_ams_ht_humidity_high??!1,onChange:y=>h.mutate({on_ams_ht_humidity_high:y})})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-sm text-white",children:"AMS-HT Temperature High"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"AMS-HT temperature exceeds threshold"})]}),a.jsx(Fn,{checked:t.on_ams_ht_temperature_high??!1,onChange:y=>h.mutate({on_ams_ht_temperature_high:y})})]})]}),a.jsxs("div",{className:"space-y-2",children:[a.jsx("p",{className:"text-xs text-bambu-gray uppercase tracking-wide",children:"Print Queue"}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-sm text-white",children:"Job Added"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Job added to queue"})]}),a.jsx(Fn,{checked:t.on_queue_job_added??!1,onChange:y=>h.mutate({on_queue_job_added:y})})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-sm text-white",children:"Job Assigned"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Model-based job assigned to printer"})]}),a.jsx(Fn,{checked:t.on_queue_job_assigned??!1,onChange:y=>h.mutate({on_queue_job_assigned:y})})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-sm text-white",children:"Job Started"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Queue job started printing"})]}),a.jsx(Fn,{checked:t.on_queue_job_started??!1,onChange:y=>h.mutate({on_queue_job_started:y})})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-sm text-white",children:"Job Waiting"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Job waiting for filament"})]}),a.jsx(Fn,{checked:t.on_queue_job_waiting??!0,onChange:y=>h.mutate({on_queue_job_waiting:y})})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-sm text-white",children:"Job Skipped"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Job skipped (previous failed)"})]}),a.jsx(Fn,{checked:t.on_queue_job_skipped??!0,onChange:y=>h.mutate({on_queue_job_skipped:y})})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-sm text-white",children:"Job Failed"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Job failed to start"})]}),a.jsx(Fn,{checked:t.on_queue_job_failed??!0,onChange:y=>h.mutate({on_queue_job_failed:y})})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-sm text-white",children:"Queue Complete"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"All queue jobs finished"})]}),a.jsx(Fn,{checked:t.on_queue_completed??!1,onChange:y=>h.mutate({on_queue_completed:y})})]})]}),a.jsxs("div",{className:"space-y-2",children:[a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(X1,{className:"w-4 h-4 text-purple-400"}),a.jsx("p",{className:"text-sm text-white",children:"Quiet Hours"})]}),a.jsx(Fn,{checked:t.quiet_hours_enabled,onChange:y=>h.mutate({quiet_hours_enabled:y})})]}),t.quiet_hours_enabled&&a.jsxs("div",{className:"pl-4 border-l-2 border-bambu-dark-tertiary space-y-2",children:[a.jsx("p",{className:"text-xs text-bambu-gray",children:"No notifications during these hours"}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(tr,{className:"w-4 h-4 text-bambu-gray"}),a.jsxs("span",{className:"text-sm text-white",children:[x(t.quiet_hours_start)||"22:00"," - ",x(t.quiet_hours_end)||"07:00"]})]}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Edit provider to change quiet hours"})]})]}),a.jsxs("div",{className:"space-y-2",children:[a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(ti,{className:"w-4 h-4 text-emerald-400"}),a.jsx("p",{className:"text-sm text-white",children:"Daily Digest"})]}),a.jsx(Fn,{checked:t.daily_digest_enabled,onChange:y=>h.mutate({daily_digest_enabled:y})})]}),t.daily_digest_enabled&&a.jsxs("div",{className:"pl-4 border-l-2 border-bambu-dark-tertiary space-y-2",children:[a.jsx("p",{className:"text-xs text-bambu-gray",children:"Batch notifications into a single daily summary"}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(tr,{className:"w-4 h-4 text-bambu-gray"}),a.jsxs("span",{className:"text-sm text-white",children:["Send at ",x(t.daily_digest_time)||"08:00"]})]}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Edit provider to change digest time"})]})]}),a.jsxs("div",{className:"flex gap-2 pt-2",children:[a.jsxs(Te,{size:"sm",variant:"secondary",onClick:()=>e(t),className:"flex-1",children:[a.jsx(mg,{className:"w-4 h-4"}),"Edit"]}),a.jsx(Te,{size:"sm",variant:"secondary",onClick:()=>i(!0),className:"text-red-400 hover:text-red-300",children:a.jsx(an,{className:"w-4 h-4"})})]})]})]})}),r&&a.jsx(Zn,{title:"Delete Notification Provider",message:`Are you sure you want to delete "${t.name}"? This cannot be undone.`,confirmText:"Delete",variant:"danger",onConfirm:()=>{p.mutate(),i(!1)},onCancel:()=>i(!1)})]})}const _q=[{value:"email",label:"Email",description:"SMTP email notifications"},{value:"telegram",label:"Telegram",description:"Notifications via Telegram bot"},{value:"discord",label:"Discord",description:"Send to Discord channel via webhook"},{value:"ntfy",label:"ntfy",description:"Free, self-hostable push notifications"},{value:"pushover",label:"Pushover",description:"Simple, reliable push notifications"},{value:"callmebot",label:"CallMeBot/WhatsApp",description:"Free WhatsApp notifications via CallMeBot"},{value:"webhook",label:"Webhook",description:"Generic HTTP POST to any URL"}];function TKe({provider:t,onClose:e}){const n=sn(),r=!!t,[i,s]=_.useState(t?.name||""),[o,l]=_.useState(t?.provider_type||"email"),[c,u]=_.useState(t?.printer_id||null),[d,h]=_.useState(t?.quiet_hours_enabled||!1),[p,m]=_.useState(t?.quiet_hours_start||"22:00"),[x,y]=_.useState(t?.quiet_hours_end||"07:00"),[v,b]=_.useState(t?.daily_digest_enabled||!1),[S,N]=_.useState(t?.daily_digest_time||"08:00"),[T,k]=_.useState(t?.on_print_start??!1),[C,E]=_.useState(t?.on_print_complete??!0),[P,A]=_.useState(t?.on_print_failed??!0),[D,I]=_.useState(t?.on_print_stopped??!0),[L,U]=_.useState(t?.on_print_progress??!1),[j,$]=_.useState(t?.on_printer_offline??!1),[K,B]=_.useState(t?.on_printer_error??!1),[X,Y]=_.useState(t?.on_filament_low??!1),[ne,H]=_.useState(t?.on_maintenance_due??!1),[W,re]=_.useState(t?.config?Object.fromEntries(Object.entries(t.config).map(([q,ee])=>[q,String(ee)])):{}),[ie,pe]=_.useState(null),[me,de]=_.useState(null),{data:Ee}=ct({queryKey:["printers"],queryFn:ce.getPrinters});_.useEffect(()=>{const q=ee=>{ee.key==="Escape"&&e()};return window.addEventListener("keydown",q),()=>window.removeEventListener("keydown",q)},[e]);const se=gt({mutationFn:()=>ce.testNotificationConfig({provider_type:o,config:W}),onSuccess:q=>{pe(q),de(null)},onError:q=>{pe({success:!1,message:q.message})}}),Ae=gt({mutationFn:q=>ce.createNotificationProvider(q),onSuccess:()=>{n.invalidateQueries({queryKey:["notification-providers"]}),e()},onError:q=>{de(q.message)}}),Fe=gt({mutationFn:q=>ce.updateNotificationProvider(t.id,q),onSuccess:()=>{n.invalidateQueries({queryKey:["notification-providers"]}),e()},onError:q=>{de(q.message)}}),ge=q=>{if(q.preventDefault(),de(null),!i.trim()){de("Name is required");return}const ee=Q(o);for(const ye of ee)if(!W[ye.key]?.trim()){de(`${ye.label} is required`);return}const V={name:i.trim(),provider_type:o,config:W,printer_id:c,quiet_hours_enabled:d,quiet_hours_start:d?p:null,quiet_hours_end:d?x:null,daily_digest_enabled:v,daily_digest_time:v?S:null,on_print_start:T,on_print_complete:C,on_print_failed:P,on_print_stopped:D,on_print_progress:L,on_printer_offline:j,on_printer_error:K,on_filament_low:X,on_maintenance_due:ne};r?Fe.mutate(V):Ae.mutate(V)},Ze=Ae.isPending||Fe.isPending,G=q=>{switch(q){case"callmebot":return[{key:"phone",label:"Phone Number",placeholder:"+1234567890",type:"text",required:!0},{key:"apikey",label:"API Key",placeholder:"Your CallMeBot API key",type:"text",required:!0}];case"ntfy":return[{key:"server",label:"Server URL",placeholder:"https://ntfy.sh",type:"text",required:!1},{key:"topic",label:"Topic",placeholder:"my-bambuddy",type:"text",required:!0},{key:"auth_token",label:"Auth Token",placeholder:"Optional authentication",type:"password",required:!1}];case"pushover":return[{key:"user_key",label:"User Key",placeholder:"Your Pushover user key",type:"text",required:!0},{key:"app_token",label:"App Token",placeholder:"Your Pushover app token",type:"text",required:!0},{key:"priority",label:"Priority",placeholder:"0 (normal)",type:"number",required:!1}];case"telegram":return[{key:"bot_token",label:"Bot Token",placeholder:"Bot token from @BotFather",type:"password",required:!0},{key:"chat_id",label:"Chat ID",placeholder:"Your chat or group ID",type:"text",required:!0}];case"email":return[{key:"smtp_server",label:"SMTP Server",placeholder:"smtp.gmail.com",type:"text",required:!0},{key:"smtp_port",label:"SMTP Port",placeholder:"587",type:"number",required:!1},{key:"security",label:"Security",type:"select",required:!1,options:[{value:"starttls",label:"STARTTLS (Port 587)"},{value:"ssl",label:"SSL/TLS (Port 465)"},{value:"none",label:"None (Port 25)"}]},{key:"auth_enabled",label:"Authentication",type:"select",required:!1,options:[{value:"true",label:"Enabled"},{value:"false",label:"Disabled"}]},{key:"username",label:"Username",placeholder:"your@email.com",type:"text",required:!1},{key:"password",label:"Password",placeholder:"App password",type:"password",required:!1},{key:"from_email",label:"From Email",placeholder:"your@email.com",type:"text",required:!0},{key:"to_email",label:"To Email",placeholder:"recipient@email.com",type:"text",required:!0}];case"discord":return[{key:"webhook_url",label:"Webhook URL",placeholder:"https://discord.com/api/webhooks/...",type:"text",required:!0}];case"webhook":return[{key:"webhook_url",label:"Webhook URL",placeholder:"https://example.com/webhook",type:"text",required:!0},{key:"payload_format",label:"Payload Format",type:"select",required:!1,options:[{value:"generic",label:"Generic JSON"},{value:"slack",label:"Slack / Mattermost"}]},{key:"auth_header",label:"Authorization",placeholder:"Bearer token (optional)",type:"password",required:!1},{key:"field_title",label:"Title Field Name",placeholder:"title",type:"text",required:!1,showIf:ee=>ee.payload_format!=="slack"},{key:"field_message",label:"Message Field Name",placeholder:"message",type:"text",required:!1,showIf:ee=>ee.payload_format!=="slack"}];default:return[]}},Q=q=>G(q).filter(ee=>ee.required),he=G(o);return a.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4 overflow-y-auto",onClick:e,children:a.jsxs("div",{className:"bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-lg my-8 max-h-[90vh] overflow-y-auto",onClick:q=>q.stopPropagation(),children:[a.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary",children:[a.jsx("h2",{className:"text-lg font-semibold text-white",children:r?"Edit Notification Provider":"Add Notification Provider"}),a.jsx("button",{onClick:e,className:"text-bambu-gray hover:text-white transition-colors",children:a.jsx(Lt,{className:"w-5 h-5"})})]}),a.jsxs("form",{onSubmit:ge,className:"p-6 space-y-4",children:[me&&a.jsx("div",{className:"p-3 bg-red-500/20 border border-red-500/50 rounded-lg text-sm text-red-400",children:me}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Name *"}),a.jsx("input",{type:"text",value:i,onChange:q=>s(q.target.value),placeholder:"My Notifications",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"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Provider Type *"}),a.jsx("select",{value:o,onChange:q=>{l(q.target.value),re({}),pe(null)},disabled:r,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 disabled:opacity-50",children:_q.map(q=>a.jsx("option",{value:q.value,children:q.label},q.value))}),a.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:_q.find(q=>q.value===o)?.description})]}),a.jsxs("div",{className:"space-y-3",children:[a.jsx("p",{className:"text-sm text-bambu-gray",children:"Configuration"}),he.filter(q=>!("showIf"in q)||q.showIf?.(W)!==!1).map(q=>a.jsxs("div",{children:[a.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[q.label," ",q.required&&"*"]}),q.type==="select"&&"options"in q&&q.options?a.jsx("select",{value:W[q.key]||q.options[0]?.value||"",onChange:ee=>{re({...W,[q.key]:ee.target.value}),pe(null)},className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:q.options.map(ee=>a.jsx("option",{value:ee.value,children:ee.label},ee.value))}):a.jsx("input",{type:q.type,value:W[q.key]||"",onChange:ee=>{re({...W,[q.key]:ee.target.value}),pe(null)},placeholder:q.placeholder,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"})]},q.key))]}),a.jsx("div",{className:"flex gap-2",children:a.jsxs(Te,{type:"button",variant:"secondary",onClick:()=>{pe(null),se.mutate()},disabled:se.isPending||!W[Q(o)[0]?.key],className:"flex-1",children:[se.isPending?a.jsx(pt,{className:"w-4 h-4 animate-spin"}):a.jsx(OR,{className:"w-4 h-4"}),"Test Configuration"]})}),ie&&a.jsx("div",{className:`p-3 rounded-lg flex items-center gap-2 ${ie.success?"bg-bambu-green/20 border border-bambu-green/50 text-bambu-green":"bg-red-500/20 border border-red-500/50 text-red-400"}`,children:ie.success?a.jsxs(a.Fragment,{children:[a.jsx(Ar,{className:"w-5 h-5"}),a.jsx("span",{children:ie.message})]}):a.jsxs(a.Fragment,{children:[a.jsx(Ji,{className:"w-5 h-5"}),a.jsx("span",{children:ie.message})]})}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Printer Filter"}),a.jsxs("select",{value:c??"",onChange:q=>u(q.target.value?Number(q.target.value):null),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[a.jsx("option",{value:"",children:"All printers"}),Ee?.map(q=>a.jsx("option",{value:q.id,children:q.name},q.id))]}),a.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Only send notifications for events from this printer"})]}),a.jsxs("div",{className:"space-y-2",children:[a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx("label",{className:"text-sm text-white",children:"Quiet Hours (Do Not Disturb)"}),a.jsx(Fn,{checked:d,onChange:h})]}),d&&a.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Start"}),a.jsx("input",{type:"time",value:p,onChange:q=>m(q.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"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"End"}),a.jsx("input",{type:"time",value:x,onChange:q=>y(q.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"})]})]})]}),a.jsxs("div",{className:"space-y-2",children:[a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("label",{className:"text-sm text-white",children:"Daily Digest"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Batch notifications into a single daily summary"})]}),a.jsx(Fn,{checked:v,onChange:b})]}),v&&a.jsxs("div",{children:[a.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Send digest at"}),a.jsx("input",{type:"time",value:S,onChange:q=>N(q.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"}),a.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Events will be collected and sent as a single summary at this time"})]})]}),a.jsxs("div",{className:"space-y-3",children:[a.jsx("p",{className:"text-sm text-bambu-gray",children:"Notification Events"}),a.jsxs("div",{className:"space-y-2 p-3 bg-bambu-dark rounded-lg",children:[a.jsx("p",{className:"text-xs text-bambu-gray uppercase tracking-wide mb-2",children:"Print Events"}),a.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx("span",{className:"text-sm text-white",children:"Start"}),a.jsx(Fn,{checked:T,onChange:k})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx("span",{className:"text-sm text-white",children:"Complete"}),a.jsx(Fn,{checked:C,onChange:E})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx("span",{className:"text-sm text-white",children:"Failed"}),a.jsx(Fn,{checked:P,onChange:A})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx("span",{className:"text-sm text-white",children:"Stopped"}),a.jsx(Fn,{checked:D,onChange:I})]}),a.jsxs("div",{className:"flex items-center justify-between col-span-2",children:[a.jsxs("div",{children:[a.jsx("span",{className:"text-sm text-white",children:"Progress"}),a.jsx("span",{className:"text-xs text-bambu-gray ml-1",children:"(25%, 50%, 75%)"})]}),a.jsx(Fn,{checked:L,onChange:U})]})]})]}),a.jsxs("div",{className:"space-y-2 p-3 bg-bambu-dark rounded-lg",children:[a.jsx("p",{className:"text-xs text-bambu-gray uppercase tracking-wide mb-2",children:"Printer Status"}),a.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx("span",{className:"text-sm text-white",children:"Offline"}),a.jsx(Fn,{checked:j,onChange:$})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx("span",{className:"text-sm text-white",children:"Error"}),a.jsx(Fn,{checked:K,onChange:B})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx("span",{className:"text-sm text-white",children:"Low Filament"}),a.jsx(Fn,{checked:X,onChange:Y})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx("span",{className:"text-sm text-white",children:"Maintenance"}),a.jsx(Fn,{checked:ne,onChange:H})]})]})]})]}),a.jsxs("div",{className:"flex gap-3 pt-2",children:[a.jsx(Te,{type:"button",variant:"secondary",onClick:e,className:"flex-1",children:"Cancel"}),a.jsxs(Te,{type:"submit",disabled:Ze,className:"flex-1",children:[Ze?a.jsx(pt,{className:"w-4 h-4 animate-spin"}):a.jsx(ms,{className:"w-4 h-4"}),r?"Save":"Add"]})]})]})]})})}function AKe({template:t,onClose:e}){const n=sn(),r=_.useRef(null),[i,s]=_.useState(t.title_template),[o,l]=_.useState(t.body_template),[c,u]=_.useState(null),[d,h]=_.useState(!0),{data:p}=ct({queryKey:["template-variables"],queryFn:ce.getTemplateVariables}),m=p?.find(k=>k.event_type===t.event_type),{data:x,isLoading:y}=ct({queryKey:["template-preview",t.event_type,i,o],queryFn:()=>ce.previewTemplate({event_type:t.event_type,title_template:i,body_template:o}),enabled:d&&i.length>0&&o.length>0});_.useEffect(()=>{const k=C=>{C.key==="Escape"&&e()};return window.addEventListener("keydown",k),()=>window.removeEventListener("keydown",k)},[e]);const v=gt({mutationFn:k=>ce.updateNotificationTemplate(t.id,k),onSuccess:()=>{n.invalidateQueries({queryKey:["notification-templates"]}),e()},onError:k=>{u(k.message)}}),b=gt({mutationFn:()=>ce.resetNotificationTemplate(t.id),onSuccess:k=>{s(k.title_template),l(k.body_template),n.invalidateQueries({queryKey:["notification-templates"]})},onError:k=>{u(k.message)}}),S=k=>{if(k.preventDefault(),u(null),!i.trim()){u("Title is required");return}if(!o.trim()){u("Body is required");return}v.mutate({title_template:i,body_template:o})},N=k=>{const C=r.current;if(!C)return;const E=C.selectionStart,P=C.selectionEnd,A=o,D=A.substring(0,E),I=A.substring(P),L=D+`{${k}}`+I;l(L),setTimeout(()=>{C.focus();const U=E+k.length+2;C.setSelectionRange(U,U)},0)},T=i!==t.title_template||o!==t.body_template;return a.jsx("div",{className:"fixed inset-0 bg-black/80 flex items-center justify-center z-50 p-4",children:a.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg w-full max-w-2xl max-h-[90vh] flex flex-col",children:[a.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary shrink-0",children:[a.jsxs("h2",{className:"text-lg font-semibold text-white",children:["Edit Template: ",t.name]}),a.jsx("button",{onClick:e,className:"p-1 hover:bg-bambu-dark-tertiary rounded transition-colors",children:a.jsx(Lt,{className:"w-5 h-5 text-bambu-gray"})})]}),a.jsxs("form",{onSubmit:S,className:"flex-1 overflow-y-auto p-4 space-y-4",children:[c&&a.jsx("div",{className:"p-3 bg-red-500/20 border border-red-500/50 rounded text-red-400 text-sm",children:c}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm font-medium text-bambu-gray mb-1",children:"Title"}),a.jsx("input",{type:"text",value:i,onChange:k=>s(k.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white focus:outline-none focus:ring-1 focus:ring-bambu-green",placeholder:"Notification title..."})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm font-medium text-bambu-gray mb-1",children:"Body"}),a.jsx("textarea",{ref:r,value:o,onChange:k=>l(k.target.value),rows:4,className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white focus:outline-none focus:ring-1 focus:ring-bambu-green font-mono text-sm resize-none",placeholder:"Notification body..."})]}),m&&a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm font-medium text-bambu-gray mb-2",children:"Available Variables"}),a.jsx("div",{className:"flex flex-wrap gap-2",children:m.variables.map(k=>a.jsxs("button",{type:"button",onClick:()=>N(k),className:"inline-flex items-center gap-1 px-2 py-1 bg-bambu-dark hover:bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded text-xs text-bambu-gray hover:text-white transition-colors",children:[a.jsx(fr,{className:"w-3 h-3"}),k]},k))}),a.jsx("p",{className:"text-xs text-bambu-gray/60 mt-1",children:"Click to insert at cursor position in body"})]}),a.jsxs("div",{children:[a.jsxs("div",{className:"flex items-center justify-between mb-2",children:[a.jsxs("label",{className:"text-sm font-medium text-bambu-gray flex items-center gap-2",children:[a.jsx(xc,{className:"w-4 h-4"}),"Live Preview"]}),a.jsx("button",{type:"button",onClick:()=>h(!d),className:"text-xs text-bambu-green hover:text-bambu-green-light",children:d?"Hide":"Show"})]}),d&&a.jsx("div",{className:"bg-bambu-dark border border-bambu-dark-tertiary rounded p-3 space-y-2",children:y?a.jsxs("div",{className:"flex items-center gap-2 text-bambu-gray text-sm",children:[a.jsx(pt,{className:"w-4 h-4 animate-spin"}),"Loading preview..."]}):x?a.jsxs(a.Fragment,{children:[a.jsxs("div",{children:[a.jsx("span",{className:"text-xs text-bambu-gray",children:"Title:"}),a.jsx("div",{className:"text-white font-medium",children:x.title})]}),a.jsxs("div",{children:[a.jsx("span",{className:"text-xs text-bambu-gray",children:"Body:"}),a.jsx("div",{className:"text-white whitespace-pre-wrap text-sm",children:x.body})]})]}):a.jsx("div",{className:"text-bambu-gray text-sm",children:"Enter template content to see preview"})})]})]}),a.jsxs("div",{className:"flex items-center justify-between p-4 border-t border-bambu-dark-tertiary shrink-0",children:[a.jsxs(Te,{type:"button",variant:"ghost",onClick:()=>b.mutate(),disabled:b.isPending,className:"text-orange-400 hover:text-orange-300",children:[b.isPending?a.jsx(pt,{className:"w-4 h-4 animate-spin mr-2"}):a.jsx(Lh,{className:"w-4 h-4 mr-2"}),"Reset to Default"]}),a.jsxs("div",{className:"flex gap-2",children:[a.jsx(Te,{type:"button",variant:"secondary",onClick:e,children:"Cancel"}),a.jsxs(Te,{onClick:S,disabled:v.isPending||!T,children:[v.isPending?a.jsx(pt,{className:"w-4 h-4 animate-spin mr-2"}):a.jsx(ms,{className:"w-4 h-4 mr-2"}),"Save"]})]})]})]})})}const CKe={print_start:"Print Started",print_complete:"Print Complete",print_failed:"Print Failed",print_stopped:"Print Stopped",print_progress:"Progress",printer_offline:"Printer Offline",printer_error:"Printer Error",filament_low:"Low Filament",maintenance_due:"Maintenance Due",test:"Test"},jKe={print_start:"text-blue-400",print_complete:"text-bambu-green",print_failed:"text-red-400",print_stopped:"text-orange-400",print_progress:"text-yellow-400",printer_offline:"text-gray-400",printer_error:"text-rose-400",filament_low:"text-cyan-400",maintenance_due:"text-purple-400",test:"text-bambu-gray"};function PKe({onClose:t}){const e=sn(),{showToast:n}=Hn(),[r,i]=_.useState(7),[s,o]=_.useState(null),[l,c]=_.useState(!1),{data:u}=ct({queryKey:["settings"],queryFn:ce.getSettings}),d=u?.time_format||"system",{data:h,isLoading:p,refetch:m,isRefetching:x}=ct({queryKey:["notification-logs",r,l],queryFn:()=>ce.getNotificationLogs({days:r,limit:100,success:l?!1:void 0})}),{data:y}=ct({queryKey:["notification-log-stats",r],queryFn:()=>ce.getNotificationLogStats(r)}),v=gt({mutationFn:()=>ce.clearNotificationLogs(30),onSuccess:S=>{n(S.message,"success"),e.invalidateQueries({queryKey:["notification-logs"]}),e.invalidateQueries({queryKey:["notification-log-stats"]})},onError:S=>{n(`Failed to clear logs: ${S.message}`,"error")}}),b=S=>{const N=zi(S);if(!N)return"";const k=new Date().getTime()-N.getTime();return k<6e4?"Just now":k<36e5?`${Math.floor(k/6e4)}m ago`:k<864e5?`${Math.floor(k/36e5)}h ago`:N.toLocaleDateString()+" "+Yfe(N,d)};return a.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",children:a.jsxs("div",{className:"bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg w-full max-w-3xl max-h-[85vh] flex flex-col",children:[a.jsxs("div",{className:"p-4 border-b border-bambu-dark-tertiary flex items-center justify-between",children:[a.jsxs("div",{className:"flex items-center gap-3",children:[a.jsx(W0,{className:"w-5 h-5 text-bambu-green"}),a.jsx("h2",{className:"text-lg font-semibold text-white",children:"Notification Log"})]}),a.jsx("button",{onClick:t,className:"text-bambu-gray hover:text-white transition-colors",children:"×"})]}),y&&a.jsx("div",{className:"px-4 py-3 border-b border-bambu-dark-tertiary bg-bambu-dark/50",children:a.jsxs("div",{className:"flex items-center gap-6 text-sm",children:[a.jsxs("span",{className:"text-bambu-gray",children:["Last ",r," days: ",a.jsx("span",{className:"text-white font-medium",children:y.total})," notifications"]}),a.jsxs("span",{className:"flex items-center gap-1 text-bambu-green",children:[a.jsx(Ar,{className:"w-4 h-4"}),y.success_count," sent"]}),y.failure_count>0&&a.jsxs("span",{className:"flex items-center gap-1 text-red-400",children:[a.jsx(Ji,{className:"w-4 h-4"}),y.failure_count," failed"]})]})}),a.jsxs("div",{className:"px-4 py-3 border-b border-bambu-dark-tertiary flex items-center gap-4",children:[a.jsxs("select",{value:r,onChange:S=>i(Number(S.target.value)),className:"px-3 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm focus:outline-none focus:ring-1 focus:ring-bambu-green",children:[a.jsx("option",{value:1,children:"Last 24 hours"}),a.jsx("option",{value:7,children:"Last 7 days"}),a.jsx("option",{value:30,children:"Last 30 days"}),a.jsx("option",{value:90,children:"Last 90 days"})]}),a.jsxs("label",{className:"flex items-center gap-2 text-sm text-bambu-gray cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:l,onChange:S=>c(S.target.checked),className:"rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),"Show failed only"]}),a.jsx("div",{className:"flex-1"}),a.jsxs(Te,{size:"sm",variant:"secondary",onClick:()=>m(),disabled:x,children:[x?a.jsx(pt,{className:"w-4 h-4 animate-spin"}):a.jsx(Dr,{className:"w-4 h-4"}),"Refresh"]}),a.jsxs(Te,{size:"sm",variant:"secondary",onClick:()=>v.mutate(),disabled:v.isPending,className:"text-red-400 hover:text-red-300",children:[v.isPending?a.jsx(pt,{className:"w-4 h-4 animate-spin"}):a.jsx(an,{className:"w-4 h-4"}),"Clear Old"]})]}),a.jsx("div",{className:"flex-1 overflow-y-auto p-4",children:p?a.jsx("div",{className:"flex justify-center py-12",children:a.jsx(pt,{className:"w-6 h-6 text-bambu-green animate-spin"})}):h&&h.length>0?a.jsx("div",{className:"space-y-2",children:h.map(S=>a.jsx(DKe,{log:S,isExpanded:s===S.id,onToggle:()=>o(s===S.id?null:S.id),formatDate:b,formatFullDate:N=>Vg(N,d)},S.id))}):a.jsxs("div",{className:"text-center py-12 text-bambu-gray",children:[a.jsx(W0,{className:"w-12 h-12 mx-auto mb-3 opacity-30"}),a.jsx("p",{className:"text-sm",children:l?"No failed notifications":"No notifications logged"})]})})]})})}function DKe({log:t,isExpanded:e,onToggle:n,formatDate:r,formatFullDate:i}){return a.jsxs("div",{className:`border rounded-lg overflow-hidden transition-colors ${t.success?"border-bambu-dark-tertiary bg-bambu-dark/30":"border-red-500/30 bg-red-500/5"}`,children:[a.jsxs("button",{className:"w-full px-3 py-2 flex items-center gap-3 text-left hover:bg-bambu-dark/50 transition-colors",onClick:n,children:[t.success?a.jsx(Ar,{className:"w-4 h-4 text-bambu-green shrink-0"}):a.jsx(Ji,{className:"w-4 h-4 text-red-400 shrink-0"}),a.jsx("span",{className:`text-xs font-medium ${jKe[t.event_type]||"text-bambu-gray"}`,children:CKe[t.event_type]||t.event_type}),a.jsx("span",{className:"text-sm text-white truncate flex-1",children:t.provider_name||"Unknown Provider"}),t.printer_name&&a.jsx("span",{className:"text-xs text-bambu-gray",children:t.printer_name}),a.jsx("span",{className:"text-xs text-bambu-gray shrink-0",children:r(t.created_at)}),e?a.jsx(yh,{className:"w-4 h-4 text-bambu-gray shrink-0"}):a.jsx(Kr,{className:"w-4 h-4 text-bambu-gray shrink-0"})]}),e&&a.jsxs("div",{className:"px-3 py-2 border-t border-bambu-dark-tertiary bg-bambu-dark/20 space-y-2",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-xs text-bambu-gray mb-1",children:"Title"}),a.jsx("p",{className:"text-sm text-white",children:t.title})]}),a.jsxs("div",{children:[a.jsx("p",{className:"text-xs text-bambu-gray mb-1",children:"Message"}),a.jsx("p",{className:"text-sm text-white whitespace-pre-wrap",children:t.message})]}),!t.success&&t.error_message&&a.jsxs("div",{children:[a.jsx("p",{className:"text-xs text-red-400 mb-1",children:"Error"}),a.jsx("p",{className:"text-sm text-red-300",children:t.error_message})]}),a.jsxs("div",{className:"flex gap-4 text-xs text-bambu-gray pt-1",children:[a.jsxs("span",{children:["Provider: ",t.provider_type]}),a.jsxs("span",{children:["Time: ",i(t.created_at)]})]})]})]})}function RKe(){const t=sn(),[e,n]=_.useState(!1),[r,i]=_.useState(""),[s,o]=_.useState("auto"),[l,c]=_.useState(!1),[u,d]=_.useState("all"),[h,p]=_.useState(!1),[m,x]=_.useState(!1),{data:y,isLoading:v}=ct({queryKey:["spoolman-settings"],queryFn:ce.getSpoolmanSettings}),{data:b,isLoading:S,refetch:N}=ct({queryKey:["spoolman-status"],queryFn:ce.getSpoolmanStatus,refetchInterval:3e4}),{data:T}=ct({queryKey:["printers"],queryFn:ce.getPrinters});_.useEffect(()=>{y&&(n(y.spoolman_enabled==="true"),i(y.spoolman_url||""),o(y.spoolman_sync_mode||"auto"),p(!0))},[y]),_.useEffect(()=>{if(!h||!y)return;if(y.spoolman_enabled==="true"!==e||(y.spoolman_url||"")!==r||(y.spoolman_sync_mode||"auto")!==s){const $=setTimeout(()=>{k.mutate()},500);return()=>clearTimeout($)}},[e,r,s,h]);const k=gt({mutationFn:()=>ce.updateSpoolmanSettings({spoolman_enabled:e?"true":"false",spoolman_url:r,spoolman_sync_mode:s}),onSuccess:()=>{t.invalidateQueries({queryKey:["spoolman-settings"]}),t.invalidateQueries({queryKey:["spoolman-status"]}),c(!0),setTimeout(()=>c(!1),2e3)}}),C=gt({mutationFn:ce.connectSpoolman,onSuccess:()=>{N()}}),E=gt({mutationFn:ce.disconnectSpoolman,onSuccess:()=>{N()}}),P=gt({mutationFn:ce.syncAllPrintersAms,onSuccess:j=>{j.success}}),A=gt({mutationFn:j=>ce.syncPrinterAms(j),onSuccess:j=>{j.success}}),D=()=>{u==="all"?P.mutate():A.mutate(u)},I=P.isPending||A.isPending,L=u==="all"?P.data:A.data,U=u==="all"?P.isSuccess:A.isSuccess;return v?a.jsxs(St,{children:[a.jsx(Kn,{children:a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(Eu,{className:"w-5 h-5 text-bambu-green"}),a.jsx("h2",{className:"text-lg font-semibold text-white",children:"Spoolman Integration"})]})}),a.jsx(Nt,{children:a.jsx("div",{className:"flex justify-center py-8",children:a.jsx(pt,{className:"w-6 h-6 text-bambu-green animate-spin"})})})]}):a.jsxs(St,{children:[a.jsx(Kn,{children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(Eu,{className:"w-5 h-5 text-bambu-green"}),a.jsx("h2",{className:"text-lg font-semibold text-white",children:"Spoolman Integration"})]}),k.isPending&&a.jsx(pt,{className:"w-4 h-4 text-bambu-green animate-spin"}),l&&a.jsx(Wi,{className:"w-4 h-4 text-bambu-green"})]})}),a.jsxs(Nt,{className:"space-y-4",children:[a.jsx("p",{className:"text-sm text-bambu-gray",children:"Connect to Spoolman for filament inventory tracking. AMS data will sync automatically."}),a.jsx("div",{className:"p-3 bg-blue-500/10 border border-blue-500/30 rounded-lg",children:a.jsxs("div",{className:"flex gap-2",children:[a.jsx(nl,{className:"w-4 h-4 text-blue-400 flex-shrink-0 mt-0.5"}),a.jsxs("div",{className:"text-xs text-blue-300",children:[a.jsx("p",{className:"font-medium mb-1",children:"How Sync Works"}),a.jsxs("ul",{className:"list-disc list-inside space-y-0.5 text-blue-300/80",children:[a.jsx("li",{children:"Only official Bambu Lab spools with RFID are synced"}),a.jsx("li",{children:"New spools are auto-created in Spoolman on first sync"}),a.jsx("li",{children:"Non-Bambu Lab spools (third-party, refilled) are skipped"})]}),a.jsx("p",{className:"font-medium mt-2 mb-1",children:"Linking Existing Spools"}),a.jsx("p",{className:"text-blue-300/80",children:'To link existing Spoolman spools to your AMS, hover over an AMS slot and click "Link to Spoolman".'})]})]})}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-white",children:"Enable Spoolman"}),a.jsx("p",{className:"text-sm text-bambu-gray",children:"Sync filament data with Spoolman server"})]}),a.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:e,onChange:j=>n(j.target.checked),className:"sr-only peer"}),a.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Spoolman URL"}),a.jsx("input",{type:"text",placeholder:"http://192.168.1.100:7912",value:r,onChange:j=>i(j.target.value),disabled:!e,className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray/50 focus:border-bambu-green focus:outline-none disabled:opacity-50"}),a.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"URL of your Spoolman server (e.g., http://localhost:7912)"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Sync Mode"}),a.jsxs("select",{value:s,onChange:j=>o(j.target.value),disabled:!e,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 disabled:opacity-50",children:[a.jsx("option",{value:"auto",children:"Automatic"}),a.jsx("option",{value:"manual",children:"Manual Only"})]}),a.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:s==="auto"?"AMS data syncs automatically when changes are detected":"Only sync when manually triggered"})]}),e&&a.jsxs("div",{className:"pt-2 border-t border-bambu-dark-tertiary",children:[a.jsxs("div",{className:"flex items-center justify-between mb-3",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("span",{className:"text-sm text-bambu-gray",children:"Status:"}),S?a.jsx(pt,{className:"w-4 h-4 text-bambu-gray animate-spin"}):b?.connected?a.jsxs("span",{className:"flex items-center gap-1 text-sm text-green-500",children:[a.jsx(Wi,{className:"w-4 h-4"}),"Connected"]}):a.jsxs("span",{className:"flex items-center gap-1 text-sm text-red-500",children:[a.jsx(Lt,{className:"w-4 h-4"}),"Disconnected"]})]}),a.jsx("div",{className:"flex gap-2",children:b?.connected?a.jsxs(Te,{variant:"secondary",size:"sm",onClick:()=>E.mutate(),disabled:E.isPending,children:[E.isPending?a.jsx(pt,{className:"w-4 h-4 animate-spin"}):a.jsx(Ade,{className:"w-4 h-4"}),"Disconnect"]}):a.jsxs(Te,{size:"sm",onClick:()=>C.mutate(),disabled:C.isPending||!r,children:[C.isPending?a.jsx(pt,{className:"w-4 h-4 animate-spin"}):a.jsx(fc,{className:"w-4 h-4"}),"Connect"]})})]}),C.isError&&a.jsx("div",{className:"mb-3 p-2 bg-red-500/20 border border-red-500/50 rounded text-sm text-red-400",children:C.error.message}),b?.connected&&a.jsxs("div",{className:"space-y-3",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-sm text-white",children:"Sync AMS Data"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Manually sync printer AMS data to Spoolman"})]}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsxs("div",{className:"relative flex-1",children:[a.jsxs("select",{value:u,onChange:j=>d(j.target.value==="all"?"all":Number(j.target.value)),className:"w-full px-3 py-2 pr-8 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none appearance-none cursor-pointer",children:[a.jsx("option",{value:"all",children:"All Printers"}),T?.map(j=>a.jsx("option",{value:j.id,children:j.name},j.id))]}),a.jsx(Kr,{className:"absolute right-2 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}),a.jsxs(Te,{variant:"secondary",size:"sm",onClick:D,disabled:I,children:[I?a.jsx(pt,{className:"w-4 h-4 animate-spin"}):a.jsx(Dr,{className:"w-4 h-4"}),"Sync"]})]})]}),U&&L&&a.jsxs("div",{className:"mt-3 space-y-2",children:[a.jsx("div",{className:`p-2 rounded text-sm ${L.success?"bg-green-500/20 border border-green-500/50 text-green-400":"bg-yellow-500/20 border border-yellow-500/50 text-yellow-400"}`,children:L.success?`Synced ${L.synced_count} spool${L.synced_count!==1?"s":""} successfully`:`Synced ${L.synced_count} spool${L.synced_count!==1?"s":""} with ${L.errors.length} error${L.errors.length!==1?"s":""}`}),L.skipped_count>0&&a.jsxs("div",{className:"p-2 bg-amber-500/10 border border-amber-500/30 rounded text-sm",children:[a.jsxs("div",{className:"flex items-center justify-between text-amber-400 mb-1",children:[a.jsxs("div",{className:"flex items-center gap-1.5",children:[a.jsx(Sn,{className:"w-3.5 h-3.5"}),a.jsxs("span",{className:"font-medium",children:[L.skipped_count," spool",L.skipped_count!==1?"s":""," skipped"]})]}),L.skipped_count>5&&a.jsx("button",{onClick:()=>x(!m),className:"text-xs text-amber-400 hover:text-amber-300 underline",children:m?"Show less":"Show all"})]}),a.jsxs("ul",{className:"text-xs text-amber-300/80 space-y-0.5",children:[(m?L.skipped:L.skipped.slice(0,5)).map((j,$)=>a.jsxs("li",{className:"flex items-center gap-2",children:[j.color&&a.jsx("span",{className:"w-3 h-3 rounded-full border border-white/20",style:{backgroundColor:`#${j.color}`}}),a.jsx("span",{children:j.location}),a.jsxs("span",{className:"text-amber-300/60",children:["- ",j.reason]})]},$)),!m&&L.skipped_count>5&&a.jsxs("li",{className:"text-amber-300/60 italic",children:["...and ",L.skipped_count-5," more"]})]})]}),L.errors.length>0&&a.jsxs("div",{className:"p-2 bg-red-500/10 border border-red-500/30 rounded text-sm",children:[a.jsx("div",{className:"text-red-400 font-medium mb-1",children:"Errors:"}),a.jsx("ul",{className:"text-xs text-red-300/80 space-y-0.5",children:L.errors.map((j,$)=>a.jsx("li",{children:j},$))})]})]})]})]})]})}function OKe({link:t,onClose:e}){const n=sn(),{mode:r}=Fh(),i=!!t,s=_.useRef(null),[o,l]=_.useState(t?.name||""),[c,u]=_.useState(t?.url||""),[d,h]=_.useState(t?.icon||"link"),[p,m]=_.useState(!!t?.custom_icon),[x,y]=_.useState(t?.custom_icon?ce.getExternalLinkIconUrl(t.id):null),[v,b]=_.useState(null),[S,N]=_.useState(null);_.useEffect(()=>{const I=L=>{L.key==="Escape"&&e()};return window.addEventListener("keydown",I),()=>window.removeEventListener("keydown",I)},[e]);const T=gt({mutationFn:async I=>{const L=await ce.createExternalLink(I);return v?await ce.uploadExternalLinkIcon(L.id,v):L},onSuccess:()=>{n.invalidateQueries({queryKey:["external-links"]}),e()},onError:I=>{N(I.message)}}),k=gt({mutationFn:async I=>{let L=await ce.updateExternalLink(t.id,I);return v?L=await ce.uploadExternalLinkIcon(t.id,v):!p&&t?.custom_icon&&(L=await ce.deleteExternalLinkIcon(t.id)),L},onSuccess:()=>{n.invalidateQueries({queryKey:["external-links"]}),e()},onError:I=>{N(I.message)}}),C=I=>{const L=I.target.files?.[0];if(L){if(!["image/png","image/jpeg","image/gif","image/svg+xml","image/webp","image/x-icon"].includes(L.type)){N("Please select a valid image file (PNG, JPG, GIF, SVG, WebP, or ICO)");return}if(L.size>1024*1024){N("Image file must be less than 1MB");return}b(L),m(!0);const j=new FileReader;j.onload=$=>{y($.target?.result)},j.readAsDataURL(L)}},E=()=>{b(null),y(null),m(!1),s.current&&(s.current.value="")},P=I=>{if(I.preventDefault(),N(null),!o.trim()){N("Name is required");return}if(!c.trim()){N("URL is required");return}if(!c.startsWith("http://")&&!c.startsWith("https://")){N("URL must start with http:// or https://");return}const L={name:o.trim(),url:c.trim(),icon:d};i?k.mutate(L):T.mutate(L)},A=T.isPending||k.isPending,D=wM(d);return a.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",onClick:e,children:a.jsxs("div",{className:"bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-md",onClick:I=>I.stopPropagation(),children:[a.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary",children:[a.jsxs("div",{className:"flex items-center gap-3",children:[a.jsx("div",{className:"p-2 rounded-full bg-bambu-green/20 text-bambu-green",children:p&&x?a.jsx("img",{src:x,alt:"",className:`w-5 h-5 rounded ${r==="dark"?"invert opacity-[0.65]":"opacity-60"}`}):a.jsx(D,{className:"w-5 h-5"})}),a.jsx("h2",{className:"text-lg font-semibold text-white",children:i?"Edit Link":"Add External Link"})]}),a.jsx("button",{onClick:e,className:"text-bambu-gray hover:text-white transition-colors",children:a.jsx(Lt,{className:"w-5 h-5"})})]}),a.jsxs("form",{onSubmit:P,className:"p-6 space-y-4",children:[S&&a.jsx("div",{className:"p-3 bg-red-500/20 border border-red-500/50 rounded-lg text-sm text-red-400",children:S}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Name *"}),a.jsx("input",{type:"text",value:o,onChange:I=>l(I.target.value),placeholder:"My Link",maxLength:50,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"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"URL *"}),a.jsx("input",{type:"text",value:c,onChange:I=>u(I.target.value),placeholder:"https://example.com",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"})]}),a.jsxs("div",{className:"space-y-3",children:[a.jsx("label",{className:"block text-sm text-bambu-gray",children:"Icon"}),a.jsxs("div",{className:"p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary",children:[a.jsxs("div",{className:"flex items-center justify-between mb-2",children:[a.jsx("span",{className:"text-sm text-white",children:"Custom Icon"}),a.jsx("input",{ref:s,type:"file",accept:"image/png,image/jpeg,image/gif,image/svg+xml,image/webp,image/x-icon",className:"hidden",onChange:C}),p&&x?a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("img",{src:x,alt:"Custom icon",className:`w-8 h-8 rounded border border-bambu-dark-tertiary ${r==="dark"?"invert opacity-[0.65]":"opacity-60"}`}),a.jsx("button",{type:"button",onClick:E,className:"p-1 text-red-400 hover:text-red-300 transition-colors",title:"Remove custom icon",children:a.jsx(an,{className:"w-4 h-4"})})]}):a.jsxs(Te,{type:"button",variant:"secondary",size:"sm",onClick:()=>s.current?.click(),children:[a.jsx(Ba,{className:"w-4 h-4"}),"Upload"]})]}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"PNG, JPG, GIF, SVG, WebP, or ICO. Max 1MB."})]}),!p&&a.jsxs("div",{children:[a.jsx("span",{className:"text-sm text-bambu-gray block mb-2",children:"Or choose a preset icon"}),a.jsx(Ffe,{value:d,onChange:h})]})]}),a.jsxs("div",{className:"flex gap-3 pt-2",children:[a.jsx(Te,{type:"button",variant:"secondary",onClick:e,className:"flex-1",children:"Cancel"}),a.jsxs(Te,{type:"submit",disabled:A,className:"flex-1",children:[A?a.jsx(pt,{className:"w-4 h-4 animate-spin"}):a.jsx(ms,{className:"w-4 h-4"}),i?"Save":"Add"]})]})]})]})})}function LKe(){const t=sn(),[e,n]=_.useState(!1),[r,i]=_.useState(null),[s,o]=_.useState(null),[l,c]=_.useState(null),{data:u,isLoading:d}=ct({queryKey:["external-links"],queryFn:ce.getExternalLinks}),h=gt({mutationFn:S=>ce.deleteExternalLink(S),onSuccess:()=>{t.invalidateQueries({queryKey:["external-links"]})}}),p=gt({mutationFn:S=>ce.reorderExternalLinks(S),onSuccess:()=>{t.invalidateQueries({queryKey:["external-links"]})}}),m=(S,N)=>{c(N),S.dataTransfer.effectAllowed="move"},x=S=>{S.preventDefault(),S.dataTransfer.dropEffect="move"},y=(S,N)=>{if(S.preventDefault(),l===null||l===N||!u)return;const T=u.map(P=>P.id),k=T.indexOf(l),C=T.indexOf(N);if(k===-1||C===-1)return;const E=[...T];E.splice(k,1),E.splice(C,0,l),p.mutate(E),c(null)},v=S=>{o(S)},b=()=>{s&&(h.mutate(s.id),o(null))};return a.jsxs(a.Fragment,{children:[a.jsxs(St,{children:[a.jsx(Kn,{children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(fc,{className:"w-5 h-5 text-bambu-green"}),a.jsx("h2",{className:"text-lg font-semibold text-white",children:"Sidebar Links"})]}),a.jsxs(Te,{size:"sm",onClick:()=>n(!0),children:[a.jsx(fr,{className:"w-4 h-4"}),"Add Link"]})]})}),a.jsxs(Nt,{children:[a.jsx("p",{className:"text-sm text-bambu-gray mb-4",children:"Add external links to the sidebar navigation. Drag to reorder."}),d?a.jsx("div",{className:"flex justify-center py-8",children:a.jsx(pt,{className:"w-6 h-6 text-bambu-green animate-spin"})}):u&&u.length>0?a.jsx("div",{className:"space-y-2",children:u.map(S=>{const N=wM(S.icon);return a.jsxs("div",{draggable:!0,onDragStart:T=>m(T,S.id),onDragOver:x,onDrop:T=>y(T,S.id),className:`flex items-center gap-3 p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary transition-colors ${l===S.id?"opacity-50":""}`,children:[a.jsx(Hg,{className:"w-6 h-6 md:w-4 md:h-4 text-bambu-gray cursor-grab flex-shrink-0"}),a.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark-tertiary text-bambu-gray",children:a.jsx(N,{className:"w-4 h-4"})}),a.jsxs("div",{className:"flex-1 min-w-0",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("span",{className:"text-white font-medium truncate",children:S.name}),a.jsx(Xr,{className:"w-3 h-3 text-bambu-gray flex-shrink-0"})]}),a.jsx("span",{className:"text-sm text-bambu-gray truncate block",children:S.url})]}),a.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[a.jsx("button",{onClick:()=>i(S),className:"p-2 rounded-lg hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white transition-colors",title:"Edit",children:a.jsx(ea,{className:"w-4 h-4"})}),a.jsx("button",{onClick:()=>v(S),disabled:h.isPending,className:"p-2 rounded-lg hover:bg-red-500/20 text-bambu-gray hover:text-red-400 transition-colors disabled:opacity-50",title:"Delete",children:a.jsx(an,{className:"w-4 h-4"})})]})]},S.id)})}):a.jsxs("div",{className:"text-center py-8 text-bambu-gray",children:[a.jsx(fc,{className:"w-8 h-8 mx-auto mb-2 opacity-50"}),a.jsx("p",{children:"No external links configured"}),a.jsx("p",{className:"text-sm",children:'Click "Add Link" to add one'})]})]})]}),(e||r)&&a.jsx(OKe,{link:r,onClose:()=>{n(!1),i(null)}}),s&&a.jsx(Zn,{title:"Delete Link",message:`Are you sure you want to delete "${s.name}"? This action cannot be undone.`,confirmText:"Delete",cancelText:"Cancel",variant:"danger",onConfirm:b,onCancel:()=>o(null)})]})}function FKe(){const{t}=On(),e=sn(),{showToast:n}=Hn(),[r,i]=_.useState(!1),[s,o]=_.useState(""),[l,c]=_.useState("immediate"),[u,d]=_.useState("3DPrinter-X1-Carbon"),[h,p]=_.useState(null),[m,x]=_.useState(!1),[y,v]=_.useState(null),{data:b,isLoading:S}=ct({queryKey:["virtual-printer-settings"],queryFn:x1.getSettings,refetchInterval:1e4}),{data:N}=ct({queryKey:["virtual-printer-models"],queryFn:x1.getModels}),{data:T}=ct({queryKey:["printers"],queryFn:ce.getPrinters});_.useEffect(()=>{if(b){i(b.enabled);let U=b.mode==="queue"?"review":b.mode;U!=="immediate"&&U!=="review"&&U!=="print_queue"&&U!=="proxy"&&(U="immediate"),c(U),d(b.model),p(b.target_printer_id)}},[b]);const k=gt({mutationFn:U=>x1.updateSettings(U),onSuccess:()=>{e.invalidateQueries({queryKey:["virtual-printer-settings"]}),n(t("virtualPrinter.toast.updated")),v(null)},onError:U=>{if(n(U.message||t("virtualPrinter.toast.failedToUpdate"),"error"),b){i(b.enabled);const j=b.mode==="queue"?"review":b.mode;c(["immediate","review","print_queue","proxy"].includes(j)?j:"immediate"),d(b.model),p(b.target_printer_id)}v(null)}}),C=()=>{const U=!r;if(U){if(l==="proxy"){if(!h){n(t("virtualPrinter.toast.targetPrinterRequired"),"error");return}}else if(!s&&!b?.access_code_set){n(t("virtualPrinter.toast.accessCodeRequired"),"error");return}}i(U),v("toggle"),k.mutate({enabled:U,access_code:l!=="proxy"&&s||void 0,mode:l,target_printer_id:l==="proxy"?h??void 0:void 0})},E=()=>{if(!s){n(t("virtualPrinter.toast.accessCodeEmpty"),"error");return}if(s.length!==8){n(t("virtualPrinter.toast.accessCodeLength"),"error");return}v("accessCode"),k.mutate({access_code:s}),o("")},P=U=>{c(U),v("mode"),k.mutate({mode:U})},A=U=>{p(U),v("targetPrinter"),k.mutate({target_printer_id:U})},D=U=>{d(U),v("model"),k.mutate({model:U})};if(S)return a.jsx(St,{children:a.jsx(Nt,{className:"py-8 flex justify-center",children:a.jsx(pt,{className:"w-6 h-6 animate-spin text-bambu-green"})})});const I=b?.status,L=I?.running||!1;return a.jsxs("div",{className:"flex flex-col lg:flex-row gap-6 lg:gap-8",children:[a.jsx("div",{className:"space-y-6 lg:w-[480px] lg:flex-shrink-0",children:a.jsxs(St,{children:[a.jsx(Kn,{children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(Ur,{className:"w-5 h-5 text-bambu-green"}),a.jsx("h2",{className:"text-lg font-semibold text-white",children:t("virtualPrinter.title")})]}),I&&a.jsxs("div",{className:`flex items-center gap-2 text-sm ${L?"text-green-400":"text-bambu-gray"}`,children:[a.jsx("span",{className:`w-2 h-2 rounded-full ${L?"bg-green-400 animate-pulse":"bg-gray-500"}`}),t(L?"virtualPrinter.running":"virtualPrinter.stopped")]})]})}),a.jsxs(Nt,{className:"space-y-4",children:[a.jsx("p",{className:"text-sm text-bambu-gray",children:t(l==="proxy"?"virtualPrinter.description.proxy":"virtualPrinter.description.default")}),a.jsxs("div",{className:"flex items-center justify-between py-3 border-t border-bambu-dark-tertiary",children:[a.jsxs("div",{children:[a.jsx("div",{className:"text-white font-medium",children:t("virtualPrinter.enable.title")}),a.jsx("div",{className:"text-sm text-bambu-gray",children:L?l==="proxy"?t("virtualPrinter.enable.proxyingTo",{name:T?.find(U=>U.id===h)?.name||"printer"}):t("virtualPrinter.enable.visibleInSlicer"):t("virtualPrinter.enable.notActive")})]}),a.jsx("button",{onClick:C,disabled:y==="toggle",className:`relative w-12 h-6 rounded-full transition-colors ${r?"bg-bambu-green":"bg-bambu-dark-tertiary"} ${y==="toggle"?"opacity-50":""}`,children:a.jsx("span",{className:`absolute top-1 left-1 w-4 h-4 bg-white rounded-full transition-transform ${r?"translate-x-6":""}`})})]}),l!=="proxy"&&a.jsxs("div",{className:"py-3 border-t border-bambu-dark-tertiary",children:[a.jsx("div",{className:"text-white font-medium mb-2",children:t("virtualPrinter.model.title")}),a.jsx("div",{className:"text-sm text-bambu-gray mb-3",children:t("virtualPrinter.model.description")}),a.jsxs("div",{className:"relative",children:[a.jsx("select",{value:u,onChange:U=>D(U.target.value),disabled:y==="model",className:"w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-2 text-white appearance-none cursor-pointer disabled:opacity-50 disabled:cursor-not-allowed pr-10",children:N?.models&&Object.entries(N.models).sort(([,U],[,j])=>U.localeCompare(j)).map(([U,j])=>a.jsx("option",{value:U,children:j},U))}),a.jsx(Kr,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}),r&&L&&a.jsxs("p",{className:"text-xs text-bambu-gray mt-2",children:[a.jsx(nl,{className:"w-3 h-3 inline mr-1"}),t("virtualPrinter.model.restartWarning")]})]}),l!=="proxy"&&a.jsxs("div",{className:"py-3 border-t border-bambu-dark-tertiary",children:[a.jsx("div",{className:"text-white font-medium mb-2",children:t("virtualPrinter.accessCode.title")}),a.jsx("div",{className:"text-sm text-bambu-gray mb-3",children:b?.access_code_set?a.jsxs("span",{className:"flex items-center gap-1 text-green-400",children:[a.jsx(Wi,{className:"w-4 h-4"}),t("virtualPrinter.accessCode.isSet")]}):a.jsxs("span",{className:"flex items-center gap-1 text-yellow-400",children:[a.jsx(Sn,{className:"w-4 h-4"}),t("virtualPrinter.accessCode.notSet")]})}),a.jsxs("div",{className:"flex gap-2",children:[a.jsxs("div",{className:"relative flex-1",children:[a.jsx("input",{type:m?"text":"password",value:s,onChange:U=>o(U.target.value),placeholder:b?.access_code_set?t("virtualPrinter.accessCode.placeholderChange"):t("virtualPrinter.accessCode.placeholder"),maxLength:8,className:"w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-2 text-white placeholder-bambu-gray pr-10 font-mono"}),a.jsx("button",{onClick:()=>x(!m),className:"absolute right-2 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white",children:m?a.jsx(uM,{className:"w-4 h-4"}):a.jsx(xc,{className:"w-4 h-4"})})]}),a.jsx(Te,{onClick:E,disabled:!s||y==="accessCode",variant:"primary",children:y==="accessCode"?a.jsx(pt,{className:"w-4 h-4 animate-spin"}):t("common.save")})]}),a.jsxs("p",{className:"text-xs text-bambu-gray mt-2",children:[t("virtualPrinter.accessCode.hint"),s&&a.jsxs("span",{className:s.length===8?"text-green-400":"text-yellow-400",children:[" ",t("virtualPrinter.accessCode.charCount",{count:s.length})]})]})]}),l==="proxy"&&a.jsxs("div",{className:"py-3 border-t border-bambu-dark-tertiary",children:[a.jsx("div",{className:"text-white font-medium mb-2",children:t("virtualPrinter.targetPrinter.title")}),a.jsx("div",{className:"text-sm text-bambu-gray mb-3",children:h?a.jsxs("span",{className:"flex items-center gap-1 text-green-400",children:[a.jsx(Wi,{className:"w-4 h-4"}),t("virtualPrinter.targetPrinter.configured")]}):a.jsxs("span",{className:"flex items-center gap-1 text-yellow-400",children:[a.jsx(Sn,{className:"w-4 h-4"}),t("virtualPrinter.targetPrinter.notConfigured")]})}),a.jsxs("div",{className:"relative",children:[a.jsxs("select",{value:h??"",onChange:U=>{const j=parseInt(U.target.value,10);isNaN(j)||A(j)},disabled:y==="targetPrinter",className:"w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-2 text-white appearance-none cursor-pointer disabled:opacity-50 disabled:cursor-not-allowed pr-10",children:[a.jsx("option",{value:"",children:t("virtualPrinter.targetPrinter.placeholder")}),T?.map(U=>a.jsxs("option",{value:U.id,children:[U.name," (",U.ip_address,")"]},U.id))]}),a.jsx(Kr,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}),a.jsx("p",{className:"text-xs text-bambu-gray mt-2",children:t("virtualPrinter.targetPrinter.hint")}),!T?.length&&a.jsxs("p",{className:"text-xs text-yellow-400 mt-2",children:[a.jsx(Sn,{className:"w-3 h-3 inline mr-1"}),t("virtualPrinter.targetPrinter.noPrinters")]})]}),a.jsxs("div",{className:"py-3 border-t border-bambu-dark-tertiary",children:[a.jsx("div",{className:"text-white font-medium mb-2",children:t("virtualPrinter.mode.title")}),a.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[a.jsxs("button",{onClick:()=>P("immediate"),disabled:y==="mode",className:`p-3 rounded-lg border text-left transition-colors ${l==="immediate"?"border-bambu-green bg-bambu-green/10":"border-bambu-dark-tertiary hover:border-bambu-gray"}`,children:[a.jsx("div",{className:"text-white font-medium",children:t("virtualPrinter.mode.archive")}),a.jsx("div",{className:"text-xs text-bambu-gray",children:t("virtualPrinter.mode.archiveDesc")})]}),a.jsxs("button",{onClick:()=>P("review"),disabled:y==="mode",className:`p-3 rounded-lg border text-left transition-colors ${l==="review"?"border-bambu-green bg-bambu-green/10":"border-bambu-dark-tertiary hover:border-bambu-gray"}`,children:[a.jsx("div",{className:"text-white font-medium",children:t("virtualPrinter.mode.review")}),a.jsx("div",{className:"text-xs text-bambu-gray",children:t("virtualPrinter.mode.reviewDesc")})]}),a.jsxs("button",{onClick:()=>P("print_queue"),disabled:y==="mode",className:`p-3 rounded-lg border text-left transition-colors ${l==="print_queue"?"border-bambu-green bg-bambu-green/10":"border-bambu-dark-tertiary hover:border-bambu-gray"}`,children:[a.jsx("div",{className:"text-white font-medium",children:t("virtualPrinter.mode.queue")}),a.jsx("div",{className:"text-xs text-bambu-gray",children:t("virtualPrinter.mode.queueDesc")})]}),a.jsxs("button",{onClick:()=>P("proxy"),disabled:y==="mode",className:`p-3 rounded-lg border text-left transition-colors ${l==="proxy"?"border-blue-500 bg-blue-500/10":"border-bambu-dark-tertiary hover:border-bambu-gray"}`,children:[a.jsxs("div",{className:"flex items-center gap-1.5 text-white font-medium",children:[a.jsx(Iz,{className:"w-4 h-4"}),t("virtualPrinter.mode.proxy")]}),a.jsx("div",{className:"text-xs text-bambu-gray",children:t("virtualPrinter.mode.proxyDesc")})]})]})]})]})]})}),a.jsxs("div",{className:"space-y-6 lg:w-[480px] lg:flex-shrink-0",children:[a.jsx(St,{className:"border-l-4 border-l-yellow-500",children:a.jsx(Nt,{className:"py-4",children:a.jsxs("div",{className:"flex items-start gap-3",children:[a.jsx(Sn,{className:"w-5 h-5 text-yellow-500 flex-shrink-0 mt-0.5"}),a.jsxs("div",{className:"text-sm",children:[a.jsx("p",{className:"text-white font-medium mb-2",children:t("virtualPrinter.setupRequired.title")}),a.jsx("p",{className:"text-bambu-gray mb-3",children:t("virtualPrinter.setupRequired.description")}),a.jsxs("a",{href:"https://wiki.bambuddy.cool/features/virtual-printer/",target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-2 px-4 py-2 bg-yellow-500/20 border border-yellow-500/50 rounded-md text-yellow-400 hover:bg-yellow-500/30 transition-colors",children:[a.jsx(Xr,{className:"w-4 h-4"}),t("virtualPrinter.setupRequired.readGuide")]})]})]})})}),a.jsx(St,{children:a.jsx(Nt,{className:"py-4",children:a.jsxs("div",{className:"flex items-start gap-3",children:[a.jsx(nl,{className:"w-5 h-5 text-blue-400 flex-shrink-0 mt-0.5"}),a.jsxs("div",{className:"text-sm text-bambu-gray",children:[a.jsx("p",{className:"mb-2",children:a.jsxs("strong",{className:"text-white",children:[t(l==="proxy"?"virtualPrinter.howItWorks.titleProxy":"virtualPrinter.howItWorks.title"),":"]})}),l==="proxy"?a.jsxs("ol",{className:"list-decimal list-inside space-y-1",children:[a.jsx("li",{children:t("virtualPrinter.howItWorks.proxyStep1")}),a.jsx("li",{children:t("virtualPrinter.howItWorks.proxyStep2")}),a.jsx("li",{children:t("virtualPrinter.howItWorks.proxyStep3")}),a.jsx("li",{children:t("virtualPrinter.howItWorks.proxyStep4")}),a.jsx("li",{children:t("virtualPrinter.howItWorks.proxyStep5")})]}):a.jsxs("ol",{className:"list-decimal list-inside space-y-1",children:[a.jsx("li",{children:t("virtualPrinter.howItWorks.step1")}),a.jsx("li",{children:t("virtualPrinter.howItWorks.step2")}),a.jsx("li",{children:t("virtualPrinter.howItWorks.step3")}),a.jsx("li",{children:t("virtualPrinter.howItWorks.step4")}),a.jsx("li",{children:t("virtualPrinter.howItWorks.step5")}),a.jsx("li",{children:t("virtualPrinter.howItWorks.step6")})]})]})]})})}),I&&L&&a.jsxs(St,{children:[a.jsx(Kn,{children:a.jsx("h3",{className:"text-md font-semibold text-white",children:t("virtualPrinter.status.title")})}),a.jsx(Nt,{children:I.mode==="proxy"&&I.proxy?a.jsxs("div",{className:"grid grid-cols-2 gap-4 text-sm",children:[a.jsxs("div",{children:[a.jsx("div",{className:"text-bambu-gray",children:t("virtualPrinter.status.targetPrinter")}),a.jsx("div",{className:"text-white",children:T?.find(U=>U.id===h)?.name||I.proxy.target_host}),a.jsx("div",{className:"text-xs text-bambu-gray font-mono",children:I.proxy.target_host})]}),a.jsxs("div",{children:[a.jsx("div",{className:"text-bambu-gray",children:t("virtualPrinter.status.mode")}),a.jsxs("div",{className:"text-white flex items-center gap-1.5",children:[a.jsx(Iz,{className:"w-4 h-4"}),t("virtualPrinter.mode.proxy")]})]}),a.jsxs("div",{children:[a.jsx("div",{className:"text-bambu-gray",children:t("virtualPrinter.status.ftpPort")}),a.jsx("div",{className:"text-white font-mono",children:I.proxy.ftp_port})]}),a.jsxs("div",{children:[a.jsx("div",{className:"text-bambu-gray",children:t("virtualPrinter.status.mqttPort")}),a.jsx("div",{className:"text-white font-mono",children:I.proxy.mqtt_port})]}),a.jsxs("div",{children:[a.jsx("div",{className:"text-bambu-gray",children:t("virtualPrinter.status.ftpConnections")}),a.jsx("div",{className:"text-white",children:I.proxy.ftp_connections})]}),a.jsxs("div",{children:[a.jsx("div",{className:"text-bambu-gray",children:t("virtualPrinter.status.mqttConnections")}),a.jsx("div",{className:"text-white",children:I.proxy.mqtt_connections})]})]}):a.jsxs("div",{className:"grid grid-cols-2 gap-4 text-sm",children:[a.jsxs("div",{children:[a.jsx("div",{className:"text-bambu-gray",children:t("virtualPrinter.status.printerName")}),a.jsx("div",{className:"text-white",children:I.name})]}),a.jsxs("div",{children:[a.jsx("div",{className:"text-bambu-gray",children:t("virtualPrinter.status.model")}),a.jsx("div",{className:"text-white",children:I.model_name||I.model})]}),a.jsxs("div",{children:[a.jsx("div",{className:"text-bambu-gray",children:t("virtualPrinter.status.serialNumber")}),a.jsx("div",{className:"text-white font-mono",children:I.serial})]}),a.jsxs("div",{children:[a.jsx("div",{className:"text-bambu-gray",children:t("virtualPrinter.status.mode")}),a.jsx("div",{className:"text-white capitalize",children:I.mode})]}),a.jsxs("div",{children:[a.jsx("div",{className:"text-bambu-gray",children:t("virtualPrinter.status.pendingFiles")}),a.jsx("div",{className:"text-white",children:I.pending_files})]})]})})]})]})]})}function Sq({status:t}){if(!t)return null;const e={success:"bg-green-500/20 text-green-400",failed:"bg-red-500/20 text-red-400",skipped:"bg-yellow-500/20 text-yellow-400",running:"bg-blue-500/20 text-blue-400"},n={success:a.jsx(Ar,{className:"w-3 h-3"}),failed:a.jsx(Ji,{className:"w-3 h-3"}),skipped:a.jsx(LR,{className:"w-3 h-3"}),running:a.jsx(pt,{className:"w-3 h-3 animate-spin"})};return a.jsxs("span",{className:`inline-flex items-center gap-1 px-2 py-0.5 rounded text-xs font-medium ${e[t]||"bg-gray-500/20 text-gray-400"}`,children:[n[t],t.charAt(0).toUpperCase()+t.slice(1)]})}function IKe(t){return t?new Date(t).toLocaleString():"-"}function Nq(t){if(!t)return"-";const e=new Date(t),n=new Date,r=e.getTime()-n.getTime(),i=Math.round(r/6e4);if(i<0){const s=Math.abs(i);if(s<60)return`${s}m ago`;const o=Math.floor(s/60);return o<24?`${o}h ago`:`${Math.floor(o/24)}d ago`}else{if(i<60)return`in ${i}m`;const s=Math.floor(i/60);return s<24?`in ${s}h`:`in ${Math.floor(s/24)}d`}}function UKe(){const t=sn(),{showToast:e}=Hn(),{t:n}=On(),[r,i]=_.useState(""),[s,o]=_.useState(""),[l,c]=_.useState("main"),[u,d]=_.useState(!1),[h,p]=_.useState("daily"),[m,x]=_.useState(!0),[y,v]=_.useState(!0),[b,S]=_.useState(!1),[N,T]=_.useState(!0),[k,C]=_.useState(!1),[E,P]=_.useState(!1),[A,D]=_.useState(""),[I,L]=_.useState(!1),[U,j]=_.useState(null),[$,K]=_.useState(null),B=_.useRef(null);_.useEffect(()=>{if(k||E){const z=O=>(O.preventDefault(),O.returnValue="A backup operation is in progress. Are you sure you want to leave?",O.returnValue);return window.addEventListener("beforeunload",z),()=>window.removeEventListener("beforeunload",z)}},[k,E]);const[X,Y]=_.useState(!1),[ne,H]=_.useState(null),W=_.useRef(null),re=_.useRef(!1),{data:ie,isLoading:pe}=ct({queryKey:["github-backup-config"],queryFn:ce.getGitHubBackupConfig}),{data:me}=ct({queryKey:["github-backup-status"],queryFn:ce.getGitHubBackupStatus,refetchInterval:te=>te.state.data?.is_running?500:1e4}),{data:de}=ct({queryKey:["github-backup-logs"],queryFn:()=>ce.getGitHubBackupLogs(20)}),{data:Ee}=ct({queryKey:["cloud-status"],queryFn:ce.getCloudStatus}),{data:se}=ct({queryKey:["printers"],queryFn:ce.getPrinters}),Ae=jR({queries:(se??[]).map(te=>({queryKey:["printerStatus",te.id],queryFn:()=>ce.getPrinterStatus(te.id),staleTime:1e4,refetchInterval:3e4}))}),Fe=(se??[]).map((te,z)=>({printer:te,connected:Ae[z]?.data?.connected??!1})),ge=Fe.length,Ze=Fe.filter(te=>te.connected).length,G=ge>0&&Ze===0,Q=Ze>0&&Ze{ie&&(i(ie.repository_url),c(ie.branch),d(ie.schedule_enabled),p(ie.schedule_type),x(ie.backup_kprofiles),v(ie.backup_cloud_profiles),S(ie.backup_settings),T(ie.enabled),o(""),setTimeout(()=>{re.current=!0},100))},[ie]);const he=_.useCallback(async(te=!1)=>{if(ie?.has_token)try{te&&s?(await ce.saveGitHubBackupConfig({repository_url:r,access_token:s,branch:l,schedule_enabled:u,schedule_type:h,backup_kprofiles:m,backup_cloud_profiles:y,backup_settings:b,enabled:N}),o(""),e("Token updated")):(await ce.updateGitHubBackupConfig({repository_url:r,branch:l,schedule_enabled:u,schedule_type:h,backup_kprofiles:m,backup_cloud_profiles:y,backup_settings:b,enabled:N}),e("Settings saved")),t.invalidateQueries({queryKey:["github-backup-config"]}),t.invalidateQueries({queryKey:["github-backup-status"]})}catch(z){e(`Failed to save: ${z.message}`,"error")}},[ie?.has_token,r,s,l,u,h,m,y,b,N,t,e]);_.useEffect(()=>{if(!(!re.current||!ie?.has_token))return W.current&&clearTimeout(W.current),W.current=setTimeout(()=>{he(!1)},500),()=>{W.current&&clearTimeout(W.current)}},[r,l,u,h,m,y,b,N,he,ie?.has_token]),_.useEffect(()=>{if(!(!re.current||!ie?.has_token||!s))return W.current&&clearTimeout(W.current),W.current=setTimeout(()=>{he(!0)},1e3),()=>{W.current&&clearTimeout(W.current)}},[s,he,ie?.has_token]);const q=gt({mutationFn:te=>ce.saveGitHubBackupConfig(te),onSuccess:()=>{t.invalidateQueries({queryKey:["github-backup-config"]}),t.invalidateQueries({queryKey:["github-backup-status"]}),e("GitHub backup enabled"),o(""),re.current=!0},onError:te=>{e(`Failed to save: ${te.message}`,"error")}}),ee=gt({mutationFn:ce.triggerGitHubBackup,onSuccess:te=>{t.invalidateQueries({queryKey:["github-backup-status"]}),t.invalidateQueries({queryKey:["github-backup-logs"]}),te.success?te.files_changed>0?e(`Backup complete - ${te.files_changed} files updated`):e("Backup skipped - no changes"):e(`Backup failed: ${te.message}`,"error")},onError:te=>{e(`Backup failed: ${te.message}`,"error")}}),V=gt({mutationFn:()=>ce.clearGitHubBackupLogs(0),onSuccess:te=>{t.invalidateQueries({queryKey:["github-backup-logs"]}),e(`Cleared ${te.deleted} logs`)},onError:te=>{e(`Failed to clear logs: ${te.message}`,"error")}}),ye=async()=>{Y(!0),H(null);try{let te;if(s){if(!r){e("Enter repository URL","error"),Y(!1);return}te=await ce.testGitHubConnection(r,s)}else if(ie?.has_token)te=await ce.testGitHubStoredConnection();else{e("Enter repository URL and access token","error"),Y(!1);return}H({success:te.success,message:te.message})}catch(te){H({success:!1,message:te.message})}finally{Y(!1)}},je=()=>{if(!r){e("Repository URL is required","error");return}if(!s){e("Access token is required","error");return}q.mutate({repository_url:r,access_token:s,branch:l,schedule_enabled:u,schedule_type:h,backup_kprofiles:m,backup_cloud_profiles:y,backup_settings:b,enabled:N})};return pe?a.jsx("div",{className:"flex items-center justify-center py-12",children:a.jsx(pt,{className:"w-8 h-8 animate-spin text-bambu-green"})}):a.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[a.jsxs("div",{className:"space-y-6",children:[a.jsxs(St,{children:[a.jsx(Kn,{children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(pP,{className:"w-5 h-5 text-gray-400"}),a.jsx("h2",{className:"text-lg font-semibold text-white",children:"GitHub Backup"})]}),ie&&Ee?.is_authenticated&&a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("span",{className:"text-sm text-bambu-gray",children:"Enabled"}),a.jsx(Fn,{checked:N,onChange:T})]})]})}),a.jsx(Nt,{className:"space-y-4",children:Ee?.is_authenticated?a.jsxs(a.Fragment,{children:[a.jsx("p",{className:"text-sm text-bambu-gray",children:"Automatically sync your profiles to a private GitHub repository for backup and version history."}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Repository URL"}),a.jsx("input",{type:"text",value:r,onChange:te=>{i(te.target.value),H(null)},placeholder:"https://github.com/username/bambuddy-backup",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"})]}),a.jsxs("div",{children:[a.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:["Personal Access Token ",ie?.has_token&&a.jsx("span",{className:"text-green-400",children:"(saved)"})]}),a.jsx("input",{type:"password",value:s,onChange:te=>{o(te.target.value),H(null)},placeholder:ie?.has_token?"Enter new token to update":"ghp_xxxxxxxxxxxx",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"}),a.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Fine-grained token with Contents read/write permission"})]}),a.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Branch"}),a.jsx("input",{type:"text",value:l,onChange:te=>c(te.target.value),placeholder:"main",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"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Auto-backup"}),a.jsxs("select",{value:u?h:"disabled",onChange:te=>{te.target.value==="disabled"?d(!1):(d(!0),p(te.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",children:[a.jsx("option",{value:"disabled",children:"Manual only"}),a.jsx("option",{value:"hourly",children:"Hourly"}),a.jsx("option",{value:"daily",children:"Daily"}),a.jsx("option",{value:"weekly",children:"Weekly"})]})]})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-2",children:"Include in backup"}),a.jsxs("div",{className:"space-y-2",children:[a.jsxs("label",{className:`flex items-start gap-2 ${G?"cursor-not-allowed opacity-60":"cursor-pointer"}`,children:[a.jsx("input",{type:"checkbox",checked:m,onChange:te=>x(te.target.checked),className:"w-4 h-4 mt-0.5 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green",disabled:G}),a.jsxs("div",{className:"flex-1",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("span",{className:`text-sm ${G?"text-bambu-gray":"text-white"}`,children:"K-Profiles"}),G&&a.jsxs("span",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-xs bg-yellow-500/20 text-yellow-400",children:[a.jsx(Sn,{className:"w-3 h-3"}),"No printers connected"]}),Q&&a.jsxs("span",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-xs bg-yellow-500/20 text-yellow-400",children:[a.jsx(Sn,{className:"w-3 h-3"}),Ze,"/",ge," connected"]})]}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Pressure advance calibration from connected printers"})]})]}),a.jsxs("label",{className:"flex items-start gap-2 cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:y,onChange:te=>v(te.target.checked),className:"w-4 h-4 mt-0.5 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green",disabled:!Ee?.is_authenticated}),a.jsxs("div",{children:[a.jsx("span",{className:`text-sm ${Ee?.is_authenticated?"text-white":"text-bambu-gray"}`,children:"Cloud Profiles"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Filament, printer, and process presets from Bambu Cloud"})]})]}),a.jsxs("label",{className:"flex items-start gap-2 cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:b,onChange:te=>S(te.target.checked),className:"w-4 h-4 mt-0.5 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),a.jsxs("div",{children:[a.jsx("span",{className:"text-white text-sm",children:"App Settings"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Bambuddy configuration (excludes sensitive data)"})]})]})]})]}),a.jsxs("div",{className:"border-t border-bambu-dark-tertiary pt-4 space-y-3",children:[me?.configured&&a.jsxs("div",{className:"flex items-center justify-between text-sm",children:[a.jsx("div",{className:"flex items-center gap-2 text-bambu-gray",children:me.last_backup_at?a.jsxs(a.Fragment,{children:[a.jsxs("span",{children:["Last backup: ",Nq(me.last_backup_at)]}),a.jsx(Sq,{status:me.last_backup_status})]}):a.jsx("span",{children:"No backups yet"})}),me.next_scheduled_run&&a.jsxs("span",{className:"text-bambu-gray",children:[a.jsx(tr,{className:"w-3 h-3 inline mr-1"}),"Next: ",Nq(me.next_scheduled_run)]})]}),ne&&a.jsxs("div",{className:`text-sm flex items-center gap-1 ${ne.success?"text-green-400":"text-red-400"}`,children:[ne.success?a.jsx(Ar,{className:"w-4 h-4"}):a.jsx(Ji,{className:"w-4 h-4"}),ne.message]}),a.jsx("div",{className:"flex flex-wrap items-center gap-2",children:me?.configured?a.jsx(a.Fragment,{children:ee.isPending||me.is_running?a.jsxs("div",{className:"flex items-center gap-2 text-bambu-green",children:[a.jsx(pt,{className:"w-4 h-4 animate-spin"}),a.jsx("span",{className:"text-sm",children:me.progress||"Starting backup..."})]}):a.jsxs(a.Fragment,{children:[a.jsxs(Te,{variant:"primary",size:"sm",onClick:()=>ee.mutate(),disabled:!ie?.enabled,children:[a.jsx(So,{className:"w-4 h-4"}),"Backup Now"]}),a.jsxs(Te,{variant:"secondary",size:"sm",onClick:ye,disabled:X,children:[X?a.jsx(pt,{className:"w-4 h-4 animate-spin"}):a.jsx(Dr,{className:"w-4 h-4"}),"Test"]})]})}):a.jsxs(a.Fragment,{children:[a.jsxs(Te,{variant:"primary",size:"sm",onClick:je,disabled:q.isPending||!r||!s,children:[q.isPending?a.jsx(pt,{className:"w-4 h-4 animate-spin"}):a.jsx(Ar,{className:"w-4 h-4"}),"Enable Backup"]}),a.jsxs(Te,{variant:"secondary",size:"sm",onClick:ye,disabled:X||!r||!s,children:[X?a.jsx(pt,{className:"w-4 h-4 animate-spin"}):a.jsx(Dr,{className:"w-4 h-4"}),"Test Connection"]})]})})]})]}):a.jsxs("div",{className:"flex items-start gap-2 p-3 bg-yellow-500/10 border border-yellow-500/30 rounded-lg",children:[a.jsx(Sn,{className:"w-4 h-4 text-yellow-400 mt-0.5 flex-shrink-0"}),a.jsx("p",{className:"text-sm text-yellow-400",children:"Bambu Cloud login required. Sign in under Profiles → Cloud Profiles to enable GitHub backup."})]})})]}),de&&de.length>0&&a.jsxs(St,{children:[a.jsx(Kn,{children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(W0,{className:"w-5 h-5 text-gray-400"}),a.jsx("h2",{className:"text-lg font-semibold text-white",children:"History"})]}),a.jsxs(Te,{variant:"ghost",size:"sm",onClick:()=>V.mutate(),disabled:V.isPending,children:[a.jsx(an,{className:"w-4 h-4"}),"Clear"]})]})}),a.jsx(Nt,{children:a.jsx("div",{className:"overflow-x-auto",children:a.jsxs("table",{className:"w-full text-sm",children:[a.jsx("thead",{children:a.jsxs("tr",{className:"text-bambu-gray border-b border-bambu-dark-tertiary",children:[a.jsx("th",{className:"text-left py-2 px-2",children:"Date"}),a.jsx("th",{className:"text-left py-2 px-2",children:"Status"}),a.jsx("th",{className:"text-left py-2 px-2",children:"Commit"})]})}),a.jsx("tbody",{children:de.slice(0,10).map(te=>a.jsxs("tr",{className:"border-b border-bambu-dark-tertiary/50 hover:bg-bambu-dark-secondary",children:[a.jsx("td",{className:"py-2 px-2 text-white",children:IKe(te.started_at)}),a.jsx("td",{className:"py-2 px-2",children:a.jsx(Sq,{status:te.status})}),a.jsx("td",{className:"py-2 px-2",children:te.commit_sha?a.jsxs("a",{href:`${ie?.repository_url}/commit/${te.commit_sha}`,target:"_blank",rel:"noopener noreferrer",className:"text-bambu-green hover:underline inline-flex items-center gap-1",children:[te.commit_sha.substring(0,7),a.jsx(Xr,{className:"w-3 h-3"})]}):a.jsx("span",{className:"text-bambu-gray",children:"-"})})]},te.id))})]})})})]})]}),a.jsx("div",{className:"space-y-6",children:a.jsxs(St,{children:[a.jsx(Kn,{children:a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(Eu,{className:"w-5 h-5 text-gray-400"}),a.jsx("h2",{className:"text-lg font-semibold text-white",children:"Local Backup"})]})}),a.jsxs(Nt,{className:"space-y-4",children:[a.jsx("p",{className:"text-sm text-bambu-gray",children:"Create a complete backup of your Bambuddy data including the database, archives, uploads, and all files."}),a.jsxs("div",{className:"flex items-center justify-between py-3 border-b border-bambu-dark-tertiary",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-white",children:"Download Backup"}),a.jsx("p",{className:"text-sm text-bambu-gray",children:"Complete backup: database + all files (ZIP)"})]}),a.jsxs(Te,{variant:"secondary",size:"sm",disabled:k||E,onClick:async()=>{C(!0),D("Preparing backup...");try{D("Creating backup archive... This may take a while for large archives.");const{blob:te,filename:z}=await ce.exportBackup();D("Downloading backup file...");const O=URL.createObjectURL(te),Z=document.createElement("a");Z.href=O,Z.download=z,Z.click(),URL.revokeObjectURL(O),e("Backup downloaded successfully")}catch(te){e(`Failed to create backup: ${te instanceof Error?te.message:"Unknown error"}`,"error")}finally{C(!1),D("")}},children:[a.jsx(wi,{className:"w-4 h-4"}),"Download"]})]}),a.jsxs("div",{className:"flex items-center justify-between py-3 border-b border-bambu-dark-tertiary",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-white",children:n("backup.restoreBackup")}),a.jsx("p",{className:"text-sm text-bambu-gray",children:n("backup.restoreDescription")}),a.jsx("p",{className:"text-xs text-bambu-gray-light mt-1",children:n("backup.restoreNote")})]}),a.jsx("input",{ref:B,type:"file",accept:".zip",className:"hidden",onChange:te=>{const z=te.target.files?.[0];z&&(j(z),L(!0)),te.target.value=""}}),a.jsxs(Te,{variant:"secondary",size:"sm",disabled:E||k,onClick:()=>B.current?.click(),children:[a.jsx(Ba,{className:"w-4 h-4"}),"Restore"]})]}),$&&a.jsx("div",{className:`p-3 rounded-lg ${$.success?"bg-green-500/10 border border-green-500/30":"bg-red-500/10 border border-red-500/30"}`,children:a.jsxs("div",{className:"flex items-start gap-2 text-sm",children:[$.success?a.jsx(Ar,{className:"w-4 h-4 text-green-400 mt-0.5 flex-shrink-0"}):a.jsx(Ji,{className:"w-4 h-4 text-red-400 mt-0.5 flex-shrink-0"}),a.jsxs("div",{className:$.success?"text-green-200":"text-red-200",children:[$.message,$.success&&a.jsx("div",{className:"mt-2",children:a.jsxs(Te,{size:"sm",onClick:()=>window.location.reload(),children:[a.jsx(Lh,{className:"w-3 h-3"}),"Reload Now"]})})]})]})}),a.jsx("div",{className:"p-3 rounded-lg bg-yellow-500/10 border border-yellow-500/30",children:a.jsxs("div",{className:"flex items-start gap-2 text-sm",children:[a.jsx(Sn,{className:"w-4 h-4 text-yellow-400 mt-0.5 flex-shrink-0"}),a.jsxs("div",{className:"text-yellow-200",children:[a.jsx("span",{className:"font-medium",children:"Restore replaces all data."})," ",a.jsx("span",{className:"text-yellow-200/70",children:"Your current database and files will be completely replaced. A restart is required after restore."})]})]})})]})]})}),I&&U&&a.jsx(Zn,{title:"Restore Backup",message:`Are you sure you want to restore from "${U.name}"? This will completely replace your current database and all files. The application will need to be restarted after restore.`,confirmText:"Restore Backup",variant:"danger",onConfirm:async()=>{L(!1),P(!0),K(null);try{D("Uploading backup file...");const te=await ce.importBackup(U);K(te),te.success?e("Backup restored. Please restart Bambuddy.","success"):e(te.message,"error")}catch(te){const z=te instanceof Error?te.message:"Failed to restore backup";K({success:!1,message:z}),e(z,"error")}finally{P(!1),D(""),j(null)}},onCancel:()=>{L(!1),j(null)}}),(k||E)&&a.jsx("div",{className:"fixed inset-0 bg-black/80 flex items-center justify-center z-[100]",children:a.jsxs("div",{className:"bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl p-8 max-w-md w-full mx-4 text-center",children:[a.jsx("div",{className:"flex justify-center mb-4",children:a.jsxs("div",{className:"relative",children:[a.jsx("div",{className:"w-16 h-16 border-4 border-bambu-dark-tertiary rounded-full"}),a.jsx("div",{className:"w-16 h-16 border-4 border-bambu-green border-t-transparent rounded-full absolute inset-0 animate-spin"})]})}),a.jsx("h3",{className:"text-xl font-semibold text-white mb-2",children:k?"Creating Backup":"Restoring Backup"}),a.jsx("p",{className:"text-bambu-gray mb-4",children:A||(k?"Preparing...":"Processing...")}),a.jsx("div",{className:"p-3 rounded-lg bg-yellow-500/10 border border-yellow-500/30",children:a.jsxs("div",{className:"flex items-start gap-2 text-sm",children:[a.jsx(Sn,{className:"w-4 h-4 text-yellow-400 mt-0.5 flex-shrink-0"}),a.jsx("p",{className:"text-yellow-200 text-left",children:"Please do not close this page or navigate away. This operation may take several minutes for large backups."})]})})]})})]})}const zKe={get:"bg-blue-500/20 text-blue-400 border-blue-500/30",post:"bg-green-500/20 text-green-400 border-green-500/30",put:"bg-yellow-500/20 text-yellow-400 border-yellow-500/30",patch:"bg-orange-500/20 text-orange-400 border-orange-500/30",delete:"bg-red-500/20 text-red-400 border-red-500/30"};function BKe(t,e){const n=e.replace("#/","").split("/");let r=t;for(const i of n)r=r[i];return r}function g0(t,e,n=0){if(n>5)return"...";if(e.$ref)return g0(t,BKe(t,e.$ref),n+1);if(e.allOf){const r={};for(const i of e.allOf){const s=g0(t,i,n+1);typeof s=="object"&&s!==null&&Object.assign(r,s)}return r}if(e.example!==void 0)return e.example;if(e.default!==void 0)return e.default;switch(e.type){case"string":return e.enum?e.enum[0]:"string";case"integer":case"number":return 0;case"boolean":return!1;case"array":return e.items?[g0(t,e.items,n+1)]:[];case"object":if(e.properties){const r={};for(const[i,s]of Object.entries(e.properties))r[i]=g0(t,s,n+1);return r}return{};default:return null}}function HKe({path:t,method:e,spec:n,schema:r,apiKey:i}){const[s,o]=_.useState(!1),[l,c]=_.useState({}),[u,d]=_.useState(""),[h,p]=_.useState(null),[m,x]=_.useState(!1),[y,v]=_.useState(!1);_.useEffect(()=>{if(s&&n.parameters){const P={};for(const A of n.parameters)A.schema?.default!==void 0&&(P[A.name]=String(A.schema.default));c(A=>({...P,...A}))}},[s,n.parameters]),_.useEffect(()=>{if(s&&n.requestBody?.content?.["application/json"]?.schema&&!u){const P=n.requestBody.content["application/json"].schema,A=g0(r,P);d(JSON.stringify(A,null,2))}},[s,n.requestBody,r,u]);const S=(()=>{const P=[];for(const A of n.parameters||[])if(A.in==="path"||A.required){const D=l[A.name];(D===void 0||D==="")&&P.push(A.name)}return P})(),N=async()=>{if(S.length>0){p({status:0,statusText:"Validation Error",headers:{},body:`Missing required parameters: ${S.join(", ")}`,duration:0});return}x(!0),p(null);try{let P=t;const A=new URLSearchParams;for(const ne of n.parameters||[]){const H=l[ne.name];H!==void 0&&H!==""&&(ne.in==="path"?P=P.replace(`{${ne.name}}`,encodeURIComponent(H)):ne.in==="query"&&A.append(ne.name,H))}const D=A.toString(),I=`${P}${D?`?${D}`:""}`,L={"Content-Type":"application/json"};i&&(L["X-API-Key"]=i);const U={method:e.toUpperCase(),headers:L};["post","put","patch"].includes(e)&&u&&(U.body=u);const j=performance.now(),$=await fetch(I,U),K=Math.round(performance.now()-j),B={};$.headers.forEach((ne,H)=>{B[H]=ne});let X;$.headers.get("content-type")?.includes("application/json")?X=await $.json():X=await $.text(),p({status:$.status,statusText:$.statusText,headers:B,body:X,duration:K})}catch(P){p({status:0,statusText:"Network Error",headers:{},body:P instanceof Error?P.message:"Unknown error",duration:0})}finally{x(!1)}},T=async()=>{if(h){const P=typeof h.body=="string"?h.body:JSON.stringify(h.body,null,2);try{await navigator.clipboard.writeText(P),v(!0),setTimeout(()=>v(!1),2e3)}catch{const A=document.createElement("textarea");A.value=P,A.style.position="fixed",A.style.left="-999999px",document.body.appendChild(A),A.select(),document.execCommand("copy"),document.body.removeChild(A),v(!0),setTimeout(()=>v(!1),2e3)}}},k=(n.parameters||[]).filter(P=>P.in==="path"),C=(n.parameters||[]).filter(P=>P.in==="query"),E=["post","put","patch"].includes(e)&&n.requestBody;return a.jsxs("div",{className:"border border-bambu-dark-tertiary rounded-lg overflow-hidden",children:[a.jsxs("button",{onClick:()=>o(!s),className:"w-full flex items-center gap-3 p-3 hover:bg-bambu-dark-tertiary/50 transition-colors text-left",children:[s?a.jsx(Kr,{className:"w-4 h-4 text-bambu-gray flex-shrink-0"}):a.jsx(vs,{className:"w-4 h-4 text-bambu-gray flex-shrink-0"}),a.jsx("span",{className:`px-2 py-0.5 text-xs font-mono font-semibold uppercase rounded border ${zKe[e]||"bg-gray-500/20 text-gray-400"}`,children:e}),a.jsx("code",{className:"text-sm text-white font-mono flex-1 truncate",children:t}),n.summary&&a.jsx("span",{className:"text-sm text-bambu-gray truncate max-w-[40%]",children:n.summary})]}),s&&a.jsxs("div",{className:"border-t border-bambu-dark-tertiary p-4 space-y-4 bg-bambu-dark/50",children:[n.description&&a.jsx("p",{className:"text-sm text-bambu-gray",children:n.description}),k.length>0&&a.jsxs("div",{className:"space-y-2",children:[a.jsx("h4",{className:"text-sm font-medium text-white",children:"Path Parameters"}),a.jsx("div",{className:"space-y-2",children:k.map(P=>a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsxs("label",{className:"text-sm text-bambu-gray w-32 flex-shrink-0",children:[P.name,P.required&&a.jsx("span",{className:"text-red-400 ml-1",children:"*"})]}),a.jsx("input",{type:"text",value:l[P.name]||"",onChange:A=>c(D=>({...D,[P.name]:A.target.value})),placeholder:P.description||P.schema?.type||"value",className:"flex-1 px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm font-mono focus:border-bambu-green focus:outline-none"})]},P.name))})]}),C.length>0&&a.jsxs("div",{className:"space-y-2",children:[a.jsx("h4",{className:"text-sm font-medium text-white",children:"Query Parameters"}),a.jsx("div",{className:"space-y-2",children:C.map(P=>a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsxs("label",{className:"text-sm text-bambu-gray w-32 flex-shrink-0",children:[P.name,P.required&&a.jsx("span",{className:"text-red-400 ml-1",children:"*"})]}),P.schema?.enum?a.jsxs("select",{value:l[P.name]||"",onChange:A=>c(D=>({...D,[P.name]:A.target.value})),className:"flex-1 px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none",children:[a.jsx("option",{value:"",children:"-- Select --"}),P.schema.enum.map(A=>a.jsx("option",{value:A,children:A},A))]}):a.jsx("input",{type:"text",value:l[P.name]||"",onChange:A=>c(D=>({...D,[P.name]:A.target.value})),placeholder:P.description||P.schema?.type||"value",className:"flex-1 px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm font-mono focus:border-bambu-green focus:outline-none"})]},P.name))})]}),E&&a.jsxs("div",{className:"space-y-2",children:[a.jsx("h4",{className:"text-sm font-medium text-white",children:"Request Body"}),a.jsx("textarea",{value:u,onChange:P=>d(P.target.value),rows:8,className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm font-mono focus:border-bambu-green focus:outline-none resize-y",placeholder:"JSON request body..."})]}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsxs(Te,{onClick:N,disabled:m,children:[m?a.jsx(pt,{className:"w-4 h-4 animate-spin"}):a.jsx(So,{className:"w-4 h-4"}),"Execute"]}),S.length>0&&a.jsxs("span",{className:"text-xs text-yellow-400 flex items-center gap-1",children:[a.jsx(Vi,{className:"w-3 h-3"}),"Fill in: ",S.join(", ")]})]}),h&&a.jsxs("div",{className:"space-y-2",children:[a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("h4",{className:"text-sm font-medium text-white flex items-center gap-2",children:["Response",a.jsxs("span",{className:`px-2 py-0.5 text-xs rounded ${h.status>=200&&h.status<300?"bg-green-500/20 text-green-400":h.status>=400?"bg-red-500/20 text-red-400":"bg-yellow-500/20 text-yellow-400"}`,children:[h.status," ",h.statusText]}),a.jsxs("span",{className:"text-xs text-bambu-gray",children:[h.duration,"ms"]})]}),a.jsx(Te,{variant:"secondary",size:"sm",onClick:T,children:y?a.jsx(Ar,{className:"w-3 h-3 text-green-400"}):a.jsx(Ul,{className:"w-3 h-3"})})]}),a.jsx("pre",{className:"p-3 bg-bambu-dark rounded-lg text-sm font-mono text-white overflow-auto max-h-96 border border-bambu-dark-tertiary",children:typeof h.body=="string"?h.body:JSON.stringify(h.body,null,2)})]})]})]})}function $Ke({apiKey:t=""}){const[e,n]=_.useState(null),[r,i]=_.useState(!0),[s,o]=_.useState(null),[l,c]=_.useState(new Set),[u,d]=_.useState("");if(_.useEffect(()=>{async function v(){try{const b=await fetch("/openapi.json");if(!b.ok)throw new Error("Failed to fetch OpenAPI schema");const S=await b.json();n(S)}catch(b){o(b instanceof Error?b.message:"Unknown error")}finally{i(!1)}}v()},[]),r)return a.jsx("div",{className:"flex justify-center py-12",children:a.jsx(pt,{className:"w-8 h-8 text-bambu-green animate-spin"})});if(s||!e)return a.jsx(St,{children:a.jsx(Nt,{className:"py-8",children:a.jsxs("div",{className:"text-center text-red-400",children:[a.jsx(Vi,{className:"w-12 h-12 mx-auto mb-3 opacity-50"}),a.jsx("p",{children:"Failed to load API schema"}),a.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:s})]})})});const h={};for(const[v,b]of Object.entries(e.paths))for(const[S,N]of Object.entries(b)){if(S==="parameters")continue;const T=N.tags||["Other"];for(const k of T)h[k]||(h[k]=[]),h[k].push({path:v,method:S,spec:N})}const p=Object.entries(h).map(([v,b])=>{if(!u)return{tag:v,endpoints:b};const S=b.filter(({path:N,method:T,spec:k})=>{const C=u.toLowerCase();return N.toLowerCase().includes(C)||T.toLowerCase().includes(C)||(k.summary?.toLowerCase()||"").includes(C)||(k.description?.toLowerCase()||"").includes(C)});return{tag:v,endpoints:S}}).filter(({endpoints:v})=>v.length>0).sort((v,b)=>v.tag.localeCompare(b.tag)),m=v=>{c(b=>{const S=new Set(b);return S.has(v)?S.delete(v):S.add(v),S})},x=()=>{c(new Set(p.map(v=>v.tag)))},y=()=>{c(new Set)};return a.jsxs("div",{className:"space-y-4",children:[a.jsxs("div",{className:"flex items-center justify-between gap-4",children:[a.jsx("div",{className:"flex-1",children:a.jsx("input",{type:"text",value:u,onChange:v=>d(v.target.value),placeholder:"Search endpoints...",className:"w-full max-w-md px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(Te,{variant:"secondary",size:"sm",onClick:x,children:"Expand All"}),a.jsx(Te,{variant:"secondary",size:"sm",onClick:y,children:"Collapse All"}),a.jsxs("a",{href:"/docs",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1 text-sm text-bambu-green hover:underline",children:[a.jsx(Xr,{className:"w-4 h-4"}),"Swagger UI"]})]})]}),a.jsxs("p",{className:"text-sm text-bambu-gray",children:[p.reduce((v,b)=>v+b.endpoints.length,0)," endpoints in ",p.length," categories"]}),a.jsx("div",{className:"space-y-3",children:p.map(({tag:v,endpoints:b})=>a.jsxs(St,{children:[a.jsx("button",{onClick:()=>m(v),className:"w-full flex items-center justify-between p-4 hover:bg-bambu-dark-tertiary/30 transition-colors text-left",children:a.jsxs("div",{className:"flex items-center gap-2",children:[l.has(v)?a.jsx(Kr,{className:"w-5 h-5 text-bambu-gray"}):a.jsx(vs,{className:"w-5 h-5 text-bambu-gray"}),a.jsx("h3",{className:"text-base font-semibold text-white capitalize",children:v.replace(/-/g," ")}),a.jsx("span",{className:"text-xs bg-bambu-dark-tertiary px-2 py-0.5 rounded-full text-bambu-gray",children:b.length})]})}),l.has(v)&&a.jsx(Nt,{className:"pt-0 space-y-2",children:b.map(({path:S,method:N,spec:T})=>a.jsx(HKe,{path:S,method:N,spec:T,schema:e,apiKey:t},`${N}-${S}`))})]},v))})]})}const VKe=["general","network","plugs","notifications","filament","apikeys","virtual-printer","users","backup"];function GKe(){const t=sn(),e=Tc(),[n,r]=NR(),{t:i,i18n:s}=On(),{showToast:o}=Hn(),{authEnabled:l,user:c,refreshAuth:u}=Ci(),{mode:d,darkStyle:h,darkBackground:p,darkAccent:m,lightStyle:x,lightBackground:y,lightAccent:v,setDarkStyle:b,setDarkBackground:S,setDarkAccent:N,setLightStyle:T,setLightBackground:k,setLightAccent:C}=Fh(),[E,P]=_.useState(null),[A,D]=_.useState(!1),[I,L]=_.useState(null),[U,j]=_.useState(!1),[$,K]=_.useState(null),[B,X]=_.useState(null),[Y,ne]=_.useState(!1),[H,W]=_.useState(VW()),re=n.get("tab"),ie=re&&VKe.includes(re)?re:"general",[pe,me]=_.useState(ie),de=le=>{me(le),le==="general"?n.delete("tab"):n.set("tab",le),r(n,{replace:!0})},[Ee,se]=_.useState(!1),[Ae,Fe]=_.useState(""),[ge,Ze]=_.useState({can_queue:!0,can_control_printer:!1,can_read_status:!0}),[G,Q]=_.useState(null),[he,q]=_.useState(null),[ee,V]=_.useState(""),[ye,je]=_.useState(!1),[te,z]=_.useState(!1),[O,Z]=_.useState(null),[oe,we]=_.useState(!1),[_e,ae]=_.useState(!1),[Le,Be]=_.useState(!1),[Ve,He]=_.useState({currentPassword:"",newPassword:"",confirmPassword:""}),[xe,Pe]=_.useState(!1),[Ie,Se]=_.useState(!1),[Ke,Me]=_.useState(!1),[it,ke]=_.useState(null),[Xe,ze]=_.useState(null),[ue,$e]=_.useState(null),[be,Je]=_.useState(!1),[at,jt]=_.useState({username:"",password:"",confirmPassword:"",role:"user",group_ids:[]}),[Dt,yn]=_.useState(!1),[cn,rr]=_.useState(null),[Vn,Jn]=_.useState(null),[xn,sr]=_.useState({name:"",description:"",permissions:[]}),[Gn,Xn]=_.useState(new Set),[Nn,hi]=_.useState(null),[ai,Ce]=_.useState(!1),[tt,dt]=_.useState({}),[ht,ut]=_.useState({}),Et=le=>{W(le),Vfe(le),o(i("settings.toast.settingsSaved"),"success")},fe=()=>{localStorage.removeItem("sidebarOrder"),window.location.reload()},{data:Re,isLoading:Ge}=ct({queryKey:["settings"],queryFn:ce.getSettings}),{data:Ne,isLoading:Oe}=ct({queryKey:["smart-plugs"],queryFn:ce.getSmartPlugs}),{data:nt,isLoading:Ye}=ct({queryKey:["smart-plugs-energy",Ne?.map(le=>le.id)],queryFn:async()=>{if(!Ne||Ne.length===0)return null;const le=await Promise.all(Ne.filter(as=>as.enabled).map(async as=>{try{const ss=await ce.getSmartPlugStatus(as.id);return{plug:as,status:ss}}catch{return{plug:as,status:null}}}));let _t=0,Ln=0,er=0,Co=0,ed=0;for(const{plug:as,status:ss}of le){const Gx=as.plug_type==="mqtt"&&ss?.energy?.power!=null;(ss?.reachable||Gx)&&ss?.energy&&(ed++,ss.energy?.power!=null&&(_t+=ss.energy.power),ss.energy?.today!=null&&(Ln+=ss.energy.today),ss.energy?.yesterday!=null&&(er+=ss.energy.yesterday),ss.energy?.total!=null&&(Co+=ss.energy.total))}return{totalPower:_t,totalToday:Ln,totalYesterday:er,totalLifetime:Co,reachableCount:ed,totalPlugs:Ne.filter(as=>as.enabled).length}},enabled:pe==="plugs"&&!!Ne&&Ne.length>0,refetchInterval:pe==="plugs"?1e4:!1}),{data:Tt,isLoading:At}=ct({queryKey:["notification-providers"],queryFn:ce.getNotificationProviders}),{data:It,isLoading:Rt}=ct({queryKey:["api-keys"],queryFn:ce.getAPIKeys}),Mt=gt({mutationFn:le=>ce.createAPIKey(le),onSuccess:le=>{Q(le.key||null),se(!1),Fe(""),t.invalidateQueries({queryKey:["api-keys"]}),o(i("settings.toast.apiKeyCreated"))},onError:le=>{o(`Failed to create API key: ${le.message}`,"error")}}),en=gt({mutationFn:le=>ce.deleteAPIKey(le),onSuccess:()=>{t.invalidateQueries({queryKey:["api-keys"]}),o(i("settings.toast.apiKeyDeleted"))},onError:le=>{o(`Failed to delete API key: ${le.message}`,"error")}}),{data:Ht}=ct({queryKey:["printers"],queryFn:ce.getPrinters}),{data:hn,isLoading:un}=ct({queryKey:["notification-templates"],queryFn:ce.getNotificationTemplates}),{data:Mn}=ct({queryKey:["virtual-printer-settings"],queryFn:x1.getSettings,refetchInterval:1e4}),Gt=Mn?.status?.running??!1,{data:on}=ct({queryKey:["ffmpeg-status"],queryFn:ce.checkFfmpeg}),{data:dn}=ct({queryKey:["version"],queryFn:ce.getVersion}),{data:Yt,refetch:ir,isRefetching:Pn}=ct({queryKey:["updateCheck"],queryFn:ce.checkForUpdates,staleTime:300*1e3}),{data:si,refetch:ar}=ct({queryKey:["updateStatus"],queryFn:ce.getUpdateStatus,refetchInterval:le=>{const _t=le.state.data;return _t?.status==="downloading"||_t?.status==="installing"?1e3:!1}}),{data:dr}=ct({queryKey:["mqtt-status"],queryFn:ce.getMQTTStatus,refetchInterval:pe==="network"?5e3:!1}),{data:rt}=ct({queryKey:["github-backup-status"],queryFn:ce.getGitHubBackupStatus}),{data:Pt}=ct({queryKey:["cloud-status"],queryFn:ce.getCloudStatus}),{hasPermission:qt}=Ci(),{data:vt=[],isLoading:wn}=ct({queryKey:["users"],queryFn:()=>ce.getUsers(),enabled:l&&qt("users:read")}),{data:Fr=[],isLoading:Qr}=ct({queryKey:["groups"],queryFn:()=>ce.getGroups(),enabled:l&&qt("groups:read")}),{data:Br}=ct({queryKey:["permissions"],queryFn:()=>ce.getPermissions(),enabled:l&&qt("groups:read")}),Ys=gt({mutationFn:le=>ce.createUser(le),onSuccess:()=>{t.invalidateQueries({queryKey:["users"]}),t.invalidateQueries({queryKey:["groups"]}),Se(!1),jt({username:"",password:"",confirmPassword:"",role:"user",group_ids:[]}),o(i("settings.toast.userCreated"))},onError:le=>{o(le.message,"error")}}),nn=gt({mutationFn:({id:le,data:_t})=>ce.updateUser(le,_t),onSuccess:()=>{t.invalidateQueries({queryKey:["users"]}),t.invalidateQueries({queryKey:["groups"]}),Me(!1),ke(null),jt({username:"",password:"",confirmPassword:"",role:"user",group_ids:[]}),o(i("settings.toast.userUpdated"))},onError:le=>{o(le.message,"error")}}),ln=gt({mutationFn:({id:le,deleteItems:_t})=>ce.deleteUser(le,_t),onSuccess:()=>{t.invalidateQueries({queryKey:["users"]}),o(i("settings.toast.userDeleted")),ze(null),$e(null)},onError:le=>{o(le.message,"error")}}),Si=async le=>{ze(le),Je(!0);try{const _t=await ce.getUserItemsCount(le);$e(_t)}catch{$e({archives:0,queue_items:0,library_files:0})}finally{Je(!1)}},Es=gt({mutationFn:le=>ce.createGroup(le),onSuccess:()=>{t.invalidateQueries({queryKey:["groups"]}),yn(!1),da(),o(i("settings.toast.groupCreated"))},onError:le=>{o(le.message,"error")}}),Eo=gt({mutationFn:({id:le,data:_t})=>ce.updateGroup(le,_t),onSuccess:()=>{t.invalidateQueries({queryKey:["groups"]}),rr(null),da(),o(i("settings.toast.groupUpdated"))},onError:le=>{o(le.message,"error")}}),To=gt({mutationFn:le=>ce.deleteGroup(le),onSuccess:()=>{t.invalidateQueries({queryKey:["groups"]}),o(i("settings.toast.groupDeleted"))},onError:le=>{o(le.message,"error")}}),Ao=()=>{if(!at.username||!at.password){o(i("settings.toast.fillRequiredFields"),"error");return}if(at.password!==at.confirmPassword){o(i("settings.toast.passwordsDoNotMatch"),"error");return}if(at.password.length<6){o(i("settings.toast.passwordTooShort"),"error");return}Ys.mutate({username:at.username,password:at.password,role:at.role,group_ids:at.group_ids.length>0?at.group_ids:void 0})},Ts=le=>{if(at.password){if(at.password!==at.confirmPassword){o(i("settings.toast.passwordsDoNotMatch"),"error");return}if(at.password.length<6){o(i("settings.toast.passwordTooShort"),"error");return}}const _t={username:at.username||void 0,password:at.password||void 0,role:at.role,group_ids:at.group_ids};_t.password||delete _t.password,nn.mutate({id:le,data:_t})},Ni=le=>{ke(le.id),jt({username:le.username,password:"",confirmPassword:"",role:le.role,group_ids:le.groups?.map(_t=>_t.id)||[]}),Me(!0)},Qs=le=>{jt(_t=>({..._t,group_ids:_t.group_ids.includes(le)?_t.group_ids.filter(Ln=>Ln!==le):[..._t.group_ids,le]}))},da=()=>{sr({name:"",description:"",permissions:[]}),Xn(new Set)},Hr=()=>{if(!xn.name.trim()){o(i("settings.toast.enterGroupName"),"error");return}Es.mutate({name:xn.name,description:xn.description||void 0,permissions:xn.permissions})},Bx=()=>{if(cn){if(!xn.name.trim()){o(i("settings.toast.enterGroupName"),"error");return}Eo.mutate({id:cn.id,data:{name:xn.name!==cn.name?xn.name:void 0,description:xn.description,permissions:xn.permissions}})}},Gh=le=>{rr(le),sr({name:le.name,description:le.description||"",permissions:le.permissions});const _t=new Set;Br?.categories.forEach(Ln=>{Ln.permissions.some(er=>le.permissions.includes(er.value))&&_t.add(Ln.name)}),Xn(_t)},Gl=le=>{Xn(_t=>{const Ln=new Set(_t);return Ln.has(le)?Ln.delete(le):Ln.add(le),Ln})},Hx=le=>{sr(_t=>{const Ln=_t.permissions.includes(le)?_t.permissions.filter(er=>er!==le):[..._t.permissions,le];return{..._t,permissions:Ln}})},Rm=(le,_t)=>{sr(Ln=>{const er=le.permissions.map(as=>as.value),Co=Ln.permissions.filter(as=>!er.includes(as)),ed=_t?[...Co,...er]:Co;return{...Ln,permissions:ed}})},Om=le=>le.permissions.every(_t=>xn.permissions.includes(_t.value)),qh=le=>{const _t=le.permissions.filter(Ln=>xn.permissions.includes(Ln.value));return _t.length>0&&_t.length{le.is_docker?o(le.message,"error"):ar()}}),[Pc,ha]=_.useState(null),bl=gt({mutationFn:ce.testAllNotificationProviders,onSuccess:le=>{ha(le),t.invalidateQueries({queryKey:["notification-providers"]}),le.failed===0?o(`All ${le.tested} providers tested successfully!`,"success"):o(`${le.success}/${le.tested} providers succeeded`,le.failed>0?"error":"success")},onError:le=>{o(`Failed to test providers: ${le.message}`,"error")}}),ql=gt({mutationFn:async le=>{if(!Ne)return{success:0,failed:0};const _t=Ne.filter(er=>er.enabled),Ln=await Promise.all(_t.map(async er=>{try{return await ce.controlSmartPlug(er.id,le),{success:!0}}catch{return{success:!1}}}));return{success:Ln.filter(er=>er.success).length,failed:Ln.filter(er=>!er.success).length}},onSuccess:(le,_t)=>{t.invalidateQueries({queryKey:["smart-plugs"]}),t.invalidateQueries({queryKey:["smart-plugs-energy"]}),le.failed===0?o(`All ${le.success} plugs turned ${_t}`,"success"):o(`${le.success} plugs turned ${_t}, ${le.failed} failed`,"error")},onError:le=>{o(`Failed: ${le.message}`,"error")}}),yl=_.useRef(null),Lm=_.useRef(!1),Fm=_.useRef(!0);_.useEffect(()=>{if(Re&&!E){const le={...Re,external_url:Re.external_url||window.location.origin};P(le),setTimeout(()=>{Fm.current=!1},100)}},[Re,E]);const Im=gt({mutationFn:ce.updateSettings,onSuccess:le=>{t.setQueryData(["settings"],le),P(le),t.invalidateQueries({queryKey:["archiveStats"]}),o(i("settings.toast.settingsSaved"),"success")},onError:le=>{o(`Failed to save: ${le.message}`,"error")},onSettled:()=>{Lm.current=!1}}),Ju=gt({mutationFn:({id:le,data:_t})=>ce.updatePrinter(le,_t),onSuccess:()=>{t.invalidateQueries({queryKey:["printers"]}),o(i("settings.toast.cameraSettingsSaved"),"success")},onError:le=>{o(`Failed to update printer: ${le.message}`,"error")}});_.useEffect(()=>{if(!(Fm.current||!E||!Re||!(Re.auto_archive!==E.auto_archive||Re.save_thumbnails!==E.save_thumbnails||Re.capture_finish_photo!==E.capture_finish_photo||Re.default_filament_cost!==E.default_filament_cost||Re.currency!==E.currency||Re.energy_cost_per_kwh!==E.energy_cost_per_kwh||Re.energy_tracking_mode!==E.energy_tracking_mode||Re.check_updates!==E.check_updates||(Re.check_printer_firmware??!0)!==(E.check_printer_firmware??!0)||Re.notification_language!==E.notification_language||Re.ams_humidity_good!==E.ams_humidity_good||Re.ams_humidity_fair!==E.ams_humidity_fair||Re.ams_temp_good!==E.ams_temp_good||Re.ams_temp_fair!==E.ams_temp_fair||Re.ams_history_retention_days!==E.ams_history_retention_days||Re.per_printer_mapping_expanded!==E.per_printer_mapping_expanded||Re.date_format!==E.date_format||Re.time_format!==E.time_format||Re.default_printer_id!==E.default_printer_id||Re.ftp_retry_enabled!==E.ftp_retry_enabled||Re.ftp_retry_count!==E.ftp_retry_count||Re.ftp_retry_delay!==E.ftp_retry_delay||Re.ftp_timeout!==E.ftp_timeout||Re.mqtt_enabled!==E.mqtt_enabled||Re.mqtt_broker!==E.mqtt_broker||Re.mqtt_port!==E.mqtt_port||Re.mqtt_username!==E.mqtt_username||Re.mqtt_password!==E.mqtt_password||Re.mqtt_topic_prefix!==E.mqtt_topic_prefix||Re.mqtt_use_tls!==E.mqtt_use_tls||Re.external_url!==E.external_url||Re.ha_enabled!==E.ha_enabled||Re.ha_url!==E.ha_url||Re.ha_token!==E.ha_token||(Re.library_archive_mode??"ask")!==(E.library_archive_mode??"ask")||Number(Re.library_disk_warning_gb??5)!==Number(E.library_disk_warning_gb??5)||(Re.camera_view_mode??"window")!==(E.camera_view_mode??"window")||Re.prometheus_enabled!==E.prometheus_enabled||Re.prometheus_token!==E.prometheus_token))&&!Lm.current)return yl.current&&clearTimeout(yl.current),yl.current=setTimeout(()=>{if(Lm.current)return;Lm.current=!0;const _t={auto_archive:E.auto_archive,save_thumbnails:E.save_thumbnails,capture_finish_photo:E.capture_finish_photo,default_filament_cost:E.default_filament_cost,currency:E.currency,energy_cost_per_kwh:E.energy_cost_per_kwh,energy_tracking_mode:E.energy_tracking_mode,check_updates:E.check_updates,check_printer_firmware:E.check_printer_firmware,notification_language:E.notification_language,ams_humidity_good:E.ams_humidity_good,ams_humidity_fair:E.ams_humidity_fair,ams_temp_good:E.ams_temp_good,ams_temp_fair:E.ams_temp_fair,ams_history_retention_days:E.ams_history_retention_days,per_printer_mapping_expanded:E.per_printer_mapping_expanded,date_format:E.date_format,time_format:E.time_format,default_printer_id:E.default_printer_id,ftp_retry_enabled:E.ftp_retry_enabled,ftp_retry_count:E.ftp_retry_count,ftp_retry_delay:E.ftp_retry_delay,ftp_timeout:E.ftp_timeout,mqtt_enabled:E.mqtt_enabled,mqtt_broker:E.mqtt_broker,mqtt_port:E.mqtt_port,mqtt_username:E.mqtt_username,mqtt_password:E.mqtt_password,mqtt_topic_prefix:E.mqtt_topic_prefix,mqtt_use_tls:E.mqtt_use_tls,external_url:E.external_url,ha_enabled:E.ha_enabled,ha_url:E.ha_url,ha_token:E.ha_token,library_archive_mode:E.library_archive_mode,library_disk_warning_gb:E.library_disk_warning_gb,camera_view_mode:E.camera_view_mode,prometheus_enabled:E.prometheus_enabled,prometheus_token:E.prometheus_token};Im.mutate(_t)},500),()=>{yl.current&&clearTimeout(yl.current)}},[E,Re,Im]);const fn=_.useCallback((le,_t)=>{P(Ln=>Ln?{...Ln,[le]:_t}:null)},[]),Mv=async(le,_t,Ln)=>{if(!_t){o(i("settings.toast.enterCameraUrl"),"error");return}ut(er=>({...er,[le]:!0})),dt(er=>({...er,[le]:null}));try{const er=await ce.testExternalCamera(le,_t,Ln);dt(Co=>({...Co,[le]:er})),er.success?o(i("settings.toast.cameraConnected",{resolution:er.resolution||""}),"success"):o(er.error||i("settings.toast.connectionFailed"),"error")}catch(er){const Co=er instanceof Error?er.message:i("settings.toast.testFailed");dt(ed=>({...ed,[le]:{success:!1,error:Co}})),o(Co,"error")}finally{ut(er=>({...er,[le]:!1}))}},[$x,kv]=_.useState({}),Vx=_.useRef({}),Um=_.useRef(new Set);_.useEffect(()=>{if(Ht){const le={};Ht.forEach(_t=>{_t.external_camera_url&&!Um.current.has(_t.id)&&(le[_t.id]=_t.external_camera_url,Um.current.add(_t.id))}),Object.keys(le).length>0&&kv(_t=>({..._t,...le}))}},[Ht]);const W2=(le,_t)=>{kv(Ln=>({...Ln,[le]:_t})),Vx.current[le]&&clearTimeout(Vx.current[le]),Vx.current[le]=setTimeout(()=>{Ju.mutate({id:le,data:{external_camera_url:_t||null}})},800)},Ev=(le,_t)=>{const Ln={};_t.type!==void 0&&(Ln.external_camera_type=_t.type||null),_t.enabled!==void 0&&(Ln.external_camera_enabled=_t.enabled),Ju.mutate({id:le,data:Ln})};return Ge||!E?a.jsx("div",{className:"p-4 md:p-8 flex justify-center",children:a.jsx(pt,{className:"w-8 h-8 text-bambu-green animate-spin"})}):a.jsxs("div",{className:"p-4 md:p-8",children:[a.jsxs("div",{className:"mb-8",children:[a.jsx("h1",{className:"text-2xl font-bold text-white",children:i("settings.title")}),a.jsx("p",{className:"text-bambu-gray",children:i("settings.configureBambuddy")})]}),a.jsxs("div",{className:"flex gap-1 mb-6 border-b border-bambu-dark-tertiary overflow-x-auto",children:[a.jsx("button",{onClick:()=>de("general"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px ${pe==="general"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:i("settings.tabs.general")}),a.jsxs("button",{onClick:()=>de("plugs"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${pe==="plugs"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[a.jsx(al,{className:"w-4 h-4"}),i("settings.tabs.smartPlugs"),Ne&&Ne.length>0&&a.jsx("span",{className:"text-xs bg-bambu-dark-tertiary px-1.5 py-0.5 rounded-full",children:Ne.length})]}),a.jsxs("button",{onClick:()=>de("notifications"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${pe==="notifications"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[a.jsx(Sg,{className:"w-4 h-4"}),i("settings.tabs.notifications"),Tt&&Tt.length>0&&a.jsx("span",{className:"text-xs bg-bambu-dark-tertiary px-1.5 py-0.5 rounded-full",children:Tt.length})]}),a.jsxs("button",{onClick:()=>de("filament"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${pe==="filament"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[a.jsx(Mue,{className:"w-4 h-4"}),i("settings.tabs.filament")]}),a.jsxs("button",{onClick:()=>de("network"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${pe==="network"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[a.jsx(Mg,{className:"w-4 h-4"}),i("settings.tabs.network"),a.jsx("span",{className:`w-2 h-2 rounded-full ${dr?.enabled?"bg-green-400":"bg-gray-500"}`})]}),a.jsxs("button",{onClick:()=>de("apikeys"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${pe==="apikeys"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[a.jsx(Ko,{className:"w-4 h-4"}),i("settings.tabs.apiKeys"),It&&It.length>0&&a.jsx("span",{className:"text-xs bg-bambu-dark-tertiary px-1.5 py-0.5 rounded-full",children:It.length})]}),a.jsxs("button",{onClick:()=>de("virtual-printer"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${pe==="virtual-printer"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[a.jsx(Ur,{className:"w-4 h-4"}),i("settings.tabs.virtualPrinter"),a.jsx("span",{className:`w-2 h-2 rounded-full ${Gt?"bg-green-400":"bg-gray-500"}`})]}),a.jsxs("button",{onClick:()=>de("users"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${pe==="users"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[a.jsx(pg,{className:"w-4 h-4"}),i("settings.tabs.users"),l&&a.jsx("span",{className:`w-2 h-2 rounded-full ${l?"bg-green-400":"bg-gray-500"}`})]}),a.jsxs("button",{onClick:()=>de("backup"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${pe==="backup"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[a.jsx(Eu,{className:"w-4 h-4"}),i("settings.tabs.backup"),a.jsx("span",{className:`w-2 h-2 rounded-full ${Pt?.is_authenticated&&rt?.configured&&rt?.enabled?"bg-green-400":"bg-gray-500"}`})]})]}),pe==="general"&&a.jsxs("div",{className:"flex flex-col lg:flex-row gap-6 lg:gap-8",children:[a.jsxs("div",{className:"space-y-6 flex-1 lg:max-w-xl",children:[a.jsxs(St,{children:[a.jsx(Kn,{children:a.jsx("h2",{className:"text-lg font-semibold text-white",children:i("settings.general")})}),a.jsxs(Nt,{className:"space-y-4",children:[a.jsxs("div",{children:[a.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[a.jsx(oh,{className:"w-4 h-4 inline mr-1"}),i("settings.language")]}),a.jsxs("div",{className:"relative",children:[a.jsx("select",{value:s.language,onChange:le=>{s.changeLanguage(le.target.value),o(i("settings.toast.settingsSaved"),"success")},className:"w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer",children:yz.map(le=>a.jsxs("option",{value:le.code,children:[le.nativeName," (",le.name,")"]},le.code))}),a.jsx(Kr,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}),a.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:i("settings.languageDescription")})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:i("settings.defaultView")}),a.jsxs("div",{className:"relative",children:[a.jsx("select",{value:H,onChange:le=>Et(le.target.value),className:"w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer",children:X0.map(le=>a.jsx("option",{value:le.to,children:i(le.labelKey)},le.id))}),a.jsx(Kr,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}),a.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:i("settings.defaultViewDescription")})]}),a.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Date Format"}),a.jsxs("div",{className:"relative",children:[a.jsxs("select",{value:E.date_format||"system",onChange:le=>fn("date_format",le.target.value),className:"w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer",children:[a.jsx("option",{value:"system",children:i("settings.systemDefault")}),a.jsx("option",{value:"us",children:"US (MM/DD/YYYY)"}),a.jsx("option",{value:"eu",children:"EU (DD/MM/YYYY)"}),a.jsx("option",{value:"iso",children:"ISO (YYYY-MM-DD)"})]}),a.jsx(Kr,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Time Format"}),a.jsxs("div",{className:"relative",children:[a.jsxs("select",{value:E.time_format||"system",onChange:le=>fn("time_format",le.target.value),className:"w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer",children:[a.jsx("option",{value:"system",children:i("settings.systemDefault")}),a.jsx("option",{value:"12h",children:"12-hour (3:30 PM)"}),a.jsx("option",{value:"24h",children:"24-hour (15:30)"})]}),a.jsx(Kr,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]})]})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Default Printer"}),a.jsxs("div",{className:"relative",children:[a.jsxs("select",{value:E.default_printer_id??"",onChange:le=>fn("default_printer_id",le.target.value?Number(le.target.value):null),className:"w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer",children:[a.jsx("option",{value:"",children:i("settings.noDefaultPrinter")}),Ht?.map(le=>a.jsx("option",{value:le.id,children:le.name},le.id))]}),a.jsx(Kr,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}),a.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Pre-select this printer for uploads, reprints, and other operations."})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-white",children:i("settings.sidebarOrder")}),a.jsx("p",{className:"text-sm text-bambu-gray",children:"Drag items in the sidebar to reorder. Reset to default order here."})]}),a.jsxs(Te,{variant:"secondary",size:"sm",onClick:fe,children:[a.jsx(Lh,{className:"w-4 h-4"}),"Reset"]})]})]})]}),a.jsxs(St,{children:[a.jsx(Kn,{children:a.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[a.jsx(PW,{className:"w-5 h-5"}),"Appearance"]})}),a.jsxs(Nt,{className:"space-y-6",children:[a.jsxs("div",{className:`space-y-3 p-4 rounded-lg border ${d==="dark"?"border-bambu-green bg-bambu-green/5":"border-bambu-dark-tertiary"}`,children:[a.jsxs("h3",{className:"text-sm font-medium text-white flex items-center gap-2",children:["Dark Mode",d==="dark"&&a.jsx("span",{className:"text-xs text-bambu-green",children:"(active)"})]}),a.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Background"}),a.jsxs("select",{value:p,onChange:le=>{S(le.target.value),o(i("settings.toast.settingsSaved"),"success")},className:"w-full px-2 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[a.jsx("option",{value:"neutral",children:"Neutral"}),a.jsx("option",{value:"warm",children:"Warm"}),a.jsx("option",{value:"cool",children:"Cool"}),a.jsx("option",{value:"oled",children:"OLED Black"}),a.jsx("option",{value:"slate",children:"Slate Blue"}),a.jsx("option",{value:"forest",children:"Forest Green"})]})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Accent"}),a.jsxs("select",{value:m,onChange:le=>{N(le.target.value),o(i("settings.toast.settingsSaved"),"success")},className:"w-full px-2 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[a.jsx("option",{value:"green",children:"Green"}),a.jsx("option",{value:"teal",children:"Teal"}),a.jsx("option",{value:"blue",children:"Blue"}),a.jsx("option",{value:"orange",children:"Orange"}),a.jsx("option",{value:"purple",children:"Purple"}),a.jsx("option",{value:"red",children:"Red"})]})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Style"}),a.jsxs("select",{value:h,onChange:le=>{b(le.target.value),o(i("settings.toast.settingsSaved"),"success")},className:"w-full px-2 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[a.jsx("option",{value:"classic",children:"Classic"}),a.jsx("option",{value:"glow",children:"Glow"}),a.jsx("option",{value:"vibrant",children:"Vibrant"})]})]})]})]}),a.jsxs("div",{className:`space-y-3 p-4 rounded-lg border ${d==="light"?"border-bambu-green bg-bambu-green/5":"border-bambu-dark-tertiary"}`,children:[a.jsxs("h3",{className:"text-sm font-medium text-white flex items-center gap-2",children:["Light Mode",d==="light"&&a.jsx("span",{className:"text-xs text-bambu-green",children:"(active)"})]}),a.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Background"}),a.jsxs("select",{value:y,onChange:le=>{k(le.target.value),o(i("settings.toast.settingsSaved"),"success")},className:"w-full px-2 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[a.jsx("option",{value:"neutral",children:"Neutral"}),a.jsx("option",{value:"warm",children:"Warm"}),a.jsx("option",{value:"cool",children:"Cool"})]})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Accent"}),a.jsxs("select",{value:v,onChange:le=>{C(le.target.value),o(i("settings.toast.settingsSaved"),"success")},className:"w-full px-2 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[a.jsx("option",{value:"green",children:"Green"}),a.jsx("option",{value:"teal",children:"Teal"}),a.jsx("option",{value:"blue",children:"Blue"}),a.jsx("option",{value:"orange",children:"Orange"}),a.jsx("option",{value:"purple",children:"Purple"}),a.jsx("option",{value:"red",children:"Red"})]})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Style"}),a.jsxs("select",{value:x,onChange:le=>{T(le.target.value),o(i("settings.toast.settingsSaved"),"success")},className:"w-full px-2 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[a.jsx("option",{value:"classic",children:"Classic"}),a.jsx("option",{value:"glow",children:"Glow"}),a.jsx("option",{value:"vibrant",children:"Vibrant"})]})]})]})]}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Toggle between dark and light mode using the sun/moon icon in the sidebar."})]})]}),a.jsxs(St,{children:[a.jsx(Kn,{children:a.jsx("h2",{className:"text-lg font-semibold text-white",children:i("settings.archiveSettings")})}),a.jsxs(Nt,{className:"space-y-4",children:[a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-white",children:"Auto-archive prints"}),a.jsx("p",{className:"text-sm text-bambu-gray",children:"Automatically save 3MF files when prints complete"})]}),a.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:E.auto_archive,onChange:le=>fn("auto_archive",le.target.checked),className:"sr-only peer"}),a.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-white",children:i("settings.saveThumbnails")}),a.jsx("p",{className:"text-sm text-bambu-gray",children:"Extract and save preview images from 3MF files"})]}),a.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:E.save_thumbnails,onChange:le=>fn("save_thumbnails",le.target.checked),className:"sr-only peer"}),a.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-white",children:i("settings.captureFinishPhoto")}),a.jsx("p",{className:"text-sm text-bambu-gray",children:"Take a photo from printer camera when print completes"})]}),a.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:E.capture_finish_photo,onChange:le=>fn("capture_finish_photo",le.target.checked),className:"sr-only peer"}),a.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]}),E.capture_finish_photo&&on&&!on.installed&&a.jsxs("div",{className:"flex items-start gap-2 p-3 bg-yellow-500/10 border border-yellow-500/30 rounded-lg",children:[a.jsx(Sn,{className:"w-5 h-5 text-yellow-500 flex-shrink-0 mt-0.5"}),a.jsxs("div",{className:"text-sm",children:[a.jsx("p",{className:"text-yellow-500 font-medium",children:"ffmpeg not installed"}),a.jsxs("p",{className:"text-bambu-gray mt-1",children:["Camera capture requires ffmpeg. Install it via"," ",a.jsx("code",{className:"bg-bambu-dark-tertiary px-1 rounded",children:"brew install ffmpeg"})," (macOS) or"," ",a.jsx("code",{className:"bg-bambu-dark-tertiary px-1 rounded",children:"apt install ffmpeg"})," (Linux)."]})]})]})]})]})]}),a.jsxs("div",{className:"space-y-6 flex-1 lg:max-w-md",children:[a.jsxs(St,{children:[a.jsx(Kn,{children:a.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[a.jsx(IR,{className:"w-5 h-5 text-bambu-green"}),"Camera"]})}),a.jsxs(Nt,{className:"space-y-4",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Camera View Mode"}),a.jsxs("select",{value:E.camera_view_mode??"window",onChange:le=>fn("camera_view_mode",le.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",children:[a.jsx("option",{value:"window",children:i("settings.newWindow")}),a.jsx("option",{value:"embedded",children:i("settings.embeddedOverlay")})]}),a.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:E.camera_view_mode==="embedded"?"Camera opens in a resizable overlay on the main screen":"Camera opens in a separate browser window"})]}),a.jsxs("div",{className:"border-t border-bambu-dark-tertiary pt-4 mt-4",children:[a.jsx("h3",{className:"text-sm font-medium text-white mb-2",children:i("settings.externalCameras")}),a.jsx("p",{className:"text-xs text-bambu-gray mb-3",children:"Configure external cameras to replace the built-in printer camera. Supports MJPEG streams, RTSP, HTTP snapshots, and USB cameras (V4L2). When enabled, the external camera is used for live view and finish photos."}),Ht&&Ht.length>0?a.jsx("div",{className:"space-y-3",children:Ht.map(le=>a.jsxs("div",{className:"p-3 bg-bambu-dark rounded-lg",children:[a.jsxs("div",{className:"flex items-center justify-between mb-2",children:[a.jsx("span",{className:"text-white font-medium text-sm",children:le.name}),a.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:le.external_camera_enabled,onChange:_t=>Ev(le.id,{enabled:_t.target.checked}),className:"sr-only peer"}),a.jsx("div",{className:"w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green"})]})]}),le.external_camera_enabled&&a.jsxs("div",{className:"space-y-2 mt-2",children:[a.jsx("input",{type:"text",placeholder:le.external_camera_type==="usb"?"Device path (/dev/video0)":"Camera URL (rtsp://... or http://...)",value:$x[le.id]??le.external_camera_url??"",onChange:_t=>W2(le.id,_t.target.value),className:"w-full 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"}),a.jsxs("div",{className:"flex gap-2",children:[a.jsxs("select",{value:le.external_camera_type||"mjpeg",onChange:_t=>Ev(le.id,{type:_t.target.value}),className:"flex-1 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",children:[a.jsx("option",{value:"mjpeg",children:"MJPEG Stream"}),a.jsx("option",{value:"rtsp",children:"RTSP Stream"}),a.jsx("option",{value:"snapshot",children:"HTTP Snapshot"}),a.jsx("option",{value:"usb",children:"USB Camera (V4L2)"})]}),a.jsx(Te,{size:"sm",variant:"secondary",onClick:()=>Mv(le.id,$x[le.id]??le.external_camera_url??"",le.external_camera_type||"mjpeg"),disabled:ht[le.id]||!($x[le.id]??le.external_camera_url),children:ht[le.id]?a.jsx(pt,{className:"w-4 h-4 animate-spin"}):"Test"})]}),tt[le.id]&&a.jsx("div",{className:`text-xs flex items-center gap-1 ${tt[le.id]?.success?"text-green-500":"text-red-500"}`,children:tt[le.id]?.success?a.jsxs(a.Fragment,{children:[a.jsx(Ar,{className:"w-3 h-3"}),"Connected",tt[le.id]?.resolution&&` (${tt[le.id]?.resolution})`]}):a.jsxs(a.Fragment,{children:[a.jsx(Ji,{className:"w-3 h-3"}),tt[le.id]?.error||i("settings.toast.connectionFailed")]})})]})]},le.id))}):a.jsx("p",{className:"text-xs text-bambu-gray italic",children:i("settings.noPrintersConfigured")})]})]})]}),a.jsxs(St,{children:[a.jsx(Kn,{children:a.jsx("h2",{className:"text-lg font-semibold text-white",children:i("settings.costTracking")})}),a.jsxs(Nt,{className:"space-y-4",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Default filament cost (per kg)"}),a.jsx("input",{type:"number",step:"0.01",min:"0",value:E.default_filament_cost,onChange:le=>fn("default_filament_cost",parseFloat(le.target.value)||0),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"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Currency"}),a.jsxs("select",{value:E.currency,onChange:le=>fn("currency",le.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",children:[a.jsx("option",{value:"USD",children:"USD ($)"}),a.jsx("option",{value:"EUR",children:"EUR (€)"}),a.jsx("option",{value:"GBP",children:"GBP (£)"}),a.jsx("option",{value:"CHF",children:"CHF (Fr.)"}),a.jsx("option",{value:"JPY",children:"JPY (¥)"}),a.jsx("option",{value:"CNY",children:"CNY (¥)"}),a.jsx("option",{value:"CAD",children:"CAD ($)"}),a.jsx("option",{value:"AUD",children:"AUD ($)"})]})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Electricity cost per kWh"}),a.jsx("input",{type:"number",step:"0.01",min:"0",value:E.energy_cost_per_kwh,onChange:le=>fn("energy_cost_per_kwh",parseFloat(le.target.value)||0),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"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Energy display mode"}),a.jsxs("select",{value:E.energy_tracking_mode||"total",onChange:le=>fn("energy_tracking_mode",le.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",children:[a.jsx("option",{value:"print",children:i("settings.printsOnly")}),a.jsx("option",{value:"total",children:i("settings.totalConsumption")})]}),a.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:E.energy_tracking_mode==="print"?"Dashboard shows sum of energy used during prints":"Dashboard shows lifetime energy from smart plugs"})]})]})]}),a.jsxs(St,{children:[a.jsx(Kn,{children:a.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[a.jsx(fs,{className:"w-5 h-5 text-bambu-green"}),"File Manager"]})}),a.jsxs(Nt,{className:"space-y-4",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Create Archive Entry When Printing"}),a.jsxs("select",{value:E.library_archive_mode??"ask",onChange:le=>fn("library_archive_mode",le.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",children:[a.jsx("option",{value:"always",children:i("settings.archiveMode.always")}),a.jsx("option",{value:"never",children:i("settings.archiveMode.never")}),a.jsx("option",{value:"ask",children:i("settings.archiveMode.ask")})]}),a.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"When printing from File Manager, optionally create an archive entry"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Low Disk Space Warning"}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("input",{type:"number",min:"0.5",max:"100",step:"0.5",value:E.library_disk_warning_gb??5,onChange:le=>fn("library_disk_warning_gb",parseFloat(le.target.value)||5),className:"w-24 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"}),a.jsx("span",{className:"text-bambu-gray",children:"GB"})]}),a.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Show warning when free disk space falls below this threshold"})]})]})]})]}),a.jsxs("div",{className:"space-y-6 flex-1 lg:max-w-sm",children:[a.jsx(LKe,{}),a.jsxs(St,{children:[a.jsx(Kn,{children:a.jsx("h2",{className:"text-lg font-semibold text-white",children:"Updates"})}),a.jsxs(Nt,{className:"space-y-4",children:[a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-white",children:i("settings.checkForUpdatesLabel")}),a.jsx("p",{className:"text-sm text-bambu-gray",children:"Automatically check for new versions on startup"})]}),a.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:E.check_updates,onChange:le=>fn("check_updates",le.target.checked),className:"sr-only peer"}),a.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-white",children:i("settings.checkPrinterFirmware")}),a.jsx("p",{className:"text-sm text-bambu-gray",children:"Check for printer firmware updates from Bambu Lab"})]}),a.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:E.check_printer_firmware??!0,onChange:le=>fn("check_printer_firmware",le.target.checked),className:"sr-only peer"}),a.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]}),a.jsxs("div",{className:"border-t border-bambu-dark-tertiary pt-4",children:[a.jsxs("div",{className:"flex items-center justify-between mb-2",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-white",children:i("settings.currentVersion")}),a.jsxs("p",{className:"text-sm text-bambu-gray",children:["v",dn?.version||"..."]})]}),a.jsxs(Te,{variant:"secondary",size:"sm",onClick:()=>ir(),disabled:Pn,children:[Pn?a.jsx(pt,{className:"w-4 h-4 animate-spin"}):a.jsx(Dr,{className:"w-4 h-4"}),"Check now"]})]}),Yt?.update_available?a.jsxs("div",{className:"mt-4 p-3 bg-bambu-green/10 border border-bambu-green/30 rounded-lg",children:[a.jsxs("div",{className:"flex items-start justify-between",children:[a.jsxs("div",{children:[a.jsxs("p",{className:"text-bambu-green font-medium",children:["Update available: v",Yt.latest_version]}),Yt.release_name&&Yt.release_name!==Yt.latest_version&&a.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:Yt.release_name})]}),a.jsxs("div",{className:"flex items-center gap-2",children:[Yt.release_notes&&a.jsx("button",{onClick:()=>we(!0),className:"text-bambu-gray hover:text-white transition-colors text-sm underline",children:"Release Notes"}),Yt.release_url&&a.jsx("a",{href:Yt.release_url,target:"_blank",rel:"noopener noreferrer",className:"text-bambu-gray hover:text-white transition-colors",title:i("settings.viewReleaseOnGitHub"),children:a.jsx(Xr,{className:"w-4 h-4"})})]})]}),si?.status==="downloading"||si?.status==="installing"?a.jsxs("div",{className:"mt-3",children:[a.jsxs("div",{className:"flex items-center gap-2 text-sm text-bambu-gray",children:[a.jsx(pt,{className:"w-4 h-4 animate-spin"}),a.jsx("span",{children:si.message})]}),a.jsx("div",{className:"mt-2 w-full bg-bambu-dark-tertiary rounded-full h-2",children:a.jsx("div",{className:"bg-bambu-green h-2 rounded-full transition-all duration-300",style:{width:`${si.progress}%`}})})]}):si?.status==="complete"?a.jsx("div",{className:"mt-3 p-2 bg-bambu-green/20 rounded text-sm text-bambu-green",children:si.message}):si?.status==="error"?a.jsx("div",{className:"mt-3 p-2 bg-red-500/20 rounded text-sm text-red-400",children:si.error||si.message}):Yt?.is_docker?a.jsxs("div",{className:"mt-3 p-3 bg-bambu-dark-tertiary rounded-lg",children:[a.jsx("p",{className:"text-sm text-bambu-gray mb-2",children:"Update via Docker Compose:"}),a.jsx("code",{className:"block text-xs bg-bambu-dark p-2 rounded text-bambu-green font-mono",children:"docker compose pull && docker compose up -d"})]}):a.jsxs(Te,{className:"mt-3",onClick:()=>Zu.mutate(),disabled:Zu.isPending,children:[Zu.isPending?a.jsx(pt,{className:"w-4 h-4 animate-spin"}):a.jsx(wi,{className:"w-4 h-4"}),"Install Update"]})]}):Yt?.error?a.jsxs("div",{className:"mt-2 p-2 bg-red-500/10 border border-red-500/30 rounded text-sm text-red-400",children:["Failed to check for updates: ",Yt.error]}):Yt&&!Yt.update_available?a.jsx("p",{className:"mt-2 text-sm text-bambu-gray",children:"You're running the latest version"}):null]})]})]}),a.jsxs(St,{children:[a.jsx(Kn,{children:a.jsx("h2",{className:"text-lg font-semibold text-white",children:i("settings.dataManagement")})}),a.jsxs(Nt,{className:"space-y-4",children:[a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-white",children:i("settings.clearNotificationLogs")}),a.jsx("p",{className:"text-sm text-bambu-gray",children:i("settings.clearNotificationLogsDescription")})]}),a.jsxs(Te,{variant:"secondary",size:"sm",onClick:()=>je(!0),children:[a.jsx(an,{className:"w-4 h-4"}),i("common.clear")]})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-white",children:i("settings.resetUiPreferences")}),a.jsx("p",{className:"text-sm text-bambu-gray",children:i("settings.resetUiPreferencesDescription")})]}),a.jsxs(Te,{variant:"secondary",size:"sm",onClick:()=>z(!0),children:[a.jsx(an,{className:"w-4 h-4"}),"Reset"]})]}),a.jsxs("div",{className:"flex items-center justify-between pt-4 border-t border-bambu-dark-tertiary",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-white",children:"Backup & Restore"}),a.jsx("p",{className:"text-sm text-bambu-gray",children:"Export/import settings and configure GitHub backup"})]}),a.jsxs(Te,{variant:"secondary",size:"sm",onClick:()=>de("backup"),children:[a.jsx(Eu,{className:"w-4 h-4"}),"Go to Backup"]})]})]})]})]})]}),pe==="network"&&E&&a.jsxs("div",{className:"flex flex-col lg:flex-row gap-6",children:[a.jsxs("div",{className:"flex-1 lg:max-w-xl space-y-4",children:[a.jsxs(St,{children:[a.jsx(Kn,{children:a.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[a.jsx(oh,{className:"w-5 h-5 text-blue-400"}),"External URL"]})}),a.jsxs(Nt,{className:"space-y-4",children:[a.jsx("p",{className:"text-sm text-bambu-gray",children:"The external URL where Bambuddy is accessible. Used for notification images and external integrations."}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Bambuddy URL"}),a.jsx("input",{type:"text",value:E.external_url??"",onChange:le=>fn("external_url",le.target.value),placeholder:"http://192.168.1.100:8000",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"}),a.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Include protocol and port (e.g., http://192.168.1.100:8000)"})]})]})]}),a.jsxs(St,{children:[a.jsx(Kn,{children:a.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[a.jsx(Dr,{className:"w-5 h-5 text-blue-400"}),"FTP Retry"]})}),a.jsxs(Nt,{className:"space-y-4",children:[a.jsx("p",{className:"text-sm text-bambu-gray",children:"Retry FTP operations when printer WiFi is unreliable. Applies to 3MF downloads, print uploads, timelapse downloads, and firmware updates."}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-white",children:i("settings.enableRetry")}),a.jsx("p",{className:"text-sm text-bambu-gray",children:"Automatically retry failed FTP operations"})]}),a.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:E.ftp_retry_enabled??!0,onChange:le=>fn("ftp_retry_enabled",le.target.checked),className:"sr-only peer"}),a.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]}),E.ftp_retry_enabled&&a.jsxs("div",{className:"space-y-4 pt-2 border-t border-bambu-dark-tertiary",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Retry attempts"}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("input",{type:"number",min:"1",max:"10",value:E.ftp_retry_count??3,onChange:le=>fn("ftp_retry_count",Math.min(10,Math.max(1,parseInt(le.target.value)||3))),className:"w-24 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"}),a.jsx("span",{className:"text-bambu-gray",children:"times"})]}),a.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Number of retry attempts before giving up (1-10)"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Retry delay"}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("input",{type:"number",min:"1",max:"30",value:E.ftp_retry_delay??2,onChange:le=>fn("ftp_retry_delay",Math.min(30,Math.max(1,parseInt(le.target.value)||2))),className:"w-24 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"}),a.jsx("span",{className:"text-bambu-gray",children:"seconds"})]}),a.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Wait time between retries (1-30)"})]})]}),a.jsxs("div",{className:"pt-2 border-t border-bambu-dark-tertiary",children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Connection timeout"}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("input",{type:"number",min:"10",max:"120",value:E.ftp_timeout??30,onChange:le=>fn("ftp_timeout",Math.min(120,Math.max(10,parseInt(le.target.value)||30))),className:"w-24 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"}),a.jsx("span",{className:"text-bambu-gray",children:"seconds"})]}),a.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Socket timeout for slow connections. Increase for A1/A1 Mini printers with weak WiFi (10-120)"})]})]})]})]}),a.jsxs("div",{className:"flex-1 lg:max-w-xl space-y-4",children:[a.jsxs(St,{children:[a.jsx(Kn,{children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[a.jsx(Iy,{className:"w-5 h-5 text-bambu-green"}),"Home Assistant"]}),E.ha_enabled&&Nn&&a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("span",{className:`w-2.5 h-2.5 rounded-full ${Nn.success?"bg-green-400":"bg-red-400"}`}),a.jsx("span",{className:`text-sm ${Nn.success?"text-green-400":"text-red-400"}`,children:Nn.success?"Connected":"Disconnected"})]})]})}),a.jsxs(Nt,{className:"space-y-4",children:[a.jsx("p",{className:"text-sm text-bambu-gray",children:"Connect to Home Assistant to control smart plugs via HA's REST API. Supports switch, light, input_boolean, and script entities."}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-white",children:i("settings.enableHomeAssistant")}),a.jsx("p",{className:"text-xs text-bambu-gray",children:i("settings.homeAssistantDescription")})]}),a.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:E.ha_enabled??!1,onChange:le=>fn("ha_enabled",le.target.checked),className:"sr-only peer"}),a.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]}),E.ha_enabled&&a.jsxs(a.Fragment,{children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Home Assistant URL"}),a.jsx("input",{type:"text",value:E.ha_url??"",onChange:le=>fn("ha_url",le.target.value),placeholder:"http://192.168.1.100:8123",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"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Long-Lived Access Token"}),a.jsx("input",{type:"password",value:E.ha_token??"",onChange:le=>fn("ha_token",le.target.value),placeholder:"eyJ0eXAiOiJKV1QiLC...",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"}),a.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Create a token in HA: Profile → Long-Lived Access Tokens → Create Token"})]}),E.ha_url&&E.ha_token&&a.jsx("div",{className:"pt-2 border-t border-bambu-dark-tertiary",children:a.jsxs(Te,{variant:"secondary",size:"sm",disabled:ai,onClick:async()=>{Ce(!0),hi(null);try{const le=await ce.testHAConnection(E.ha_url,E.ha_token);hi(le)}catch(le){hi({success:!1,message:null,error:le instanceof Error?le.message:i("common.unknownError")})}finally{Ce(!1)}},children:[ai?a.jsx(pt,{className:"w-4 h-4 animate-spin"}):a.jsx(Mg,{className:"w-4 h-4"}),i("settings.testConnection")]})})]})]})]}),a.jsxs(St,{children:[a.jsx(Kn,{children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[a.jsx(Mg,{className:"w-5 h-5 text-blue-400"}),"MQTT Publishing"]}),dr?.enabled&&a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("span",{className:`w-2.5 h-2.5 rounded-full ${dr.connected?"bg-green-400":"bg-red-400"}`}),a.jsx("span",{className:`text-sm ${dr.connected?"text-green-400":"text-red-400"}`,children:dr.connected?"Connected":"Disconnected"})]})]})}),a.jsxs(Nt,{className:"space-y-4",children:[a.jsx("p",{className:"text-sm text-bambu-gray",children:"Publish BamBuddy events to an external MQTT broker for integration with Node-RED, Home Assistant, and other automation systems."}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-white",children:i("settings.enableMqtt")}),a.jsx("p",{className:"text-sm text-bambu-gray",children:"Publish events to external MQTT broker"})]}),a.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:E.mqtt_enabled??!1,onChange:le=>fn("mqtt_enabled",le.target.checked),className:"sr-only peer"}),a.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]}),E.mqtt_enabled&&a.jsxs("div",{className:"space-y-4 pt-2 border-t border-bambu-dark-tertiary",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Broker hostname"}),a.jsx("input",{type:"text",value:E.mqtt_broker??"",onChange:le=>fn("mqtt_broker",le.target.value),placeholder:"mqtt.example.com or 192.168.1.100",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"})]}),a.jsxs("div",{className:"flex items-end gap-4",children:[a.jsxs("div",{className:"flex-1",children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Port"}),a.jsx("input",{type:"number",min:"1",max:"65535",value:E.mqtt_port??1883,onChange:le=>fn("mqtt_port",Math.min(65535,Math.max(1,parseInt(le.target.value)||1883))),className:"w-24 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]}),a.jsxs("div",{className:"flex items-center gap-3 pb-2",children:[a.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:E.mqtt_use_tls??!1,onChange:le=>{const _t=le.target.checked;fn("mqtt_use_tls",_t);const Ln=E.mqtt_port??1883;_t&&Ln===1883?fn("mqtt_port",8883):!_t&&Ln===8883&&fn("mqtt_port",1883)},className:"sr-only peer"}),a.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]}),a.jsx("span",{className:"text-white text-sm",children:i("settings.useTls")})]})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Username (optional)"}),a.jsx("input",{type:"text",value:E.mqtt_username??"",onChange:le=>fn("mqtt_username",le.target.value),placeholder:i("settings.leaveEmptyForAnonymous"),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"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Password (optional)"}),a.jsx("input",{type:"password",value:E.mqtt_password??"",onChange:le=>fn("mqtt_password",le.target.value),placeholder:i("settings.leaveEmptyForAnonymous"),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"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Topic prefix"}),a.jsx("input",{type:"text",value:E.mqtt_topic_prefix??"bambuddy",onChange:le=>fn("mqtt_topic_prefix",le.target.value),placeholder:"bambuddy",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"}),a.jsxs("p",{className:"text-xs text-bambu-gray mt-1",children:["Topics will be: ",E.mqtt_topic_prefix||"bambuddy","/printers//status, etc."]})]}),dr&&a.jsx("div",{className:"pt-3 mt-3 border-t border-bambu-dark-tertiary",children:a.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[a.jsx("span",{className:`w-2 h-2 rounded-full ${dr.connected?"bg-green-400":"bg-red-400"}`}),a.jsx("span",{className:"text-bambu-gray",children:dr.connected?a.jsxs(a.Fragment,{children:[i("settings.mqttConnectedTo")," ",a.jsxs("span",{className:"text-white",children:[dr.broker,":",dr.port]})]}):i("settings.spoolmanDisconnected")})]})})]})]})]})]}),a.jsx("div",{className:"flex-1 lg:max-w-md space-y-4",children:a.jsxs(St,{children:[a.jsx(Kn,{children:a.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[a.jsx(wP,{className:"w-5 h-5 text-orange-400"}),"Prometheus Metrics"]})}),a.jsxs(Nt,{className:"space-y-4",children:[a.jsxs("p",{className:"text-sm text-bambu-gray",children:["Expose printer metrics at ",a.jsx("code",{className:"bg-bambu-dark px-1 rounded",children:"/api/v1/metrics"})," for Prometheus/Grafana monitoring."]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-white",children:i("settings.enableMetricsEndpoint")}),a.jsx("p",{className:"text-xs text-bambu-gray",children:i("settings.prometheusDescription")})]}),a.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:E.prometheus_enabled??!1,onChange:le=>fn("prometheus_enabled",le.target.checked),className:"sr-only peer"}),a.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]}),E.prometheus_enabled&&a.jsxs("div",{className:"space-y-4 pt-2 border-t border-bambu-dark-tertiary",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Bearer Token (optional)"}),a.jsx("input",{type:"password",value:E.prometheus_token??"",onChange:le=>fn("prometheus_token",le.target.value),placeholder:i("settings.leaveEmptyForNoAuth"),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"}),a.jsxs("p",{className:"text-xs text-bambu-gray mt-1",children:["If set, requests must include ",a.jsx("code",{className:"bg-bambu-dark px-1 rounded",children:"Authorization: Bearer "})]})]}),a.jsxs("div",{className:"pt-2 border-t border-bambu-dark-tertiary",children:[a.jsx("p",{className:"text-sm text-white mb-2",children:i("settings.availableMetrics")}),a.jsxs("div",{className:"text-xs text-bambu-gray space-y-1",children:[a.jsxs("p",{children:[a.jsx("code",{className:"text-orange-400",children:"bambuddy_printer_connected"})," - Connection status"]}),a.jsxs("p",{children:[a.jsx("code",{className:"text-orange-400",children:"bambuddy_printer_state"})," - Printer state (idle/printing/etc)"]}),a.jsxs("p",{children:[a.jsx("code",{className:"text-orange-400",children:"bambuddy_print_progress"})," - Print progress 0-100%"]}),a.jsxs("p",{children:[a.jsx("code",{className:"text-orange-400",children:"bambuddy_bed_temp_celsius"})," - Bed temperature"]}),a.jsxs("p",{children:[a.jsx("code",{className:"text-orange-400",children:"bambuddy_nozzle_temp_celsius"})," - Nozzle temperature"]}),a.jsxs("p",{children:[a.jsx("code",{className:"text-orange-400",children:"bambuddy_prints_total"})," - Total prints by result"]}),a.jsx("p",{className:"text-bambu-gray/70 italic",children:"...and more (layers, fans, queue, filament usage)"})]})]})]})]})]})})]}),Nn&&a.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50",children:a.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg p-6 max-w-md w-full mx-4",children:[a.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[Nn.success?a.jsx(Ar,{className:"w-8 h-8 text-green-400"}):a.jsx(Ji,{className:"w-8 h-8 text-red-400"}),a.jsx("h3",{className:"text-lg font-medium text-white",children:Nn.success?"Connection Successful":"Connection Failed"})]}),a.jsx("p",{className:"text-bambu-gray mb-6",children:Nn.success?Nn.message||"Successfully connected to Home Assistant.":Nn.error||"Failed to connect to Home Assistant."}),a.jsx("div",{className:"flex justify-end",children:a.jsx(Te,{variant:"primary",onClick:()=>hi(null),children:"OK"})})]})}),pe==="plugs"&&a.jsxs("div",{className:"max-w-4xl",children:[a.jsxs("div",{className:"flex items-start justify-between mb-6",children:[a.jsxs("div",{children:[a.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[a.jsx(al,{className:"w-5 h-5 text-bambu-green"}),"Smart Plugs"]}),a.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:"Connect smart plugs (Tasmota or Home Assistant) to automate power control and track energy usage for your printers."})]}),a.jsxs("div",{className:"flex items-center gap-2 pt-1 shrink-0",children:[Ne&&Ne.filter(le=>le.enabled).length>1&&a.jsxs(a.Fragment,{children:[a.jsxs(Te,{variant:"secondary",size:"sm",className:"whitespace-nowrap",onClick:()=>Z("on"),disabled:ql.isPending,title:i("settings.turnAllPlugsOn"),children:[ql.isPending?a.jsx(pt,{className:"w-4 h-4 animate-spin"}):a.jsx(qu,{className:"w-4 h-4 text-bambu-green"}),"All On"]}),a.jsxs(Te,{variant:"secondary",size:"sm",className:"whitespace-nowrap",onClick:()=>Z("off"),disabled:ql.isPending,title:i("settings.turnAllPlugsOff"),children:[ql.isPending?a.jsx(pt,{className:"w-4 h-4 animate-spin"}):a.jsx(bM,{className:"w-4 h-4 text-red-400"}),"All Off"]})]}),a.jsxs(Te,{className:"whitespace-nowrap",onClick:()=>{L(null),D(!0)},children:[a.jsx(fr,{className:"w-4 h-4"}),"Add Smart Plug"]})]})]}),Ne&&Ne.length>0&&a.jsxs(St,{className:"mb-6",children:[a.jsx(Kn,{children:a.jsxs("h3",{className:"text-base font-semibold text-white flex items-center gap-2",children:[a.jsx(_h,{className:"w-4 h-4 text-yellow-400"}),"Energy Summary",Ye&&a.jsx(pt,{className:"w-4 h-4 animate-spin text-bambu-gray ml-2"})]})}),a.jsx(Nt,{children:nt?a.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[a.jsxs("div",{className:"bg-bambu-dark rounded-lg p-3",children:[a.jsxs("div",{className:"flex items-center gap-2 text-bambu-gray text-xs mb-1",children:[a.jsx(_h,{className:"w-3 h-3"}),"Current Power"]}),a.jsxs("div",{className:"text-xl font-bold text-white",children:[nt.totalPower.toFixed(1),a.jsx("span",{className:"text-sm font-normal text-bambu-gray ml-1",children:"W"})]}),a.jsxs("div",{className:"text-xs text-bambu-gray mt-1",children:[nt.reachableCount,"/",nt.totalPlugs," plugs online"]})]}),a.jsxs("div",{className:"bg-bambu-dark rounded-lg p-3",children:[a.jsxs("div",{className:"flex items-center gap-2 text-bambu-gray text-xs mb-1",children:[a.jsx(ti,{className:"w-3 h-3"}),"Today"]}),a.jsxs("div",{className:"text-xl font-bold text-white",children:[nt.totalToday.toFixed(2),a.jsx("span",{className:"text-sm font-normal text-bambu-gray ml-1",children:"kWh"})]}),E&&E.energy_cost_per_kwh>0&&a.jsxs("div",{className:"text-xs text-bambu-gray mt-1",children:["~",(nt.totalToday*E.energy_cost_per_kwh).toFixed(2)," ",E.currency]})]}),a.jsxs("div",{className:"bg-bambu-dark rounded-lg p-3",children:[a.jsxs("div",{className:"flex items-center gap-2 text-bambu-gray text-xs mb-1",children:[a.jsx(wP,{className:"w-3 h-3"}),"Yesterday"]}),a.jsxs("div",{className:"text-xl font-bold text-white",children:[nt.totalYesterday.toFixed(2),a.jsx("span",{className:"text-sm font-normal text-bambu-gray ml-1",children:"kWh"})]}),E&&E.energy_cost_per_kwh>0&&a.jsxs("div",{className:"text-xs text-bambu-gray mt-1",children:["~",(nt.totalYesterday*E.energy_cost_per_kwh).toFixed(2)," ",E.currency]})]}),a.jsxs("div",{className:"bg-bambu-dark rounded-lg p-3",children:[a.jsxs("div",{className:"flex items-center gap-2 text-bambu-gray text-xs mb-1",children:[a.jsx(mP,{className:"w-3 h-3"}),"Total"]}),a.jsxs("div",{className:"text-xl font-bold text-white",children:[nt.totalLifetime.toFixed(1),a.jsx("span",{className:"text-sm font-normal text-bambu-gray ml-1",children:"kWh"})]}),E&&E.energy_cost_per_kwh>0&&a.jsxs("div",{className:"text-xs text-bambu-gray mt-1",children:["~",(nt.totalLifetime*E.energy_cost_per_kwh).toFixed(2)," ",E.currency]})]})]}):Ye?null:a.jsx("p",{className:"text-sm text-bambu-gray",children:"Enable plugs to see energy summary"})})]}),Oe?a.jsx("div",{className:"flex justify-center py-12",children:a.jsx(pt,{className:"w-8 h-8 text-bambu-green animate-spin"})}):Ne&&Ne.length>0?a.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:Ne.map(le=>a.jsx(NKe,{plug:le,onEdit:_t=>{L(_t),D(!0)}},le.id))}):a.jsx(St,{children:a.jsx(Nt,{className:"py-12",children:a.jsxs("div",{className:"text-center text-bambu-gray",children:[a.jsx(al,{className:"w-16 h-16 mx-auto mb-4 opacity-30"}),a.jsx("p",{className:"text-lg font-medium text-white mb-2",children:i("settings.noSmartPlugsTitle")}),a.jsx("p",{className:"text-sm mb-4",children:i("settings.noSmartPlugsDescription")}),a.jsxs(Te,{onClick:()=>{L(null),D(!0)},children:[a.jsx(fr,{className:"w-4 h-4"}),i("settings.addFirstSmartPlug")]})]})})})]}),pe==="notifications"&&a.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-8",children:[a.jsxs("div",{children:[a.jsxs("div",{className:"flex items-center justify-between mb-4",children:[a.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[a.jsx(Sg,{className:"w-5 h-5 text-bambu-green"}),i("settings.providers")]}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsxs(Te,{size:"sm",variant:"secondary",onClick:()=>ne(!0),children:[a.jsx(W0,{className:"w-4 h-4"}),i("settings.log")]}),Tt&&Tt.length>0&&a.jsxs(Te,{size:"sm",variant:"secondary",onClick:()=>{ha(null),bl.mutate()},disabled:bl.isPending,children:[bl.isPending?a.jsx(pt,{className:"w-4 h-4 animate-spin"}):a.jsx(OR,{className:"w-4 h-4"}),i("settings.testAll")]}),a.jsxs(Te,{size:"sm",onClick:()=>{K(null),j(!0)},children:[a.jsx(fr,{className:"w-4 h-4"}),"Add"]})]})]}),a.jsx(St,{className:"mb-4",children:a.jsx(Nt,{className:"py-3",children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-white text-sm font-medium",children:i("settings.notificationLanguage")}),a.jsx("p",{className:"text-xs text-bambu-gray",children:i("settings.notificationLanguageDescription")})]}),a.jsx("select",{value:E.notification_language||"en",onChange:le=>fn("notification_language",le.target.value),className:"px-2 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm focus:outline-none focus:ring-1 focus:ring-bambu-green",children:yz.map(le=>a.jsx("option",{value:le.code,children:le.nativeName},le.code))})]})})}),Pc&&a.jsx(St,{className:"mb-4",children:a.jsxs(Nt,{className:"py-3",children:[a.jsxs("div",{className:"flex items-center justify-between mb-2",children:[a.jsx("span",{className:"text-sm font-medium text-white",children:i("settings.testResults")}),a.jsx("button",{onClick:()=>ha(null),className:"text-bambu-gray hover:text-white text-xs",children:i("common.dismiss")})]}),a.jsxs("div",{className:"flex items-center gap-4 text-sm mb-2",children:[a.jsxs("span",{className:"flex items-center gap-1 text-bambu-green",children:[a.jsx(Ar,{className:"w-4 h-4"}),i("settings.testPassedCount",{count:Pc.success})]}),Pc.failed>0&&a.jsxs("span",{className:"flex items-center gap-1 text-red-400",children:[a.jsx(Ji,{className:"w-4 h-4"}),i("settings.testFailedCount",{count:Pc.failed})]})]}),Pc.results.filter(le=>!le.success).length>0&&a.jsx("div",{className:"space-y-1 mt-2 pt-2 border-t border-bambu-dark-tertiary",children:Pc.results.filter(le=>!le.success).map(le=>a.jsxs("div",{className:"text-xs text-red-400",children:[a.jsxs("span",{className:"font-medium",children:[le.provider_name,":"]})," ",le.message]},le.provider_id))})]})}),At?a.jsx("div",{className:"flex justify-center py-12",children:a.jsx(pt,{className:"w-6 h-6 text-bambu-green animate-spin"})}):Tt&&Tt.length>0?a.jsx("div",{className:"space-y-3",children:Tt.map(le=>a.jsx(EKe,{provider:le,onEdit:_t=>{K(_t),j(!0)}},le.id))}):a.jsx(St,{children:a.jsx(Nt,{className:"py-8",children:a.jsxs("div",{className:"text-center text-bambu-gray",children:[a.jsx(Sg,{className:"w-12 h-12 mx-auto mb-3 opacity-30"}),a.jsx("p",{className:"text-sm font-medium text-white mb-2",children:i("settings.noProvidersTitle")}),a.jsx("p",{className:"text-xs mb-3",children:i("settings.noProvidersDescription")}),a.jsxs(Te,{size:"sm",onClick:()=>{K(null),j(!0)},children:[a.jsx(fr,{className:"w-4 h-4"}),i("settings.addProvider")]})]})})})]}),a.jsxs("div",{children:[a.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2 mb-4",children:[a.jsx(fs,{className:"w-5 h-5 text-bambu-green"}),i("settings.messageTemplates")]}),a.jsx("p",{className:"text-sm text-bambu-gray mb-4",children:i("settings.messageTemplatesDescription")}),un?a.jsx("div",{className:"flex justify-center py-8",children:a.jsx(pt,{className:"w-6 h-6 text-bambu-green animate-spin"})}):hn&&hn.length>0?a.jsx("div",{className:"space-y-2",children:hn.map(le=>a.jsx(St,{className:"cursor-pointer hover:border-bambu-green/50 transition-colors",onClick:()=>X(le),children:a.jsx(Nt,{className:"py-2.5 px-3",children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{className:"min-w-0 flex-1",children:[a.jsx("p",{className:"text-white font-medium text-sm truncate",children:le.name}),a.jsx("p",{className:"text-bambu-gray text-xs truncate mt-0.5",children:le.title_template})]}),a.jsx("button",{className:"p-1.5 hover:bg-bambu-dark-tertiary rounded transition-colors shrink-0 ml-2",onClick:_t=>{_t.stopPropagation(),X(le)},children:a.jsx(mg,{className:"w-4 h-4 text-bambu-gray"})})]})})},le.id))}):a.jsx(St,{children:a.jsx(Nt,{className:"py-8",children:a.jsxs("div",{className:"text-center text-bambu-gray",children:[a.jsx(fs,{className:"w-12 h-12 mx-auto mb-3 opacity-30"}),a.jsx("p",{className:"text-sm",children:i("settings.noTemplatesAvailable")})]})})})]})]}),pe==="apikeys"&&a.jsxs("div",{className:"grid grid-cols-1 xl:grid-cols-2 gap-8",children:[a.jsxs("div",{children:[a.jsxs("div",{className:"flex items-start justify-between gap-4 mb-6",children:[a.jsxs("div",{className:"flex-1",children:[a.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[a.jsx(Ko,{className:"w-5 h-5 text-bambu-green"}),i("settings.apiKeys")]}),a.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:i("settings.apiKeysDescription")})]}),a.jsxs(Te,{size:"sm",onClick:()=>se(!0),className:"flex-shrink-0",children:[a.jsx(fr,{className:"w-4 h-4"}),i("settings.createKey")]})]}),G&&a.jsx(St,{className:"mb-6 border-bambu-green",children:a.jsx(Nt,{className:"py-4",children:a.jsxs("div",{className:"flex items-start gap-3",children:[a.jsx(Ar,{className:"w-5 h-5 text-bambu-green flex-shrink-0 mt-0.5"}),a.jsxs("div",{className:"flex-1",children:[a.jsx("p",{className:"text-white font-medium mb-1",children:i("settings.apiKeyCreated")}),a.jsx("p",{className:"text-sm text-bambu-gray mb-2",children:i("settings.apiKeyCopyWarning")}),a.jsxs("div",{className:"flex items-center gap-2 bg-bambu-dark rounded-lg p-2",children:[a.jsx("code",{className:"flex-1 text-sm text-bambu-green font-mono break-all",children:G}),a.jsx(Te,{variant:"secondary",size:"sm",onClick:async()=>{try{if(navigator.clipboard&&navigator.clipboard.writeText)await navigator.clipboard.writeText(G);else{const le=document.createElement("textarea");le.value=G,le.style.position="fixed",le.style.left="-999999px",document.body.appendChild(le),le.select(),document.execCommand("copy"),document.body.removeChild(le)}o(i("settings.toast.keyCopied"))}catch{o(i("settings.toast.copyFailed"),"error")}},children:a.jsx(Ul,{className:"w-4 h-4"})})]}),a.jsxs("div",{className:"flex gap-2 mt-3",children:[a.jsx(Te,{variant:"secondary",size:"sm",onClick:()=>{V(G),o(i("settings.toast.keyAddedToBrowser"))},children:i("settings.useInApiBrowser")}),a.jsx(Te,{variant:"secondary",size:"sm",onClick:()=>Q(null),children:i("common.dismiss")})]})]})]})})}),Ee&&a.jsxs(St,{className:"mb-6",children:[a.jsx(Kn,{children:a.jsx("h3",{className:"text-base font-semibold text-white",children:i("settings.createNewApiKey")})}),a.jsxs(Nt,{className:"space-y-4",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:i("settings.keyName")}),a.jsx("input",{type:"text",value:Ae,onChange:le=>Fe(le.target.value),placeholder:i("settings.keyNamePlaceholder"),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"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-2",children:i("common.permissions")}),a.jsxs("div",{className:"space-y-2",children:[a.jsxs("label",{className:"flex items-center gap-3 cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:ge.can_read_status,onChange:le=>Ze(_t=>({..._t,can_read_status:le.target.checked})),className:"w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green"}),a.jsxs("div",{children:[a.jsx("span",{className:"text-white",children:i("settings.readStatus")}),a.jsx("p",{className:"text-xs text-bambu-gray",children:i("settings.readStatusDescription")})]})]}),a.jsxs("label",{className:"flex items-center gap-3 cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:ge.can_queue,onChange:le=>Ze(_t=>({..._t,can_queue:le.target.checked})),className:"w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green"}),a.jsxs("div",{children:[a.jsx("span",{className:"text-white",children:i("settings.manageQueue")}),a.jsx("p",{className:"text-xs text-bambu-gray",children:i("settings.manageQueueDescription")})]})]}),a.jsxs("label",{className:"flex items-center gap-3 cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:ge.can_control_printer,onChange:le=>Ze(_t=>({..._t,can_control_printer:le.target.checked})),className:"w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green"}),a.jsxs("div",{children:[a.jsx("span",{className:"text-white",children:i("settings.controlPrinter")}),a.jsx("p",{className:"text-xs text-bambu-gray",children:i("settings.controlPrinterDescription")})]})]})]})]}),a.jsxs("div",{className:"flex items-center gap-2 pt-2",children:[a.jsxs(Te,{onClick:()=>Mt.mutate({name:Ae||i("settings.unnamedKey"),...ge}),disabled:Mt.isPending,children:[Mt.isPending?a.jsx(pt,{className:"w-4 h-4 animate-spin"}):a.jsx(fr,{className:"w-4 h-4"}),i("settings.createKey")]}),a.jsx(Te,{variant:"secondary",onClick:()=>se(!1),children:i("common.cancel")})]})]})]}),Rt?a.jsx("div",{className:"flex justify-center py-12",children:a.jsx(pt,{className:"w-8 h-8 text-bambu-green animate-spin"})}):It&&It.length>0?a.jsx("div",{className:"space-y-3",children:It.map(le=>a.jsx(St,{children:a.jsx(Nt,{className:"py-3",children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{className:"flex items-center gap-3",children:[a.jsx(Ko,{className:`w-5 h-5 ${le.enabled?"text-bambu-green":"text-bambu-gray"}`}),a.jsxs("div",{children:[a.jsx("p",{className:"text-white font-medium",children:le.name}),a.jsxs("p",{className:"text-xs text-bambu-gray",children:[le.key_prefix,"••••••••",le.last_used&&` · ${i("settings.lastUsed")}: ${$g(le.last_used)}`]})]})]}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsxs("div",{className:"flex gap-1 text-xs",children:[le.can_read_status&&a.jsx("span",{className:"px-1.5 py-0.5 bg-blue-500/20 text-blue-400 rounded",children:i("settings.read")}),le.can_queue&&a.jsx("span",{className:"px-1.5 py-0.5 bg-green-500/20 text-green-400 rounded",children:i("queue.title")}),le.can_control_printer&&a.jsx("span",{className:"px-1.5 py-0.5 bg-orange-500/20 text-orange-400 rounded",children:i("settings.control")})]}),a.jsx(Te,{variant:"secondary",size:"sm",onClick:()=>q(le.id),children:a.jsx(an,{className:"w-4 h-4 text-red-400"})})]})]})})},le.id))}):a.jsx(St,{children:a.jsx(Nt,{className:"py-12",children:a.jsxs("div",{className:"text-center text-bambu-gray",children:[a.jsx(Ko,{className:"w-16 h-16 mx-auto mb-4 opacity-30"}),a.jsx("p",{className:"text-lg font-medium text-white mb-2",children:i("settings.apiKeysEmptyTitle")}),a.jsx("p",{className:"text-sm mb-4",children:i("settings.apiKeysEmptyDescription")}),a.jsxs(Te,{onClick:()=>se(!0),children:[a.jsx(fr,{className:"w-4 h-4"}),i("settings.createFirstKey")]})]})})}),a.jsxs(St,{className:"mt-6",children:[a.jsx(Kn,{children:a.jsx("h3",{className:"text-base font-semibold text-white",children:i("settings.webhookEndpoints")})}),a.jsxs(Nt,{className:"space-y-3 text-sm",children:[a.jsx("p",{className:"text-bambu-gray",children:i("settings.webhookApiKeyHint")}),a.jsxs("div",{className:"space-y-2 font-mono text-xs",children:[a.jsxs("div",{className:"p-2 bg-bambu-dark rounded",children:[a.jsx("span",{className:"text-blue-400",children:"GET"})," ",a.jsx("span",{className:"text-white",children:"/api/v1/webhook/status"}),a.jsxs("span",{className:"text-bambu-gray",children:[" - ",i("settings.webhook.getAllStatus")]})]}),a.jsxs("div",{className:"p-2 bg-bambu-dark rounded",children:[a.jsx("span",{className:"text-blue-400",children:"GET"})," ",a.jsx("span",{className:"text-white",children:"/api/v1/webhook/status/:id"}),a.jsxs("span",{className:"text-bambu-gray",children:[" - ",i("settings.webhook.getSpecificStatus")]})]}),a.jsxs("div",{className:"p-2 bg-bambu-dark rounded",children:[a.jsx("span",{className:"text-green-400",children:"POST"})," ",a.jsx("span",{className:"text-white",children:"/api/v1/webhook/queue"}),a.jsxs("span",{className:"text-bambu-gray",children:[" - ",i("settings.webhook.addToQueue")]})]}),a.jsxs("div",{className:"p-2 bg-bambu-dark rounded",children:[a.jsx("span",{className:"text-orange-400",children:"POST"})," ",a.jsx("span",{className:"text-white",children:"/api/v1/webhook/printer/:id/pause"}),a.jsxs("span",{className:"text-bambu-gray",children:[" - ",i("settings.webhook.pausePrint")]})]}),a.jsxs("div",{className:"p-2 bg-bambu-dark rounded",children:[a.jsx("span",{className:"text-orange-400",children:"POST"})," ",a.jsx("span",{className:"text-white",children:"/api/v1/webhook/printer/:id/resume"}),a.jsxs("span",{className:"text-bambu-gray",children:[" - ",i("settings.webhook.resumePrint")]})]}),a.jsxs("div",{className:"p-2 bg-bambu-dark rounded",children:[a.jsx("span",{className:"text-red-400",children:"POST"})," ",a.jsx("span",{className:"text-white",children:"/api/v1/webhook/printer/:id/stop"}),a.jsxs("span",{className:"text-bambu-gray",children:[" - ",i("settings.webhook.stopPrint")]})]})]})]})]})]}),a.jsxs("div",{children:[a.jsxs("div",{className:"mb-6",children:[a.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[a.jsx(oh,{className:"w-5 h-5 text-bambu-green"}),i("settings.apiBrowser")]}),a.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:i("settings.apiBrowserDescription")})]}),a.jsx(St,{className:"mb-4",children:a.jsxs(Nt,{className:"py-3",children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-2",children:i("settings.apiKeyForTesting")}),a.jsx("input",{type:"text",value:ee,onChange:le=>V(le.target.value),placeholder:i("settings.apiKeyPlaceholder"),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white font-mono text-sm focus:border-bambu-green focus:outline-none"}),a.jsx("p",{className:"text-xs text-bambu-gray mt-2",children:i("settings.apiKeyHint")})]})}),a.jsx($Ke,{apiKey:ee})]})]}),pe==="virtual-printer"&&a.jsx(FKe,{}),pe==="filament"&&E&&a.jsxs("div",{className:"flex flex-col lg:flex-row gap-6 lg:gap-8",children:[a.jsx("div",{className:"flex-1 lg:max-w-xl",children:a.jsxs(St,{children:[a.jsx(Kn,{children:a.jsx("h2",{className:"text-lg font-semibold text-white",children:i("settings.amsDisplayThresholds")})}),a.jsxs(Nt,{className:"space-y-4",children:[a.jsx("p",{className:"text-sm text-bambu-gray",children:i("settings.amsThresholdsDescription")}),a.jsxs("div",{className:"space-y-3",children:[a.jsxs("div",{className:"flex items-center gap-2 text-white",children:[a.jsx(DR,{className:"w-4 h-4 text-blue-400"}),a.jsx("span",{className:"font-medium",children:i("settings.humidity")})]}),a.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[a.jsxs("div",{children:[a.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[i("settings.goodGreen")," ≤"]}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("input",{type:"number",min:"0",max:"100",value:E.ams_humidity_good??40,onChange:le=>fn("ams_humidity_good",parseInt(le.target.value)||40),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"}),a.jsx("span",{className:"text-bambu-gray",children:"%"})]})]}),a.jsxs("div",{children:[a.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[i("settings.fairOrange")," ≤"]}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("input",{type:"number",min:"0",max:"100",value:E.ams_humidity_fair??60,onChange:le=>fn("ams_humidity_fair",parseInt(le.target.value)||60),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"}),a.jsx("span",{className:"text-bambu-gray",children:"%"})]})]})]}),a.jsx("p",{className:"text-xs text-bambu-gray",children:i("settings.aboveFairBad")})]}),a.jsxs("div",{className:"space-y-3 pt-2 border-t border-bambu-dark-tertiary",children:[a.jsxs("div",{className:"flex items-center gap-2 text-white",children:[a.jsx(vM,{className:"w-4 h-4 text-orange-400"}),a.jsx("span",{className:"font-medium",children:i("settings.temperature")})]}),a.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[a.jsxs("div",{children:[a.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[i("settings.goodBlue")," ≤"]}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("input",{type:"number",step:"0.5",min:"0",max:"60",value:E.ams_temp_good??28,onChange:le=>fn("ams_temp_good",parseFloat(le.target.value)||28),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"}),a.jsx("span",{className:"text-bambu-gray",children:"°C"})]})]}),a.jsxs("div",{children:[a.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[i("settings.fairOrange")," ≤"]}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("input",{type:"number",step:"0.5",min:"0",max:"60",value:E.ams_temp_fair??35,onChange:le=>fn("ams_temp_fair",parseFloat(le.target.value)||35),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"}),a.jsx("span",{className:"text-bambu-gray",children:"°C"})]})]})]}),a.jsx("p",{className:"text-xs text-bambu-gray",children:i("settings.aboveFairHot")})]}),a.jsxs("div",{className:"space-y-3 pt-4 border-t border-bambu-dark-tertiary",children:[a.jsxs("div",{className:"flex items-center gap-2 text-white",children:[a.jsx(Eu,{className:"w-4 h-4 text-purple-400"}),a.jsx("span",{className:"font-medium",children:i("settings.historyRetention")})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:i("settings.keepSensorHistory")}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("input",{type:"number",min:"1",max:"365",value:E.ams_history_retention_days??30,onChange:le=>fn("ams_history_retention_days",parseInt(le.target.value)||30),className:"w-24 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"}),a.jsx("span",{className:"text-bambu-gray",children:i("common.days")})]})]}),a.jsx("p",{className:"text-xs text-bambu-gray",children:i("settings.historyRetentionDescription")})]}),a.jsxs("div",{className:"space-y-3 pt-4 border-t border-bambu-dark-tertiary",children:[a.jsxs("div",{className:"flex items-center gap-2 text-white",children:[a.jsx(Ur,{className:"w-4 h-4 text-bambu-green"}),a.jsx("span",{className:"font-medium",children:i("settings.printModal")})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-white",children:i("settings.expandCustomMapping")}),a.jsx("p",{className:"text-xs text-bambu-gray mt-0.5",children:i("settings.expandCustomMappingDescription")})]}),a.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:E.per_printer_mapping_expanded??!1,onChange:le=>fn("per_printer_mapping_expanded",le.target.checked),className:"sr-only peer"}),a.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]})]})]})]})}),a.jsx("div",{className:"flex-1 lg:max-w-xl",children:a.jsx(RKe,{})})]}),he!==null&&a.jsx(Zn,{title:i("settings.deleteApiKeyTitle"),message:i("settings.deleteApiKeyMessage"),confirmText:i("settings.deleteKey"),variant:"danger",onConfirm:()=>{en.mutate(he),q(null)},onCancel:()=>q(null)}),A&&a.jsx(MKe,{plug:I,onClose:()=>{D(!1),L(null)}}),U&&a.jsx(TKe,{provider:$,onClose:()=>{j(!1),K(null)}}),B&&a.jsx(AKe,{template:B,onClose:()=>X(null)}),Y&&a.jsx(PKe,{onClose:()=>ne(!1)}),ye&&a.jsx(Zn,{title:i("settings.clearNotificationLogs"),message:i("settings.clearLogsMessage"),confirmText:i("settings.clearLogs"),variant:"warning",onConfirm:async()=>{je(!1);try{const le=await ce.clearNotificationLogs(30);o(le.message,"success")}catch{o(i("settings.toast.clearLogsFailed"),"error")}},onCancel:()=>je(!1)}),te&&a.jsx(Zn,{title:i("settings.resetUiPreferences"),message:i("settings.resetUiPreferencesMessage"),confirmText:i("settings.resetPreferences"),variant:"default",onConfirm:()=>{z(!1),localStorage.clear(),o(i("settings.toast.uiPreferencesReset"),"success"),setTimeout(()=>window.location.reload(),1e3)},onCancel:()=>z(!1)}),O&&a.jsx(Zn,{title:`Turn All Plugs ${O==="on"?"On":"Off"}`,message:`This will turn ${O==="on"?"ON":"OFF"} all ${Ne?.filter(le=>le.enabled).length||0} enabled smart plugs. ${O==="off"?"Any running printers may be affected!":""}`,confirmText:`Turn All ${O==="on"?"On":"Off"}`,variant:O==="off"?"danger":"warning",onConfirm:()=>{const le=O;Z(null),ql.mutate(le)},onCancel:()=>Z(null)}),oe&&Yt?.release_notes&&a.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",onClick:()=>we(!1),children:a.jsxs(St,{className:"w-full max-w-2xl max-h-[80vh] flex flex-col",onClick:le=>le.stopPropagation(),children:[a.jsxs(Kn,{className:"flex flex-row items-center justify-between shrink-0",children:[a.jsxs("div",{children:[a.jsxs("h2",{className:"text-lg font-semibold text-white",children:["Release Notes - v",Yt.latest_version]}),Yt.release_name&&Yt.release_name!==Yt.latest_version&&a.jsx("p",{className:"text-sm text-bambu-gray",children:Yt.release_name})]}),a.jsx("button",{onClick:()=>we(!1),className:"p-1 rounded hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white",children:a.jsx(Lt,{className:"w-5 h-5"})})]}),a.jsx(Nt,{className:"overflow-y-auto flex-1",children:a.jsx("pre",{className:"text-sm text-bambu-gray whitespace-pre-wrap font-sans",children:Yt.release_notes})}),a.jsxs("div",{className:"p-4 border-t border-bambu-dark-tertiary shrink-0 flex gap-2",children:[Yt.release_url&&a.jsx("a",{href:Yt.release_url,target:"_blank",rel:"noopener noreferrer",className:"flex-1",children:a.jsxs(Te,{variant:"secondary",className:"w-full",children:[a.jsx(Xr,{className:"w-4 h-4"}),"View on GitHub"]})}),a.jsx(Te,{onClick:()=>we(!1),className:"flex-1",children:"Close"})]})]})}),pe==="users"&&a.jsxs("div",{className:"space-y-6",children:[a.jsx(St,{children:a.jsx(Nt,{className:"py-4",children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{className:"flex items-center gap-3",children:[a.jsx("div",{className:`w-10 h-10 rounded-full flex items-center justify-center ${l?"bg-green-500/20":"bg-gray-500/20"}`,children:l?a.jsx(iT,{className:"w-5 h-5 text-green-400"}):a.jsx(rT,{className:"w-5 h-5 text-gray-400"})}),a.jsxs("div",{children:[a.jsx("h3",{className:"text-white font-medium",children:i("settings.authentication")}),a.jsx("p",{className:"text-sm text-bambu-gray",children:i(l?"settings.authEnabledDescription":"settings.authDisabledDescription")})]})]}),l?c?.is_admin&&a.jsxs(Te,{variant:"secondary",onClick:()=>ae(!0),children:[a.jsx(rT,{className:"w-4 h-4"}),i("common.disable")]}):a.jsxs(Te,{onClick:()=>e("/setup"),children:[a.jsx(iT,{className:"w-4 h-4"}),i("common.enable")]})]})})}),l&&a.jsxs("div",{className:"grid grid-cols-1 xl:grid-cols-2 gap-6",children:[a.jsxs("div",{className:"space-y-6",children:[c&&a.jsxs(St,{children:[a.jsx(Kn,{children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("h3",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[a.jsx(pg,{className:"w-5 h-5 text-bambu-green"}),i("settings.currentUser")]}),a.jsxs(Te,{size:"sm",variant:"ghost",onClick:()=>Be(!0),children:[a.jsx(Ko,{className:"w-4 h-4"}),i("settings.changePassword")]})]})}),a.jsx(Nt,{children:a.jsx("div",{className:"flex items-center justify-between",children:a.jsxs("div",{children:[a.jsx("p",{className:"text-white font-medium text-lg",children:c.username}),a.jsxs("div",{className:"flex flex-wrap gap-1 mt-2",children:[c.is_admin&&a.jsx("span",{className:"px-2 py-0.5 rounded-full text-xs font-medium bg-purple-500/20 text-purple-300",children:i("settings.admin")}),c.groups?.map(le=>a.jsx("span",{className:`px-2 py-0.5 rounded-full text-xs font-medium ${le.name==="Administrators"?"bg-purple-500/20 text-purple-300":le.name==="Operators"?"bg-blue-500/20 text-blue-300":le.name==="Viewers"?"bg-green-500/20 text-green-300":"bg-gray-500/20 text-gray-300"}`,children:le.name},le.id))]})]})})})]}),a.jsxs(St,{children:[a.jsx(Kn,{children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("h3",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[a.jsx(pg,{className:"w-5 h-5 text-bambu-green"}),i("settings.users")]}),qt("users:create")&&a.jsxs(Te,{size:"sm",onClick:()=>{Se(!0),jt({username:"",password:"",confirmPassword:"",role:"user",group_ids:[]})},children:[a.jsx(fr,{className:"w-4 h-4"}),i("settings.addUser")]})]})}),a.jsx(Nt,{children:wn?a.jsx("div",{className:"flex items-center justify-center py-8",children:a.jsx(pt,{className:"w-6 h-6 text-bambu-green animate-spin"})}):vt.length===0?a.jsx("p",{className:"text-center text-bambu-gray py-8",children:i("settings.noUsersFound")}):a.jsx("div",{className:"divide-y divide-bambu-dark-tertiary",children:vt.map(le=>a.jsxs("div",{className:"py-3 flex items-center justify-between",children:[a.jsxs("div",{className:"flex-1 min-w-0",children:[a.jsx("p",{className:"text-white font-medium truncate",children:le.username}),a.jsxs("div",{className:"flex flex-wrap gap-1 mt-1",children:[le.is_admin&&a.jsx("span",{className:"px-2 py-0.5 rounded-full text-xs font-medium bg-purple-500/20 text-purple-300",children:i("settings.admin")}),le.groups?.map(_t=>a.jsx("span",{className:`px-2 py-0.5 rounded-full text-xs font-medium ${_t.name==="Administrators"?"bg-purple-500/20 text-purple-300":_t.name==="Operators"?"bg-blue-500/20 text-blue-300":_t.name==="Viewers"?"bg-green-500/20 text-green-300":"bg-gray-500/20 text-gray-300"}`,children:_t.name},_t.id))]})]}),a.jsxs("div",{className:"flex items-center gap-1 ml-4",children:[qt("users:update")&&a.jsx(Te,{size:"sm",variant:"ghost",onClick:()=>Ni(le),children:a.jsx(mg,{className:"w-4 h-4"})}),qt("users:delete")&&le.id!==c?.id&&a.jsx(Te,{size:"sm",variant:"ghost",onClick:()=>Si(le.id),children:a.jsx(an,{className:"w-4 h-4"})})]})]},le.id))})})]})]}),a.jsx("div",{children:a.jsxs(St,{children:[a.jsx(Kn,{children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("h3",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[a.jsx(aT,{className:"w-5 h-5 text-bambu-green"}),i("settings.groups")]}),qt("groups:create")&&a.jsxs(Te,{size:"sm",onClick:()=>{yn(!0),da()},children:[a.jsx(fr,{className:"w-4 h-4"}),i("settings.addGroup")]})]})}),a.jsx(Nt,{children:Qr?a.jsx("div",{className:"flex items-center justify-center py-8",children:a.jsx(pt,{className:"w-6 h-6 text-bambu-green animate-spin"})}):Fr.length===0?a.jsx("p",{className:"text-center text-bambu-gray py-8",children:i("settings.noGroupsFound")}):a.jsx("div",{className:"divide-y divide-bambu-dark-tertiary",children:Fr.map(le=>a.jsxs("div",{className:"py-3",children:[a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(aT,{className:`w-4 h-4 ${le.name==="Administrators"?"text-purple-400":le.name==="Operators"?"text-blue-400":le.name==="Viewers"?"text-green-400":"text-bambu-gray"}`}),a.jsx("span",{className:"text-white font-medium",children:le.name}),le.is_system&&a.jsx("span",{className:"px-2 py-0.5 rounded text-xs bg-yellow-500/20 text-yellow-400",children:i("settings.system")})]}),a.jsxs("div",{className:"flex items-center gap-1",children:[qt("groups:update")&&a.jsx(Te,{size:"sm",variant:"ghost",onClick:()=>Gh(le),children:a.jsx(mg,{className:"w-4 h-4"})}),qt("groups:delete")&&!le.is_system&&a.jsx(Te,{size:"sm",variant:"ghost",onClick:()=>Jn(le.id),children:a.jsx(an,{className:"w-4 h-4"})})]})]}),a.jsx("p",{className:"text-sm text-bambu-gray mt-1 ml-6",children:le.description||i("settings.noDescription")}),a.jsxs("div",{className:"flex items-center gap-4 mt-2 ml-6 text-xs text-bambu-gray",children:[a.jsx("span",{children:i("settings.userCount",{count:le.user_count})}),a.jsx("span",{children:i("settings.permissionCount",{count:le.permissions.length})})]})]},le.id))})})]})})]}),!l&&a.jsx(St,{children:a.jsx(Nt,{className:"py-6",children:a.jsxs("div",{className:"text-center",children:[a.jsx(rT,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),a.jsx("h3",{className:"text-lg font-medium text-white mb-2",children:i("settings.authDisabledTitle")}),a.jsx("p",{className:"text-sm text-bambu-gray mb-4 max-w-md mx-auto",children:i("settings.authDisabledMessage")}),a.jsxs("ul",{className:"space-y-2 text-sm text-bambu-gray mb-6 text-left max-w-xs mx-auto",children:[a.jsxs("li",{className:"flex items-start gap-2",children:[a.jsx(Ar,{className:"w-4 h-4 text-bambu-green mt-0.5 flex-shrink-0"}),a.jsx("span",{children:i("settings.authDisabledFeature1")})]}),a.jsxs("li",{className:"flex items-start gap-2",children:[a.jsx(Ar,{className:"w-4 h-4 text-bambu-green mt-0.5 flex-shrink-0"}),a.jsx("span",{children:i("settings.authDisabledFeature2")})]}),a.jsxs("li",{className:"flex items-start gap-2",children:[a.jsx(Ar,{className:"w-4 h-4 text-bambu-green mt-0.5 flex-shrink-0"}),a.jsx("span",{children:i("settings.authDisabledFeature3")})]})]}),a.jsxs(Te,{onClick:()=>e("/setup"),children:[a.jsx(iT,{className:"w-4 h-4"}),i("settings.enableAuthentication")]})]})})})]}),Ie&&a.jsx("div",{className:"fixed inset-0 bg-black flex items-center justify-center z-50 p-4",onClick:()=>{Se(!1),jt({username:"",password:"",confirmPassword:"",role:"user",group_ids:[]})},children:a.jsxs(St,{className:"w-full max-w-md",onClick:le=>le.stopPropagation(),children:[a.jsx(Kn,{children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(pg,{className:"w-5 h-5 text-bambu-green"}),a.jsx("h2",{className:"text-lg font-semibold text-white",children:i("settings.createUser")})]}),a.jsx(Te,{variant:"ghost",size:"sm",onClick:()=>{Se(!1),jt({username:"",password:"",confirmPassword:"",role:"user",group_ids:[]})},children:a.jsx(Lt,{className:"w-5 h-5"})})]})}),a.jsxs(Nt,{children:[a.jsxs("div",{className:"space-y-4",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:i("settings.username")}),a.jsx("input",{type:"text",value:at.username,onChange:le=>jt({...at,username:le.target.value}),className:"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:i("settings.enterUsername"),autoComplete:"username"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:i("settings.password")}),a.jsx("input",{type:"password",value:at.password,onChange:le=>jt({...at,password:le.target.value}),className:"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:i("settings.enterPassword"),autoComplete:"new-password",minLength:6})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:i("settings.confirmPassword")}),a.jsx("input",{type:"password",value:at.confirmPassword,onChange:le=>jt({...at,confirmPassword:le.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors ${at.confirmPassword&&at.password!==at.confirmPassword?"border-red-500":"border-bambu-dark-tertiary"}`,placeholder:i("settings.confirmPasswordPlaceholder"),autoComplete:"new-password",minLength:6}),at.confirmPassword&&at.password!==at.confirmPassword&&a.jsx("p",{className:"text-red-400 text-xs mt-1",children:i("settings.passwordsDoNotMatch")})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:"Groups"}),a.jsxs("div",{className:"space-y-2 max-h-40 overflow-y-auto p-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg",children:[Fr.map(le=>a.jsxs("label",{className:"flex items-center gap-3 px-2 py-1.5 rounded hover:bg-bambu-dark-tertiary cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:at.group_ids.includes(le.id),onChange:()=>Qs(le.id),className:"w-4 h-4 rounded border-bambu-gray text-bambu-green focus:ring-bambu-green focus:ring-offset-0 bg-bambu-dark"}),a.jsx("span",{className:"text-sm text-white",children:le.name}),le.is_system&&a.jsx("span",{className:"text-xs text-yellow-400",children:"(System)"})]},le.id)),Fr.length===0&&a.jsx("p",{className:"text-sm text-bambu-gray",children:i("settings.noGroupsAvailable")})]})]})]}),a.jsxs("div",{className:"mt-6 flex justify-end gap-3",children:[a.jsx(Te,{variant:"secondary",onClick:()=>{Se(!1),jt({username:"",password:"",confirmPassword:"",role:"user",group_ids:[]})},children:"Cancel"}),a.jsx(Te,{onClick:Ao,disabled:Ys.isPending||!at.username||!at.password||at.password!==at.confirmPassword||at.password.length<6,children:Ys.isPending?a.jsxs(a.Fragment,{children:[a.jsx(pt,{className:"w-4 h-4 animate-spin"}),"Creating..."]}):a.jsxs(a.Fragment,{children:[a.jsx(fr,{className:"w-4 h-4"}),"Create User"]})})]})]})]})}),Ke&&it!==null&&a.jsx("div",{className:"fixed inset-0 bg-black flex items-center justify-center z-50 p-4",onClick:()=>{Me(!1),ke(null),jt({username:"",password:"",confirmPassword:"",role:"user",group_ids:[]})},children:a.jsxs(St,{className:"w-full max-w-md",onClick:le=>le.stopPropagation(),children:[a.jsx(Kn,{children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(mg,{className:"w-5 h-5 text-bambu-green"}),a.jsx("h2",{className:"text-lg font-semibold text-white",children:i("settings.editUser")})]}),a.jsx(Te,{variant:"ghost",size:"sm",onClick:()=>{Me(!1),ke(null),jt({username:"",password:"",confirmPassword:"",role:"user",group_ids:[]})},children:a.jsx(Lt,{className:"w-5 h-5"})})]})}),a.jsxs(Nt,{children:[a.jsxs("div",{className:"space-y-4",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:i("settings.username")}),a.jsx("input",{type:"text",value:at.username,onChange:le=>jt({...at,username:le.target.value}),className:"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:i("settings.enterUsername"),autoComplete:"username"})]}),a.jsxs("div",{children:[a.jsxs("label",{className:"block text-sm font-medium text-white mb-2",children:["Password ",a.jsx("span",{className:"text-bambu-gray font-normal",children:"(leave blank to keep current)"})]}),a.jsx("input",{type:"password",value:at.password,onChange:le=>jt({...at,password:le.target.value,confirmPassword:""}),className:"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:i("settings.enterNewPassword"),autoComplete:"new-password",minLength:6})]}),at.password&&a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:i("settings.confirmPassword")}),a.jsx("input",{type:"password",value:at.confirmPassword,onChange:le=>jt({...at,confirmPassword:le.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors ${at.confirmPassword&&at.password!==at.confirmPassword?"border-red-500":"border-bambu-dark-tertiary"}`,placeholder:i("settings.confirmNewPassword"),autoComplete:"new-password",minLength:6}),at.confirmPassword&&at.password!==at.confirmPassword&&a.jsx("p",{className:"text-red-400 text-xs mt-1",children:i("settings.passwordsDoNotMatch")})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:"Groups"}),a.jsx("div",{className:"space-y-2 max-h-40 overflow-y-auto p-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg",children:Fr.map(le=>a.jsxs("label",{className:"flex items-center gap-3 px-2 py-1.5 rounded hover:bg-bambu-dark-tertiary cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:at.group_ids.includes(le.id),onChange:()=>Qs(le.id),className:"w-4 h-4 rounded border-bambu-gray text-bambu-green focus:ring-bambu-green focus:ring-offset-0 bg-bambu-dark"}),a.jsx("span",{className:"text-sm text-white",children:le.name}),le.is_system&&a.jsx("span",{className:"text-xs text-yellow-400",children:"(System)"})]},le.id))})]})]}),a.jsxs("div",{className:"mt-6 flex justify-end gap-3",children:[a.jsx(Te,{variant:"secondary",onClick:()=>{Me(!1),ke(null),jt({username:"",password:"",confirmPassword:"",role:"user",group_ids:[]})},children:"Cancel"}),a.jsx(Te,{onClick:()=>Ts(it),disabled:nn.isPending||!at.username||!!(at.password&&(at.password!==at.confirmPassword||at.password.length<6)),children:nn.isPending?a.jsxs(a.Fragment,{children:[a.jsx(pt,{className:"w-4 h-4 animate-spin"}),"Saving..."]}):a.jsxs(a.Fragment,{children:[a.jsx(ms,{className:"w-4 h-4"}),"Save Changes"]})})]})]})]})}),Xe!==null&&a.jsx("div",{className:"fixed inset-0 bg-black/80 flex items-center justify-center z-50 p-4",onClick:()=>{ze(null),$e(null)},children:a.jsxs(St,{className:"w-full max-w-md",onClick:le=>le.stopPropagation(),children:[a.jsx(Kn,{children:a.jsxs("div",{className:"flex items-center gap-2 text-red-400",children:[a.jsx(an,{className:"w-5 h-5"}),a.jsx("h3",{className:"text-lg font-semibold",children:i("settings.deleteUserTitle")})]})}),a.jsx(Nt,{className:"space-y-4",children:be?a.jsx("div",{className:"flex items-center justify-center py-4",children:a.jsx("div",{className:"animate-spin rounded-full h-6 w-6 border-2 border-bambu-green border-t-transparent"})}):ue&&ue.archives+ue.queue_items+ue.library_files>0?a.jsxs(a.Fragment,{children:[a.jsx("p",{className:"text-white",children:i("settings.userHasCreated")}),a.jsxs("ul",{className:"list-disc list-inside text-bambu-gray space-y-1",children:[ue.archives>0&&a.jsxs("li",{children:[ue.archives," archive",ue.archives!==1?"s":""]}),ue.queue_items>0&&a.jsxs("li",{children:[ue.queue_items," queue item",ue.queue_items!==1?"s":""]}),ue.library_files>0&&a.jsxs("li",{children:[ue.library_files," library file",ue.library_files!==1?"s":""]})]}),a.jsx("p",{className:"text-bambu-gray text-sm",children:i("settings.userItemsQuestion")}),a.jsxs("div",{className:"flex flex-col gap-2",children:[a.jsx(Te,{variant:"danger",onClick:()=>ln.mutate({id:Xe,deleteItems:!0}),disabled:ln.isPending,className:"justify-center",children:"Delete user AND their items"}),a.jsx(Te,{variant:"secondary",onClick:()=>ln.mutate({id:Xe,deleteItems:!1}),disabled:ln.isPending,className:"justify-center",children:"Delete user, keep items (become ownerless)"}),a.jsx(Te,{variant:"ghost",onClick:()=>{ze(null),$e(null)},disabled:ln.isPending,className:"justify-center",children:"Cancel"})]})]}):a.jsxs(a.Fragment,{children:[a.jsx("p",{className:"text-white",children:i("settings.deleteUserConfirm")}),a.jsx("p",{className:"text-bambu-gray text-sm",children:i("settings.actionCannotBeUndone")}),a.jsxs("div",{className:"flex gap-2 justify-end",children:[a.jsx(Te,{variant:"ghost",onClick:()=>{ze(null),$e(null)},disabled:ln.isPending,children:"Cancel"}),a.jsx(Te,{variant:"danger",onClick:()=>ln.mutate({id:Xe,deleteItems:!1}),disabled:ln.isPending,children:"Delete User"})]})]})})]})}),(Dt||cn)&&a.jsx("div",{className:"fixed inset-0 bg-black flex items-center justify-center z-50 p-4",onClick:()=>{yn(!1),rr(null),da()},children:a.jsxs(St,{className:"w-full max-w-2xl max-h-[90vh] overflow-y-auto",onClick:le=>le.stopPropagation(),children:[a.jsx(Kn,{children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(aT,{className:"w-5 h-5 text-bambu-green"}),a.jsx("h2",{className:"text-lg font-semibold text-white",children:cn?"Edit Group":"Create Group"})]}),a.jsx(Te,{variant:"ghost",size:"sm",onClick:()=>{yn(!1),rr(null),da()},children:a.jsx(Lt,{className:"w-5 h-5"})})]})}),a.jsxs(Nt,{children:[a.jsxs("div",{className:"space-y-4",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:i("settings.groupName")}),a.jsx("input",{type:"text",value:xn.name,onChange:le=>sr({...xn,name:le.target.value}),disabled:cn?.is_system,className:"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 disabled:opacity-50",placeholder:i("settings.enterGroupName")}),cn?.is_system&&a.jsx("p",{className:"text-xs text-yellow-400 mt-1",children:i("settings.systemGroupWarning")})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:"Description"}),a.jsx("textarea",{value:xn.description,onChange:le=>sr({...xn,description:le.target.value}),rows:2,className:"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 resize-none",placeholder:i("settings.enterDescriptionOptional")})]}),a.jsxs("div",{children:[a.jsxs("label",{className:"block text-sm font-medium text-white mb-2",children:["Permissions (",xn.permissions.length," selected)"]}),a.jsx("div",{className:"space-y-2 max-h-96 overflow-y-auto",children:Br?.categories.map(le=>a.jsxs("div",{className:"border border-bambu-dark-tertiary rounded-lg overflow-hidden",children:[a.jsxs("div",{className:"flex items-center justify-between px-4 py-2 bg-bambu-dark-secondary cursor-pointer hover:bg-bambu-dark-tertiary transition-colors",onClick:()=>Gl(le.name),children:[a.jsxs("div",{className:"flex items-center gap-3",children:[a.jsx("button",{type:"button",onClick:_t=>{_t.stopPropagation(),Rm(le,!Om(le))},className:`w-5 h-5 rounded border flex items-center justify-center transition-colors ${Om(le)?"bg-bambu-green border-bambu-green":qh(le)?"bg-bambu-green/50 border-bambu-green":"border-bambu-gray hover:border-white"}`,children:(Om(le)||qh(le))&&a.jsx(Wi,{className:"w-3 h-3 text-white"})}),a.jsx("span",{className:"text-white font-medium",children:le.name}),a.jsxs("span",{className:"text-xs text-bambu-gray",children:["(",le.permissions.filter(_t=>xn.permissions.includes(_t.value)).length,"/",le.permissions.length,")"]})]}),Gn.has(le.name)?a.jsx(Kr,{className:"w-4 h-4 text-bambu-gray"}):a.jsx(vs,{className:"w-4 h-4 text-bambu-gray"})]}),Gn.has(le.name)&&a.jsx("div",{className:"p-3 bg-bambu-dark space-y-2",children:le.permissions.map(_t=>a.jsxs("label",{className:"flex items-center gap-3 px-2 py-1.5 rounded hover:bg-bambu-dark-secondary cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:xn.permissions.includes(_t.value),onChange:()=>Hx(_t.value),className:"w-4 h-4 rounded border-bambu-gray text-bambu-green focus:ring-bambu-green focus:ring-offset-0 bg-bambu-dark-secondary"}),a.jsx("span",{className:"text-sm text-bambu-gray",children:_t.label})]},_t.value))})]},le.name))})]})]}),a.jsxs("div",{className:"mt-6 flex justify-end gap-3",children:[a.jsx(Te,{variant:"secondary",onClick:()=>{yn(!1),rr(null),da()},children:"Cancel"}),a.jsx(Te,{onClick:cn?Bx:Hr,disabled:Es.isPending||Eo.isPending||!xn.name.trim(),children:Es.isPending||Eo.isPending?a.jsxs(a.Fragment,{children:[a.jsx(pt,{className:"w-4 h-4 animate-spin"}),cn?"Saving...":"Creating..."]}):a.jsxs(a.Fragment,{children:[a.jsx(ms,{className:"w-4 h-4"}),cn?"Save Changes":"Create Group"]})})]})]})]})}),Vn!==null&&a.jsx(Zn,{title:i("settings.deleteGroupTitle"),message:i("settings.deleteGroupMessage"),confirmText:i("settings.deleteGroup"),variant:"danger",onConfirm:()=>{To.mutate(Vn),Jn(null)},onCancel:()=>Jn(null)}),pe==="backup"&&a.jsx(UKe,{}),_e&&a.jsx(Zn,{title:i("settings.disableAuthenticationTitle"),message:i("settings.disableAuthenticationMessage"),confirmText:i("settings.disableAuthentication"),variant:"danger",onConfirm:async()=>{try{await ce.disableAuth(),o(i("settings.toast.authDisabled"),"success"),await u(),ae(!1),window.location.href="/"}catch(le){const _t=le instanceof Error?le.message:i("settings.toast.authDisableFailed");o(_t,"error")}},onCancel:()=>ae(!1)}),Le&&a.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",onClick:()=>{Be(!1),He({currentPassword:"",newPassword:"",confirmPassword:""})},children:a.jsxs(St,{className:"w-full max-w-md",onClick:le=>le.stopPropagation(),children:[a.jsx(Kn,{children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(Ko,{className:"w-5 h-5 text-bambu-green"}),a.jsx("h2",{className:"text-lg font-semibold text-white",children:i("settings.changePassword")})]}),a.jsx(Te,{variant:"ghost",size:"sm",onClick:()=>{Be(!1),He({currentPassword:"",newPassword:"",confirmPassword:""})},children:a.jsx(Lt,{className:"w-5 h-5"})})]})}),a.jsxs(Nt,{children:[a.jsxs("div",{className:"space-y-4",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:"Current Password"}),a.jsx("input",{type:"password",value:Ve.currentPassword,onChange:le=>He({...Ve,currentPassword:le.target.value}),className:"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:i("settings.enterCurrentPassword"),autoComplete:"current-password"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:"New Password"}),a.jsx("input",{type:"password",value:Ve.newPassword,onChange:le=>He({...Ve,newPassword:le.target.value}),className:"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:i("settings.enterNewPasswordMin6"),autoComplete:"new-password",minLength:6})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:"Confirm New Password"}),a.jsx("input",{type:"password",value:Ve.confirmPassword,onChange:le=>He({...Ve,confirmPassword:le.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors ${Ve.confirmPassword&&Ve.newPassword!==Ve.confirmPassword?"border-red-500":"border-bambu-dark-tertiary"}`,placeholder:i("settings.confirmNewPassword"),autoComplete:"new-password",minLength:6}),Ve.confirmPassword&&Ve.newPassword!==Ve.confirmPassword&&a.jsx("p",{className:"text-red-400 text-xs mt-1",children:i("settings.passwordsDoNotMatch")})]})]}),a.jsxs("div",{className:"mt-6 flex justify-end gap-3",children:[a.jsx(Te,{variant:"secondary",onClick:()=>{Be(!1),He({currentPassword:"",newPassword:"",confirmPassword:""})},children:"Cancel"}),a.jsx(Te,{onClick:async()=>{if(Ve.newPassword!==Ve.confirmPassword){o(i("settings.toast.passwordsDoNotMatch"),"error");return}if(Ve.newPassword.length<6){o(i("settings.toast.passwordTooShort"),"error");return}Pe(!0);try{await ce.changePassword(Ve.currentPassword,Ve.newPassword),o(i("settings.toast.passwordChanged"),"success"),Be(!1),He({currentPassword:"",newPassword:"",confirmPassword:""})}catch(le){const _t=le instanceof Error?le.message:"Failed to change password";o(_t,"error")}finally{Pe(!1)}},disabled:xe||!Ve.currentPassword||!Ve.newPassword||Ve.newPassword!==Ve.confirmPassword||Ve.newPassword.length<6,children:xe?a.jsxs(a.Fragment,{children:[a.jsx(pt,{className:"w-4 h-4 animate-spin"}),"Changing..."]}):a.jsxs(a.Fragment,{children:[a.jsx(Ko,{className:"w-4 h-4"}),"Change Password"]})})]})]})]})})]})}const Wre=t=>{const e=parseFloat(t);return(Math.trunc(e*1e3)/1e3).toFixed(3)},qKe=t=>t.startsWith("HH")?"HF":"S",WKe=t=>{const e=t.match(/^([A-Z]{2}\d{2})/);return e?e[1]:"HH00"},fR=t=>{const e=["High Flow_","High Flow ","Standard_","Standard ","HF_","HF ","S_","S "];for(const r of e)if(t.startsWith(r))return t.slice(r.length);const n=t.indexOf("_");return n>0?t.slice(n+1):t};function Gj({profile:t,onEdit:e,onCopy:n,selectionMode:r,isSelected:i,onToggleSelect:s,note:o}){const l=qKe(t.nozzle_id),c=t.nozzle_diameter,u=()=>{r&&s?s():e()};return a.jsxs("div",{className:"flex items-center gap-2",children:[r&&a.jsx("button",{onClick:s,className:"text-bambu-gray hover:text-white transition-colors p-1",children:i?a.jsx(Gs,{className:"w-4 h-4 text-bambu-green"}):a.jsx(cl,{className:"w-4 h-4"})}),a.jsxs("button",{onClick:u,className:`flex-1 text-left px-3 py-2 bg-bambu-dark rounded hover:bg-bambu-dark-tertiary transition-colors ${i?"ring-1 ring-bambu-green":""}`,children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("span",{className:"text-bambu-green font-mono text-sm font-bold whitespace-nowrap",children:Wre(t.k_value)}),a.jsx("span",{className:"text-white text-sm truncate flex-1",title:t.name,children:t.name||"Unnamed"}),o&&a.jsx("span",{title:"Has note",children:a.jsx(OW,{className:"w-3 h-3 text-yellow-500"})}),a.jsxs("span",{className:"text-xs text-bambu-gray whitespace-nowrap",children:[l," ",c]})]}),o&&a.jsxs("div",{className:"text-xs mt-0.5 truncate text-yellow-500/70",title:o,children:["Note: ",o.length>50?o.substring(0,50)+"...":o]})]}),!r&&n&&a.jsx("button",{onClick:d=>{d.stopPropagation(),n()},className:"text-bambu-gray hover:text-white transition-colors p-1",title:"Copy profile",children:a.jsx(Ul,{className:"w-4 h-4"})})]})}function qj({profile:t,printerId:e,nozzleDiameter:n,existingProfiles:r=[],isDualNozzle:i=!1,initialNote:s="",initialNoteKey:o=null,onClose:l,onSave:c,onSaveNote:u,hasPermission:d}){const{t:h}=On(),{showToast:p}=Hn(),[m,x]=_.useState(t?.name||""),[y,v]=_.useState(t?.k_value?Wre(t.k_value):"0.020"),[b,S]=_.useState(t?.filament_id||""),[N,T]=_.useState(t?.nozzle_id?WKe(t.nozzle_id):"HH00"),[k,C]=_.useState(t?.nozzle_diameter||n),[E,P]=_.useState(t?[t.extruder_id]:i?[0,1]:[0]),[A,D]=_.useState(!1),[I,L]=_.useState({current:0,total:0}),[U,j]=_.useState(s),$=ei.useMemo(()=>{const W=new Map;for(const re of r)if(re.filament_id&&!W.has(re.filament_id)){const ie=fR(re.name||"");W.set(re.filament_id,{id:re.filament_id,name:ie||re.filament_id})}return Array.from(W.values()).sort((re,ie)=>re.name.localeCompare(ie.name))},[r]),K=gt({mutationFn:W=>(console.log("[KProfile] Calling API..."),ce.setKProfile(e,W)),onSuccess:W=>{if(console.log("[KProfile] Save success:",W),p(h("kProfiles.toast.profileSaved")),u&&U!==s){let re;U===""&&o?re=o:t&&t.slot_id>0?re=t.setting_id||`slot_${t.slot_id}_${t.filament_id}_${t.extruder_id}`:re=`name_${m}_${b}`,u(re,U)}D(!0),setTimeout(()=>{D(!1),c()},2500)},onError:W=>{console.error("[KProfile] Save error:",W),p(W.message,"error"),D(!1)}}),B=gt({mutationFn:W=>(console.log("[KProfile] Deleting profile..."),ce.deleteKProfile(e,W)),onSuccess:W=>{console.log("[KProfile] Delete success:",W),p(h("kProfiles.toast.profileDeleted")),D(!0),setTimeout(()=>{D(!1),l()},4e3)},onError:W=>{console.error("[KProfile] Delete error:",W),p(W.message,"error"),D(!1)}}),[X,Y]=_.useState(!1),ne=()=>{t&&B.mutate({slot_id:t.slot_id,extruder_id:t.extruder_id,nozzle_id:t.nozzle_id,nozzle_diameter:t.nozzle_diameter,filament_id:t.filament_id,setting_id:t.setting_id})},H=async W=>{if(W.preventDefault(),i&&!t&&E.length===0){p(h("kProfiles.toast.selectAtLeastOneExtruder"),"error");return}const re=parseFloat(y).toFixed(6),ie=`${N}-${k}`;if(t||E.length===1){const me={name:m,k_value:re,filament_id:b,nozzle_id:ie,nozzle_diameter:k,extruder_id:t?t.extruder_id:E[0],setting_id:t?.setting_id,slot_id:t?.slot_id??0};console.log("[KProfile] Saving profile:",me),K.mutate(me);return}D(!0),L({current:1,total:E.length});const pe=E.map(me=>({name:m,k_value:re,filament_id:b,nozzle_id:ie,nozzle_diameter:k,extruder_id:me,setting_id:void 0,slot_id:0}));console.log(`[KProfile] Saving ${pe.length} profiles in batch:`,pe);try{if(await ce.setKProfilesBatch(e,pe),p(h("kProfiles.toast.profilesSaved",{count:E.length})),u&&U){const me=`name_${m}_${b}`;u(me,U)}}catch(me){console.error("[KProfile] Failed to save batch:",me),p(h("kProfiles.toast.failedToSaveBatch"),"error"),D(!1),L({current:0,total:0});return}L({current:E.length,total:E.length}),setTimeout(()=>{D(!1),L({current:0,total:0}),c()},3e3)};return a.jsxs("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",children:[a.jsxs(St,{className:"w-full max-w-md relative",children:[A&&a.jsxs("div",{className:"absolute inset-0 bg-bambu-dark-secondary/90 flex flex-col items-center justify-center z-10 rounded-lg",children:[a.jsx(pt,{className:"w-8 h-8 text-bambu-green animate-spin mb-3"}),a.jsx("p",{className:"text-white font-medium",children:I.total>1?h("kProfiles.modal.savingExtruder",{current:I.current,total:I.total}):h("kProfiles.modal.syncing")}),a.jsx("p",{className:"text-bambu-gray text-sm mt-1",children:h("kProfiles.modal.pleaseWait")})]}),a.jsxs(Nt,{className:"p-0",children:[a.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[a.jsx("h2",{className:"text-xl font-semibold text-white",children:h(t?"kProfiles.modal.editTitle":"kProfiles.modal.addTitle")}),a.jsx("button",{onClick:l,className:"text-bambu-gray hover:text-white transition-colors",disabled:A,children:a.jsx(Lt,{className:"w-5 h-5"})})]}),a.jsxs("form",{onSubmit:H,className:"p-4 space-y-4",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:h("kProfiles.modal.profileName")}),a.jsx("input",{type:"text",value:m,onChange:W=>x(W.target.value),disabled:!!t,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 ${t?"opacity-60 cursor-not-allowed":""}`,placeholder:h("kProfiles.modal.profileNamePlaceholder"),required:!t})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:h("kProfiles.modal.kValue")}),a.jsx("input",{type:"text",inputMode:"decimal",value:y,onChange:W=>{const re=W.target.value;(re===""||/^\d*\.?\d*$/.test(re))&&v(re)},onBlur:W=>{const re=parseFloat(W.target.value);isNaN(re)||v((Math.trunc(re*1e3)/1e3).toFixed(3))},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 font-mono",placeholder:h("kProfiles.modal.kValuePlaceholder"),required:!0}),a.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:h("kProfiles.modal.kValueHelp")})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:h("kProfiles.modal.filament")}),a.jsxs("select",{value:b,onChange:W=>{const re=W.target.value;if(S(re),!t&&re&&!m){const ie=$.find(pe=>pe.id===re);ie&&x(`${N==="HH00"?"HF":"S"} ${ie.name}`)}},disabled:!!t,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 ${t?"opacity-60 cursor-not-allowed":""}`,required:!t,children:[a.jsx("option",{value:"",children:h("kProfiles.modal.selectFilament")}),t?.filament_id&&a.jsx("option",{value:t.filament_id,children:$.find(W=>W.id===t.filament_id)?.name||t.filament_id},t.filament_id),!t&&$.map(W=>a.jsx("option",{value:W.id,children:W.name},W.id))]}),!t&&$.length===0&&a.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:h("kProfiles.modal.noFilamentsHelp")})]}),a.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:h("kProfiles.modal.flowType")}),a.jsxs("select",{value:N,onChange:W=>{const re=W.target.value;if(T(re),!t&&b&&!m){const ie=$.find(pe=>pe.id===b);ie&&x(`${re==="HS00"?"HF":"S"} ${ie.name}`)}},disabled:!!t,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 ${t?"opacity-60 cursor-not-allowed":""}`,children:[a.jsx("option",{value:"HH00",children:h("kProfiles.modal.highFlow")}),a.jsx("option",{value:"HS00",children:h("kProfiles.modal.standard")})]})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:h("kProfiles.modal.nozzleSize")}),a.jsxs("select",{value:k,onChange:W=>C(W.target.value),disabled:!!t,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 ${t?"opacity-60 cursor-not-allowed":""}`,children:[a.jsx("option",{value:"0.2",children:"0.2mm"}),a.jsx("option",{value:"0.4",children:"0.4mm"}),a.jsx("option",{value:"0.6",children:"0.6mm"}),a.jsx("option",{value:"0.8",children:"0.8mm"})]})]})]}),i&&a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:h(t?"kProfiles.modal.extruder":"kProfiles.modal.extruders")}),t?a.jsx("div",{className:"px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white opacity-60",children:t.extruder_id===1?h("kProfiles.modal.left"):h("kProfiles.modal.right")}):a.jsxs("div",{className:"flex gap-4",children:[a.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:E.includes(1),onChange:W=>{W.target.checked?P([...E,1]):P(E.filter(re=>re!==1))},className:"w-4 h-4 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green focus:ring-offset-0 accent-bambu-green"}),a.jsx("span",{className:"text-white",children:h("kProfiles.modal.left")})]}),a.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:E.includes(0),onChange:W=>{W.target.checked?P([...E,0]):P(E.filter(re=>re!==0))},className:"w-4 h-4 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green focus:ring-offset-0 accent-bambu-green"}),a.jsx("span",{className:"text-white",children:h("kProfiles.modal.right")})]})]})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:h("kProfiles.modal.notes")}),a.jsx("textarea",{value:U,onChange:W=>j(W.target.value),placeholder:h("kProfiles.modal.notesPlaceholder"),rows:2,className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none resize-none"}),a.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:h("kProfiles.modal.notesHelp")})]}),a.jsxs("div",{className:"flex gap-2 pt-4",children:[t&&a.jsx(Te,{type:"button",variant:"secondary",onClick:()=>Y(!0),disabled:B.isPending||A||!d("kprofiles:delete"),title:d("kprofiles:delete")?void 0:h("kProfiles.permission.noDelete"),className:"text-red-500 hover:bg-red-500/10",children:B.isPending?a.jsx(pt,{className:"w-4 h-4 animate-spin"}):a.jsx(an,{className:"w-4 h-4"})}),a.jsx(Te,{type:"button",variant:"secondary",onClick:l,disabled:A,className:"flex-1",children:h("common.cancel")}),a.jsxs(Te,{type:"submit",disabled:K.isPending||A||!d(t?"kprofiles:update":"kprofiles:create"),title:d(t?"kprofiles:update":"kprofiles:create")?void 0:h(t?"kProfiles.permission.noUpdate":"kProfiles.permission.noCreate"),className:"flex-1",children:[K.isPending?a.jsx(pt,{className:"w-4 h-4 animate-spin"}):a.jsx(fM,{className:"w-4 h-4"}),h("common.save")]})]})]})]})]}),X&&a.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-[60]",children:a.jsx(St,{className:"w-full max-w-sm",children:a.jsxs(Nt,{className:"p-6",children:[a.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[a.jsx("div",{className:"w-10 h-10 rounded-full bg-red-500/20 flex items-center justify-center",children:a.jsx(an,{className:"w-5 h-5 text-red-500"})}),a.jsxs("div",{children:[a.jsx("h3",{className:"text-lg font-semibold text-white",children:h("kProfiles.deleteConfirm.title")}),a.jsx("p",{className:"text-sm text-bambu-gray",children:h("kProfiles.deleteConfirm.cannotUndo")})]})]}),a.jsx("p",{className:"text-bambu-gray mb-6",children:h("kProfiles.deleteConfirm.message",{name:t?.name})}),a.jsxs("div",{className:"flex gap-3",children:[a.jsx(Te,{variant:"secondary",onClick:()=>Y(!1),className:"flex-1",children:h("common.cancel")}),a.jsxs(Te,{onClick:()=>{Y(!1),ne()},disabled:B.isPending,className:"flex-1 bg-red-500 hover:bg-red-600 text-white",children:[B.isPending?a.jsx(pt,{className:"w-4 h-4 animate-spin"}):a.jsx(an,{className:"w-4 h-4"}),h("common.delete")]})]})]})})})]})}const m1={NOZZLE_DIAMETER:"bambusy_kprofiles_nozzle",SORT_OPTION:"bambusy_kprofiles_sort"};function KKe(){const{t}=On(),{showToast:e}=Hn(),{hasPermission:n}=Ci(),[r,i]=_.useState(null),[s,o]=_.useState(()=>localStorage.getItem(m1.NOZZLE_DIAMETER)||"0.4"),[l,c]=_.useState(null),[u,d]=_.useState(!1),[h,p]=_.useState(null),[m,x]=_.useState(""),[y,v]=_.useState("all"),[b,S]=_.useState("all"),[N,T]=_.useState(()=>localStorage.getItem(m1.SORT_OPTION)||"name"),[k,C]=_.useState(!1),[E,P]=_.useState(new Set),[A,D]=_.useState(!1),[I,L]=_.useState(!1),U=_.useCallback(V=>`${V.slot_id}_${V.extruder_id}`,[]);_.useEffect(()=>{localStorage.setItem(m1.NOZZLE_DIAMETER,s)},[s]),_.useEffect(()=>{localStorage.setItem(m1.SORT_OPTION,N)},[N]);const{data:j,isLoading:$}=ct({queryKey:["printers"],queryFn:ce.getPrinters}),{data:K,isLoading:B,isFetching:X,error:Y,refetch:ne}=ct({queryKey:["kprofiles",r,s],queryFn:async()=>{console.log("[KProfiles] Fetching profiles for printer",r,"nozzle",s);const V=await ce.getKProfiles(r,s);return console.log("[KProfiles] Received profiles:",V?.profiles?.length||0,"profiles"),V},enabled:!!r,retry:!1,staleTime:0,gcTime:0,refetchOnMount:"always"}),{data:H}=ct({queryKey:["kprofiles",r,"0.4"],queryFn:()=>ce.getKProfiles(r,"0.4"),enabled:!!r,staleTime:6e4}),{data:W,refetch:re}=ct({queryKey:["kprofile-notes",r],queryFn:()=>ce.getKProfileNotes(r),enabled:!!r,staleTime:3e4}),ie=Y?.message?.includes("not connected");_.useEffect(()=>{if(!r&&j&&j.length>0){const V=j.find(ye=>ye.is_active);V&&i(V.id)}},[r,j]),_.useEffect(()=>{if(r){const V=setTimeout(()=>{ne()},150);return()=>clearTimeout(V)}},[r,s]);const pe=j?.filter(V=>V.is_active)||[],me=ei.useMemo(()=>K?.profiles?K.profiles.filter(ye=>{const je=m.toLowerCase(),te=!je||ye.name.toLowerCase().includes(je)||ye.filament_id.toLowerCase().includes(je),z=y==="all"||y==="left"&&ye.extruder_id===1||y==="right"&&ye.extruder_id===0,O=b==="all"||b==="hf"&&ye.nozzle_id.startsWith("HH")||b==="s"&&ye.nozzle_id.startsWith("HS");return te&&z&&O}).sort((ye,je)=>{switch(N){case"k_value":return parseFloat(ye.k_value)-parseFloat(je.k_value);case"filament":return fR(ye.name).localeCompare(fR(je.name));case"name":default:return ye.name.localeCompare(je.name)}}):[],[K?.profiles,m,y,b,N]),de=j?.find(V=>V.id===r),Ee=de?.nozzle_count===2;_.useEffect(()=>{const V=ye=>{ye.target instanceof HTMLInputElement||ye.target instanceof HTMLTextAreaElement||ye.target instanceof HTMLSelectElement||l||u||h||(ye.key==="r"||ye.key==="R"?(ye.preventDefault(),ne()):ye.key==="n"||ye.key==="N"?(ye.preventDefault(),d(!0)):ye.key==="Escape"&&k&&(ye.preventDefault(),C(!1),P(new Set)))};return window.addEventListener("keydown",V),()=>window.removeEventListener("keydown",V)},[l,u,h,k,ne]);const se=_.useCallback(()=>{if(!K?.profiles||K.profiles.length===0){e(t("kProfiles.toast.noProfilesToExport"),"error");return}const V={version:1,exported_at:new Date().toISOString(),printer:de?.name||"Unknown",nozzle_diameter:s,profiles:K.profiles.map(z=>({name:z.name,k_value:z.k_value,filament_id:z.filament_id,nozzle_id:z.nozzle_id,nozzle_diameter:z.nozzle_diameter,extruder_id:z.extruder_id}))},ye=new Blob([JSON.stringify(V,null,2)],{type:"application/json"}),je=URL.createObjectURL(ye),te=document.createElement("a");te.href=je,te.download=`kprofiles_${de?.name||"printer"}_${s}mm_${new Date().toISOString().split("T")[0]}.json`,document.body.appendChild(te),te.click(),document.body.removeChild(te),URL.revokeObjectURL(je),e(t("kProfiles.toast.exportedProfiles",{count:K.profiles.length}))},[K?.profiles,de,s,e,t]),Ae=_.useCallback(()=>{const V=document.createElement("input");V.type="file",V.accept=".json",V.onchange=async ye=>{const je=ye.target.files?.[0];if(je)try{const te=await je.text(),z=JSON.parse(te);if(!z.profiles||!Array.isArray(z.profiles)){e(t("kProfiles.toast.invalidFileFormat"),"error");return}let O=0;for(const Z of z.profiles)if(!(!Z.name||!Z.k_value||!Z.filament_id))try{await ce.setKProfile(r,{name:Z.name,k_value:parseFloat(Z.k_value).toFixed(6),filament_id:Z.filament_id,nozzle_id:Z.nozzle_id||`HH00-${s}`,nozzle_diameter:Z.nozzle_diameter||s,extruder_id:Z.extruder_id??0,slot_id:0}),O++,await new Promise(oe=>setTimeout(oe,500))}catch(oe){console.error("Failed to import profile:",Z.name,oe)}e(t("kProfiles.toast.importedProfiles",{count:O,total:z.profiles.length})),ne()}catch(te){console.error("Import error:",te),e(t("kProfiles.toast.failedToParseImport"),"error")}},V.click()},[r,s,e,ne,t]),Fe=_.useCallback(V=>{P(ye=>{const je=new Set(ye);return je.has(V)?je.delete(V):je.add(V),je})},[]),ge=_.useCallback(()=>{P(new Set(me.map(V=>U(V))))},[me,U]),Ze=_.useCallback(()=>{E.size!==0&&D(!0)},[E.size]),G=_.useCallback(async()=>{const V=me.filter(je=>E.has(U(je)));L(!0);let ye=0;for(const je of V)try{await ce.deleteKProfile(r,{slot_id:je.slot_id,extruder_id:je.extruder_id,nozzle_id:je.nozzle_id,nozzle_diameter:je.nozzle_diameter,filament_id:je.filament_id,setting_id:je.setting_id}),ye++,await new Promise(te=>setTimeout(te,300))}catch(te){console.error("Failed to delete profile:",je.name,te)}e(t("kProfiles.toast.profilesDeleted",{count:ye})),L(!1),D(!1),C(!1),P(new Set),ne()},[r,E,me,e,ne,U,t]),Q=_.useCallback(V=>{const ye=[];return V.setting_id&&ye.push(V.setting_id),ye.push(`slot_${V.slot_id}_${V.filament_id}_${V.extruder_id}`),ye.push(`name_${V.name}_${V.filament_id}`),ye},[]),he=_.useCallback(async(V,ye)=>{if(r)try{await ce.setKProfileNote(r,V,ye),re()}catch(je){console.error("Failed to save note:",je),e(t("kProfiles.toast.failedToSaveNote"),"error")}},[r,re,e,t]),q=_.useCallback(V=>{if(!W?.notes)return{note:"",key:null};const ye=Q(V);for(const je of ye)if(W.notes[je])return{note:W.notes[je],key:je};return{note:"",key:null}},[W,Q]),ee=_.useCallback(V=>q(V).note,[q]);return $?a.jsx("div",{className:"flex justify-center py-12",children:a.jsx(pt,{className:"w-8 h-8 text-bambu-green animate-spin"})}):!j||j.length===0?a.jsx(St,{children:a.jsxs(Nt,{className:"py-12 text-center",children:[a.jsx(Vi,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),a.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:t("kProfiles.noPrintersConfigured")}),a.jsx("p",{className:"text-bambu-gray",children:t("kProfiles.addPrinterInSettings")})]})}):pe.length===0?a.jsx(St,{children:a.jsxs(Nt,{className:"py-12 text-center",children:[a.jsx(Ur,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),a.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:t("kProfiles.noActivePrinters")}),a.jsx("p",{className:"text-bambu-gray",children:t("kProfiles.enablePrinterConnection")})]})}):a.jsxs(a.Fragment,{children:[X&&!B&&a.jsxs("div",{className:"fixed inset-0 bg-black/50 flex flex-col items-center justify-center z-40",children:[a.jsx(pt,{className:"w-10 h-10 text-bambu-green animate-spin mb-3"}),a.jsx("p",{className:"text-white font-medium",children:t("kProfiles.loadingProfiles")})]}),a.jsxs("div",{className:"flex flex-wrap gap-4 mb-6",children:[a.jsxs("div",{className:"flex-1 min-w-48",children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:t("kProfiles.printer")}),a.jsx("select",{value:r||"",onChange:V=>i(parseInt(V.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",children:pe.map(V=>a.jsx("option",{value:V.id,children:V.name},V.id))})]}),a.jsxs("div",{className:"w-32",children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:t("kProfiles.nozzle")}),a.jsxs("select",{value:s,onChange:V=>o(V.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",children:[a.jsx("option",{value:"0.2",children:"0.2mm"}),a.jsx("option",{value:"0.4",children:"0.4mm"}),a.jsx("option",{value:"0.6",children:"0.6mm"}),a.jsx("option",{value:"0.8",children:"0.8mm"})]})]}),a.jsxs("div",{className:"flex items-end gap-2",children:[a.jsxs(Te,{variant:"secondary",onClick:()=>ne(),disabled:X||!n("kprofiles:read"),title:n("kprofiles:read")?void 0:t("kProfiles.permission.noRead"),children:[a.jsx(Dr,{className:`w-4 h-4 ${X?"animate-spin":""}`}),t("kProfiles.refresh")]}),a.jsxs(Te,{onClick:()=>d(!0),disabled:!n("kprofiles:create"),title:n("kprofiles:create")?void 0:t("kProfiles.permission.noCreate"),children:[a.jsx(fr,{className:"w-4 h-4"}),t("kProfiles.addProfile")]})]})]}),a.jsxs("div",{className:"flex flex-wrap gap-4 mb-4",children:[a.jsxs("div",{className:"flex-1 min-w-48 relative",children:[a.jsx(wa,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray"}),a.jsx("input",{type:"text",value:m,onChange:V=>x(V.target.value),placeholder:t("kProfiles.searchPlaceholder"),className:"w-full pl-10 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none"})]}),Ee&&a.jsx("div",{className:"w-36",children:a.jsxs("select",{value:y,onChange:V=>v(V.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",children:[a.jsx("option",{value:"all",children:t("kProfiles.allExtruders")}),a.jsx("option",{value:"left",children:t("kProfiles.leftOnly")}),a.jsx("option",{value:"right",children:t("kProfiles.rightOnly")})]})}),a.jsx("div",{className:"w-32",children:a.jsxs("select",{value:b,onChange:V=>S(V.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",children:[a.jsx("option",{value:"all",children:t("kProfiles.allFlow")}),a.jsx("option",{value:"hf",children:t("kProfiles.hfOnly")}),a.jsx("option",{value:"s",children:t("kProfiles.sOnly")})]})}),a.jsx("div",{className:"w-32",children:a.jsxs("select",{value:N,onChange:V=>T(V.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",children:[a.jsx("option",{value:"name",children:t("kProfiles.sortName")}),a.jsx("option",{value:"k_value",children:t("kProfiles.sortKValue")}),a.jsx("option",{value:"filament",children:t("kProfiles.sortFilament")})]})})]}),a.jsxs("div",{className:"flex flex-wrap gap-2 mb-6",children:[a.jsxs(Te,{variant:"secondary",onClick:se,disabled:!K?.profiles?.length||!n("kprofiles:read"),title:n("kprofiles:read")?void 0:t("kProfiles.permission.noExport"),children:[a.jsx(wi,{className:"w-4 h-4"}),t("kProfiles.export")]}),a.jsxs(Te,{variant:"secondary",onClick:Ae,disabled:!n("kprofiles:create"),title:n("kprofiles:create")?void 0:t("kProfiles.permission.noImport"),children:[a.jsx(Ba,{className:"w-4 h-4"}),t("kProfiles.import")]}),a.jsx("div",{className:"flex-1"}),k?a.jsxs(a.Fragment,{children:[a.jsxs(Te,{variant:"secondary",onClick:ge,children:[a.jsx(Gs,{className:"w-4 h-4"}),t("kProfiles.selectAll")]}),a.jsxs(Te,{variant:"secondary",onClick:Ze,disabled:E.size===0||!n("kprofiles:delete"),className:"text-red-500 hover:bg-red-500/10",title:n("kprofiles:delete")?void 0:t("kProfiles.permission.noDelete"),children:[a.jsx(an,{className:"w-4 h-4"}),t("kProfiles.delete")," (",E.size,")"]}),a.jsxs(Te,{variant:"secondary",onClick:()=>{C(!1),P(new Set)},children:[a.jsx(Lt,{className:"w-4 h-4"}),t("common.cancel")]})]}):a.jsxs(Te,{variant:"secondary",onClick:()=>C(!0),disabled:!me.length||!n("kprofiles:delete"),title:n("kprofiles:delete")?void 0:t("kProfiles.permission.noDelete"),children:[a.jsx(Gs,{className:"w-4 h-4"}),t("kProfiles.select")]})]}),B?a.jsx("div",{className:"flex justify-center py-12",children:a.jsx(pt,{className:"w-8 h-8 text-bambu-green animate-spin"})}):ie?a.jsx(St,{children:a.jsxs(Nt,{className:"py-12 text-center",children:[a.jsx(lm,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),a.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:t("kProfiles.printerOffline")}),a.jsx("p",{className:"text-bambu-gray mb-4",children:t("kProfiles.printerOfflineDesc")}),a.jsxs(Te,{variant:"secondary",onClick:()=>ne(),children:[a.jsx(Dr,{className:"w-4 h-4"}),t("common.refresh")]})]})}):me.length>0?Ee?a.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[a.jsxs("div",{children:[a.jsx("h3",{className:"text-sm font-medium text-bambu-gray mb-2 px-1",children:t("kProfiles.leftExtruder")}),a.jsx("div",{className:"space-y-1",children:me.filter(V=>V.extruder_id===1).map(V=>a.jsx(Gj,{profile:V,onEdit:()=>c(V),onCopy:()=>p(V),selectionMode:k,isSelected:E.has(U(V)),onToggleSelect:()=>Fe(U(V)),note:ee(V)},U(V)))})]}),a.jsxs("div",{children:[a.jsx("h3",{className:"text-sm font-medium text-bambu-gray mb-2 px-1",children:t("kProfiles.rightExtruder")}),a.jsx("div",{className:"space-y-1",children:me.filter(V=>V.extruder_id===0).map(V=>a.jsx(Gj,{profile:V,onEdit:()=>c(V),onCopy:()=>p(V),selectionMode:k,isSelected:E.has(U(V)),onToggleSelect:()=>Fe(U(V)),note:ee(V)},U(V)))})]})]}):a.jsx("div",{className:"space-y-1",children:me.map(V=>a.jsx(Gj,{profile:V,onEdit:()=>c(V),onCopy:()=>p(V),selectionMode:k,isSelected:E.has(U(V)),onToggleSelect:()=>Fe(U(V)),note:ee(V)},U(V)))}):m||y!=="all"||b!=="all"?a.jsx(St,{children:a.jsxs(Nt,{className:"py-12 text-center",children:[a.jsx(wa,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),a.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:t("kProfiles.noMatchingProfiles")}),a.jsx("p",{className:"text-bambu-gray",children:t("kProfiles.noMatchingProfilesDesc")})]})}):a.jsx(St,{children:a.jsxs(Nt,{className:"py-12 text-center",children:[a.jsx(fM,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),a.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:t("kProfiles.noKProfiles")}),a.jsx("p",{className:"text-bambu-gray mb-4",children:t("kProfiles.noKProfilesDesc",{diameter:s})}),a.jsxs(Te,{onClick:()=>d(!0),children:[a.jsx(fr,{className:"w-4 h-4"}),t("kProfiles.createFirstProfile")]})]})}),l&&r&&(()=>{const{note:V,key:ye}=q(l);return a.jsx(qj,{profile:l,printerId:r,nozzleDiameter:s,existingProfiles:H?.profiles||K?.profiles,isDualNozzle:Ee,initialNote:V,initialNoteKey:ye,onSaveNote:he,hasPermission:n,onClose:()=>{console.log("[KProfiles] Edit modal onClose - refetching profiles..."),c(null),ne()},onSave:()=>{c(null),ne()}})})(),u&&r&&a.jsx(qj,{printerId:r,nozzleDiameter:s,existingProfiles:H?.profiles||K?.profiles,isDualNozzle:Ee,onSaveNote:he,hasPermission:n,onClose:()=>{d(!1),ne()},onSave:()=>{d(!1),ne()}}),h&&r&&a.jsx(qj,{printerId:r,nozzleDiameter:s,existingProfiles:H?.profiles||K?.profiles,isDualNozzle:Ee,onSaveNote:he,hasPermission:n,profile:{...h,slot_id:0,name:`${h.name} (Copy)`},onClose:()=>{p(null),ne()},onSave:()=>{p(null),ne()}}),A&&a.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",children:a.jsx(St,{className:"w-full max-w-sm",children:a.jsxs(Nt,{className:"p-6",children:[a.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[a.jsx("div",{className:"w-10 h-10 rounded-full bg-red-500/20 flex items-center justify-center",children:a.jsx(an,{className:"w-5 h-5 text-red-500"})}),a.jsxs("div",{children:[a.jsx("h3",{className:"text-lg font-semibold text-white",children:t("kProfiles.bulkDelete.title")}),a.jsx("p",{className:"text-sm text-bambu-gray",children:t("kProfiles.bulkDelete.cannotUndo")})]})]}),a.jsx("p",{className:"text-bambu-gray mb-6",children:t("kProfiles.bulkDelete.message",{count:E.size})}),a.jsxs("div",{className:"flex gap-3",children:[a.jsx(Te,{variant:"secondary",onClick:()=>D(!1),disabled:I,className:"flex-1",children:t("common.cancel")}),a.jsxs(Te,{onClick:G,disabled:I,className:"flex-1 bg-red-500 hover:bg-red-600 text-white",children:[I?a.jsx(pt,{className:"w-4 h-4 animate-spin"}):a.jsx(an,{className:"w-4 h-4"}),t("common.delete")]})]})]})})})]})}function mF(t,e){const n=`${t} ${e||""}`,r=n.match(/@?\s*(?:BBL\s+)?(?:Bambu\s+Lab\s+)?([XPAH][1-9][A-Z]?(?:\s*(?:Carbon|mini))?|H2D)/i),i=r?r[1].trim():null,s=n.match(/(\d+\.?\d*)\s*(?:mm\s*)?nozzle|nozzle\s*(\d+\.?\d*)/i),o=s?(s[1]||s[2])+"mm":null,l=n.match(/(\d+\.?\d*)mm\s*(?:Standard|Fine|Extra Fine|Draft|Quality)?/i),c=l?l[1]+"mm":null,u=n.match(/\b(PLA|PETG|ABS|ASA|TPU|PC|PA|PVA|HIPS|PP|PET(?:-?CF)?|PA(?:-?CF)?|PLA(?:-?CF)?)\b/i),d=u?u[1].toUpperCase():null;return{printer:i,nozzle:o,layerHeight:c,filamentType:d}}function Oy(t){return/^(P[FPM]US|PF\d|PP\d)/.test(t)}function XKe(t,e){const n=zi(t);if(!n)return"";const i=new Date().getTime()-n.getTime(),s=Math.floor(i/6e4),o=Math.floor(i/36e5),l=Math.floor(i/864e5);return s<1?e("profiles.time.justNow"):s<60?e("profiles.time.minsAgo",{count:s}):o<24?e("profiles.time.hoursAgo",{count:o}):l<7?e("profiles.time.daysAgo",{count:l}):n.toLocaleDateString()}function YKe({onSuccess:t,t:e}){const{showToast:n}=Hn(),[r,i]=_.useState("email"),[s,o]=_.useState(""),[l,c]=_.useState(""),[u,d]=_.useState(""),[h,p]=_.useState(""),[m,x]=_.useState("global"),[y,v]=_.useState(null),[b,S]=_.useState(null),N=gt({mutationFn:()=>ce.cloudLogin(s,l,m),onSuccess:P=>{P.success?(n(e("profiles.login.toast.loggedIn")),t()):P.needs_verification?(v(P.verification_type||"email"),S(P.tfa_key||null),P.verification_type==="totp"?n(e("profiles.login.toast.enterTotp")):n(e("profiles.login.toast.codeSent")),i("code")):n(P.message,"error")},onError:P=>n(P.message,"error")}),T=gt({mutationFn:()=>ce.cloudVerify(s,u,b||void 0),onSuccess:P=>{P.success?(n(e("profiles.login.toast.loggedIn")),t()):n(P.message,"error")},onError:P=>n(P.message,"error")}),k=gt({mutationFn:()=>ce.cloudSetToken(h),onSuccess:()=>{n(e("profiles.login.toast.tokenSet")),t()},onError:P=>n(P.message,"error")}),C=P=>{P.preventDefault(),r==="email"?N.mutate():r==="code"?T.mutate():r==="token"&&k.mutate()},E=N.isPending||T.isPending||k.isPending;return a.jsx(St,{className:"max-w-md mx-auto",children:a.jsxs(Nt,{children:[a.jsxs("div",{className:"text-center mb-6",children:[a.jsx("div",{className:"inline-flex items-center justify-center w-12 h-12 rounded-xl bg-bambu-green/20 mb-3",children:a.jsx(cM,{className:"w-6 h-6 text-bambu-green"})}),a.jsx("h2",{className:"text-xl font-semibold text-white",children:e("profiles.login.title")}),a.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:e("profiles.login.subtitle")})]}),a.jsxs("form",{onSubmit:C,className:"space-y-4",children:[r==="email"&&a.jsxs(a.Fragment,{children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:e("profiles.login.email")}),a.jsx("input",{type:"email",value:s,onChange:P=>o(P.target.value),className:"w-full px-3 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",placeholder:"your@email.com",required:!0})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:e("profiles.login.password")}),a.jsx("input",{type:"password",value:l,onChange:P=>c(P.target.value),className:"w-full px-3 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",placeholder:"••••••••",required:!0})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:e("profiles.login.region")}),a.jsxs("select",{value:m,onChange:P=>x(P.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",children:[a.jsx("option",{value:"global",children:e("profiles.login.regionGlobal")}),a.jsx("option",{value:"china",children:e("profiles.login.regionChina")})]})]})]}),r==="code"&&a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:e(y==="totp"?"profiles.login.totpCode":"profiles.login.verificationCode")}),a.jsx("p",{className:"text-xs text-bambu-gray mb-2",children:y==="totp"?e("profiles.login.enterTotpHint"):e("profiles.login.checkEmail",{email:s})}),a.jsx("input",{type:"text",value:u,onChange:P=>d(P.target.value.replace(/\D/g,"").slice(0,6)),className:"w-full px-3 py-3 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-center text-2xl tracking-widest font-mono focus:border-bambu-green focus:outline-none",placeholder:"000000",maxLength:6,required:!0})]}),r==="token"&&a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:e("profiles.login.accessToken")}),a.jsx("p",{className:"text-xs text-bambu-gray mb-2",children:e("profiles.login.accessTokenHint")}),a.jsx("textarea",{value:h,onChange:P=>p(P.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-xs font-mono placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none resize-none",placeholder:"eyJ...",rows:4,required:!0})]}),a.jsxs("div",{className:"flex gap-2",children:[r==="code"&&a.jsx(Te,{type:"button",variant:"secondary",onClick:()=>i("email"),className:"flex-1",children:e("profiles.login.back")}),a.jsxs(Te,{type:"submit",disabled:E,className:"flex-1",children:[E?a.jsx(pt,{className:"w-4 h-4 animate-spin"}):a.jsx(Uz,{className:"w-4 h-4"}),e(r==="email"?"profiles.login.loginButton":r==="code"?"profiles.login.verifyButton":"profiles.login.setTokenButton")]})]}),r==="email"&&a.jsx("div",{className:"pt-4 border-t border-bambu-dark-tertiary",children:a.jsxs("button",{type:"button",onClick:()=>i("token"),className:"text-sm text-bambu-gray hover:text-white flex items-center gap-2 transition-colors",children:[a.jsx(Ko,{className:"w-4 h-4"}),e("profiles.login.useToken")]})}),r==="token"&&a.jsx("div",{className:"pt-4 border-t border-bambu-dark-tertiary",children:a.jsxs("button",{type:"button",onClick:()=>i("email"),className:"text-sm text-bambu-gray hover:text-white flex items-center gap-2 transition-colors",children:[a.jsx(Uz,{className:"w-4 h-4"}),e("profiles.login.useEmail")]})})]})]})})}function ig({label:t,value:e,options:n,onChange:r}){const[i,s]=_.useState(!1),o=n.find(l=>l.value===e);return a.jsxs("div",{className:"relative",children:[a.jsxs("button",{onClick:()=>s(!i),className:"flex items-center gap-2 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-sm text-white hover:border-bambu-gray-dark transition-colors",children:[a.jsxs("span",{className:"text-bambu-gray",children:[t,":"]}),a.jsx("span",{children:o?.label||"All"}),a.jsx(Kr,{className:`w-4 h-4 text-bambu-gray transition-transform ${i?"rotate-180":""}`})]}),i&&a.jsxs(a.Fragment,{children:[a.jsx("div",{className:"fixed inset-0 z-10",onClick:()=>s(!1)}),a.jsx("div",{className:"absolute top-full left-0 mt-1 min-w-[160px] bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl z-20 py-1 max-h-60 overflow-y-auto",children:n.map(l=>a.jsxs("button",{onClick:()=>{r(l.value),s(!1)},className:`w-full px-3 py-2 text-left text-sm flex items-center justify-between hover:bg-bambu-dark-tertiary transition-colors ${e===l.value?"text-bambu-green":"text-white"}`,children:[a.jsx("span",{children:l.label}),l.count!==void 0&&a.jsx("span",{className:"text-bambu-gray text-xs",children:l.count})]},l.value))})]})]})}function QKe(){const[t,e]=_.useState(!1);_.useEffect(()=>{const r=()=>{e(window.scrollY>300)};return window.addEventListener("scroll",r),()=>window.removeEventListener("scroll",r)},[]);const n=()=>{window.scrollTo({top:0,behavior:"smooth"})};return t?a.jsx("button",{onClick:n,className:"fixed bottom-6 right-6 p-3 bg-bambu-green hover:bg-bambu-green-light text-white rounded-full shadow-lg shadow-bambu-green/25 transition-all z-40","aria-label":"Scroll to top",children:a.jsx(zg,{className:"w-5 h-5"})}):null}function Wj({setting:t,onClick:e,onDuplicate:n,compareMode:r,isCompareSelected:i,compareIndex:s,compareDisabled:o,t:l}){const c=mF(t.name),u=Oy(t.setting_id);return a.jsxs("div",{className:"flex items-center gap-2 group",children:[a.jsx("button",{onClick:e,disabled:o,className:`flex-1 text-left px-3 py-2 rounded transition-colors ${i?"bg-blue-500/20 border border-blue-500/50":o?"bg-bambu-dark/50 opacity-40 cursor-not-allowed":"bg-bambu-dark hover:bg-bambu-dark-tertiary"} ${r&&!o?"cursor-pointer":""}`,children:a.jsxs("div",{className:"flex items-center gap-2",children:[i&&s!==void 0&&a.jsx("span",{className:"flex-shrink-0 w-5 h-5 rounded-full bg-blue-500 text-white text-xs flex items-center justify-center font-medium",children:s+1}),!i&&u&&a.jsx("span",{className:"flex-shrink-0 w-1.5 h-1.5 rounded-full bg-bambu-green",title:l("profiles.presets.myPreset")}),a.jsx("span",{className:"text-white text-sm truncate flex-1",title:t.name,children:t.name}),c.filamentType&&t.type==="filament"&&a.jsx("span",{className:"text-xs text-bambu-gray whitespace-nowrap",children:c.filamentType}),c.layerHeight&&t.type==="process"&&a.jsx("span",{className:"text-xs text-bambu-gray whitespace-nowrap",children:c.layerHeight}),c.printer&&a.jsx("span",{className:"text-xs text-bambu-gray whitespace-nowrap",children:c.printer})]})}),a.jsx("button",{onClick:d=>{d.stopPropagation(),n()},className:"opacity-0 group-hover:opacity-100 text-bambu-gray hover:text-white transition-all p-1",title:l("profiles.presets.duplicate"),children:a.jsx(Ul,{className:"w-4 h-4"})})]})}function mR(t,e=0){const n=" ".repeat(e);if(t===null)return"null";if(t===void 0)return"undefined";if(typeof t=="string"){if(t.includes("\\n")||t.includes(`
+ `,children:a.jsxs("div",{className:"flex items-center gap-4 p-4",children:[P&&d&&a.jsx("button",{onClick:D=>{D.stopPropagation(),d()},className:`flex items-center justify-center w-6 h-6 rounded border transition-colors ${u?"bg-bambu-green border-bambu-green text-white":"border-white/30 bg-black/30 hover:border-bambu-green/50"}`,children:u&&a.jsx(Wi,{className:"w-4 h-4"})}),P?a.jsx("div",{...v,...b,className:"flex items-center justify-center w-10 h-10 md:w-8 md:h-8 rounded-lg bg-bambu-dark cursor-grab active:cursor-grabbing hover:bg-bambu-dark-tertiary transition-colors touch-manipulation",children:a.jsx(Hg,{className:"w-6 h-6 md:w-4 md:h-4 text-bambu-gray"})}):e!==void 0?a.jsxs("div",{className:"flex items-center justify-center w-8 h-8 rounded-lg bg-bambu-dark text-bambu-gray text-sm font-medium",children:["#",e]}):a.jsx("div",{className:"w-8"}),a.jsx("div",{className:"w-14 h-14 flex-shrink-0 bg-bambu-dark rounded-lg overflow-hidden",children:t.archive_thumbnail?a.jsx("img",{src:t.plate_id!=null?ce.getArchivePlateThumbnail(t.archive_id,t.plate_id):ce.getArchiveThumbnail(t.archive_id),alt:"",className:"w-full h-full object-cover"}):t.library_file_thumbnail?a.jsx("img",{src:t.plate_id!=null?ce.getLibraryFilePlateThumbnail(t.library_file_id,t.plate_id):ce.getLibraryFileThumbnailUrl(t.library_file_id),alt:"",className:"w-full h-full object-cover"}):a.jsx("div",{className:"w-full h-full flex items-center justify-center text-bambu-gray",children:a.jsx(xs,{className:"w-6 h-6"})})}),a.jsxs("div",{className:"flex-1 min-w-0",children:[a.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[a.jsx("p",{className:"text-white font-medium truncate",children:t.archive_name||t.library_file_name||`File #${t.archive_id||t.library_file_id}`}),t.archive_id?a.jsx(Fs,{to:`/archives?highlight=${t.archive_id}`,className:"text-bambu-gray hover:text-bambu-green transition-colors flex-shrink-0",title:x("queue.viewArchive"),children:a.jsx(Xr,{className:"w-3.5 h-3.5"})}):t.library_file_id?a.jsx(Fs,{to:`/library?highlight=${t.library_file_id}`,className:"text-bambu-gray hover:text-bambu-green transition-colors flex-shrink-0",title:x("queue.viewInFileManager"),children:a.jsx(Xr,{className:"w-3.5 h-3.5"})}):null]}),a.jsxs("div",{className:"flex items-center gap-3 text-sm text-bambu-gray",children:[a.jsxs("span",{className:`flex items-center gap-1.5 ${t.printer_id===null&&!t.target_model?"text-orange-400":""} ${t.target_model?"text-blue-400":""}`,children:[a.jsx(Ur,{className:"w-3.5 h-3.5"}),t.target_model?`${x("queue.filter.any")} ${t.target_model}${t.target_location?` @ ${t.target_location}`:""}${t.required_filament_types?.length?` (${t.required_filament_types.join(", ")})`:""}`:t.printer_id===null?x("queue.filter.unassigned"):t.printer_name||`${x("common.printer")} #${t.printer_id}`]}),t.print_time_seconds&&a.jsxs("span",{className:"flex items-center gap-1.5",children:[a.jsx(yu,{className:"w-3.5 h-3.5"}),qre(t.print_time_seconds)]}),t.created_by_username&&a.jsxs("span",{className:"flex items-center gap-1.5",title:x("queue.addedBy",{name:t.created_by_username}),children:[a.jsx(om,{className:"w-3.5 h-3.5"}),t.created_by_username]}),P&&!t.manual_start&&a.jsxs("span",{className:"flex items-center gap-1.5",children:[a.jsx(tr,{className:"w-3.5 h-3.5"}),sKe(t.scheduled_time,c,x)]})]}),a.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[t.manual_start&&a.jsxs("span",{className:"text-xs px-2 py-0.5 bg-purple-500/10 text-purple-400 rounded-full border border-purple-500/20 flex items-center gap-1",children:[a.jsx(EW,{className:"w-3 h-3"}),x("queue.badges.staged")]}),t.require_previous_success&&a.jsx("span",{className:"text-xs px-2 py-0.5 bg-orange-500/10 text-orange-400 rounded-full border border-orange-500/20",children:x("queue.badges.requiresPrevious")}),t.auto_off_after&&a.jsxs("span",{className:"text-xs px-2 py-0.5 bg-blue-500/10 text-blue-400 rounded-full border border-blue-500/20 flex items-center gap-1",children:[a.jsx(qu,{className:"w-3 h-3"}),x("queue.badges.autoPowerOff")]})]}),E&&a.jsxs("div",{className:"mt-3",children:[a.jsx("div",{className:"h-2 bg-bambu-dark rounded-full overflow-hidden",children:a.jsx("div",{className:"h-full bg-gradient-to-r from-blue-500 to-blue-400 animate-pulse w-full opacity-50"})}),a.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:x("queue.printingInProgress")})]}),t.waiting_reason&&t.status==="pending"&&a.jsxs("p",{className:"text-xs text-purple-400 mt-2 flex items-start gap-1",children:[a.jsx(Vi,{className:"w-3 h-3 mt-0.5 flex-shrink-0"}),a.jsx("span",{children:t.waiting_reason})]}),t.error_message&&a.jsxs("p",{className:"text-xs text-red-400 mt-2 flex items-center gap-1",children:[a.jsx(Vi,{className:"w-3 h-3"}),t.error_message]})]}),a.jsx(oKe,{status:t.status,waitingReason:t.waiting_reason,printerState:m,t:x}),a.jsxs("div",{className:"flex items-center gap-1",children:[E&&a.jsx(Te,{variant:"ghost",size:"sm",onClick:s,disabled:!h("printers:control"),title:h("printers:control")?x("queue.actions.stopPrint"):x("queue.permissions.noStopPrint"),className:"text-red-400 hover:text-red-300 hover:bg-red-500/10",children:a.jsx(lue,{className:"w-4 h-4"})}),P&&a.jsxs(a.Fragment,{children:[t.manual_start&&a.jsx(Te,{variant:"ghost",size:"sm",onClick:l,disabled:!h("printers:control"),title:h("printers:control")?x("queue.actions.startPrint"):x("queue.permissions.noStartPrint"),className:"text-bambu-green hover:text-bambu-green-light hover:bg-bambu-green/10",children:a.jsx(So,{className:"w-4 h-4"})}),a.jsx(Te,{variant:"ghost",size:"sm",onClick:n,disabled:!p("queue","update",t.created_by_id),title:p("queue","update",t.created_by_id)?x("common.edit"):x("queue.permissions.noEdit"),children:a.jsx(ea,{className:"w-4 h-4"})}),a.jsx(Te,{variant:"ghost",size:"sm",onClick:r,disabled:!p("queue","delete",t.created_by_id),title:p("queue","delete",t.created_by_id)?x("common.cancel"):x("queue.permissions.noCancel"),className:"text-red-400 hover:text-red-300 hover:bg-red-500/10",children:a.jsx(Lt,{className:"w-4 h-4"})})]}),A&&a.jsxs(a.Fragment,{children:[a.jsx(Te,{variant:"ghost",size:"sm",onClick:o,disabled:!h("queue:create"),title:h("queue:create")?x("queue.actions.requeue"):x("queue.permissions.noRequeue"),className:"text-bambu-green hover:text-bambu-green/80 hover:bg-bambu-green/10",children:a.jsx(Dr,{className:"w-4 h-4"})}),a.jsx(Te,{variant:"ghost",size:"sm",onClick:i,disabled:!p("queue","delete",t.created_by_id),title:p("queue","delete",t.created_by_id)?x("common.remove"):x("queue.permissions.noRemove"),children:a.jsx(an,{className:"w-4 h-4"})})]})]})]})})}function cKe(){const{t}=On(),e=sn(),{showToast:n}=Hn(),{hasPermission:r,hasAnyPermission:i,canModify:s}=Ci(),[o,l]=_.useState(null),[c,u]=_.useState(""),[d,h]=_.useState(""),[p,m]=_.useState(!1),[x,y]=_.useState(null),[v,b]=_.useState(null),[S,N]=_.useState(null),[T,k]=_.useState([]),[C,E]=_.useState(!1),[P,A]=_.useState(()=>localStorage.getItem("queue.historySortBy")||"date"),[D,I]=_.useState(()=>{const te=localStorage.getItem("queue.historySortAsc");return te!==null?te==="true":!1}),[L,U]=_.useState(()=>localStorage.getItem("queue.pendingSortBy")||"position"),[j,$]=_.useState(()=>{const te=localStorage.getItem("queue.pendingSortAsc");return te!==null?te==="true":!0});_.useEffect(()=>{localStorage.setItem("queue.historySortBy",P)},[P]),_.useEffect(()=>{localStorage.setItem("queue.historySortAsc",String(D))},[D]),_.useEffect(()=>{localStorage.setItem("queue.pendingSortBy",L)},[L]),_.useEffect(()=>{localStorage.setItem("queue.pendingSortAsc",String(j))},[j]);const K=wre(eM($2,{activationConstraint:{distance:8}}),eM(H2,{coordinateGetter:Vre})),{data:B}=ct({queryKey:["settings"],queryFn:ce.getSettings}),X=B?.time_format||"system",{data:Y,isLoading:ne}=ct({queryKey:["queue",o,c],queryFn:()=>ce.getQueue(o||void 0,c||void 0),refetchInterval:5e3}),{data:H}=ct({queryKey:["printers"],queryFn:()=>ce.getPrinters()}),W=gt({mutationFn:te=>ce.cancelQueueItem(te),onSuccess:()=>{e.invalidateQueries({queryKey:["queue"]}),n(t("queue.toast.cancelled"))},onError:()=>n(t("queue.toast.cancelFailed"),"error")}),re=gt({mutationFn:te=>ce.removeFromQueue(te),onSuccess:()=>{e.invalidateQueries({queryKey:["queue"]}),n(t("queue.toast.removed"))},onError:()=>n(t("queue.toast.removeFailed"),"error")}),ie=gt({mutationFn:te=>ce.stopQueueItem(te),onSuccess:()=>{e.invalidateQueries({queryKey:["queue"]}),n(t("queue.toast.stopped"))},onError:()=>n(t("queue.toast.stopFailed"),"error")}),pe=gt({mutationFn:te=>ce.startQueueItem(te),onSuccess:()=>{e.invalidateQueries({queryKey:["queue"]}),n(t("queue.toast.released"))},onError:()=>n(t("queue.toast.startFailed"),"error")}),me=gt({mutationFn:te=>ce.reorderQueue(te),onSuccess:()=>{e.invalidateQueries({queryKey:["queue"]})},onError:()=>n(t("queue.toast.reorderFailed"),"error")}),de=gt({mutationFn:async()=>{const te=Y?.filter(z=>["completed","failed","skipped","cancelled"].includes(z.status))||[];for(const z of te)await ce.removeFromQueue(z.id);return te.length},onSuccess:te=>{e.invalidateQueries({queryKey:["queue"]}),n(t("queue.toast.historyCleared",{count:te}))},onError:()=>n(t("queue.toast.clearHistoryFailed"),"error")}),Ee=gt({mutationFn:te=>ce.bulkUpdateQueue(te),onSuccess:te=>{e.invalidateQueries({queryKey:["queue"]}),k([]),E(!1),n(te.message)},onError:()=>n(t("queue.toast.updateFailed"),"error")}),se=gt({mutationFn:async te=>{for(const z of te)await ce.cancelQueueItem(z);return te.length},onSuccess:te=>{e.invalidateQueries({queryKey:["queue"]}),k([]),n(t("queue.toast.bulkCancelled",{count:te}))},onError:()=>n(t("queue.toast.bulkCancelFailed"),"error")}),Ae=te=>{k(z=>z.includes(te)?z.filter(O=>O!==te):[...z,te])},Fe=_.useMemo(()=>{const te=new Set;return H?.forEach(z=>{z.location&&te.add(z.location)}),Y?.forEach(z=>{z.target_location&&te.add(z.target_location)}),Array.from(te).sort()},[H,Y]),ge=_.useCallback(te=>d?te.target_location?te.target_location===d:te.printer_id?H?.find(O=>O.id===te.printer_id)?.location===d:!1:!0,[d,H]),Ze=_.useMemo(()=>{let te=Y?.filter(O=>O.status==="pending")||[];d&&(te=te.filter(ge));const z=O=>{if(!O.scheduled_time)return 0;const Z=new Date(O.scheduled_time).getTime(),oe=Date.now()+4320*60*60*1e3;return Z>oe?0:Z};return[...te].sort((O,Z)=>{let oe;if(L==="name"){const we=O.archive_name||O.library_file_name||"",_e=Z.archive_name||Z.library_file_name||"";oe=we.localeCompare(_e)}else L==="printer"?oe=(O.printer_name||"").localeCompare(Z.printer_name||""):L==="time"?oe=z(O)-z(Z):oe=O.position-Z.position;return j?oe:-oe})},[Y,L,j,ge,d]),G=()=>{const te=Ze.map(z=>z.id);T.length===te.length?k([]):k(te)},Q=_.useMemo(()=>{let te=Y?.filter(z=>z.status==="printing")||[];return d&&(te=te.filter(ge)),te},[Y,d,ge]),he=_.useMemo(()=>{const te=new Set;return Q.forEach(z=>{z.printer_id&&te.add(z.printer_id)}),Array.from(te)},[Q]),q=jR({queries:he.map(te=>({queryKey:["printerStatus",te],queryFn:()=>ce.getPrinterStatus(te),refetchInterval:5e3}))}),ee=_.useMemo(()=>{const te={};return he.forEach((z,O)=>{const Z=q[O];Z?.data?.state&&(te[z]=Z.data.state)}),te},[he,q]),V=_.useMemo(()=>{let te=Y?.filter(z=>["completed","failed","skipped","cancelled"].includes(z.status))||[];return d&&(te=te.filter(ge)),[...te].sort((z,O)=>{let Z;if(P==="name"){const oe=z.archive_name||z.library_file_name||"",we=O.archive_name||O.library_file_name||"";Z=oe.localeCompare(we)}else P==="printer"?Z=(z.printer_name||"").localeCompare(O.printer_name||""):Z=new Date(O.completed_at||O.created_at).getTime()-new Date(z.completed_at||z.created_at).getTime();return D?-Z:Z})},[Y,P,D,ge,d]),ye=_.useMemo(()=>Ze.reduce((te,z)=>te+(z.print_time_seconds||0),0),[Ze]),je=te=>{const{active:z,over:O}=te;if(!O||z.id===O.id)return;const Z=Ze.findIndex(we=>we.id===z.id),oe=Ze.findIndex(we=>we.id===O.id);if(Z!==-1&&oe!==-1){const _e=q2(Ze,Z,oe).map((ae,Le)=>({id:ae.id,position:Le+1}));me.mutate(_e)}};return a.jsxs("div",{className:"p-4 md:p-8",children:[a.jsx("div",{className:"flex items-center justify-between mb-8",children:a.jsxs("div",{children:[a.jsxs("h1",{className:"text-2xl font-bold text-white flex items-center gap-3",children:[a.jsx(TW,{className:"w-7 h-7 text-bambu-green"}),t("queue.title")]}),a.jsx("p",{className:"text-bambu-gray mt-1",children:t("queue.subtitle")})]})}),a.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-4 gap-4 mb-8",children:[a.jsx(St,{className:"bg-gradient-to-br from-blue-500/10 to-transparent border-blue-500/20",children:a.jsx(Nt,{className:"p-4",children:a.jsxs("div",{className:"flex items-center gap-3",children:[a.jsx("div",{className:"w-10 h-10 rounded-lg bg-blue-500/20 flex items-center justify-center",children:a.jsx(So,{className:"w-5 h-5 text-blue-400"})}),a.jsxs("div",{children:[a.jsx("p",{className:"text-2xl font-bold text-white",children:Q.length}),a.jsx("p",{className:"text-sm text-bambu-gray",children:t("queue.summary.printing")})]})]})})}),a.jsx(St,{className:"bg-gradient-to-br from-yellow-500/10 to-transparent border-yellow-500/20",children:a.jsx(Nt,{className:"p-4",children:a.jsxs("div",{className:"flex items-center gap-3",children:[a.jsx("div",{className:"w-10 h-10 rounded-lg bg-yellow-500/20 flex items-center justify-center",children:a.jsx(tr,{className:"w-5 h-5 text-yellow-400"})}),a.jsxs("div",{children:[a.jsx("p",{className:"text-2xl font-bold text-white",children:Ze.length}),a.jsx("p",{className:"text-sm text-bambu-gray",children:t("queue.summary.queued")})]})]})})}),a.jsx(St,{className:"bg-gradient-to-br from-bambu-green/10 to-transparent border-bambu-green/20",children:a.jsx(Nt,{className:"p-4",children:a.jsxs("div",{className:"flex items-center gap-3",children:[a.jsx("div",{className:"w-10 h-10 rounded-lg bg-bambu-green/20 flex items-center justify-center",children:a.jsx(yu,{className:"w-5 h-5 text-bambu-green"})}),a.jsxs("div",{children:[a.jsx("p",{className:"text-2xl font-bold text-white",children:qre(ye)}),a.jsx("p",{className:"text-sm text-bambu-gray",children:t("queue.summary.totalTime")})]})]})})}),a.jsx(St,{className:"bg-gradient-to-br from-gray-500/10 to-transparent border-gray-500/20",children:a.jsx(Nt,{className:"p-4",children:a.jsxs("div",{className:"flex items-center gap-3",children:[a.jsx("div",{className:"w-10 h-10 rounded-lg bg-gray-500/20 flex items-center justify-center",children:a.jsx(Ar,{className:"w-5 h-5 text-gray-400"})}),a.jsxs("div",{children:[a.jsx("p",{className:"text-2xl font-bold text-white",children:V.length}),a.jsx("p",{className:"text-sm text-bambu-gray",children:t("queue.summary.history")})]})]})})})]}),a.jsxs("div",{className:"flex items-center gap-4 mb-6",children:[a.jsxs("select",{className:"px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",value:o===-1?"unassigned":o||"",onChange:te=>{const z=te.target.value;l(z==="unassigned"?-1:z===""?null:Number(z))},children:[a.jsx("option",{value:"",children:t("queue.filter.allPrinters")}),a.jsx("option",{value:"unassigned",children:t("queue.filter.unassigned")}),H?.map(te=>a.jsx("option",{value:te.id,children:te.name},te.id))]}),a.jsxs("select",{className:"px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",value:c,onChange:te=>u(te.target.value),children:[a.jsx("option",{value:"",children:t("queue.filter.allStatus")}),a.jsx("option",{value:"pending",children:t("queue.status.pending")}),a.jsx("option",{value:"printing",children:t("queue.status.printing")}),a.jsx("option",{value:"completed",children:t("queue.status.completed")}),a.jsx("option",{value:"failed",children:t("queue.status.failed")}),a.jsx("option",{value:"skipped",children:t("queue.status.skipped")}),a.jsx("option",{value:"cancelled",children:t("queue.status.cancelled")})]}),Fe.length>0&&a.jsxs("select",{className:"px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",value:d,onChange:te=>h(te.target.value),children:[a.jsx("option",{value:"",children:t("queue.filter.allLocations")}),Fe.map(te=>a.jsx("option",{value:te,children:te},te))]}),a.jsx("div",{className:"flex-1"}),V.length>0&&a.jsxs(Te,{variant:"secondary",size:"sm",onClick:()=>m(!0),disabled:!r("queue:delete_all"),title:r("queue:delete_all")?void 0:t("queue.permissions.noClearHistory"),children:[a.jsx(an,{className:"w-4 h-4"}),t("queue.clearHistory")]})]}),ne?a.jsx("div",{className:"text-center py-12 text-bambu-gray",children:t("common.loading")}):Y?.length===0?a.jsxs(St,{className:"p-12 text-center border-dashed",children:[a.jsx(ti,{className:"w-16 h-16 text-bambu-gray mx-auto mb-4 opacity-50"}),a.jsx("h3",{className:"text-xl font-medium text-white mb-2",children:t("queue.empty.title")}),a.jsx("p",{className:"text-bambu-gray max-w-md mx-auto",children:t("queue.empty.description")})]}):a.jsxs("div",{className:"space-y-8",children:[Q.length>0&&a.jsxs("div",{children:[a.jsxs("h2",{className:"text-lg font-semibold text-white mb-4 flex items-center gap-2",children:[a.jsx("div",{className:"w-2 h-2 rounded-full bg-blue-400 animate-pulse"}),t("queue.sections.currentlyPrinting")]}),a.jsx("div",{className:"space-y-3",children:Q.map(te=>a.jsx(Vj,{item:te,onEdit:()=>{},onCancel:()=>{},onRemove:()=>{},onStop:()=>N({type:"stop",item:te}),onRequeue:()=>{},onStart:()=>{},timeFormat:X,hasPermission:r,canModify:s,printerState:te.printer_id?ee[te.printer_id]:null,t},te.id))})]}),Ze.length>0&&a.jsxs("div",{children:[a.jsxs("div",{className:"flex items-center justify-between mb-4",children:[a.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[a.jsx(tr,{className:"w-5 h-5 text-yellow-400"}),t("queue.sections.queued"),a.jsxs("span",{className:"text-sm font-normal text-bambu-gray",children:["(",t("queue.itemCount",{count:Ze.length}),")"]}),a.jsx("span",{className:"text-xs text-bambu-gray ml-2",title:t("queue.reorderHint"),children:t("queue.dragToReorder")})]}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsxs("select",{className:"px-3 py-1.5 text-sm bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",value:L,onChange:te=>U(te.target.value),children:[a.jsx("option",{value:"position",children:t("queue.sort.byPosition")}),a.jsx("option",{value:"name",children:t("queue.sort.byName")}),a.jsx("option",{value:"printer",children:t("queue.sort.byPrinter")}),a.jsx("option",{value:"time",children:t("queue.sort.bySchedule")})]}),a.jsx(Te,{variant:"ghost",size:"sm",onClick:()=>$(!j),title:t(j?"common.ascending":"common.descending"),className:"px-2",children:j?a.jsx(zg,{className:"w-4 h-4"}):a.jsx(q0,{className:"w-4 h-4"})})]})]}),a.jsxs("div",{className:"flex items-center gap-3 mb-4 p-3 bg-bambu-dark rounded-lg",children:[a.jsxs(Te,{variant:"ghost",size:"sm",onClick:G,className:"flex items-center gap-2",children:[T.length===Ze.length&&Ze.length>0?a.jsx(Gs,{className:"w-4 h-4 text-bambu-green"}):a.jsx(cl,{className:"w-4 h-4"}),T.length===Ze.length&&Ze.length>0?t("queue.bulkEdit.deselectAll"):t("queue.bulkEdit.selectAll")]}),T.length>0&&a.jsxs(a.Fragment,{children:[a.jsx("span",{className:"text-sm text-bambu-gray",children:t("queue.bulkEdit.selected",{count:T.length})}),a.jsx("div",{className:"h-4 w-px bg-bambu-dark-tertiary"}),a.jsxs(Te,{variant:"ghost",size:"sm",onClick:()=>E(!0),className:"flex items-center gap-2 text-bambu-green hover:text-bambu-green-light",disabled:!i("queue:update_own","queue:update_all"),title:i("queue:update_own","queue:update_all")?void 0:t("queue.permissions.noEditItems"),children:[a.jsx(ea,{className:"w-4 h-4"}),t("queue.bulkEdit.editSelected")]}),a.jsxs(Te,{variant:"ghost",size:"sm",onClick:()=>se.mutate(T),className:"flex items-center gap-2 text-red-400 hover:text-red-300",disabled:se.isPending||!i("queue:delete_own","queue:delete_all"),title:i("queue:delete_own","queue:delete_all")?void 0:t("queue.permissions.noCancelItems"),children:[a.jsx(Lt,{className:"w-4 h-4"}),t("queue.bulkEdit.cancelSelected")]})]})]}),a.jsx(Ire,{sensors:K,collisionDetection:Mre,onDragEnd:je,children:a.jsx(Bre,{items:Ze.map(te=>te.id),strategy:XWe,children:a.jsx("div",{className:"space-y-3",children:Ze.map((te,z)=>a.jsx(Vj,{item:te,position:z+1,onEdit:()=>y(te),onCancel:()=>N({type:"cancel",item:te}),onRemove:()=>{},onStop:()=>{},onRequeue:()=>{},onStart:()=>pe.mutate(te.id),timeFormat:X,isSelected:T.includes(te.id),onToggleSelect:()=>Ae(te.id),hasPermission:r,canModify:s,t},te.id))})})})]}),V.length>0&&a.jsxs("div",{children:[a.jsxs("div",{className:"flex items-center justify-between mb-4",children:[a.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[a.jsx(Ar,{className:"w-5 h-5 text-bambu-gray"}),t("queue.sections.history"),a.jsxs("span",{className:"text-sm font-normal text-bambu-gray",children:["(",t("queue.itemCount",{count:V.length}),")"]})]}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsxs("select",{className:"px-3 py-1.5 text-sm bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",value:P,onChange:te=>A(te.target.value),children:[a.jsx("option",{value:"date",children:t("queue.sort.byDate")}),a.jsx("option",{value:"name",children:t("queue.sort.byName")}),a.jsx("option",{value:"printer",children:t("queue.sort.byPrinter")})]}),a.jsx(Te,{variant:"ghost",size:"sm",onClick:()=>I(!D),title:t(D?"queue.sort.ascendingOldest":"queue.sort.descendingNewest"),className:"px-2",children:D?a.jsx(zg,{className:"w-4 h-4"}):a.jsx(q0,{className:"w-4 h-4"})})]})]}),a.jsx("div",{className:"space-y-3",children:V.slice(0,20).map((te,z)=>a.jsx(Vj,{item:te,position:z+1,onEdit:()=>{},onCancel:()=>{},onRemove:()=>N({type:"remove",item:te}),onStop:()=>{},onRequeue:()=>b(te),onStart:()=>{},timeFormat:X,hasPermission:r,canModify:s,t},te.id))})]})]}),x&&a.jsx(Dh,{mode:"edit-queue-item",archiveId:x.archive_id??void 0,libraryFileId:x.library_file_id??void 0,archiveName:x.archive_name||x.library_file_name||`File #${x.archive_id||x.library_file_id}`,queueItem:x,onClose:()=>y(null)}),v&&a.jsx(Dh,{mode:"add-to-queue",archiveId:v.archive_id??void 0,libraryFileId:v.library_file_id??void 0,archiveName:v.archive_name||v.library_file_name||`File #${v.archive_id||v.library_file_id}`,onClose:()=>b(null)}),S&&a.jsx(Zn,{title:S.type==="cancel"?t("queue.confirm.cancelTitle"):S.type==="stop"?t("queue.confirm.stopTitle"):t("queue.confirm.removeTitle"),message:S.type==="cancel"?t("queue.confirm.cancelMessage",{name:S.item.archive_name||S.item.library_file_name||t("queue.confirm.thisPrint")}):S.type==="stop"?t("queue.confirm.stopMessage",{name:S.item.archive_name||S.item.library_file_name||t("queue.confirm.thisPrint")}):t("queue.confirm.removeMessage",{name:S.item.archive_name||S.item.library_file_name||t("queue.confirm.thisItem")}),confirmText:S.type==="cancel"?t("queue.confirm.cancelButton"):S.type==="stop"?t("queue.confirm.stopButton"):t("common.remove"),variant:"danger",onConfirm:()=>{S.type==="cancel"?W.mutate(S.item.id):S.type==="stop"?ie.mutate(S.item.id):re.mutate(S.item.id),N(null)},onCancel:()=>N(null)}),p&&a.jsx(Zn,{title:t("queue.confirm.clearHistoryTitle"),message:t("queue.confirm.clearHistoryMessage",{count:V.length}),confirmText:t("queue.clearHistory"),variant:"danger",onConfirm:()=>{de.mutate(),m(!1)},onCancel:()=>m(!1)}),C&&a.jsx(lKe,{selectedCount:T.length,printers:H?.map(te=>({id:te.id,name:te.name}))||[],onSave:te=>{Object.keys(te).length>0&&Ee.mutate({item_ids:T,...te})},onClose:()=>E(!1),isSaving:Ee.isPending,t})]})}function uKe({printDates:t,months:e=3}){const n=_.useRef(null),[r,i]=_.useState(0);_.useEffect(()=>{const S=n.current;if(!S)return;const N=new ResizeObserver(T=>{const k=T[0]?.contentRect.width||0;i(k)});return N.observe(S),()=>N.disconnect()},[]);const{weeks:s,monthLabels:o,printCounts:l}=_.useMemo(()=>{const S={};t.forEach(I=>{const L=I.split("T")[0];S[L]=(S[L]||0)+1});const N=new Date,T=new Date(N);T.setMonth(T.getMonth()-e),T.setDate(T.getDate()-T.getDay());const k=[],C=[];let E=[],P=-1;const A=new Date(T);let D=0;for(;A<=N;)A.getDay()===0&&E.length>0&&(k.push(E),E=[],D++),A.getMonth()!==P&&(C.push({month:A.toLocaleDateString("en-US",{month:"short"}),weekIndex:D}),P=A.getMonth()),E.push(new Date(A)),A.setDate(A.getDate()+1);return E.length>0&&k.push(E),{weeks:k,monthLabels:C,printCounts:S}},[t,e]),c=Math.max(1,...Object.values(l)),u=S=>{if(S===0)return"bg-bambu-dark";const N=S/c;return N<=.25?"bg-bambu-green/30":N<=.5?"bg-bambu-green/50":N<=.75?"bg-bambu-green/75":"bg-bambu-green"},d=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],h=s.length,p=32,m=2,x=r-p-16,y=h>0?Math.floor((x-(h-1)*m)/h):12,v=Math.max(8,Math.min(20,y)),b=v<=10?10:12;return a.jsx("div",{ref:n,className:"w-full flex justify-center",children:r>0&&a.jsxs("div",{children:[a.jsx("div",{className:"flex mb-1",style:{marginLeft:p+4},children:o.map(({month:S,weekIndex:N},T)=>a.jsx("div",{className:"text-bambu-gray",style:{fontSize:b,marginLeft:T===0?0:`${(N-(o[T-1]?.weekIndex||0))*(v+m)-24}px`},children:S},T))}),a.jsxs("div",{className:"flex",style:{gap:m},children:[a.jsx("div",{className:"flex flex-col",style:{gap:m,marginRight:4,width:p},children:d.map((S,N)=>a.jsx("div",{className:"text-bambu-gray flex items-center",style:{width:p,height:v,fontSize:b,visibility:N%2===1?"visible":"hidden"},children:S},S))}),s.map((S,N)=>a.jsx("div",{className:"flex flex-col",style:{gap:m},children:[0,1,2,3,4,5,6].map(T=>{const k=S.find(A=>A.getDay()===T);if(!k)return a.jsx("div",{style:{width:v,height:v}},T);const C=k.toISOString().split("T")[0],E=l[C]||0,P=C===new Date().toISOString().split("T")[0];return a.jsx("div",{className:`rounded-sm ${u(E)} ${P?"ring-1 ring-white":""}`,style:{width:v,height:v},title:`${k.toLocaleDateString()}: ${E} print${E!==1?"s":""}`},T)})},N))]}),a.jsxs("div",{className:"flex items-center gap-2 mt-3 text-bambu-gray",style:{fontSize:b},children:[a.jsx("span",{children:"Less"}),a.jsxs("div",{className:"flex",style:{gap:m},children:[a.jsx("div",{className:"rounded-sm bg-bambu-dark",style:{width:v,height:v}}),a.jsx("div",{className:"rounded-sm bg-bambu-green/30",style:{width:v,height:v}}),a.jsx("div",{className:"rounded-sm bg-bambu-green/50",style:{width:v,height:v}}),a.jsx("div",{className:"rounded-sm bg-bambu-green/75",style:{width:v,height:v}}),a.jsx("div",{className:"rounded-sm bg-bambu-green",style:{width:v,height:v}})]}),a.jsx("span",{children:"More"})]})]})})}const f1=["#00ae42","#3b82f6","#f59e0b","#ef4444","#8b5cf6","#ec4899","#14b8a6","#f97316"];function dKe(t){const e=new Date;switch(t){case"7d":return new Date(e.getTime()-10080*60*1e3);case"30d":return new Date(e.getTime()-720*60*60*1e3);case"90d":return new Date(e.getTime()-2160*60*60*1e3);case"365d":return new Date(e.getTime()-365*24*60*60*1e3);case"all":return new Date(0)}}function hKe({archives:t,currency:e="$"}){const[n,r]=_.useState("30d"),i=_.useMemo(()=>{const m=dKe(n);return t.filter(x=>(zi(x.completed_at||x.created_at)||new Date(0))>=m)},[t,n]),s=_.useMemo(()=>{const m=new Map;return i.forEach(x=>{const y=zi(x.completed_at||x.created_at)||new Date,v=`${y.getFullYear()}-${String(y.getMonth()+1).padStart(2,"0")}-${String(y.getDate()).padStart(2,"0")}`,b=m.get(v)||{date:v,filament:0,cost:0,prints:0},S=x.quantity||1;b.filament+=(x.filament_used_grams||0)*S,b.cost+=x.cost||0,b.prints+=S,m.set(v,b)}),Array.from(m.values()).sort((x,y)=>x.date.localeCompare(y.date)).map(x=>({...x,dateLabel:new Date(x.date).toLocaleDateString("en-US",{month:"short",day:"numeric"})}))},[i]),o=_.useMemo(()=>{if(n==="7d"||n==="30d")return s;const m=new Map;return i.forEach(x=>{const y=zi(x.completed_at||x.created_at)||new Date,v=new Date(y);v.setDate(y.getDate()-y.getDay());const b=`${v.getFullYear()}-${String(v.getMonth()+1).padStart(2,"0")}-${String(v.getDate()).padStart(2,"0")}`,S=m.get(b)||{week:b,filament:0,cost:0,prints:0},N=x.quantity||1;S.filament+=(x.filament_used_grams||0)*N,S.cost+=x.cost||0,S.prints+=N,m.set(b,S)}),Array.from(m.values()).sort((x,y)=>x.week.localeCompare(y.week)).map(x=>({date:x.week,dateLabel:`Week of ${new Date(x.week).toLocaleDateString("en-US",{month:"short",day:"numeric"})}`,...x}))},[i,s,n]),l=_.useMemo(()=>{const m=new Map;return i.forEach(x=>{const y=x.filament_type||"Unknown",v=x.quantity||1,b=y.split(", ");b.forEach(S=>{const N=(x.filament_used_grams||0)*v/b.length;m.set(S,(m.get(S)||0)+N)})}),Array.from(m.entries()).map(([x,y])=>({name:x,value:Math.round(y)})).sort((x,y)=>y.value-x.value)},[i]),c=_.useMemo(()=>{const m=new Date,x=[];for(let y=5;y>=0;y--){const v=new Date(m.getFullYear(),m.getMonth()-y,1),b=new Date(m.getFullYear(),m.getMonth()-y+1,0),S=v.toLocaleDateString("en-US",{month:"short",year:"2-digit"}),N=t.filter(T=>{const k=zi(T.completed_at||T.created_at)||new Date(0);return k>=v&&k<=b});x.push({month:S,filament:Math.round(N.reduce((T,k)=>T+(k.filament_used_grams||0),0)),cost:N.reduce((T,k)=>T+(k.cost||0),0),prints:N.reduce((T,k)=>T+(k.quantity||1),0)})}return x},[t]),u=n==="7d"||n==="30d"?s:o,d=i.reduce((m,x)=>m+(x.filament_used_grams||0),0),h=i.reduce((m,x)=>m+(x.cost||0),0),p=i.reduce((m,x)=>m+(x.quantity||1),0);return a.jsxs("div",{className:"space-y-6",children:[a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx("h3",{className:"text-lg font-semibold text-white",children:"Filament Usage Trends"}),a.jsx("div",{className:"flex gap-1 bg-bambu-dark rounded-lg p-1",children:["7d","30d","90d","365d","all"].map(m=>a.jsx("button",{onClick:()=>r(m),className:`px-3 py-1 text-sm rounded-md transition-colors ${n===m?"bg-bambu-green text-white":"text-bambu-gray hover:text-white"}`,children:m==="all"?"All":m.replace("d","D")},m))})]}),a.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[a.jsxs("div",{className:"bg-bambu-dark rounded-lg p-4",children:[a.jsx("p",{className:"text-sm text-bambu-gray",children:"Period Filament"}),a.jsxs("p",{className:"text-2xl font-bold text-white",children:[(d/1e3).toFixed(2),"kg"]}),a.jsxs("p",{className:"text-xs text-bambu-gray",children:[d.toFixed(0),"g total"]})]}),a.jsxs("div",{className:"bg-bambu-dark rounded-lg p-4",children:[a.jsx("p",{className:"text-sm text-bambu-gray",children:"Period Cost"}),a.jsxs("p",{className:"text-2xl font-bold text-white",children:[e,h.toFixed(2)]}),a.jsxs("p",{className:"text-xs text-bambu-gray",children:[p," prints"]})]}),a.jsxs("div",{className:"bg-bambu-dark rounded-lg p-4",children:[a.jsx("p",{className:"text-sm text-bambu-gray",children:"Avg per Print"}),a.jsxs("p",{className:"text-2xl font-bold text-white",children:[p>0?(d/p).toFixed(0):0,"g"]}),a.jsxs("p",{className:"text-xs text-bambu-gray",children:[e,p>0?(h/p).toFixed(2):"0.00"," avg"]})]})]}),u.length>0?a.jsxs("div",{className:"bg-bambu-dark rounded-lg p-4",children:[a.jsx("h4",{className:"text-sm font-medium text-bambu-gray mb-4",children:"Usage Over Time"}),a.jsx(j1,{width:"100%",height:250,children:a.jsxs(YBe,{data:u,children:[a.jsx("defs",{children:a.jsxs("linearGradient",{id:"colorFilament",x1:"0",y1:"0",x2:"0",y2:"1",children:[a.jsx("stop",{offset:"5%",stopColor:"#00ae42",stopOpacity:.3}),a.jsx("stop",{offset:"95%",stopColor:"#00ae42",stopOpacity:0})]})}),a.jsx(nN,{strokeDasharray:"3 3",stroke:"#3d3d3d"}),a.jsx(iN,{dataKey:"dateLabel",stroke:"#9ca3af",tick:{fontSize:12},interval:"preserveStartEnd"}),a.jsx(aN,{stroke:"#9ca3af",tick:{fontSize:12},tickFormatter:m=>`${m}g`}),a.jsx(D1,{contentStyle:{backgroundColor:"#2d2d2d",border:"1px solid #3d3d3d",borderRadius:"8px"},labelStyle:{color:"#fff"},formatter:m=>[`${Number(m??0).toFixed(0)}g`,"Filament"]}),a.jsx(uee,{type:"monotone",dataKey:"filament",stroke:"#00ae42",strokeWidth:2,fillOpacity:1,fill:"url(#colorFilament)"})]})})]}):a.jsx("div",{className:"bg-bambu-dark rounded-lg p-8 text-center text-bambu-gray",children:"No data for selected time range"}),a.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[a.jsxs("div",{className:"bg-bambu-dark rounded-lg p-4",children:[a.jsx("h4",{className:"text-sm font-medium text-bambu-gray mb-4",children:"By Filament Type"}),l.length>0?a.jsxs("div",{className:"flex items-center gap-4",children:[a.jsx(j1,{width:160,height:160,children:a.jsxs(KBe,{children:[a.jsx(RJ,{data:l,cx:"50%",cy:"50%",innerRadius:40,outerRadius:70,paddingAngle:2,dataKey:"value",children:l.map((m,x)=>a.jsx(pv,{fill:f1[x%f1.length]},`cell-${x}`))}),a.jsx(D1,{contentStyle:{backgroundColor:"#2d2d2d",border:"1px solid #3d3d3d",borderRadius:"8px"},formatter:m=>[`${m??0}g`,"Usage"]})]})}),a.jsx("div",{className:"flex-1 space-y-2 overflow-hidden",children:l.map((m,x)=>{const y=l.reduce((b,S)=>b+S.value,0),v=y>0?(m.value/y*100).toFixed(0):0;return a.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[a.jsx("div",{className:"w-3 h-3 rounded-sm flex-shrink-0",style:{backgroundColor:f1[x%f1.length]}}),a.jsx("span",{className:"text-white truncate flex-1",children:m.name}),a.jsxs("span",{className:"text-bambu-gray flex-shrink-0",children:[v,"%"]})]},m.name)})})]}):a.jsx("div",{className:"h-[160px] flex items-center justify-center text-bambu-gray",children:"No filament data"})]}),a.jsxs("div",{className:"bg-bambu-dark rounded-lg p-4",children:[a.jsx("h4",{className:"text-sm font-medium text-bambu-gray mb-4",children:"Monthly Comparison"}),a.jsx(j1,{width:"100%",height:200,children:a.jsxs(LBe,{data:c,children:[a.jsx(nN,{strokeDasharray:"3 3",stroke:"#3d3d3d"}),a.jsx(iN,{dataKey:"month",stroke:"#9ca3af",tick:{fontSize:12}}),a.jsx(aN,{stroke:"#9ca3af",tick:{fontSize:12},tickFormatter:m=>`${m}g`}),a.jsx(D1,{contentStyle:{backgroundColor:"#2d2d2d",border:"1px solid #3d3d3d",borderRadius:"8px"},formatter:(m,x)=>[x==="filament"?`${m??0}g`:x==="cost"?`${e}${Number(m??0).toFixed(2)}`:m??0,x==="filament"?"Filament":x==="cost"?"Cost":"Prints"]}),a.jsx(HO,{}),a.jsx(zJ,{dataKey:"filament",name:"Filament (g)",fill:"#00ae42",radius:[4,4,0,0]})]})})]})]})]})}function fKe({id:t,title:e,component:n,isHidden:r,size:i,onToggleVisibility:s,onToggleSize:o}){const{attributes:l,listeners:c,setNodeRef:u,transform:d,transition:h,isDragging:p}=$re({id:t}),m={transform:gx.Transform.toString(d),transition:h,opacity:p?.5:1};return r?null:a.jsxs("div",{ref:u,style:{...m,gridColumn:`span ${i}`},className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary overflow-hidden ${p?"ring-2 ring-bambu-green shadow-lg":""}`,children:[a.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-bambu-dark-tertiary bg-bambu-dark/30",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("button",{...l,...c,className:"cursor-grab active:cursor-grabbing p-1 hover:bg-bambu-dark-tertiary rounded transition-colors",title:"Drag to reorder",children:a.jsx(Hg,{className:"w-6 h-6 md:w-4 md:h-4 text-bambu-gray"})}),a.jsx("h3",{className:"text-sm font-medium text-white",children:e})]}),a.jsxs("div",{className:"flex items-center gap-1",children:[a.jsx("button",{onClick:o,className:"p-1 hover:bg-bambu-dark-tertiary rounded transition-colors",title:`Size: ${i===1?"1/4":i===2?"1/2":"Full"} - Click to cycle`,children:i===4?a.jsx(CW,{className:"w-4 h-4 text-bambu-gray hover:text-white"}):a.jsx(AW,{className:"w-4 h-4 text-bambu-gray hover:text-white"})}),a.jsx("button",{onClick:s,className:"p-1 hover:bg-bambu-dark-tertiary rounded transition-colors",title:"Hide widget",children:a.jsx(uM,{className:"w-4 h-4 text-bambu-gray hover:text-white"})})]})]}),a.jsx("div",{className:"p-4",children:typeof n=="function"?n(i):n})]})}function mKe({widgets:t,storageKey:e,columns:n=4,hideControls:r=!1,onResetLayout:i,renderControls:s}){const o=()=>{const T={};return t.forEach(k=>{T[k.id]=k.defaultSize||4}),T},[l,c]=_.useState(()=>{const T=localStorage.getItem(e);if(T)try{const k=JSON.parse(T);return k.sizes||(k.sizes=o()),k}catch{}return{order:t.map(k=>k.id),hidden:t.filter(k=>k.defaultVisible===!1).map(k=>k.id),sizes:o()}}),[u,d]=_.useState(!1);_.useEffect(()=>{const T=()=>d(k=>!k);return window.addEventListener("toggle-hidden-panel",T),()=>window.removeEventListener("toggle-hidden-panel",T)},[]),_.useEffect(()=>{localStorage.setItem(e,JSON.stringify(l))},[l,e]),_.useEffect(()=>{const k=t.map(C=>C.id).filter(C=>!l.order.includes(C));k.length>0&&c(C=>({...C,order:[...C.order,...k]}))},[t,l.order]);const h=wre(eM($2,{activationConstraint:{distance:8}}),eM(H2,{coordinateGetter:Vre})),p=T=>{const{active:k,over:C}=T;C&&k.id!==C.id&&c(E=>{const P=E.order.indexOf(k.id),A=E.order.indexOf(C.id);return{...E,order:q2(E.order,P,A)}})},m=T=>{c(k=>({...k,hidden:k.hidden.includes(T)?k.hidden.filter(C=>C!==T):[...k.hidden,T]}))},x=T=>{c(k=>{const C=k.sizes[T]||4,E=C===1?2:C===2?4:1;return{...k,sizes:{...k.sizes,[T]:E}}})},y=()=>{const T={order:t.map(k=>k.id),hidden:t.filter(k=>k.defaultVisible===!1).map(k=>k.id),sizes:o()};c(T),i?.()},v=l.order.map(T=>t.find(k=>k.id===T)).filter(Boolean),b=v.filter(T=>!l.hidden.includes(T.id)),S=v.filter(T=>l.hidden.includes(T.id)),N=s?.({hiddenCount:S.length,showHiddenPanel:u,setShowHiddenPanel:d,resetLayout:y});return a.jsxs("div",{className:"space-y-4",children:[N,!r&&!s&&a.jsxs("div",{className:"flex items-center justify-end gap-2",children:[a.jsxs(Te,{variant:"secondary",size:"sm",onClick:y,children:[a.jsx(Lh,{className:"w-4 h-4"}),"Reset Layout"]}),S.length>0&&a.jsxs(Te,{variant:"secondary",size:"sm",onClick:()=>d(!u),children:[a.jsx(xc,{className:"w-4 h-4"}),S.length," Hidden"]})]}),u&&S.length>0&&a.jsxs("div",{className:"p-4 bg-bambu-dark rounded-xl border border-bambu-dark-tertiary",children:[a.jsx("p",{className:"text-sm text-bambu-gray mb-3",children:"Hidden widgets (click to show):"}),a.jsx("div",{className:"flex flex-wrap gap-2",children:S.map(T=>a.jsxs("button",{onClick:()=>m(T.id),className:"px-3 py-1.5 bg-bambu-dark-tertiary hover:bg-bambu-green/20 rounded-lg text-sm text-white transition-colors flex items-center gap-2",children:[a.jsx(xc,{className:"w-3 h-3"}),T.title]},T.id))})]}),a.jsx(Ire,{sensors:h,collisionDetection:Mre,onDragEnd:p,children:a.jsx(Bre,{items:b.map(T=>T.id),strategy:fF,children:a.jsx("div",{className:"grid gap-6",style:{gridTemplateColumns:`repeat(${n}, minmax(0, 1fr))`},children:b.map(T=>a.jsx(fKe,{id:T.id,title:T.title,component:T.component,isHidden:l.hidden.includes(T.id),size:l.sizes[T.id]||2,onToggleVisibility:()=>m(T.id),onToggleSize:()=>x(T.id)},T.id))})})}),b.length===0&&a.jsxs("div",{className:"text-center py-12 text-bambu-gray",children:[a.jsx("p",{children:"All widgets are hidden."}),a.jsx(Te,{className:"mt-4",onClick:y,children:"Reset Layout"})]})]})}function pKe({stats:t,currency:e,t:n}){return a.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-3 gap-4",children:[a.jsxs("div",{className:"flex items-start gap-3",children:[a.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark text-bambu-green",children:a.jsx(bc,{className:"w-5 h-5"})}),a.jsxs("div",{children:[a.jsx("p",{className:"text-xs text-bambu-gray",children:n("stats.totalPrints")}),a.jsx("p",{className:"text-xl font-bold text-white",children:t?.total_prints||0})]})]}),a.jsxs("div",{className:"flex items-start gap-3",children:[a.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark text-blue-400",children:a.jsx(tr,{className:"w-5 h-5"})}),a.jsxs("div",{children:[a.jsx("p",{className:"text-xs text-bambu-gray",children:n("stats.printTime")}),a.jsxs("p",{className:"text-xl font-bold text-white",children:[t?.total_print_time_hours.toFixed(1)||0,"h"]})]})]}),a.jsxs("div",{className:"flex items-start gap-3",children:[a.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark text-orange-400",children:a.jsx(bc,{className:"w-5 h-5"})}),a.jsxs("div",{children:[a.jsx("p",{className:"text-xs text-bambu-gray",children:n("stats.filamentUsed")}),a.jsxs("p",{className:"text-xl font-bold text-white",children:[((t?.total_filament_grams||0)/1e3).toFixed(2),"kg"]})]})]}),a.jsxs("div",{className:"flex items-start gap-3",children:[a.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark text-green-400",children:a.jsx(mP,{className:"w-5 h-5"})}),a.jsxs("div",{children:[a.jsx("p",{className:"text-xs text-bambu-gray",children:n("stats.filamentCost")}),a.jsxs("p",{className:"text-xl font-bold text-white",children:[e," ",t?.total_cost.toFixed(2)||"0.00"]})]})]}),a.jsxs("div",{className:"flex items-start gap-3",children:[a.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark text-yellow-400",children:a.jsx(_h,{className:"w-5 h-5"})}),a.jsxs("div",{children:[a.jsx("p",{className:"text-xs text-bambu-gray",children:n("stats.energyUsed")}),a.jsxs("p",{className:"text-xl font-bold text-white",children:[t?.total_energy_kwh.toFixed(2)||"0.00"," kWh"]})]})]}),a.jsxs("div",{className:"flex items-start gap-3",children:[a.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark text-yellow-500",children:a.jsx(mP,{className:"w-5 h-5"})}),a.jsxs("div",{children:[a.jsx("p",{className:"text-xs text-bambu-gray",children:n("stats.energyCost")}),a.jsxs("p",{className:"text-xl font-bold text-white",children:[e," ",t?.total_energy_cost.toFixed(2)||"0.00"]})]})]})]})}function gKe({stats:t,printerMap:e,size:n=1,t:r}){const i=t?.total_prints?Math.round(t.successful_prints/t.total_prints*100):0,s=n===1?112:n===2?128:144,o=s/2-8,l=o*2*Math.PI;return a.jsxs("div",{className:"flex items-center gap-6",children:[a.jsxs("div",{className:"relative flex-shrink-0",style:{width:s,height:s},children:[a.jsxs("svg",{className:"w-full h-full -rotate-90",children:[a.jsx("circle",{cx:s/2,cy:s/2,r:o,fill:"none",stroke:"#3d3d3d",strokeWidth:"10"}),a.jsx("circle",{cx:s/2,cy:s/2,r:o,fill:"none",stroke:"#00ae42",strokeWidth:"10",strokeLinecap:"round",strokeDasharray:`${i/100*l} ${l}`})]}),a.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:a.jsxs("span",{className:`font-bold text-white ${n>=2?"text-2xl":"text-xl"}`,children:[i,"%"]})})]}),a.jsxs("div",{className:"flex-1 min-w-0",children:[a.jsxs("div",{className:"space-y-2",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(Ar,{className:"w-4 h-4 text-status-ok flex-shrink-0"}),a.jsx("span",{className:"text-sm text-bambu-gray",children:r("stats.successful")}),a.jsx("span",{className:"text-sm text-white font-medium",children:t?.successful_prints||0})]}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(Ji,{className:"w-4 h-4 text-status-error flex-shrink-0"}),a.jsx("span",{className:"text-sm text-bambu-gray",children:r("stats.failed")}),a.jsx("span",{className:"text-sm text-white font-medium",children:t?.failed_prints||0})]})]}),n>=2&&t?.prints_by_printer&&Object.keys(t.prints_by_printer).length>0&&a.jsxs("div",{className:"mt-4 pt-4 border-t border-bambu-dark-tertiary",children:[a.jsx("p",{className:"text-xs text-bambu-gray font-medium mb-2",children:r("stats.printsByPrinter")}),a.jsx("div",{className:`grid gap-x-6 gap-y-1 ${n===4?"grid-cols-3":"grid-cols-2"}`,style:{width:"fit-content"},children:Object.entries(t.prints_by_printer).map(([c,u])=>a.jsxs("div",{className:"flex items-center gap-3 text-sm",children:[a.jsx("span",{className:"text-bambu-gray truncate max-w-[120px]",children:e.get(c)||`${r("common.printer")} ${c}`}),a.jsx("span",{className:"text-white font-medium",children:u})]},c))})]})]})]})}function xKe({stats:t,printerMap:e,size:n=1,t:r}){const i=t?.average_time_accuracy;if(i==null)return a.jsx("div",{className:"flex items-center justify-center h-full",children:a.jsx("p",{className:"text-bambu-gray text-center py-4",children:r("stats.noTimeAccuracyData")})});const o=(Math.min(150,Math.max(50,i))-50)/100*100,c=(y=>y>=95&&y<=105?"#00ae42":y>105?"#3b82f6":"#f97316")(i),u=i-100,d=n===1?112:n===2?128:144,h=d/2-8,p=h*2*Math.PI,m=n===1?3:n===2?6:999,x=t?.time_accuracy_by_printer?Object.entries(t.time_accuracy_by_printer).slice(0,m):[];return a.jsxs("div",{className:"flex items-center gap-6",children:[a.jsxs("div",{className:"relative flex-shrink-0",style:{width:d,height:d},children:[a.jsxs("svg",{className:"w-full h-full -rotate-90",children:[a.jsx("circle",{cx:d/2,cy:d/2,r:h,fill:"none",stroke:"#3d3d3d",strokeWidth:"10"}),a.jsx("circle",{cx:d/2,cy:d/2,r:h,fill:"none",stroke:c,strokeWidth:"10",strokeLinecap:"round",strokeDasharray:`${o/100*p} ${p}`})]}),a.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center",children:[a.jsxs("span",{className:`font-bold text-white ${n>=2?"text-2xl":"text-xl"}`,children:[i.toFixed(0),"%"]}),a.jsxs("span",{className:`text-xs ${u>=0?"text-blue-400":"text-orange-400"}`,children:[u>=0?"+":"",u.toFixed(0),"%"]})]})]}),a.jsxs("div",{className:"flex-1 min-w-0",children:[a.jsxs("div",{className:"flex items-center gap-2 text-xs text-bambu-gray",children:[a.jsx(LW,{className:"w-3 h-3 flex-shrink-0"}),a.jsx("span",{children:r("stats.perfectEstimate")})]}),x.length>0&&a.jsx("div",{className:`mt-2 ${n===4?"grid grid-cols-3 gap-x-6 gap-y-1":n===2?"grid grid-cols-2 gap-x-6 gap-y-1":"space-y-1"}`,style:{width:"fit-content"},children:x.map(([y,v])=>a.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[a.jsx("span",{className:"text-bambu-gray truncate max-w-[100px]",children:e.get(y)||`${r("common.printer")} ${y}`}),a.jsxs("span",{className:`font-medium ${v>=95&&v<=105?"text-status-ok":v>105?"text-blue-400":"text-status-warning"}`,children:[v.toFixed(0),"%"]})]},y))})]})]})}function bKe({stats:t,size:e=1,t:n}){if(!t?.prints_by_filament_type||Object.keys(t.prints_by_filament_type).length===0)return a.jsx("p",{className:"text-bambu-gray text-center py-4",children:n("stats.noFilamentData")});const r=Object.entries(t.prints_by_filament_type).sort(([,l],[,c])=>c-l),i=e===1?5:e===2?8:999,s=r.slice(0,i),o=r.length>i;return e===4&&s.length>4?a.jsx("div",{className:"grid grid-cols-2 lg:grid-cols-3 gap-4",children:s.map(([l,c])=>{const u=Math.round(c/(t.total_prints||1)*100);return a.jsxs("div",{children:[a.jsxs("div",{className:"flex justify-between text-sm mb-1",children:[a.jsx("span",{className:"text-white truncate max-w-[120px]",children:l}),a.jsx("span",{className:"text-bambu-gray",children:c})]}),a.jsx("div",{className:"h-2 bg-bambu-dark rounded-full",children:a.jsx("div",{className:"h-full bg-bambu-green rounded-full transition-all",style:{width:`${u}%`}})})]},l)})}):a.jsxs("div",{className:"space-y-3",children:[s.map(([l,c])=>{const u=Math.round(c/(t.total_prints||1)*100);return a.jsxs("div",{children:[a.jsxs("div",{className:"flex justify-between text-sm mb-1",children:[a.jsx("span",{className:"text-white",children:l}),a.jsxs("span",{className:"text-bambu-gray",children:[c," ",n("common.prints")]})]}),a.jsx("div",{className:"h-2 bg-bambu-dark rounded-full",children:a.jsx("div",{className:"h-full bg-bambu-green rounded-full transition-all",style:{width:`${u}%`}})})]},l)}),o&&a.jsx("p",{className:"text-xs text-bambu-gray text-center pt-1",children:n("common.more",{count:r.length-i})})]})}function yKe({printDates:t,size:e=2}){const n=e===1?3:e===2?6:12;return a.jsx(uKe,{printDates:t,months:n})}function vKe({stats:t,printerMap:e,t:n}){return!t?.prints_by_printer||Object.keys(t.prints_by_printer).length===0?a.jsx("p",{className:"text-bambu-gray text-center py-4",children:n("stats.noPrinterData")}):a.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:Object.entries(t.prints_by_printer).map(([r,i])=>a.jsxs("div",{className:"flex items-center gap-3 p-3 bg-bambu-dark rounded-lg",children:[a.jsx("div",{className:"p-2 bg-bambu-dark-tertiary rounded-lg",children:a.jsx(Ur,{className:"w-4 h-4 text-bambu-green"})}),a.jsxs("div",{children:[a.jsx("p",{className:"text-white font-medium text-sm",children:e.get(r)||`${n("common.printer")} ${r}`}),a.jsxs("p",{className:"text-xs text-bambu-gray",children:[i," ",n("common.prints")]})]})]},r))})}function wKe({archives:t,currency:e,t:n}){return!t||t.length===0?a.jsx("p",{className:"text-bambu-gray text-center py-4",children:n("stats.noPrintData")}):a.jsx(hKe,{archives:t,currency:e})}function _Ke({size:t=1,t:e}){const{data:n,isLoading:r}=ct({queryKey:["failureAnalysis"],queryFn:()=>ce.getFailureAnalysis({days:30})});if(r)return a.jsx("div",{className:"flex justify-center py-4",children:a.jsx(pt,{className:"w-6 h-6 text-bambu-green animate-spin"})});if(!n||n.total_prints===0)return a.jsx("p",{className:"text-bambu-gray text-center py-4",children:e("stats.noPrintDataLast30Days")});const i=t===1?5:t===2?8:999,s=Object.entries(n.failures_by_reason).sort(([,c],[,u])=>u-c),o=s.slice(0,i),l=s.length>i;return a.jsxs("div",{className:`${t>=2?"flex gap-8":"space-y-4"}`,children:[a.jsxs("div",{className:t>=2?"flex-shrink-0":"",children:[a.jsx("div",{className:"flex items-center gap-4",children:a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(Sn,{className:`w-5 h-5 ${n.failure_rate>20?"text-status-error":n.failure_rate>10?"text-status-warning":"text-status-ok"}`}),a.jsxs("span",{className:`font-bold text-white ${t>=2?"text-3xl":"text-2xl"}`,children:[n.failure_rate.toFixed(1),"%"]})]})}),a.jsx("div",{className:"text-sm text-bambu-gray mt-1",children:e("stats.failedPrintsCount",{failed:n.failed_prints,total:n.total_prints})}),n.trend&&n.trend.length>=2&&a.jsx("div",{className:`${t>=2?"mt-4":"mt-2 pt-2 border-t border-bambu-dark-tertiary"}`,children:a.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[a.jsx(IW,{className:`w-4 h-4 ${n.trend[n.trend.length-1].failure_rate0&&a.jsxs("div",{className:`flex-1 ${t>=2?"border-l border-bambu-dark-tertiary pl-8":"pt-2"}`,children:[a.jsx("p",{className:"text-xs text-bambu-gray font-medium mb-2",children:t>=2?e("stats.failureReasons"):e("stats.topFailureReasons")}),a.jsx("div",{className:`${t===4?"grid grid-cols-2 gap-x-6 gap-y-1":"space-y-1"}`,children:o.map(([c,u])=>a.jsxs("div",{className:"flex items-center justify-between text-sm",children:[a.jsx("span",{className:`text-white truncate ${t===4?"max-w-[200px]":"max-w-[160px]"}`,children:c||e("common.unknown")}),a.jsx("span",{className:"text-bambu-gray ml-2",children:u})]},c))}),l&&a.jsx("p",{className:"text-xs text-bambu-gray mt-2",children:e("common.more",{count:s.length-i})})]})]})}function SKe(){const{t}=On(),{showToast:e}=Hn(),{hasPermission:n}=Ci(),[r,i]=_.useState(!1),[s,o]=_.useState(!1),[l,c]=_.useState(0),[u,d]=_.useState(0),[h,p]=_.useState(!1);_.useEffect(()=>{const A=()=>{try{const I=localStorage.getItem("bambusy-dashboard-layout");if(I){const L=JSON.parse(I);d(L.hidden?.length||0)}}catch{d(0)}};A(),window.addEventListener("storage",A);const D=setInterval(A,500);return()=>{window.removeEventListener("storage",A),clearInterval(D)}},[l]);const{data:m,isLoading:x,refetch:y}=ct({queryKey:["archiveStats"],queryFn:ce.getArchiveStats}),{data:v}=ct({queryKey:["printers"],queryFn:ce.getPrinters}),{data:b}=ct({queryKey:["archives"],queryFn:()=>ce.getArchives(void 0,void 0,1e3,0)}),{data:S}=ct({queryKey:["settings"],queryFn:ce.getSettings}),N=async A=>{o(!1),i(!0);try{const{blob:D,filename:I}=await ce.exportStats({format:A,days:90}),L=URL.createObjectURL(D),U=document.createElement("a");U.href=L,U.download=I,U.click(),URL.revokeObjectURL(L),e(t("stats.exportDownloaded"))}catch{e(t("stats.exportFailed"),"error")}finally{i(!1)}},T=async()=>{p(!0);try{const A=await ce.recalculateCosts();await y(),e(t("stats.recalculatedCosts",{count:A.updated}))}catch{e(t("stats.recalculateFailed"),"error")}finally{p(!1)}},k=S?.currency||"$",C=new Map(v?.map(A=>[String(A.id),A.name])||[]),E=b?.map(A=>A.created_at)||[];if(x)return a.jsx("div",{className:"p-4 md:p-8",children:a.jsx("div",{className:"text-center py-12 text-bambu-gray",children:t("stats.loadingStats")})});const P=[{id:"quick-stats",title:t("stats.quickStats"),component:a.jsx(pKe,{stats:m,currency:k,t}),defaultSize:2},{id:"success-rate",title:t("stats.successRate"),component:A=>a.jsx(gKe,{stats:m,printerMap:C,size:A,t}),defaultSize:1},{id:"time-accuracy",title:t("stats.timeAccuracy"),component:A=>a.jsx(xKe,{stats:m,printerMap:C,size:A,t}),defaultSize:1},{id:"filament-types",title:t("stats.filamentTypes"),component:A=>a.jsx(bKe,{stats:m,size:A,t}),defaultSize:1},{id:"failure-analysis",title:t("stats.failureAnalysis"),component:A=>a.jsx(_Ke,{size:A,t}),defaultSize:1},{id:"print-activity",title:t("stats.printActivity"),component:A=>a.jsx(yKe,{printDates:E,size:A}),defaultSize:2},{id:"prints-by-printer",title:t("stats.printsByPrinter"),component:a.jsx(vKe,{stats:m,printerMap:C,t}),defaultSize:2},{id:"filament-trends",title:t("stats.filamentTrends"),component:a.jsx(wKe,{archives:b||[],currency:k,t}),defaultSize:4}];return a.jsxs("div",{className:"p-4 md:p-8",children:[a.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4 mb-6",children:[a.jsxs("div",{children:[a.jsx("h1",{className:"text-2xl font-bold text-white",children:t("stats.title")}),a.jsx("p",{className:"text-bambu-gray",children:t("stats.subtitle")})]}),a.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[u>0&&a.jsxs(Te,{variant:"secondary",onClick:()=>{window.dispatchEvent(new CustomEvent("toggle-hidden-panel"))},children:[a.jsx(xc,{className:"w-4 h-4"}),t("stats.hiddenCount",{count:u})]}),a.jsxs(Te,{variant:"secondary",onClick:()=>{localStorage.removeItem("bambusy-dashboard-layout"),c(A=>A+1),e(t("stats.layoutReset"))},disabled:!n("settings:update"),title:n("settings:update")?void 0:t("stats.noPermissionResetLayout"),children:[a.jsx(Lh,{className:"w-4 h-4"}),t("stats.resetLayout")]}),a.jsxs(Te,{variant:"secondary",onClick:T,disabled:h||!n("archives:update_all"),title:n("archives:update_all")?t("stats.recalculateCostsHint"):t("stats.noPermissionRecalculate"),children:[h?a.jsx(pt,{className:"w-4 h-4 animate-spin"}):a.jsx(Bce,{className:"w-4 h-4"}),t("stats.recalculateCosts")]}),a.jsxs("div",{className:"relative",children:[a.jsxs(Te,{variant:"secondary",onClick:()=>o(!s),disabled:r,children:[r?a.jsx(pt,{className:"w-4 h-4 animate-spin"}):a.jsx(K1,{className:"w-4 h-4"}),t("stats.exportStats")]}),s&&a.jsxs("div",{className:"absolute right-0 top-full mt-1 w-48 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl z-20",children:[a.jsxs("button",{className:"w-full px-4 py-2 text-left text-white hover:bg-bambu-dark-tertiary transition-colors flex items-center gap-2 rounded-t-lg",onClick:()=>N("csv"),children:[a.jsx(fs,{className:"w-4 h-4"}),t("stats.exportAsCsv")]}),a.jsxs("button",{className:"w-full px-4 py-2 text-left text-white hover:bg-bambu-dark-tertiary transition-colors flex items-center gap-2 rounded-b-lg",onClick:()=>N("xlsx"),children:[a.jsx(K1,{className:"w-4 h-4"}),t("stats.exportAsExcel")]})]})]})]})]}),a.jsx(mKe,{widgets:P,storageKey:"bambusy-dashboard-layout",hideControls:!0},l)]})}function NKe({plug:t,onEdit:e}){const n=sn(),{showToast:r}=Hn(),[i,s]=_.useState(!1),[o,l]=_.useState(!1),[c,u]=_.useState(!1),[d,h]=_.useState(!1),{data:p,isLoading:m}=ct({queryKey:["smart-plug-status",t.id],queryFn:()=>ce.getSmartPlugStatus(t.id),refetchInterval:3e4}),{data:x}=ct({queryKey:["printers"],queryFn:ce.getPrinters}),y=x?.find(A=>A.id===t.printer_id),v=gt({mutationFn:A=>ce.controlSmartPlug(t.id,A),onMutate:async A=>{await n.cancelQueries({queryKey:["smart-plug-status",t.id]});const D=n.getQueryData(["smart-plug-status",t.id]),I=A==="on"?"ON":A==="off"||p?.state==="ON"?"OFF":"ON";return n.setQueryData(["smart-plug-status",t.id],L=>({...L,state:I})),{previousStatus:D}},onError:(A,D,I)=>{I?.previousStatus&&n.setQueryData(["smart-plug-status",t.id],I.previousStatus),r(`Failed to turn ${D} "${t.name}"`,"error")},onSettled:()=>{setTimeout(()=>{n.invalidateQueries({queryKey:["smart-plug-status",t.id]}),n.invalidateQueries({queryKey:["smart-plugs"]})},1e3)}}),b=gt({mutationFn:A=>ce.updateSmartPlug(t.id,A),onSuccess:()=>{n.invalidateQueries({queryKey:["smart-plugs"]}),t.printer_id&&(n.invalidateQueries({queryKey:["smartPlugByPrinter",t.printer_id]}),n.invalidateQueries({queryKey:["scriptPlugsByPrinter",t.printer_id]}))}}),S=gt({mutationFn:()=>ce.deleteSmartPlug(t.id),onSuccess:()=>{n.invalidateQueries({queryKey:["smart-plugs"]}),t.printer_id&&n.invalidateQueries({queryKey:["scriptPlugsByPrinter",t.printer_id]})}}),N=p?.state==="ON",T=t.plug_type==="mqtt"&&p?.energy?.power!==null&&p?.energy?.power!==void 0,k=(p?.reachable??!1)||T,C=v.isPending,P=(()=>{if(t.plug_type!=="tasmota"||!t.ip_address)return null;const A=t.ip_address;return t.username&&t.password?`http://${encodeURIComponent(t.username)}:${encodeURIComponent(t.password)}@${A}/`:`http://${A}/`})();return a.jsxs(a.Fragment,{children:[a.jsx(St,{className:"relative",children:a.jsxs(Nt,{className:"p-4",children:[a.jsxs("div",{className:"flex items-start justify-between gap-2 mb-3",children:[a.jsxs("div",{className:"flex items-center gap-3 min-w-0 flex-1",children:[a.jsx("div",{className:`p-2 rounded-lg flex-shrink-0 ${t.plug_type==="mqtt"?k?"bg-teal-500/20":"bg-red-500/20":k?N?"bg-bambu-green/20":"bg-bambu-dark":"bg-red-500/20"}`,children:t.plug_type==="mqtt"?a.jsx(RR,{className:`w-5 h-5 ${k?"text-teal-400":"text-red-400"}`}):t.plug_type==="homeassistant"?a.jsx(Iy,{className:`w-5 h-5 ${k?N?"text-bambu-green":"text-bambu-gray":"text-red-400"}`}):a.jsx(al,{className:`w-5 h-5 ${k?N?"text-bambu-green":"text-bambu-gray":"text-red-400"}`})}),a.jsxs("div",{className:"min-w-0",children:[a.jsx("h3",{className:"font-medium text-white truncate",children:t.name}),a.jsx("p",{className:"text-sm text-bambu-gray truncate",title:t.plug_type==="mqtt"?t.mqtt_topic??void 0:t.plug_type==="homeassistant"?t.ha_entity_id??void 0:t.ip_address??void 0,children:t.plug_type==="mqtt"?t.mqtt_topic:t.plug_type==="homeassistant"?t.ha_entity_id:t.ip_address})]})]}),a.jsxs("div",{className:"flex flex-col items-end gap-1 flex-shrink-0",children:[m?a.jsx(pt,{className:"w-4 h-4 text-bambu-gray animate-spin"}):t.plug_type==="mqtt"?a.jsxs("div",{className:"flex items-center gap-1.5 text-sm whitespace-nowrap",children:[a.jsx("span",{className:"px-1.5 py-0.5 bg-teal-500/20 text-teal-400 text-[10px] font-medium rounded flex-shrink-0",children:"MQTT"}),k&&a.jsx("span",{className:"text-status-ok",children:"✓"})]}):t.plug_type==="homeassistant"?a.jsxs("div",{className:"flex items-center gap-1 text-sm",children:[a.jsx("span",{className:"px-1 py-0.5 bg-blue-500/20 text-blue-400 text-[10px] font-medium rounded",children:"HA"}),a.jsx("span",{className:k?N?"text-status-ok":"text-bambu-gray":"text-status-error",children:k?p?.state||"?":"Offline"})]}):k?a.jsxs("div",{className:"flex items-center gap-1 text-sm",children:[a.jsx(Mg,{className:"w-4 h-4 text-status-ok"}),a.jsx("span",{className:N?"text-status-ok":"text-bambu-gray",children:p?.state||"Unknown"})]}):a.jsxs("div",{className:"flex items-center gap-1 text-sm text-status-error",children:[a.jsx(lm,{className:"w-4 h-4"}),a.jsx("span",{children:"Offline"})]}),P&&a.jsxs("a",{href:P,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1 px-2 py-0.5 bg-bambu-dark hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white text-xs rounded-full transition-colors",title:"Open plug admin page",children:[a.jsx(Xr,{className:"w-3 h-3"}),"Admin"]})]})]}),y&&a.jsxs("div",{className:"mb-3 px-2 py-1.5 bg-bambu-dark rounded-lg",children:[a.jsx("span",{className:"text-xs text-bambu-gray",children:"Linked to: "}),a.jsx("span",{className:"text-sm text-white",children:y.name})]}),(t.power_alert_enabled||t.schedule_enabled||t.plug_type==="mqtt")&&a.jsxs("div",{className:"flex flex-wrap gap-1.5 mb-3",children:[t.plug_type==="mqtt"&&a.jsxs("span",{className:"flex items-center gap-1 px-2 py-0.5 bg-teal-500/20 text-teal-400 text-xs rounded-full",children:[a.jsx(xc,{className:"w-3 h-3"}),"Monitor Only"]}),t.power_alert_enabled&&a.jsxs("span",{className:"flex items-center gap-1 px-2 py-0.5 bg-yellow-500/20 text-yellow-400 text-xs rounded-full",children:[a.jsx(Sg,{className:"w-3 h-3"}),"Alerts"]}),t.schedule_enabled&&a.jsxs("span",{className:"flex items-center gap-1 px-2 py-0.5 bg-blue-500/20 text-blue-400 text-xs rounded-full",children:[a.jsx(ti,{className:"w-3 h-3"}),t.schedule_on_time&&t.schedule_off_time?`${t.schedule_on_time} - ${t.schedule_off_time}`:t.schedule_on_time?`On ${t.schedule_on_time}`:`Off ${t.schedule_off_time}`]})]}),t.plug_type!=="mqtt"&&a.jsxs("div",{className:"flex gap-2 mb-3",children:[a.jsxs(Te,{size:"sm",variant:N?"primary":"secondary",disabled:!k||C,onClick:()=>l(!0),className:"flex-1",children:[C?a.jsx(pt,{className:"w-4 h-4 animate-spin"}):a.jsx(qu,{className:"w-4 h-4"}),"On"]}),a.jsxs(Te,{size:"sm",variant:N?"secondary":"primary",disabled:!k||C,onClick:()=>u(!0),className:"flex-1",children:[C?a.jsx(pt,{className:"w-4 h-4 animate-spin"}):a.jsx(bM,{className:"w-4 h-4"}),"Off"]})]}),t.plug_type==="mqtt"&&p?.energy&&a.jsxs("div",{className:"flex gap-2 mb-3 px-3 py-2 bg-bambu-dark rounded-lg",children:[p.energy.power!==null&&p.energy.power!==void 0&&a.jsxs("div",{className:"flex-1 text-center",children:[a.jsxs("p",{className:"text-lg font-semibold text-white",children:[Math.round(p.energy.power),"W"]}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Power"})]}),p.energy.today!==null&&p.energy.today!==void 0&&a.jsxs("div",{className:"flex-1 text-center border-l border-bambu-dark-tertiary",children:[a.jsx("p",{className:"text-lg font-semibold text-white",children:p.energy.today.toFixed(2)}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"kWh Today"})]})]}),a.jsxs("button",{onClick:()=>h(!d),className:"w-full flex items-center justify-between py-2 text-sm text-bambu-gray hover:text-white transition-colors",children:[a.jsxs("span",{className:"flex items-center gap-2",children:[a.jsx(vh,{className:"w-4 h-4"}),t.plug_type==="mqtt"?"Settings":"Automation Settings"]}),a.jsx("span",{children:d?"-":"+"})]}),d&&a.jsxs("div",{className:"pt-3 border-t border-bambu-dark-tertiary space-y-4",children:[a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(pM,{className:"w-4 h-4 text-bambu-green"}),a.jsxs("div",{children:[a.jsx("p",{className:"text-sm text-white",children:"Show in Switchbar"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Quick access from sidebar"})]})]}),a.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:t.show_in_switchbar,onChange:A=>b.mutate({show_in_switchbar:A.target.checked}),className:"sr-only peer"}),a.jsx("div",{className:"w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green"})]})]}),t.plug_type!=="mqtt"&&a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-sm text-white",children:"Enabled"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Enable automation for this plug"})]}),a.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:t.enabled,onChange:A=>b.mutate({enabled:A.target.checked}),className:"sr-only peer"}),a.jsx("div",{className:"w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green"})]})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-sm text-white",children:"Auto On"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Turn on when print starts"})]}),a.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:t.auto_on,onChange:A=>b.mutate({auto_on:A.target.checked}),className:"sr-only peer"}),a.jsx("div",{className:"w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green"})]})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-sm text-white",children:"Auto Off"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Turn off when print completes (one-shot)"})]}),a.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:t.auto_off,onChange:A=>b.mutate({auto_off:A.target.checked}),className:"sr-only peer"}),a.jsx("div",{className:"w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green"})]})]}),t.auto_off&&a.jsxs("div",{className:"space-y-3 pl-4 border-l-2 border-bambu-dark-tertiary",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-sm text-white mb-2",children:"Turn Off Delay Mode"}),a.jsxs("div",{className:"flex gap-2",children:[a.jsxs("button",{onClick:()=>b.mutate({off_delay_mode:"time"}),className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 rounded-lg text-sm transition-colors ${t.off_delay_mode==="time"?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white"}`,children:[a.jsx(tr,{className:"w-4 h-4"}),"Time"]}),a.jsxs("button",{onClick:()=>b.mutate({off_delay_mode:"temperature"}),className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 rounded-lg text-sm transition-colors ${t.off_delay_mode==="temperature"?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white"}`,children:[a.jsx(vM,{className:"w-4 h-4"}),"Temp"]})]})]}),t.off_delay_mode==="time"?a.jsxs("div",{children:[a.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Delay (minutes)"}),a.jsx("input",{type:"number",min:"1",max:"60",value:t.off_delay_minutes,onChange:A=>b.mutate({off_delay_minutes:parseInt(A.target.value)||5}),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"})]}):a.jsxs("div",{children:[a.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Temperature threshold (C)"}),a.jsx("input",{type:"number",min:"30",max:"100",value:t.off_temp_threshold,onChange:A=>b.mutate({off_temp_threshold:parseInt(A.target.value)||70}),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"}),a.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Turns off when nozzle cools below this temperature"})]})]})]}),a.jsxs("div",{className:"flex gap-2 pt-2",children:[a.jsxs(Te,{size:"sm",variant:"secondary",onClick:()=>e(t),className:"flex-1",children:[a.jsx(mg,{className:"w-4 h-4"}),"Edit"]}),a.jsx(Te,{size:"sm",variant:"secondary",onClick:()=>s(!0),className:"text-red-400 hover:text-red-300",children:a.jsx(an,{className:"w-4 h-4"})})]})]})]})}),i&&a.jsx(Zn,{title:"Delete Smart Plug",message:`Are you sure you want to delete "${t.name}"? This cannot be undone.`,confirmText:"Delete",variant:"danger",onConfirm:()=>{S.mutate(),s(!1)},onCancel:()=>s(!1)}),o&&a.jsx(Zn,{title:"Turn On Smart Plug",message:`Are you sure you want to turn on "${t.name}"?`,confirmText:"Turn On",variant:"default",onConfirm:()=>{v.mutate("on"),l(!1)},onCancel:()=>l(!1)}),c&&a.jsx(Zn,{title:"Turn Off Smart Plug",message:`Are you sure you want to turn off "${t.name}"? This will cut power to the connected device.`,confirmText:"Turn Off",variant:"danger",onConfirm:()=>{v.mutate("off"),u(!1)},onCancel:()=>u(!1)})]})}function MKe({plug:t,onClose:e}){const n=sn(),r=!!t,[i,s]=_.useState(t?.plug_type||"tasmota"),[o,l]=_.useState(t?.name||""),[c,u]=_.useState(t?.ip_address||""),[d,h]=_.useState(t?.username||""),[p,m]=_.useState(t?.password||""),[x,y]=_.useState(t?.ha_entity_id||""),[v,b]=_.useState(t?.mqtt_power_topic||t?.mqtt_topic||""),[S,N]=_.useState(t?.mqtt_power_path||""),[T,k]=_.useState((t?.mqtt_power_multiplier??t?.mqtt_multiplier??1).toString()),[C,E]=_.useState(t?.mqtt_energy_topic||""),[P,A]=_.useState(t?.mqtt_energy_path||""),[D,I]=_.useState((t?.mqtt_energy_multiplier??1).toString()),[L,U]=_.useState(t?.mqtt_state_topic||""),[j,$]=_.useState(t?.mqtt_state_path||""),[K,B]=_.useState(t?.mqtt_state_on_value||""),[X,Y]=_.useState(t?.ha_power_entity||""),[ne,H]=_.useState(t?.ha_energy_today_entity||""),[W,re]=_.useState(t?.ha_energy_total_entity||""),[ie,pe]=_.useState(""),[me,de]=_.useState(""),[Ee,se]=_.useState(!1),Ae=_.useRef(null),[Fe,ge]=_.useState(""),[Ze,G]=_.useState(!1),Q=_.useRef(null),[he,q]=_.useState(""),[ee,V]=_.useState(!1),ye=_.useRef(null),[je,te]=_.useState(""),[z,O]=_.useState(!1),Z=_.useRef(null),[oe,we]=_.useState(t?.printer_id||null),[_e,ae]=_.useState(null),[Le,Be]=_.useState(null),[Ve,He]=_.useState(t?.power_alert_enabled||!1),[xe,Pe]=_.useState(t?.power_alert_high?.toString()||""),[Ie,Se]=_.useState(t?.power_alert_low?.toString()||""),[Ke,Me]=_.useState(t?.schedule_enabled||!1),[it,ke]=_.useState(t?.schedule_on_time||""),[Xe,ze]=_.useState(t?.schedule_off_time||""),[ue,$e]=_.useState(t?.show_in_switchbar||!1),[be,Je]=_.useState(t?.show_on_printer_card??!0),[at,jt]=_.useState(!1),[Dt,yn]=_.useState({scanned:0,total:0}),[cn,rr]=_.useState([]),Vn=_.useRef(null),{data:Jn}=ct({queryKey:["printers"],queryFn:ce.getPrinters}),{data:xn}=ct({queryKey:["smart-plugs"],queryFn:ce.getSmartPlugs}),{data:sr}=ct({queryKey:["settings"],queryFn:ce.getSettings}),Gn=!!(sr?.ha_enabled&&sr?.ha_url&&sr?.ha_token);_.useEffect(()=>{const Ne=setTimeout(()=>{de(ie)},300);return()=>clearTimeout(Ne)},[ie]),_.useEffect(()=>{const Ne=Oe=>{Ae.current&&!Ae.current.contains(Oe.target)&&se(!1),Q.current&&!Q.current.contains(Oe.target)&&G(!1),ye.current&&!ye.current.contains(Oe.target)&&V(!1),Z.current&&!Z.current.contains(Oe.target)&&O(!1)};return document.addEventListener("mousedown",Ne),()=>document.removeEventListener("mousedown",Ne)},[]);const{data:Xn,isLoading:Nn,error:hi}=ct({queryKey:["ha-entities",me],queryFn:()=>ce.getHAEntities(me||void 0),enabled:i==="homeassistant"&&Gn,retry:!1,staleTime:0}),{data:ai}=ct({queryKey:["ha-sensor-entities"],queryFn:ce.getHASensorEntities,enabled:i==="homeassistant"&&Gn,retry:!1,staleTime:0});_.useEffect(()=>{const Ne=Oe=>{Oe.key==="Escape"&&e()};return window.addEventListener("keydown",Ne),()=>{window.removeEventListener("keydown",Ne),Vn.current&&clearInterval(Vn.current)}},[e]);const Ce=async()=>{jt(!0),rr([]),yn({scanned:0,total:0}),Be(null);try{await ce.startTasmotaScan();const Ne=async()=>{try{const Oe=await ce.getTasmotaScanStatus();yn({scanned:Oe.scanned,total:Oe.total});const nt=await ce.getDiscoveredTasmotaDevices();rr(nt),Oe.running||(jt(!1),Vn.current&&(clearInterval(Vn.current),Vn.current=null))}catch(Oe){console.error("Polling error:",Oe)}};await Ne(),Vn.current=setInterval(Ne,500)}catch(Ne){jt(!1);const Oe=Ne instanceof Error?Ne.message:typeof Ne=="string"?Ne:JSON.stringify(Ne);Be(Oe||"Failed to start scan")}},tt=async()=>{try{await ce.stopTasmotaScan()}catch{}jt(!1),Vn.current&&(clearInterval(Vn.current),Vn.current=null)},dt=Ne=>{u(Ne.ip_address),l(Ne.name),ae(null)},ht=gt({mutationFn:()=>ce.testSmartPlugConnection(c,d||null,p||null),onSuccess:Ne=>{ae(Ne),Be(null),!o&&Ne.device_name&&l(Ne.device_name)},onError:Ne=>{ae(null),Be(Ne.message)}}),ut=gt({mutationFn:Ne=>ce.createSmartPlug(Ne),onSuccess:()=>{n.invalidateQueries({queryKey:["smart-plugs"]}),n.invalidateQueries({queryKey:["scriptPlugsByPrinter"]}),e()},onError:Ne=>{Be(Ne.message)}}),Et=gt({mutationFn:Ne=>ce.updateSmartPlug(t.id,Ne),onSuccess:()=>{n.invalidateQueries({queryKey:["smart-plugs"]}),n.invalidateQueries({queryKey:["scriptPlugsByPrinter"]}),e()},onError:Ne=>{Be(Ne.message)}}),fe=Jn?.filter(Ne=>i==="tasmota"?!xn?.some(nt=>nt.printer_id===Ne.id&&nt.id!==t?.id&&nt.plug_type==="tasmota"):!0),Re=Ne=>{if(Ne.preventDefault(),Be(null),!o.trim()){Be("Name is required");return}if(i==="tasmota"&&!c.trim()){Be("IP address is required for Tasmota plugs");return}if(i==="homeassistant"&&!x){Be("Entity is required for Home Assistant plugs");return}if(i==="mqtt"){const nt=v.trim(),Ye=C.trim(),Tt=L.trim();if(!nt&&!Ye&&!Tt){Be("At least one MQTT topic must be configured for power, energy, or state monitoring");return}}const Oe={name:o.trim(),plug_type:i,ip_address:i==="tasmota"?c.trim():null,ha_entity_id:i==="homeassistant"?x:null,ha_power_entity:i==="homeassistant"&&X||null,ha_energy_today_entity:i==="homeassistant"&&ne||null,ha_energy_total_entity:i==="homeassistant"&&W||null,mqtt_power_topic:i==="mqtt"&&v.trim()||null,mqtt_power_path:i==="mqtt"&&S.trim()||null,mqtt_power_multiplier:i==="mqtt"&&parseFloat(T)||1,mqtt_energy_topic:i==="mqtt"&&C.trim()||null,mqtt_energy_path:i==="mqtt"&&P.trim()||null,mqtt_energy_multiplier:i==="mqtt"&&parseFloat(D)||1,mqtt_state_topic:i==="mqtt"&&L.trim()||null,mqtt_state_path:i==="mqtt"&&j.trim()||null,mqtt_state_on_value:i==="mqtt"&&K.trim()||null,username:i==="tasmota"&&d.trim()||null,password:i==="tasmota"&&p.trim()||null,printer_id:oe,power_alert_enabled:Ve,power_alert_high:xe?parseFloat(xe):null,power_alert_low:Ie?parseFloat(Ie):null,schedule_enabled:Ke,schedule_on_time:it||null,schedule_off_time:Xe||null,show_in_switchbar:ue,show_on_printer_card:be};r?Et.mutate(Oe):ut.mutate(Oe)},Ge=ut.isPending||Et.isPending;return a.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",onClick:e,children:a.jsxs("div",{className:"bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-md max-h-[90vh] flex flex-col",onClick:Ne=>Ne.stopPropagation(),children:[a.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary flex-shrink-0",children:[a.jsx("h2",{className:"text-lg font-semibold text-white",children:r?"Edit Smart Plug":"Add Smart Plug"}),a.jsx("button",{onClick:e,className:"text-bambu-gray hover:text-white transition-colors",children:a.jsx(Lt,{className:"w-5 h-5"})})]}),a.jsxs("form",{onSubmit:Re,className:"p-6 space-y-4 overflow-y-auto",children:[Le&&a.jsx("div",{className:"p-3 bg-red-500/20 border border-red-500/50 rounded-lg text-sm text-red-400",children:Le}),!r&&a.jsxs("div",{className:"flex gap-2 mb-2",children:[a.jsxs("button",{type:"button",onClick:()=>{s("tasmota"),ae(null),Be(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2.5 rounded-lg font-medium transition-colors ${i==="tasmota"?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white border border-bambu-dark-tertiary"}`,children:[a.jsx(al,{className:"w-4 h-4"}),"Tasmota"]}),a.jsxs("button",{type:"button",onClick:()=>{s("homeassistant"),ae(null),Be(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2.5 rounded-lg font-medium transition-colors ${i==="homeassistant"?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white border border-bambu-dark-tertiary"}`,children:[a.jsx(Iy,{className:"w-4 h-4"}),"HA"]}),a.jsxs("button",{type:"button",onClick:()=>{s("mqtt"),ae(null),Be(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2.5 rounded-lg font-medium transition-colors ${i==="mqtt"?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white border border-bambu-dark-tertiary"}`,children:[a.jsx(RR,{className:"w-4 h-4"}),"MQTT"]})]}),!r&&i==="tasmota"&&a.jsxs("div",{className:"space-y-3",children:[at?a.jsxs(Te,{type:"button",variant:"secondary",onClick:tt,className:"w-full",children:[a.jsx(Lt,{className:"w-4 h-4"}),"Stop Scanning"]}):a.jsxs(Te,{type:"button",variant:"primary",onClick:Ce,className:"w-full",children:[a.jsx(wa,{className:"w-4 h-4"}),"Discover Tasmota Devices"]}),at&&Dt.total>0&&a.jsxs("div",{className:"space-y-1",children:[a.jsxs("div",{className:"flex justify-between text-xs text-bambu-gray",children:[a.jsx("span",{children:"Scanning network..."}),a.jsxs("span",{children:[Dt.scanned," / ",Dt.total]})]}),a.jsx("div",{className:"w-full bg-bambu-dark-tertiary rounded-full h-2",children:a.jsx("div",{className:"bg-bambu-green h-2 rounded-full transition-all duration-300",style:{width:`${Dt.scanned/Dt.total*100}%`}})})]}),cn.length>0&&a.jsxs("div",{className:"space-y-2",children:[a.jsxs("p",{className:"text-xs text-bambu-gray",children:["Found ",cn.length," device(s) - click to select:"]}),a.jsx("div",{className:"max-h-40 overflow-y-auto space-y-1",children:cn.map(Ne=>a.jsxs("button",{type:"button",onClick:()=>dt(Ne),className:"w-full flex items-center justify-between p-2 bg-bambu-dark hover:bg-bambu-dark-tertiary rounded-lg transition-colors text-left border border-bambu-dark-tertiary",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(al,{className:"w-4 h-4 text-bambu-green"}),a.jsxs("div",{children:[a.jsx("p",{className:"text-sm text-white",children:Ne.name}),a.jsx("p",{className:"text-xs text-bambu-gray",children:Ne.ip_address})]})]}),Ne.state&&a.jsxs("span",{className:`flex items-center gap-1 text-xs ${Ne.state==="ON"?"text-bambu-green":"text-bambu-gray"}`,children:[a.jsx(qu,{className:"w-3 h-3"}),Ne.state]})]},Ne.ip_address))})]}),!at&&cn.length===0&&Dt.total>0&&a.jsx("p",{className:"text-xs text-bambu-gray text-center py-2",children:"No Tasmota devices found on your network"})]}),i==="homeassistant"&&a.jsxs("div",{className:"space-y-3",children:[!Gn&&a.jsxs("div",{className:"space-y-3",children:[a.jsxs("div",{className:"p-3 bg-yellow-500/20 border border-yellow-500/50 rounded-lg text-sm text-yellow-400",children:["Home Assistant is not configured. Set it up in"," ",a.jsx("span",{className:"font-medium",children:"Settings → Network → Home Assistant"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1 opacity-50",children:"Select Entity *"}),a.jsx("select",{disabled:!0,className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray cursor-not-allowed opacity-50",children:a.jsx("option",{children:"Choose an entity..."})})]})]}),Gn&&a.jsxs(a.Fragment,{children:[Nn&&a.jsxs("div",{className:"flex items-center justify-center py-4 text-bambu-gray",children:[a.jsx(pt,{className:"w-5 h-5 animate-spin mr-2"}),"Loading entities..."]}),hi&&a.jsxs("div",{className:"p-3 bg-red-500/20 border border-red-500/50 rounded-lg text-sm text-red-400",children:["Failed to load entities: ",hi.message]}),(()=>{const Ne=xn?.filter(Ye=>Ye.ha_entity_id&&Ye.id!==t?.id).map(Ye=>Ye.ha_entity_id)||[],Oe=(Xn||[]).filter(Ye=>!Ne.includes(Ye.entity_id)),nt=Xn?.find(Ye=>Ye.entity_id===x);return a.jsxs("div",{ref:Ae,className:"relative",children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Select Entity *"}),a.jsxs("div",{className:"relative",children:[a.jsx(wa,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"}),a.jsx("input",{type:"text",value:Ee?ie:nt?`${nt.friendly_name} (${nt.entity_id})`:"",onChange:Ye=>{pe(Ye.target.value),Ee||se(!0)},onFocus:()=>{se(!0),pe("")},placeholder:"Search entities...",className:"w-full pl-9 pr-8 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none"}),x&&!Ee&&a.jsx("button",{type:"button",onClick:()=>{y(""),pe("")},className:"absolute right-2 top-1/2 -translate-y-1/2 p-1 hover:bg-bambu-dark-tertiary rounded",children:a.jsx(Lt,{className:"w-4 h-4 text-bambu-gray hover:text-white"})}),Nn&&a.jsx(pt,{className:"absolute right-2 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray animate-spin"})]}),Ee&&a.jsxs("div",{className:"absolute z-50 w-full mt-1 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-60 overflow-y-auto",children:[Nn&&a.jsxs("div",{className:"px-3 py-2 text-sm text-bambu-gray flex items-center gap-2",children:[a.jsx(pt,{className:"w-4 h-4 animate-spin"}),"Loading..."]}),!Nn&&Oe.length===0&&a.jsx("div",{className:"px-3 py-2 text-sm text-bambu-gray",children:me?`No entities found matching "${me}"`:"No entities available"}),!Nn&&Oe.map(Ye=>a.jsxs("button",{type:"button",onClick:()=>{y(Ye.entity_id),se(!1),pe(""),o||l(Ye.friendly_name)},className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary transition-colors ${Ye.entity_id===x?"bg-bambu-green/20 text-bambu-green":"text-white"}`,children:[a.jsx("div",{className:"font-medium",children:Ye.friendly_name}),a.jsxs("div",{className:"text-xs text-bambu-gray flex items-center justify-between",children:[a.jsx("span",{children:Ye.entity_id}),a.jsx("span",{className:Ye.state==="on"?"text-bambu-green":"",children:Ye.state})]})]},Ye.entity_id))]}),a.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:me?`Searching all entities (${Oe.length} found)`:`Showing switch, light, input_boolean (${Oe.length} available)`})]})})(),x&&ai&&ai.length>0&&a.jsxs("div",{className:"border-t border-bambu-dark-tertiary pt-4 mt-4 space-y-3",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-white font-medium mb-1",children:"Energy Monitoring (Optional)"}),a.jsx("p",{className:"text-xs text-bambu-gray mb-3",children:"Search and select sensors that provide power/energy data."})]}),(()=>{const Ne=ai.filter(Ye=>Ye.unit_of_measurement==="W"||Ye.unit_of_measurement==="kW"||Ye.unit_of_measurement==="mW"),Oe=Fe?Ne.filter(Ye=>Ye.entity_id.toLowerCase().includes(Fe.toLowerCase())||Ye.friendly_name.toLowerCase().includes(Fe.toLowerCase())):Ne,nt=ai.find(Ye=>Ye.entity_id===X);return a.jsxs("div",{ref:Q,className:"relative",children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Power Sensor (W)"}),a.jsxs("div",{className:"relative",children:[a.jsx(wa,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"}),a.jsx("input",{type:"text",value:Ze?Fe:nt?`${nt.friendly_name} (${nt.state} ${nt.unit_of_measurement})`:"",onChange:Ye=>{ge(Ye.target.value),Ze||G(!0)},onFocus:()=>{G(!0),ge("")},placeholder:"Search power sensors...",className:"w-full pl-9 pr-8 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none"}),X&&!Ze&&a.jsx("button",{type:"button",onClick:()=>{Y(""),ge("")},className:"absolute right-2 top-1/2 -translate-y-1/2 p-1 hover:bg-bambu-dark-tertiary rounded",children:a.jsx(Lt,{className:"w-4 h-4 text-bambu-gray hover:text-white"})})]}),Ze&&a.jsxs("div",{className:"absolute z-50 w-full mt-1 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-48 overflow-y-auto",children:[a.jsx("button",{type:"button",onClick:()=>{Y(""),G(!1),ge("")},className:"w-full px-3 py-2 text-left text-sm text-bambu-gray hover:bg-bambu-dark-tertiary",children:"None"}),Oe.map(Ye=>a.jsxs("button",{type:"button",onClick:()=>{Y(Ye.entity_id),G(!1),ge("")},className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary ${Ye.entity_id===X?"bg-bambu-green/20 text-bambu-green":"text-white"}`,children:[a.jsx("div",{className:"font-medium",children:Ye.friendly_name}),a.jsxs("div",{className:"text-xs text-bambu-gray",children:[Ye.entity_id," • ",Ye.state," ",Ye.unit_of_measurement]})]},Ye.entity_id)),Oe.length===0&&a.jsx("div",{className:"px-3 py-2 text-sm text-bambu-gray",children:"No matching sensors"})]})]})})(),(()=>{const Ne=ai.filter(Ye=>Ye.unit_of_measurement==="kWh"||Ye.unit_of_measurement==="Wh"||Ye.unit_of_measurement==="MWh"),Oe=he?Ne.filter(Ye=>Ye.entity_id.toLowerCase().includes(he.toLowerCase())||Ye.friendly_name.toLowerCase().includes(he.toLowerCase())):Ne,nt=ai.find(Ye=>Ye.entity_id===ne);return a.jsxs("div",{ref:ye,className:"relative",children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Energy Today (kWh)"}),a.jsxs("div",{className:"relative",children:[a.jsx(wa,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"}),a.jsx("input",{type:"text",value:ee?he:nt?`${nt.friendly_name} (${nt.state} ${nt.unit_of_measurement})`:"",onChange:Ye=>{q(Ye.target.value),ee||V(!0)},onFocus:()=>{V(!0),q("")},placeholder:"Search energy sensors...",className:"w-full pl-9 pr-8 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none"}),ne&&!ee&&a.jsx("button",{type:"button",onClick:()=>{H(""),q("")},className:"absolute right-2 top-1/2 -translate-y-1/2 p-1 hover:bg-bambu-dark-tertiary rounded",children:a.jsx(Lt,{className:"w-4 h-4 text-bambu-gray hover:text-white"})})]}),ee&&a.jsxs("div",{className:"absolute z-50 w-full mt-1 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-48 overflow-y-auto",children:[a.jsx("button",{type:"button",onClick:()=>{H(""),V(!1),q("")},className:"w-full px-3 py-2 text-left text-sm text-bambu-gray hover:bg-bambu-dark-tertiary",children:"None"}),Oe.map(Ye=>a.jsxs("button",{type:"button",onClick:()=>{H(Ye.entity_id),V(!1),q("")},className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary ${Ye.entity_id===ne?"bg-bambu-green/20 text-bambu-green":"text-white"}`,children:[a.jsx("div",{className:"font-medium",children:Ye.friendly_name}),a.jsxs("div",{className:"text-xs text-bambu-gray",children:[Ye.entity_id," • ",Ye.state," ",Ye.unit_of_measurement]})]},Ye.entity_id)),Oe.length===0&&a.jsx("div",{className:"px-3 py-2 text-sm text-bambu-gray",children:"No matching sensors"})]})]})})(),(()=>{const Ne=ai.filter(Ye=>Ye.unit_of_measurement==="kWh"||Ye.unit_of_measurement==="Wh"||Ye.unit_of_measurement==="MWh"),Oe=je?Ne.filter(Ye=>Ye.entity_id.toLowerCase().includes(je.toLowerCase())||Ye.friendly_name.toLowerCase().includes(je.toLowerCase())):Ne,nt=ai.find(Ye=>Ye.entity_id===W);return a.jsxs("div",{ref:Z,className:"relative",children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Total Energy (kWh)"}),a.jsxs("div",{className:"relative",children:[a.jsx(wa,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"}),a.jsx("input",{type:"text",value:z?je:nt?`${nt.friendly_name} (${nt.state} ${nt.unit_of_measurement})`:"",onChange:Ye=>{te(Ye.target.value),z||O(!0)},onFocus:()=>{O(!0),te("")},placeholder:"Search energy sensors...",className:"w-full pl-9 pr-8 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none"}),W&&!z&&a.jsx("button",{type:"button",onClick:()=>{re(""),te("")},className:"absolute right-2 top-1/2 -translate-y-1/2 p-1 hover:bg-bambu-dark-tertiary rounded",children:a.jsx(Lt,{className:"w-4 h-4 text-bambu-gray hover:text-white"})})]}),z&&a.jsxs("div",{className:"absolute z-50 w-full mt-1 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-48 overflow-y-auto",children:[a.jsx("button",{type:"button",onClick:()=>{re(""),O(!1),te("")},className:"w-full px-3 py-2 text-left text-sm text-bambu-gray hover:bg-bambu-dark-tertiary",children:"None"}),Oe.map(Ye=>a.jsxs("button",{type:"button",onClick:()=>{re(Ye.entity_id),O(!1),te("")},className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary ${Ye.entity_id===W?"bg-bambu-green/20 text-bambu-green":"text-white"}`,children:[a.jsx("div",{className:"font-medium",children:Ye.friendly_name}),a.jsxs("div",{className:"text-xs text-bambu-gray",children:[Ye.entity_id," • ",Ye.state," ",Ye.unit_of_measurement]})]},Ye.entity_id)),Oe.length===0&&a.jsx("div",{className:"px-3 py-2 text-sm text-bambu-gray",children:"No matching sensors"})]})]})})()]})]})]}),i==="mqtt"&&a.jsxs("div",{className:"space-y-3",children:[!sr?.mqtt_broker&&a.jsxs("div",{className:"p-3 bg-yellow-500/20 border border-yellow-500/50 rounded-lg text-sm text-yellow-400",children:["MQTT broker not configured. Set broker address in"," ",a.jsx("span",{className:"font-medium",children:"Settings → Network → MQTT Publishing"})," ","(you don't need to enable publishing, just fill in the broker details)."]}),sr?.mqtt_broker&&a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:"p-3 bg-blue-500/10 border border-blue-500/30 rounded-lg text-sm text-blue-300",children:[a.jsx("p",{className:"font-medium mb-1",children:"Monitor Only"}),a.jsx("p",{className:"text-xs opacity-80",children:"MQTT plugs receive power/energy data via MQTT subscription. On/off control is not available - use your MQTT broker or home automation system."})]}),a.jsxs("div",{className:"space-y-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary",children:[a.jsx("p",{className:"text-white font-medium text-sm",children:"Power Monitoring"}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Topic"}),a.jsx("input",{type:"text",value:v,onChange:Ne=>b(Ne.target.value),placeholder:"zigbee2mqtt/shelly-working-room",className:"w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none"})]}),a.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"JSON Path"}),a.jsx("input",{type:"text",value:S,onChange:Ne=>N(Ne.target.value),placeholder:"power_l1",className:"w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Multiplier"}),a.jsx("input",{type:"text",value:T,onChange:Ne=>k(Ne.target.value),placeholder:"1",className:"w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none"})]})]}),a.jsxs("p",{className:"text-xs text-bambu-gray",children:['JSON path extracts value from JSON payload (e.g., "power_l1"). Leave empty if topic publishes raw numeric values.',a.jsx("br",{}),"Use multiplier 0.001 for mW→W, 1000 for kW→W."]})]}),a.jsxs("div",{className:"space-y-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary",children:[a.jsxs("p",{className:"text-white font-medium text-sm",children:["Energy Monitoring ",a.jsx("span",{className:"text-bambu-gray font-normal",children:"(optional)"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Topic"}),a.jsx("input",{type:"text",value:C,onChange:Ne=>E(Ne.target.value),placeholder:"Same as power topic, or different",className:"w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none"})]}),a.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"JSON Path"}),a.jsx("input",{type:"text",value:P,onChange:Ne=>A(Ne.target.value),placeholder:"energy_l1",className:"w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Multiplier"}),a.jsx("input",{type:"text",value:D,onChange:Ne=>I(Ne.target.value),placeholder:"1",className:"w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none"})]})]}),a.jsxs("p",{className:"text-xs text-bambu-gray",children:["JSON path extracts value from JSON payload. Leave empty for raw values.",a.jsx("br",{}),"Use multiplier 0.001 for Wh→kWh, 1000 for MWh→kWh."]})]}),a.jsxs("div",{className:"space-y-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary",children:[a.jsxs("p",{className:"text-white font-medium text-sm",children:["State Monitoring ",a.jsx("span",{className:"text-bambu-gray font-normal",children:"(optional)"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Topic"}),a.jsx("input",{type:"text",value:L,onChange:Ne=>U(Ne.target.value),placeholder:"Same as power topic, or different",className:"w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none"})]}),a.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"JSON Path"}),a.jsx("input",{type:"text",value:j,onChange:Ne=>$(Ne.target.value),placeholder:"state_l1",className:"w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"ON Value"}),a.jsx("input",{type:"text",value:K,onChange:Ne=>B(Ne.target.value),placeholder:"ON, true, 1",className:"w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none"})]})]}),a.jsxs("p",{className:"text-xs text-bambu-gray",children:["JSON path extracts value from JSON payload. Leave empty for raw values.",a.jsx("br",{}),'ON value: the exact string that means "ON". Leave empty for auto-detect (ON, true, 1).']})]})]})]}),i==="tasmota"&&a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"IP Address *"}),a.jsxs("div",{className:"flex gap-2",children:[a.jsx("input",{type:"text",value:c,onChange:Ne=>{u(Ne.target.value),ae(null)},placeholder:"192.168.1.100",className:"flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"}),a.jsxs(Te,{type:"button",variant:"secondary",onClick:()=>ht.mutate(),disabled:!c.trim()||ht.isPending,children:[ht.isPending?a.jsx(pt,{className:"w-4 h-4 animate-spin"}):a.jsx(Mg,{className:"w-4 h-4"}),"Test"]})]})]}),i==="tasmota"&&_e&&a.jsx("div",{className:`p-3 rounded-lg flex items-center gap-2 ${_e.success?"bg-bambu-green/20 border border-bambu-green/50 text-bambu-green":"bg-red-500/20 border border-red-500/50 text-red-400"}`,children:_e.success?a.jsxs(a.Fragment,{children:[a.jsx(Ar,{className:"w-5 h-5"}),a.jsxs("div",{children:[a.jsx("p",{className:"font-medium",children:"Connected!"}),a.jsxs("p",{className:"text-sm opacity-80",children:[_e.device_name&&`Device: ${_e.device_name} - `,"State: ",_e.state]})]})]}):a.jsxs(a.Fragment,{children:[a.jsx(lm,{className:"w-5 h-5"}),a.jsx("span",{children:"Connection failed"})]})}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Name *"}),a.jsx("input",{type:"text",value:o,onChange:Ne=>l(Ne.target.value),placeholder:"Living Room Plug",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"})]}),i==="tasmota"&&a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Username"}),a.jsx("input",{type:"text",value:d,onChange:Ne=>h(Ne.target.value),placeholder:"admin",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"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Password"}),a.jsx("input",{type:"password",value:p,onChange:Ne=>m(Ne.target.value),placeholder:"********",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"})]})]}),a.jsx("p",{className:"text-xs text-bambu-gray -mt-2",children:"Leave empty if your Tasmota device doesn't require authentication"})]}),i!=="mqtt"&&a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Link to Printer"}),a.jsxs("select",{value:oe??"",onChange:Ne=>we(Ne.target.value?Number(Ne.target.value):null),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[a.jsx("option",{value:"",children:"No printer (manual control only)"}),fe?.map(Ne=>a.jsx("option",{value:Ne.id,children:Ne.name},Ne.id))]}),a.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Linking enables automatic on/off when prints start/complete"})]}),a.jsxs("div",{className:"border-t border-bambu-dark-tertiary pt-4",children:[a.jsxs("div",{className:"flex items-center justify-between mb-3",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(Sg,{className:"w-4 h-4 text-bambu-green"}),a.jsx("span",{className:"text-white font-medium",children:"Power Alerts"})]}),a.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:Ve,onChange:Ne=>He(Ne.target.checked),className:"sr-only peer"}),a.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]}),Ve&&a.jsxs("div",{className:"space-y-3",children:[a.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Alert if above (W)"}),a.jsx("input",{type:"number",value:xe,onChange:Ne=>Pe(Ne.target.value),placeholder:"e.g. 200",min:"0",max:"5000",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"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Alert if below (W)"}),a.jsx("input",{type:"number",value:Ie,onChange:Ne=>Se(Ne.target.value),placeholder:"e.g. 10",min:"0",max:"5000",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"})]})]}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Get notified when power consumption crosses these thresholds. Leave empty to disable that direction."})]})]}),i!=="mqtt"&&a.jsxs("div",{className:"border-t border-bambu-dark-tertiary pt-4",children:[a.jsxs("div",{className:"flex items-center justify-between mb-3",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(tr,{className:"w-4 h-4 text-bambu-green"}),a.jsx("span",{className:"text-white font-medium",children:"Daily Schedule"})]}),a.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:Ke,onChange:Ne=>Me(Ne.target.checked),className:"sr-only peer"}),a.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]}),Ke&&a.jsxs("div",{className:"space-y-3",children:[a.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Turn On at"}),a.jsx("input",{type:"time",value:it,onChange:Ne=>ke(Ne.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"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Turn Off at"}),a.jsx("input",{type:"time",value:Xe,onChange:Ne=>ze(Ne.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"})]})]}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Automatically turn the plug on/off at these times daily. Leave empty to skip that action."})]})]}),a.jsx("div",{className:"border-t border-bambu-dark-tertiary pt-4",children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(pM,{className:"w-4 h-4 text-bambu-green"}),a.jsxs("div",{children:[a.jsx("span",{className:"text-white font-medium",children:"Show in Switchbar"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Quick access from sidebar"})]})]}),a.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:ue,onChange:Ne=>$e(Ne.target.checked),className:"sr-only peer"}),a.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]})}),i==="homeassistant"&&a.jsx("div",{className:"border-t border-bambu-dark-tertiary pt-4",children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(xc,{className:"w-4 h-4 text-bambu-green"}),a.jsxs("div",{children:[a.jsx("span",{className:"text-white font-medium",children:"Show on Printer Card"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Display button on printer card"})]})]}),a.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:be,onChange:Ne=>Je(Ne.target.checked),className:"sr-only peer"}),a.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]})}),a.jsxs("div",{className:"flex gap-3 pt-2",children:[a.jsx(Te,{type:"button",variant:"secondary",onClick:e,className:"flex-1",children:"Cancel"}),a.jsxs(Te,{type:"submit",disabled:Ge,className:"flex-1",children:[Ge?a.jsx(pt,{className:"w-4 h-4 animate-spin"}):a.jsx(ms,{className:"w-4 h-4"}),r?"Save":"Add"]})]})]})]})})}function Fn({checked:t,onChange:e,disabled:n}){const r=i=>{i.preventDefault(),i.stopPropagation(),n||e(!t)};return a.jsx("button",{type:"button",role:"switch","aria-checked":t,disabled:n,onClick:r,className:`relative inline-flex w-11 h-7 md:w-9 md:h-5 rounded-full transition-colors flex-shrink-0 focus:outline-none focus:ring-2 focus:ring-bambu-green focus:ring-offset-2 focus:ring-offset-bambu-dark ${n?"bg-bambu-dark-tertiary/50 cursor-not-allowed opacity-50":t?"bg-bambu-green cursor-pointer":"bg-bambu-dark-tertiary cursor-pointer hover:bg-bambu-dark-tertiary/80"}`,children:a.jsx("span",{className:`pointer-events-none absolute top-[3px] md:top-[2px] left-[3px] md:left-[2px] w-5 h-5 md:w-4 md:h-4 bg-white rounded-full shadow transition-transform duration-200 ease-in-out ${t?"translate-x-4":"translate-x-0"}`})})}const kKe={callmebot:"CallMeBot/WhatsApp",ntfy:"ntfy",pushover:"Pushover",telegram:"Telegram",email:"Email",discord:"Discord",webhook:"Webhook"};function EKe({provider:t,onEdit:e}){const n=sn(),[r,i]=_.useState(!1),[s,o]=_.useState(!1),[l,c]=_.useState(null),{data:u}=ct({queryKey:["printers"],queryFn:ce.getPrinters}),d=u?.find(y=>y.id===t.printer_id),h=gt({mutationFn:y=>ce.updateNotificationProvider(t.id,y),onSuccess:()=>{n.invalidateQueries({queryKey:["notification-providers"]})}}),p=gt({mutationFn:()=>ce.deleteNotificationProvider(t.id),onSuccess:()=>{n.invalidateQueries({queryKey:["notification-providers"]})}}),m=gt({mutationFn:()=>ce.testNotificationProvider(t.id),onSuccess:y=>{c(y),n.invalidateQueries({queryKey:["notification-providers"]})},onError:y=>{c({success:!1,message:y.message})}}),x=y=>y||"";return a.jsxs(a.Fragment,{children:[a.jsx(St,{className:"relative",children:a.jsxs(Nt,{className:"p-4",children:[a.jsxs("div",{className:"flex items-start justify-between mb-3",children:[a.jsxs("div",{className:"flex items-center gap-3",children:[a.jsx("div",{className:`p-2 rounded-lg ${t.enabled?"bg-bambu-green/20":"bg-bambu-dark"}`,children:a.jsx(Sg,{className:`w-5 h-5 ${t.enabled?"text-bambu-green":"text-bambu-gray"}`})}),a.jsxs("div",{children:[a.jsx("h3",{className:"font-medium text-white",children:t.name}),a.jsx("p",{className:"text-sm text-bambu-gray",children:kKe[t.provider_type]||t.provider_type})]})]}),a.jsxs("div",{className:"flex items-center gap-3",children:[t.last_success&&a.jsxs("span",{className:"text-xs text-status-ok hidden sm:inline",children:["Last: ",$g(t.last_success)]}),t.last_error&&t.last_error_at&&(!t.last_success||(zi(t.last_error_at)?.getTime()||0)>(zi(t.last_success)?.getTime()||0))&&a.jsx("span",{className:"text-xs text-status-error",title:t.last_error,children:"Error"}),a.jsx(Fn,{checked:t.enabled,onChange:y=>h.mutate({enabled:y})})]})]}),d&&a.jsxs("div",{className:"mb-3 px-2 py-1.5 bg-bambu-dark rounded-lg",children:[a.jsx("span",{className:"text-xs text-bambu-gray",children:"Printer: "}),a.jsx("span",{className:"text-sm text-white",children:d.name})]}),!d&&!t.printer_id&&a.jsx("div",{className:"mb-3 px-2 py-1.5 bg-bambu-dark rounded-lg",children:a.jsx("span",{className:"text-xs text-bambu-gray",children:"All printers"})}),a.jsxs("div",{className:"mb-3 flex flex-wrap gap-1",children:[t.on_print_start&&a.jsx("span",{className:"px-2 py-0.5 bg-blue-500/20 text-blue-400 text-xs rounded",children:"Start"}),t.on_plate_not_empty&&a.jsx("span",{className:"px-2 py-0.5 bg-rose-600/20 text-rose-300 text-xs rounded",children:"Plate Check"}),t.on_print_complete&&a.jsx("span",{className:"px-2 py-0.5 bg-bambu-green/20 text-bambu-green text-xs rounded",children:"Complete"}),t.on_print_failed&&a.jsx("span",{className:"px-2 py-0.5 bg-red-500/20 text-red-400 text-xs rounded",children:"Failed"}),t.on_print_stopped&&a.jsx("span",{className:"px-2 py-0.5 bg-orange-500/20 text-orange-400 text-xs rounded",children:"Stopped"}),t.on_print_progress&&a.jsx("span",{className:"px-2 py-0.5 bg-yellow-500/20 text-yellow-400 text-xs rounded",children:"Progress"}),t.on_printer_offline&&a.jsx("span",{className:"px-2 py-0.5 bg-gray-500/20 text-gray-400 text-xs rounded",children:"Offline"}),t.on_printer_error&&a.jsx("span",{className:"px-2 py-0.5 bg-rose-500/20 text-rose-400 text-xs rounded",children:"Error"}),t.on_filament_low&&a.jsx("span",{className:"px-2 py-0.5 bg-cyan-500/20 text-cyan-400 text-xs rounded",children:"Low Filament"}),t.on_maintenance_due&&a.jsx("span",{className:"px-2 py-0.5 bg-purple-500/20 text-purple-400 text-xs rounded",children:"Maintenance"}),t.on_ams_humidity_high&&a.jsx("span",{className:"px-2 py-0.5 bg-blue-600/20 text-blue-300 text-xs rounded",children:"AMS Humidity"}),t.on_ams_temperature_high&&a.jsx("span",{className:"px-2 py-0.5 bg-orange-600/20 text-orange-300 text-xs rounded",children:"AMS Temp"}),t.on_ams_ht_humidity_high&&a.jsx("span",{className:"px-2 py-0.5 bg-cyan-600/20 text-cyan-300 text-xs rounded",children:"AMS-HT Humidity"}),t.on_ams_ht_temperature_high&&a.jsx("span",{className:"px-2 py-0.5 bg-amber-600/20 text-amber-300 text-xs rounded",children:"AMS-HT Temp"}),t.quiet_hours_enabled&&a.jsxs("span",{className:"px-2 py-0.5 bg-indigo-500/20 text-indigo-400 text-xs rounded flex items-center gap-1",children:[a.jsx(X1,{className:"w-3 h-3"}),"Quiet"]}),t.daily_digest_enabled&&a.jsxs("span",{className:"px-2 py-0.5 bg-emerald-500/20 text-emerald-400 text-xs rounded flex items-center gap-1",children:[a.jsx(ti,{className:"w-3 h-3"}),"Digest ",t.daily_digest_time]})]}),a.jsx("div",{className:"mb-3",children:a.jsxs(Te,{size:"sm",variant:"secondary",disabled:m.isPending,onClick:()=>{c(null),m.mutate()},className:"w-full",children:[m.isPending?a.jsx(pt,{className:"w-4 h-4 animate-spin"}):a.jsx(OR,{className:"w-4 h-4"}),"Send Test Notification"]})}),l&&a.jsxs("div",{className:`mb-3 p-2 rounded-lg flex items-center gap-2 text-sm ${l.success?"bg-bambu-green/20 text-bambu-green":"bg-red-500/20 text-red-400"}`,children:[l.success?a.jsx(Ar,{className:"w-4 h-4"}):a.jsx(Ji,{className:"w-4 h-4"}),a.jsx("span",{children:l.message})]}),a.jsxs("button",{onClick:()=>o(!s),className:"w-full flex items-center justify-between py-2 text-sm text-bambu-gray hover:text-white transition-colors border-t border-bambu-dark-tertiary",children:[a.jsxs("span",{className:"flex items-center gap-2",children:[a.jsx(vh,{className:"w-4 h-4"}),"Event Settings"]}),s?a.jsx(yh,{className:"w-4 h-4"}):a.jsx(Kr,{className:"w-4 h-4"})]}),s&&a.jsxs("div",{className:"pt-3 border-t border-bambu-dark-tertiary space-y-4",children:[a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-sm text-white",children:"Enabled"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Send notifications from this provider"})]}),a.jsx(Fn,{checked:t.enabled,onChange:y=>h.mutate({enabled:y})})]}),a.jsxs("div",{className:"space-y-2",children:[a.jsx("p",{className:"text-xs text-bambu-gray uppercase tracking-wide",children:"Print Events"}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx("p",{className:"text-sm text-white",children:"Print Started"}),a.jsx(Fn,{checked:t.on_print_start,onChange:y=>h.mutate({on_print_start:y})})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-sm text-white",children:"Plate Not Empty"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Objects detected before print"})]}),a.jsx(Fn,{checked:t.on_plate_not_empty??!0,onChange:y=>h.mutate({on_plate_not_empty:y})})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx("p",{className:"text-sm text-white",children:"Print Completed"}),a.jsx(Fn,{checked:t.on_print_complete,onChange:y=>h.mutate({on_print_complete:y})})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx("p",{className:"text-sm text-white",children:"Print Failed"}),a.jsx(Fn,{checked:t.on_print_failed,onChange:y=>h.mutate({on_print_failed:y})})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx("p",{className:"text-sm text-white",children:"Print Stopped"}),a.jsx(Fn,{checked:t.on_print_stopped,onChange:y=>h.mutate({on_print_stopped:y})})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-sm text-white",children:"Progress Milestones"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Notify at 25%, 50%, 75%"})]}),a.jsx(Fn,{checked:t.on_print_progress,onChange:y=>h.mutate({on_print_progress:y})})]})]}),a.jsxs("div",{className:"space-y-2",children:[a.jsx("p",{className:"text-xs text-bambu-gray uppercase tracking-wide",children:"Printer Status"}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx("p",{className:"text-sm text-white",children:"Printer Offline"}),a.jsx(Fn,{checked:t.on_printer_offline,onChange:y=>h.mutate({on_printer_offline:y})})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx("p",{className:"text-sm text-white",children:"Printer Error"}),a.jsx(Fn,{checked:t.on_printer_error,onChange:y=>h.mutate({on_printer_error:y})})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx("p",{className:"text-sm text-white",children:"Low Filament"}),a.jsx(Fn,{checked:t.on_filament_low,onChange:y=>h.mutate({on_filament_low:y})})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-sm text-white",children:"Maintenance Due"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Notify when maintenance is needed"})]}),a.jsx(Fn,{checked:t.on_maintenance_due??!1,onChange:y=>h.mutate({on_maintenance_due:y})})]})]}),a.jsxs("div",{className:"space-y-2",children:[a.jsx("p",{className:"text-xs text-bambu-gray uppercase tracking-wide",children:"AMS Alarms"}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-sm text-white",children:"AMS Humidity High"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Regular AMS humidity exceeds threshold"})]}),a.jsx(Fn,{checked:t.on_ams_humidity_high??!1,onChange:y=>h.mutate({on_ams_humidity_high:y})})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-sm text-white",children:"AMS Temperature High"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Regular AMS temperature exceeds threshold"})]}),a.jsx(Fn,{checked:t.on_ams_temperature_high??!1,onChange:y=>h.mutate({on_ams_temperature_high:y})})]})]}),a.jsxs("div",{className:"space-y-2",children:[a.jsx("p",{className:"text-xs text-bambu-gray uppercase tracking-wide",children:"AMS-HT Alarms"}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-sm text-white",children:"AMS-HT Humidity High"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"AMS-HT humidity exceeds threshold"})]}),a.jsx(Fn,{checked:t.on_ams_ht_humidity_high??!1,onChange:y=>h.mutate({on_ams_ht_humidity_high:y})})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-sm text-white",children:"AMS-HT Temperature High"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"AMS-HT temperature exceeds threshold"})]}),a.jsx(Fn,{checked:t.on_ams_ht_temperature_high??!1,onChange:y=>h.mutate({on_ams_ht_temperature_high:y})})]})]}),a.jsxs("div",{className:"space-y-2",children:[a.jsx("p",{className:"text-xs text-bambu-gray uppercase tracking-wide",children:"Print Queue"}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-sm text-white",children:"Job Added"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Job added to queue"})]}),a.jsx(Fn,{checked:t.on_queue_job_added??!1,onChange:y=>h.mutate({on_queue_job_added:y})})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-sm text-white",children:"Job Assigned"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Model-based job assigned to printer"})]}),a.jsx(Fn,{checked:t.on_queue_job_assigned??!1,onChange:y=>h.mutate({on_queue_job_assigned:y})})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-sm text-white",children:"Job Started"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Queue job started printing"})]}),a.jsx(Fn,{checked:t.on_queue_job_started??!1,onChange:y=>h.mutate({on_queue_job_started:y})})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-sm text-white",children:"Job Waiting"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Job waiting for filament"})]}),a.jsx(Fn,{checked:t.on_queue_job_waiting??!0,onChange:y=>h.mutate({on_queue_job_waiting:y})})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-sm text-white",children:"Job Skipped"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Job skipped (previous failed)"})]}),a.jsx(Fn,{checked:t.on_queue_job_skipped??!0,onChange:y=>h.mutate({on_queue_job_skipped:y})})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-sm text-white",children:"Job Failed"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Job failed to start"})]}),a.jsx(Fn,{checked:t.on_queue_job_failed??!0,onChange:y=>h.mutate({on_queue_job_failed:y})})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-sm text-white",children:"Queue Complete"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"All queue jobs finished"})]}),a.jsx(Fn,{checked:t.on_queue_completed??!1,onChange:y=>h.mutate({on_queue_completed:y})})]})]}),a.jsxs("div",{className:"space-y-2",children:[a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(X1,{className:"w-4 h-4 text-purple-400"}),a.jsx("p",{className:"text-sm text-white",children:"Quiet Hours"})]}),a.jsx(Fn,{checked:t.quiet_hours_enabled,onChange:y=>h.mutate({quiet_hours_enabled:y})})]}),t.quiet_hours_enabled&&a.jsxs("div",{className:"pl-4 border-l-2 border-bambu-dark-tertiary space-y-2",children:[a.jsx("p",{className:"text-xs text-bambu-gray",children:"No notifications during these hours"}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(tr,{className:"w-4 h-4 text-bambu-gray"}),a.jsxs("span",{className:"text-sm text-white",children:[x(t.quiet_hours_start)||"22:00"," - ",x(t.quiet_hours_end)||"07:00"]})]}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Edit provider to change quiet hours"})]})]}),a.jsxs("div",{className:"space-y-2",children:[a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(ti,{className:"w-4 h-4 text-emerald-400"}),a.jsx("p",{className:"text-sm text-white",children:"Daily Digest"})]}),a.jsx(Fn,{checked:t.daily_digest_enabled,onChange:y=>h.mutate({daily_digest_enabled:y})})]}),t.daily_digest_enabled&&a.jsxs("div",{className:"pl-4 border-l-2 border-bambu-dark-tertiary space-y-2",children:[a.jsx("p",{className:"text-xs text-bambu-gray",children:"Batch notifications into a single daily summary"}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(tr,{className:"w-4 h-4 text-bambu-gray"}),a.jsxs("span",{className:"text-sm text-white",children:["Send at ",x(t.daily_digest_time)||"08:00"]})]}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Edit provider to change digest time"})]})]}),a.jsxs("div",{className:"flex gap-2 pt-2",children:[a.jsxs(Te,{size:"sm",variant:"secondary",onClick:()=>e(t),className:"flex-1",children:[a.jsx(mg,{className:"w-4 h-4"}),"Edit"]}),a.jsx(Te,{size:"sm",variant:"secondary",onClick:()=>i(!0),className:"text-red-400 hover:text-red-300",children:a.jsx(an,{className:"w-4 h-4"})})]})]})]})}),r&&a.jsx(Zn,{title:"Delete Notification Provider",message:`Are you sure you want to delete "${t.name}"? This cannot be undone.`,confirmText:"Delete",variant:"danger",onConfirm:()=>{p.mutate(),i(!1)},onCancel:()=>i(!1)})]})}const _q=[{value:"email",label:"Email",description:"SMTP email notifications"},{value:"telegram",label:"Telegram",description:"Notifications via Telegram bot"},{value:"discord",label:"Discord",description:"Send to Discord channel via webhook"},{value:"ntfy",label:"ntfy",description:"Free, self-hostable push notifications"},{value:"pushover",label:"Pushover",description:"Simple, reliable push notifications"},{value:"callmebot",label:"CallMeBot/WhatsApp",description:"Free WhatsApp notifications via CallMeBot"},{value:"webhook",label:"Webhook",description:"Generic HTTP POST to any URL"}];function TKe({provider:t,onClose:e}){const n=sn(),r=!!t,[i,s]=_.useState(t?.name||""),[o,l]=_.useState(t?.provider_type||"email"),[c,u]=_.useState(t?.printer_id||null),[d,h]=_.useState(t?.quiet_hours_enabled||!1),[p,m]=_.useState(t?.quiet_hours_start||"22:00"),[x,y]=_.useState(t?.quiet_hours_end||"07:00"),[v,b]=_.useState(t?.daily_digest_enabled||!1),[S,N]=_.useState(t?.daily_digest_time||"08:00"),[T,k]=_.useState(t?.on_print_start??!1),[C,E]=_.useState(t?.on_print_complete??!0),[P,A]=_.useState(t?.on_print_failed??!0),[D,I]=_.useState(t?.on_print_stopped??!0),[L,U]=_.useState(t?.on_print_progress??!1),[j,$]=_.useState(t?.on_printer_offline??!1),[K,B]=_.useState(t?.on_printer_error??!1),[X,Y]=_.useState(t?.on_filament_low??!1),[ne,H]=_.useState(t?.on_maintenance_due??!1),[W,re]=_.useState(t?.config?Object.fromEntries(Object.entries(t.config).map(([q,ee])=>[q,String(ee)])):{}),[ie,pe]=_.useState(null),[me,de]=_.useState(null),{data:Ee}=ct({queryKey:["printers"],queryFn:ce.getPrinters});_.useEffect(()=>{const q=ee=>{ee.key==="Escape"&&e()};return window.addEventListener("keydown",q),()=>window.removeEventListener("keydown",q)},[e]);const se=gt({mutationFn:()=>ce.testNotificationConfig({provider_type:o,config:W}),onSuccess:q=>{pe(q),de(null)},onError:q=>{pe({success:!1,message:q.message})}}),Ae=gt({mutationFn:q=>ce.createNotificationProvider(q),onSuccess:()=>{n.invalidateQueries({queryKey:["notification-providers"]}),e()},onError:q=>{de(q.message)}}),Fe=gt({mutationFn:q=>ce.updateNotificationProvider(t.id,q),onSuccess:()=>{n.invalidateQueries({queryKey:["notification-providers"]}),e()},onError:q=>{de(q.message)}}),ge=q=>{if(q.preventDefault(),de(null),!i.trim()){de("Name is required");return}const ee=Q(o);for(const ye of ee)if(!W[ye.key]?.trim()){de(`${ye.label} is required`);return}const V={name:i.trim(),provider_type:o,config:W,printer_id:c,quiet_hours_enabled:d,quiet_hours_start:d?p:null,quiet_hours_end:d?x:null,daily_digest_enabled:v,daily_digest_time:v?S:null,on_print_start:T,on_print_complete:C,on_print_failed:P,on_print_stopped:D,on_print_progress:L,on_printer_offline:j,on_printer_error:K,on_filament_low:X,on_maintenance_due:ne};r?Fe.mutate(V):Ae.mutate(V)},Ze=Ae.isPending||Fe.isPending,G=q=>{switch(q){case"callmebot":return[{key:"phone",label:"Phone Number",placeholder:"+1234567890",type:"text",required:!0},{key:"apikey",label:"API Key",placeholder:"Your CallMeBot API key",type:"text",required:!0}];case"ntfy":return[{key:"server",label:"Server URL",placeholder:"https://ntfy.sh",type:"text",required:!1},{key:"topic",label:"Topic",placeholder:"my-bambuddy",type:"text",required:!0},{key:"auth_token",label:"Auth Token",placeholder:"Optional authentication",type:"password",required:!1}];case"pushover":return[{key:"user_key",label:"User Key",placeholder:"Your Pushover user key",type:"text",required:!0},{key:"app_token",label:"App Token",placeholder:"Your Pushover app token",type:"text",required:!0},{key:"priority",label:"Priority",placeholder:"0 (normal)",type:"number",required:!1}];case"telegram":return[{key:"bot_token",label:"Bot Token",placeholder:"Bot token from @BotFather",type:"password",required:!0},{key:"chat_id",label:"Chat ID",placeholder:"Your chat or group ID",type:"text",required:!0}];case"email":return[{key:"smtp_server",label:"SMTP Server",placeholder:"smtp.gmail.com",type:"text",required:!0},{key:"smtp_port",label:"SMTP Port",placeholder:"587",type:"number",required:!1},{key:"security",label:"Security",type:"select",required:!1,options:[{value:"starttls",label:"STARTTLS (Port 587)"},{value:"ssl",label:"SSL/TLS (Port 465)"},{value:"none",label:"None (Port 25)"}]},{key:"auth_enabled",label:"Authentication",type:"select",required:!1,options:[{value:"true",label:"Enabled"},{value:"false",label:"Disabled"}]},{key:"username",label:"Username",placeholder:"your@email.com",type:"text",required:!1},{key:"password",label:"Password",placeholder:"App password",type:"password",required:!1},{key:"from_email",label:"From Email",placeholder:"your@email.com",type:"text",required:!0},{key:"to_email",label:"To Email",placeholder:"recipient@email.com",type:"text",required:!0}];case"discord":return[{key:"webhook_url",label:"Webhook URL",placeholder:"https://discord.com/api/webhooks/...",type:"text",required:!0}];case"webhook":return[{key:"webhook_url",label:"Webhook URL",placeholder:"https://example.com/webhook",type:"text",required:!0},{key:"payload_format",label:"Payload Format",type:"select",required:!1,options:[{value:"generic",label:"Generic JSON"},{value:"slack",label:"Slack / Mattermost"}]},{key:"auth_header",label:"Authorization",placeholder:"Bearer token (optional)",type:"password",required:!1},{key:"field_title",label:"Title Field Name",placeholder:"title",type:"text",required:!1,showIf:ee=>ee.payload_format!=="slack"},{key:"field_message",label:"Message Field Name",placeholder:"message",type:"text",required:!1,showIf:ee=>ee.payload_format!=="slack"}];default:return[]}},Q=q=>G(q).filter(ee=>ee.required),he=G(o);return a.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4 overflow-y-auto",onClick:e,children:a.jsxs("div",{className:"bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-lg my-8 max-h-[90vh] overflow-y-auto",onClick:q=>q.stopPropagation(),children:[a.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary",children:[a.jsx("h2",{className:"text-lg font-semibold text-white",children:r?"Edit Notification Provider":"Add Notification Provider"}),a.jsx("button",{onClick:e,className:"text-bambu-gray hover:text-white transition-colors",children:a.jsx(Lt,{className:"w-5 h-5"})})]}),a.jsxs("form",{onSubmit:ge,className:"p-6 space-y-4",children:[me&&a.jsx("div",{className:"p-3 bg-red-500/20 border border-red-500/50 rounded-lg text-sm text-red-400",children:me}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Name *"}),a.jsx("input",{type:"text",value:i,onChange:q=>s(q.target.value),placeholder:"My Notifications",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"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Provider Type *"}),a.jsx("select",{value:o,onChange:q=>{l(q.target.value),re({}),pe(null)},disabled:r,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 disabled:opacity-50",children:_q.map(q=>a.jsx("option",{value:q.value,children:q.label},q.value))}),a.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:_q.find(q=>q.value===o)?.description})]}),a.jsxs("div",{className:"space-y-3",children:[a.jsx("p",{className:"text-sm text-bambu-gray",children:"Configuration"}),he.filter(q=>!("showIf"in q)||q.showIf?.(W)!==!1).map(q=>a.jsxs("div",{children:[a.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[q.label," ",q.required&&"*"]}),q.type==="select"&&"options"in q&&q.options?a.jsx("select",{value:W[q.key]||q.options[0]?.value||"",onChange:ee=>{re({...W,[q.key]:ee.target.value}),pe(null)},className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:q.options.map(ee=>a.jsx("option",{value:ee.value,children:ee.label},ee.value))}):a.jsx("input",{type:q.type,value:W[q.key]||"",onChange:ee=>{re({...W,[q.key]:ee.target.value}),pe(null)},placeholder:q.placeholder,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"})]},q.key))]}),a.jsx("div",{className:"flex gap-2",children:a.jsxs(Te,{type:"button",variant:"secondary",onClick:()=>{pe(null),se.mutate()},disabled:se.isPending||!W[Q(o)[0]?.key],className:"flex-1",children:[se.isPending?a.jsx(pt,{className:"w-4 h-4 animate-spin"}):a.jsx(OR,{className:"w-4 h-4"}),"Test Configuration"]})}),ie&&a.jsx("div",{className:`p-3 rounded-lg flex items-center gap-2 ${ie.success?"bg-bambu-green/20 border border-bambu-green/50 text-bambu-green":"bg-red-500/20 border border-red-500/50 text-red-400"}`,children:ie.success?a.jsxs(a.Fragment,{children:[a.jsx(Ar,{className:"w-5 h-5"}),a.jsx("span",{children:ie.message})]}):a.jsxs(a.Fragment,{children:[a.jsx(Ji,{className:"w-5 h-5"}),a.jsx("span",{children:ie.message})]})}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Printer Filter"}),a.jsxs("select",{value:c??"",onChange:q=>u(q.target.value?Number(q.target.value):null),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[a.jsx("option",{value:"",children:"All printers"}),Ee?.map(q=>a.jsx("option",{value:q.id,children:q.name},q.id))]}),a.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Only send notifications for events from this printer"})]}),a.jsxs("div",{className:"space-y-2",children:[a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx("label",{className:"text-sm text-white",children:"Quiet Hours (Do Not Disturb)"}),a.jsx(Fn,{checked:d,onChange:h})]}),d&&a.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Start"}),a.jsx("input",{type:"time",value:p,onChange:q=>m(q.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"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"End"}),a.jsx("input",{type:"time",value:x,onChange:q=>y(q.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"})]})]})]}),a.jsxs("div",{className:"space-y-2",children:[a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("label",{className:"text-sm text-white",children:"Daily Digest"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Batch notifications into a single daily summary"})]}),a.jsx(Fn,{checked:v,onChange:b})]}),v&&a.jsxs("div",{children:[a.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Send digest at"}),a.jsx("input",{type:"time",value:S,onChange:q=>N(q.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"}),a.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Events will be collected and sent as a single summary at this time"})]})]}),a.jsxs("div",{className:"space-y-3",children:[a.jsx("p",{className:"text-sm text-bambu-gray",children:"Notification Events"}),a.jsxs("div",{className:"space-y-2 p-3 bg-bambu-dark rounded-lg",children:[a.jsx("p",{className:"text-xs text-bambu-gray uppercase tracking-wide mb-2",children:"Print Events"}),a.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx("span",{className:"text-sm text-white",children:"Start"}),a.jsx(Fn,{checked:T,onChange:k})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx("span",{className:"text-sm text-white",children:"Complete"}),a.jsx(Fn,{checked:C,onChange:E})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx("span",{className:"text-sm text-white",children:"Failed"}),a.jsx(Fn,{checked:P,onChange:A})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx("span",{className:"text-sm text-white",children:"Stopped"}),a.jsx(Fn,{checked:D,onChange:I})]}),a.jsxs("div",{className:"flex items-center justify-between col-span-2",children:[a.jsxs("div",{children:[a.jsx("span",{className:"text-sm text-white",children:"Progress"}),a.jsx("span",{className:"text-xs text-bambu-gray ml-1",children:"(25%, 50%, 75%)"})]}),a.jsx(Fn,{checked:L,onChange:U})]})]})]}),a.jsxs("div",{className:"space-y-2 p-3 bg-bambu-dark rounded-lg",children:[a.jsx("p",{className:"text-xs text-bambu-gray uppercase tracking-wide mb-2",children:"Printer Status"}),a.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx("span",{className:"text-sm text-white",children:"Offline"}),a.jsx(Fn,{checked:j,onChange:$})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx("span",{className:"text-sm text-white",children:"Error"}),a.jsx(Fn,{checked:K,onChange:B})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx("span",{className:"text-sm text-white",children:"Low Filament"}),a.jsx(Fn,{checked:X,onChange:Y})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx("span",{className:"text-sm text-white",children:"Maintenance"}),a.jsx(Fn,{checked:ne,onChange:H})]})]})]})]}),a.jsxs("div",{className:"flex gap-3 pt-2",children:[a.jsx(Te,{type:"button",variant:"secondary",onClick:e,className:"flex-1",children:"Cancel"}),a.jsxs(Te,{type:"submit",disabled:Ze,className:"flex-1",children:[Ze?a.jsx(pt,{className:"w-4 h-4 animate-spin"}):a.jsx(ms,{className:"w-4 h-4"}),r?"Save":"Add"]})]})]})]})})}function AKe({template:t,onClose:e}){const n=sn(),r=_.useRef(null),[i,s]=_.useState(t.title_template),[o,l]=_.useState(t.body_template),[c,u]=_.useState(null),[d,h]=_.useState(!0),{data:p}=ct({queryKey:["template-variables"],queryFn:ce.getTemplateVariables}),m=p?.find(k=>k.event_type===t.event_type),{data:x,isLoading:y}=ct({queryKey:["template-preview",t.event_type,i,o],queryFn:()=>ce.previewTemplate({event_type:t.event_type,title_template:i,body_template:o}),enabled:d&&i.length>0&&o.length>0});_.useEffect(()=>{const k=C=>{C.key==="Escape"&&e()};return window.addEventListener("keydown",k),()=>window.removeEventListener("keydown",k)},[e]);const v=gt({mutationFn:k=>ce.updateNotificationTemplate(t.id,k),onSuccess:()=>{n.invalidateQueries({queryKey:["notification-templates"]}),e()},onError:k=>{u(k.message)}}),b=gt({mutationFn:()=>ce.resetNotificationTemplate(t.id),onSuccess:k=>{s(k.title_template),l(k.body_template),n.invalidateQueries({queryKey:["notification-templates"]})},onError:k=>{u(k.message)}}),S=k=>{if(k.preventDefault(),u(null),!i.trim()){u("Title is required");return}if(!o.trim()){u("Body is required");return}v.mutate({title_template:i,body_template:o})},N=k=>{const C=r.current;if(!C)return;const E=C.selectionStart,P=C.selectionEnd,A=o,D=A.substring(0,E),I=A.substring(P),L=D+`{${k}}`+I;l(L),setTimeout(()=>{C.focus();const U=E+k.length+2;C.setSelectionRange(U,U)},0)},T=i!==t.title_template||o!==t.body_template;return a.jsx("div",{className:"fixed inset-0 bg-black/80 flex items-center justify-center z-50 p-4",children:a.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg w-full max-w-2xl max-h-[90vh] flex flex-col",children:[a.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary shrink-0",children:[a.jsxs("h2",{className:"text-lg font-semibold text-white",children:["Edit Template: ",t.name]}),a.jsx("button",{onClick:e,className:"p-1 hover:bg-bambu-dark-tertiary rounded transition-colors",children:a.jsx(Lt,{className:"w-5 h-5 text-bambu-gray"})})]}),a.jsxs("form",{onSubmit:S,className:"flex-1 overflow-y-auto p-4 space-y-4",children:[c&&a.jsx("div",{className:"p-3 bg-red-500/20 border border-red-500/50 rounded text-red-400 text-sm",children:c}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm font-medium text-bambu-gray mb-1",children:"Title"}),a.jsx("input",{type:"text",value:i,onChange:k=>s(k.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white focus:outline-none focus:ring-1 focus:ring-bambu-green",placeholder:"Notification title..."})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm font-medium text-bambu-gray mb-1",children:"Body"}),a.jsx("textarea",{ref:r,value:o,onChange:k=>l(k.target.value),rows:4,className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white focus:outline-none focus:ring-1 focus:ring-bambu-green font-mono text-sm resize-none",placeholder:"Notification body..."})]}),m&&a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm font-medium text-bambu-gray mb-2",children:"Available Variables"}),a.jsx("div",{className:"flex flex-wrap gap-2",children:m.variables.map(k=>a.jsxs("button",{type:"button",onClick:()=>N(k),className:"inline-flex items-center gap-1 px-2 py-1 bg-bambu-dark hover:bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded text-xs text-bambu-gray hover:text-white transition-colors",children:[a.jsx(fr,{className:"w-3 h-3"}),k]},k))}),a.jsx("p",{className:"text-xs text-bambu-gray/60 mt-1",children:"Click to insert at cursor position in body"})]}),a.jsxs("div",{children:[a.jsxs("div",{className:"flex items-center justify-between mb-2",children:[a.jsxs("label",{className:"text-sm font-medium text-bambu-gray flex items-center gap-2",children:[a.jsx(xc,{className:"w-4 h-4"}),"Live Preview"]}),a.jsx("button",{type:"button",onClick:()=>h(!d),className:"text-xs text-bambu-green hover:text-bambu-green-light",children:d?"Hide":"Show"})]}),d&&a.jsx("div",{className:"bg-bambu-dark border border-bambu-dark-tertiary rounded p-3 space-y-2",children:y?a.jsxs("div",{className:"flex items-center gap-2 text-bambu-gray text-sm",children:[a.jsx(pt,{className:"w-4 h-4 animate-spin"}),"Loading preview..."]}):x?a.jsxs(a.Fragment,{children:[a.jsxs("div",{children:[a.jsx("span",{className:"text-xs text-bambu-gray",children:"Title:"}),a.jsx("div",{className:"text-white font-medium",children:x.title})]}),a.jsxs("div",{children:[a.jsx("span",{className:"text-xs text-bambu-gray",children:"Body:"}),a.jsx("div",{className:"text-white whitespace-pre-wrap text-sm",children:x.body})]})]}):a.jsx("div",{className:"text-bambu-gray text-sm",children:"Enter template content to see preview"})})]})]}),a.jsxs("div",{className:"flex items-center justify-between p-4 border-t border-bambu-dark-tertiary shrink-0",children:[a.jsxs(Te,{type:"button",variant:"ghost",onClick:()=>b.mutate(),disabled:b.isPending,className:"text-orange-400 hover:text-orange-300",children:[b.isPending?a.jsx(pt,{className:"w-4 h-4 animate-spin mr-2"}):a.jsx(Lh,{className:"w-4 h-4 mr-2"}),"Reset to Default"]}),a.jsxs("div",{className:"flex gap-2",children:[a.jsx(Te,{type:"button",variant:"secondary",onClick:e,children:"Cancel"}),a.jsxs(Te,{onClick:S,disabled:v.isPending||!T,children:[v.isPending?a.jsx(pt,{className:"w-4 h-4 animate-spin mr-2"}):a.jsx(ms,{className:"w-4 h-4 mr-2"}),"Save"]})]})]})]})})}const CKe={print_start:"Print Started",print_complete:"Print Complete",print_failed:"Print Failed",print_stopped:"Print Stopped",print_progress:"Progress",printer_offline:"Printer Offline",printer_error:"Printer Error",filament_low:"Low Filament",maintenance_due:"Maintenance Due",test:"Test"},jKe={print_start:"text-blue-400",print_complete:"text-bambu-green",print_failed:"text-red-400",print_stopped:"text-orange-400",print_progress:"text-yellow-400",printer_offline:"text-gray-400",printer_error:"text-rose-400",filament_low:"text-cyan-400",maintenance_due:"text-purple-400",test:"text-bambu-gray"};function PKe({onClose:t}){const e=sn(),{showToast:n}=Hn(),[r,i]=_.useState(7),[s,o]=_.useState(null),[l,c]=_.useState(!1),{data:u}=ct({queryKey:["settings"],queryFn:ce.getSettings}),d=u?.time_format||"system",{data:h,isLoading:p,refetch:m,isRefetching:x}=ct({queryKey:["notification-logs",r,l],queryFn:()=>ce.getNotificationLogs({days:r,limit:100,success:l?!1:void 0})}),{data:y}=ct({queryKey:["notification-log-stats",r],queryFn:()=>ce.getNotificationLogStats(r)}),v=gt({mutationFn:()=>ce.clearNotificationLogs(30),onSuccess:S=>{n(S.message,"success"),e.invalidateQueries({queryKey:["notification-logs"]}),e.invalidateQueries({queryKey:["notification-log-stats"]})},onError:S=>{n(`Failed to clear logs: ${S.message}`,"error")}}),b=S=>{const N=zi(S);if(!N)return"";const k=new Date().getTime()-N.getTime();return k<6e4?"Just now":k<36e5?`${Math.floor(k/6e4)}m ago`:k<864e5?`${Math.floor(k/36e5)}h ago`:N.toLocaleDateString()+" "+Yfe(N,d)};return a.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",children:a.jsxs("div",{className:"bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg w-full max-w-3xl max-h-[85vh] flex flex-col",children:[a.jsxs("div",{className:"p-4 border-b border-bambu-dark-tertiary flex items-center justify-between",children:[a.jsxs("div",{className:"flex items-center gap-3",children:[a.jsx(W0,{className:"w-5 h-5 text-bambu-green"}),a.jsx("h2",{className:"text-lg font-semibold text-white",children:"Notification Log"})]}),a.jsx("button",{onClick:t,className:"text-bambu-gray hover:text-white transition-colors",children:"×"})]}),y&&a.jsx("div",{className:"px-4 py-3 border-b border-bambu-dark-tertiary bg-bambu-dark/50",children:a.jsxs("div",{className:"flex items-center gap-6 text-sm",children:[a.jsxs("span",{className:"text-bambu-gray",children:["Last ",r," days: ",a.jsx("span",{className:"text-white font-medium",children:y.total})," notifications"]}),a.jsxs("span",{className:"flex items-center gap-1 text-bambu-green",children:[a.jsx(Ar,{className:"w-4 h-4"}),y.success_count," sent"]}),y.failure_count>0&&a.jsxs("span",{className:"flex items-center gap-1 text-red-400",children:[a.jsx(Ji,{className:"w-4 h-4"}),y.failure_count," failed"]})]})}),a.jsxs("div",{className:"px-4 py-3 border-b border-bambu-dark-tertiary flex items-center gap-4",children:[a.jsxs("select",{value:r,onChange:S=>i(Number(S.target.value)),className:"px-3 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm focus:outline-none focus:ring-1 focus:ring-bambu-green",children:[a.jsx("option",{value:1,children:"Last 24 hours"}),a.jsx("option",{value:7,children:"Last 7 days"}),a.jsx("option",{value:30,children:"Last 30 days"}),a.jsx("option",{value:90,children:"Last 90 days"})]}),a.jsxs("label",{className:"flex items-center gap-2 text-sm text-bambu-gray cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:l,onChange:S=>c(S.target.checked),className:"rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),"Show failed only"]}),a.jsx("div",{className:"flex-1"}),a.jsxs(Te,{size:"sm",variant:"secondary",onClick:()=>m(),disabled:x,children:[x?a.jsx(pt,{className:"w-4 h-4 animate-spin"}):a.jsx(Dr,{className:"w-4 h-4"}),"Refresh"]}),a.jsxs(Te,{size:"sm",variant:"secondary",onClick:()=>v.mutate(),disabled:v.isPending,className:"text-red-400 hover:text-red-300",children:[v.isPending?a.jsx(pt,{className:"w-4 h-4 animate-spin"}):a.jsx(an,{className:"w-4 h-4"}),"Clear Old"]})]}),a.jsx("div",{className:"flex-1 overflow-y-auto p-4",children:p?a.jsx("div",{className:"flex justify-center py-12",children:a.jsx(pt,{className:"w-6 h-6 text-bambu-green animate-spin"})}):h&&h.length>0?a.jsx("div",{className:"space-y-2",children:h.map(S=>a.jsx(DKe,{log:S,isExpanded:s===S.id,onToggle:()=>o(s===S.id?null:S.id),formatDate:b,formatFullDate:N=>Vg(N,d)},S.id))}):a.jsxs("div",{className:"text-center py-12 text-bambu-gray",children:[a.jsx(W0,{className:"w-12 h-12 mx-auto mb-3 opacity-30"}),a.jsx("p",{className:"text-sm",children:l?"No failed notifications":"No notifications logged"})]})})]})})}function DKe({log:t,isExpanded:e,onToggle:n,formatDate:r,formatFullDate:i}){return a.jsxs("div",{className:`border rounded-lg overflow-hidden transition-colors ${t.success?"border-bambu-dark-tertiary bg-bambu-dark/30":"border-red-500/30 bg-red-500/5"}`,children:[a.jsxs("button",{className:"w-full px-3 py-2 flex items-center gap-3 text-left hover:bg-bambu-dark/50 transition-colors",onClick:n,children:[t.success?a.jsx(Ar,{className:"w-4 h-4 text-bambu-green shrink-0"}):a.jsx(Ji,{className:"w-4 h-4 text-red-400 shrink-0"}),a.jsx("span",{className:`text-xs font-medium ${jKe[t.event_type]||"text-bambu-gray"}`,children:CKe[t.event_type]||t.event_type}),a.jsx("span",{className:"text-sm text-white truncate flex-1",children:t.provider_name||"Unknown Provider"}),t.printer_name&&a.jsx("span",{className:"text-xs text-bambu-gray",children:t.printer_name}),a.jsx("span",{className:"text-xs text-bambu-gray shrink-0",children:r(t.created_at)}),e?a.jsx(yh,{className:"w-4 h-4 text-bambu-gray shrink-0"}):a.jsx(Kr,{className:"w-4 h-4 text-bambu-gray shrink-0"})]}),e&&a.jsxs("div",{className:"px-3 py-2 border-t border-bambu-dark-tertiary bg-bambu-dark/20 space-y-2",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-xs text-bambu-gray mb-1",children:"Title"}),a.jsx("p",{className:"text-sm text-white",children:t.title})]}),a.jsxs("div",{children:[a.jsx("p",{className:"text-xs text-bambu-gray mb-1",children:"Message"}),a.jsx("p",{className:"text-sm text-white whitespace-pre-wrap",children:t.message})]}),!t.success&&t.error_message&&a.jsxs("div",{children:[a.jsx("p",{className:"text-xs text-red-400 mb-1",children:"Error"}),a.jsx("p",{className:"text-sm text-red-300",children:t.error_message})]}),a.jsxs("div",{className:"flex gap-4 text-xs text-bambu-gray pt-1",children:[a.jsxs("span",{children:["Provider: ",t.provider_type]}),a.jsxs("span",{children:["Time: ",i(t.created_at)]})]})]})]})}function RKe(){const t=sn(),[e,n]=_.useState(!1),[r,i]=_.useState(""),[s,o]=_.useState("auto"),[l,c]=_.useState(!1),[u,d]=_.useState("all"),[h,p]=_.useState(!1),[m,x]=_.useState(!1),{data:y,isLoading:v}=ct({queryKey:["spoolman-settings"],queryFn:ce.getSpoolmanSettings}),{data:b,isLoading:S,refetch:N}=ct({queryKey:["spoolman-status"],queryFn:ce.getSpoolmanStatus,refetchInterval:3e4}),{data:T}=ct({queryKey:["printers"],queryFn:ce.getPrinters});_.useEffect(()=>{y&&(n(y.spoolman_enabled==="true"),i(y.spoolman_url||""),o(y.spoolman_sync_mode||"auto"),p(!0))},[y]),_.useEffect(()=>{if(!h||!y)return;if(y.spoolman_enabled==="true"!==e||(y.spoolman_url||"")!==r||(y.spoolman_sync_mode||"auto")!==s){const $=setTimeout(()=>{k.mutate()},500);return()=>clearTimeout($)}},[e,r,s,h]);const k=gt({mutationFn:()=>ce.updateSpoolmanSettings({spoolman_enabled:e?"true":"false",spoolman_url:r,spoolman_sync_mode:s}),onSuccess:()=>{t.invalidateQueries({queryKey:["spoolman-settings"]}),t.invalidateQueries({queryKey:["spoolman-status"]}),c(!0),setTimeout(()=>c(!1),2e3)}}),C=gt({mutationFn:ce.connectSpoolman,onSuccess:()=>{N()}}),E=gt({mutationFn:ce.disconnectSpoolman,onSuccess:()=>{N()}}),P=gt({mutationFn:ce.syncAllPrintersAms,onSuccess:j=>{j.success}}),A=gt({mutationFn:j=>ce.syncPrinterAms(j),onSuccess:j=>{j.success}}),D=()=>{u==="all"?P.mutate():A.mutate(u)},I=P.isPending||A.isPending,L=u==="all"?P.data:A.data,U=u==="all"?P.isSuccess:A.isSuccess;return v?a.jsxs(St,{children:[a.jsx(Kn,{children:a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(Eu,{className:"w-5 h-5 text-bambu-green"}),a.jsx("h2",{className:"text-lg font-semibold text-white",children:"Spoolman Integration"})]})}),a.jsx(Nt,{children:a.jsx("div",{className:"flex justify-center py-8",children:a.jsx(pt,{className:"w-6 h-6 text-bambu-green animate-spin"})})})]}):a.jsxs(St,{children:[a.jsx(Kn,{children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(Eu,{className:"w-5 h-5 text-bambu-green"}),a.jsx("h2",{className:"text-lg font-semibold text-white",children:"Spoolman Integration"})]}),k.isPending&&a.jsx(pt,{className:"w-4 h-4 text-bambu-green animate-spin"}),l&&a.jsx(Wi,{className:"w-4 h-4 text-bambu-green"})]})}),a.jsxs(Nt,{className:"space-y-4",children:[a.jsx("p",{className:"text-sm text-bambu-gray",children:"Connect to Spoolman for filament inventory tracking. AMS data will sync automatically."}),a.jsx("div",{className:"p-3 bg-blue-500/10 border border-blue-500/30 rounded-lg",children:a.jsxs("div",{className:"flex gap-2",children:[a.jsx(nl,{className:"w-4 h-4 text-blue-400 flex-shrink-0 mt-0.5"}),a.jsxs("div",{className:"text-xs text-blue-300",children:[a.jsx("p",{className:"font-medium mb-1",children:"How Sync Works"}),a.jsxs("ul",{className:"list-disc list-inside space-y-0.5 text-blue-300/80",children:[a.jsx("li",{children:"Only official Bambu Lab spools with RFID are synced"}),a.jsx("li",{children:"New spools are auto-created in Spoolman on first sync"}),a.jsx("li",{children:"Non-Bambu Lab spools (third-party, refilled) are skipped"})]}),a.jsx("p",{className:"font-medium mt-2 mb-1",children:"Linking Existing Spools"}),a.jsx("p",{className:"text-blue-300/80",children:'To link existing Spoolman spools to your AMS, hover over an AMS slot and click "Link to Spoolman".'})]})]})}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-white",children:"Enable Spoolman"}),a.jsx("p",{className:"text-sm text-bambu-gray",children:"Sync filament data with Spoolman server"})]}),a.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:e,onChange:j=>n(j.target.checked),className:"sr-only peer"}),a.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Spoolman URL"}),a.jsx("input",{type:"text",placeholder:"http://192.168.1.100:7912",value:r,onChange:j=>i(j.target.value),disabled:!e,className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray/50 focus:border-bambu-green focus:outline-none disabled:opacity-50"}),a.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"URL of your Spoolman server (e.g., http://localhost:7912)"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Sync Mode"}),a.jsxs("select",{value:s,onChange:j=>o(j.target.value),disabled:!e,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 disabled:opacity-50",children:[a.jsx("option",{value:"auto",children:"Automatic"}),a.jsx("option",{value:"manual",children:"Manual Only"})]}),a.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:s==="auto"?"AMS data syncs automatically when changes are detected":"Only sync when manually triggered"})]}),e&&a.jsxs("div",{className:"pt-2 border-t border-bambu-dark-tertiary",children:[a.jsxs("div",{className:"flex items-center justify-between mb-3",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("span",{className:"text-sm text-bambu-gray",children:"Status:"}),S?a.jsx(pt,{className:"w-4 h-4 text-bambu-gray animate-spin"}):b?.connected?a.jsxs("span",{className:"flex items-center gap-1 text-sm text-green-500",children:[a.jsx(Wi,{className:"w-4 h-4"}),"Connected"]}):a.jsxs("span",{className:"flex items-center gap-1 text-sm text-red-500",children:[a.jsx(Lt,{className:"w-4 h-4"}),"Disconnected"]})]}),a.jsx("div",{className:"flex gap-2",children:b?.connected?a.jsxs(Te,{variant:"secondary",size:"sm",onClick:()=>E.mutate(),disabled:E.isPending,children:[E.isPending?a.jsx(pt,{className:"w-4 h-4 animate-spin"}):a.jsx(Ade,{className:"w-4 h-4"}),"Disconnect"]}):a.jsxs(Te,{size:"sm",onClick:()=>C.mutate(),disabled:C.isPending||!r,children:[C.isPending?a.jsx(pt,{className:"w-4 h-4 animate-spin"}):a.jsx(fc,{className:"w-4 h-4"}),"Connect"]})})]}),C.isError&&a.jsx("div",{className:"mb-3 p-2 bg-red-500/20 border border-red-500/50 rounded text-sm text-red-400",children:C.error.message}),b?.connected&&a.jsxs("div",{className:"space-y-3",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-sm text-white",children:"Sync AMS Data"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Manually sync printer AMS data to Spoolman"})]}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsxs("div",{className:"relative flex-1",children:[a.jsxs("select",{value:u,onChange:j=>d(j.target.value==="all"?"all":Number(j.target.value)),className:"w-full px-3 py-2 pr-8 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none appearance-none cursor-pointer",children:[a.jsx("option",{value:"all",children:"All Printers"}),T?.map(j=>a.jsx("option",{value:j.id,children:j.name},j.id))]}),a.jsx(Kr,{className:"absolute right-2 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}),a.jsxs(Te,{variant:"secondary",size:"sm",onClick:D,disabled:I,children:[I?a.jsx(pt,{className:"w-4 h-4 animate-spin"}):a.jsx(Dr,{className:"w-4 h-4"}),"Sync"]})]})]}),U&&L&&a.jsxs("div",{className:"mt-3 space-y-2",children:[a.jsx("div",{className:`p-2 rounded text-sm ${L.success?"bg-green-500/20 border border-green-500/50 text-green-400":"bg-yellow-500/20 border border-yellow-500/50 text-yellow-400"}`,children:L.success?`Synced ${L.synced_count} spool${L.synced_count!==1?"s":""} successfully`:`Synced ${L.synced_count} spool${L.synced_count!==1?"s":""} with ${L.errors.length} error${L.errors.length!==1?"s":""}`}),L.skipped_count>0&&a.jsxs("div",{className:"p-2 bg-amber-500/10 border border-amber-500/30 rounded text-sm",children:[a.jsxs("div",{className:"flex items-center justify-between text-amber-400 mb-1",children:[a.jsxs("div",{className:"flex items-center gap-1.5",children:[a.jsx(Sn,{className:"w-3.5 h-3.5"}),a.jsxs("span",{className:"font-medium",children:[L.skipped_count," spool",L.skipped_count!==1?"s":""," skipped"]})]}),L.skipped_count>5&&a.jsx("button",{onClick:()=>x(!m),className:"text-xs text-amber-400 hover:text-amber-300 underline",children:m?"Show less":"Show all"})]}),a.jsxs("ul",{className:"text-xs text-amber-300/80 space-y-0.5",children:[(m?L.skipped:L.skipped.slice(0,5)).map((j,$)=>a.jsxs("li",{className:"flex items-center gap-2",children:[j.color&&a.jsx("span",{className:"w-3 h-3 rounded-full border border-white/20",style:{backgroundColor:`#${j.color}`}}),a.jsx("span",{children:j.location}),a.jsxs("span",{className:"text-amber-300/60",children:["- ",j.reason]})]},$)),!m&&L.skipped_count>5&&a.jsxs("li",{className:"text-amber-300/60 italic",children:["...and ",L.skipped_count-5," more"]})]})]}),L.errors.length>0&&a.jsxs("div",{className:"p-2 bg-red-500/10 border border-red-500/30 rounded text-sm",children:[a.jsx("div",{className:"text-red-400 font-medium mb-1",children:"Errors:"}),a.jsx("ul",{className:"text-xs text-red-300/80 space-y-0.5",children:L.errors.map((j,$)=>a.jsx("li",{children:j},$))})]})]})]})]})]})}function OKe({link:t,onClose:e}){const n=sn(),{mode:r}=Fh(),i=!!t,s=_.useRef(null),[o,l]=_.useState(t?.name||""),[c,u]=_.useState(t?.url||""),[d,h]=_.useState(t?.icon||"link"),[p,m]=_.useState(!!t?.custom_icon),[x,y]=_.useState(t?.custom_icon?ce.getExternalLinkIconUrl(t.id):null),[v,b]=_.useState(null),[S,N]=_.useState(null);_.useEffect(()=>{const I=L=>{L.key==="Escape"&&e()};return window.addEventListener("keydown",I),()=>window.removeEventListener("keydown",I)},[e]);const T=gt({mutationFn:async I=>{const L=await ce.createExternalLink(I);return v?await ce.uploadExternalLinkIcon(L.id,v):L},onSuccess:()=>{n.invalidateQueries({queryKey:["external-links"]}),e()},onError:I=>{N(I.message)}}),k=gt({mutationFn:async I=>{let L=await ce.updateExternalLink(t.id,I);return v?L=await ce.uploadExternalLinkIcon(t.id,v):!p&&t?.custom_icon&&(L=await ce.deleteExternalLinkIcon(t.id)),L},onSuccess:()=>{n.invalidateQueries({queryKey:["external-links"]}),e()},onError:I=>{N(I.message)}}),C=I=>{const L=I.target.files?.[0];if(L){if(!["image/png","image/jpeg","image/gif","image/svg+xml","image/webp","image/x-icon"].includes(L.type)){N("Please select a valid image file (PNG, JPG, GIF, SVG, WebP, or ICO)");return}if(L.size>1024*1024){N("Image file must be less than 1MB");return}b(L),m(!0);const j=new FileReader;j.onload=$=>{y($.target?.result)},j.readAsDataURL(L)}},E=()=>{b(null),y(null),m(!1),s.current&&(s.current.value="")},P=I=>{if(I.preventDefault(),N(null),!o.trim()){N("Name is required");return}if(!c.trim()){N("URL is required");return}if(!c.startsWith("http://")&&!c.startsWith("https://")){N("URL must start with http:// or https://");return}const L={name:o.trim(),url:c.trim(),icon:d};i?k.mutate(L):T.mutate(L)},A=T.isPending||k.isPending,D=wM(d);return a.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",onClick:e,children:a.jsxs("div",{className:"bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-md",onClick:I=>I.stopPropagation(),children:[a.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary",children:[a.jsxs("div",{className:"flex items-center gap-3",children:[a.jsx("div",{className:"p-2 rounded-full bg-bambu-green/20 text-bambu-green",children:p&&x?a.jsx("img",{src:x,alt:"",className:`w-5 h-5 rounded ${r==="dark"?"invert opacity-[0.65]":"opacity-60"}`}):a.jsx(D,{className:"w-5 h-5"})}),a.jsx("h2",{className:"text-lg font-semibold text-white",children:i?"Edit Link":"Add External Link"})]}),a.jsx("button",{onClick:e,className:"text-bambu-gray hover:text-white transition-colors",children:a.jsx(Lt,{className:"w-5 h-5"})})]}),a.jsxs("form",{onSubmit:P,className:"p-6 space-y-4",children:[S&&a.jsx("div",{className:"p-3 bg-red-500/20 border border-red-500/50 rounded-lg text-sm text-red-400",children:S}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Name *"}),a.jsx("input",{type:"text",value:o,onChange:I=>l(I.target.value),placeholder:"My Link",maxLength:50,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"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"URL *"}),a.jsx("input",{type:"text",value:c,onChange:I=>u(I.target.value),placeholder:"https://example.com",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"})]}),a.jsxs("div",{className:"space-y-3",children:[a.jsx("label",{className:"block text-sm text-bambu-gray",children:"Icon"}),a.jsxs("div",{className:"p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary",children:[a.jsxs("div",{className:"flex items-center justify-between mb-2",children:[a.jsx("span",{className:"text-sm text-white",children:"Custom Icon"}),a.jsx("input",{ref:s,type:"file",accept:"image/png,image/jpeg,image/gif,image/svg+xml,image/webp,image/x-icon",className:"hidden",onChange:C}),p&&x?a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("img",{src:x,alt:"Custom icon",className:`w-8 h-8 rounded border border-bambu-dark-tertiary ${r==="dark"?"invert opacity-[0.65]":"opacity-60"}`}),a.jsx("button",{type:"button",onClick:E,className:"p-1 text-red-400 hover:text-red-300 transition-colors",title:"Remove custom icon",children:a.jsx(an,{className:"w-4 h-4"})})]}):a.jsxs(Te,{type:"button",variant:"secondary",size:"sm",onClick:()=>s.current?.click(),children:[a.jsx(Ba,{className:"w-4 h-4"}),"Upload"]})]}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"PNG, JPG, GIF, SVG, WebP, or ICO. Max 1MB."})]}),!p&&a.jsxs("div",{children:[a.jsx("span",{className:"text-sm text-bambu-gray block mb-2",children:"Or choose a preset icon"}),a.jsx(Ffe,{value:d,onChange:h})]})]}),a.jsxs("div",{className:"flex gap-3 pt-2",children:[a.jsx(Te,{type:"button",variant:"secondary",onClick:e,className:"flex-1",children:"Cancel"}),a.jsxs(Te,{type:"submit",disabled:A,className:"flex-1",children:[A?a.jsx(pt,{className:"w-4 h-4 animate-spin"}):a.jsx(ms,{className:"w-4 h-4"}),i?"Save":"Add"]})]})]})]})})}function LKe(){const t=sn(),[e,n]=_.useState(!1),[r,i]=_.useState(null),[s,o]=_.useState(null),[l,c]=_.useState(null),{data:u,isLoading:d}=ct({queryKey:["external-links"],queryFn:ce.getExternalLinks}),h=gt({mutationFn:S=>ce.deleteExternalLink(S),onSuccess:()=>{t.invalidateQueries({queryKey:["external-links"]})}}),p=gt({mutationFn:S=>ce.reorderExternalLinks(S),onSuccess:()=>{t.invalidateQueries({queryKey:["external-links"]})}}),m=(S,N)=>{c(N),S.dataTransfer.effectAllowed="move"},x=S=>{S.preventDefault(),S.dataTransfer.dropEffect="move"},y=(S,N)=>{if(S.preventDefault(),l===null||l===N||!u)return;const T=u.map(P=>P.id),k=T.indexOf(l),C=T.indexOf(N);if(k===-1||C===-1)return;const E=[...T];E.splice(k,1),E.splice(C,0,l),p.mutate(E),c(null)},v=S=>{o(S)},b=()=>{s&&(h.mutate(s.id),o(null))};return a.jsxs(a.Fragment,{children:[a.jsxs(St,{children:[a.jsx(Kn,{children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(fc,{className:"w-5 h-5 text-bambu-green"}),a.jsx("h2",{className:"text-lg font-semibold text-white",children:"Sidebar Links"})]}),a.jsxs(Te,{size:"sm",onClick:()=>n(!0),children:[a.jsx(fr,{className:"w-4 h-4"}),"Add Link"]})]})}),a.jsxs(Nt,{children:[a.jsx("p",{className:"text-sm text-bambu-gray mb-4",children:"Add external links to the sidebar navigation. Drag to reorder."}),d?a.jsx("div",{className:"flex justify-center py-8",children:a.jsx(pt,{className:"w-6 h-6 text-bambu-green animate-spin"})}):u&&u.length>0?a.jsx("div",{className:"space-y-2",children:u.map(S=>{const N=wM(S.icon);return a.jsxs("div",{draggable:!0,onDragStart:T=>m(T,S.id),onDragOver:x,onDrop:T=>y(T,S.id),className:`flex items-center gap-3 p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary transition-colors ${l===S.id?"opacity-50":""}`,children:[a.jsx(Hg,{className:"w-6 h-6 md:w-4 md:h-4 text-bambu-gray cursor-grab flex-shrink-0"}),a.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark-tertiary text-bambu-gray",children:a.jsx(N,{className:"w-4 h-4"})}),a.jsxs("div",{className:"flex-1 min-w-0",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("span",{className:"text-white font-medium truncate",children:S.name}),a.jsx(Xr,{className:"w-3 h-3 text-bambu-gray flex-shrink-0"})]}),a.jsx("span",{className:"text-sm text-bambu-gray truncate block",children:S.url})]}),a.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[a.jsx("button",{onClick:()=>i(S),className:"p-2 rounded-lg hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white transition-colors",title:"Edit",children:a.jsx(ea,{className:"w-4 h-4"})}),a.jsx("button",{onClick:()=>v(S),disabled:h.isPending,className:"p-2 rounded-lg hover:bg-red-500/20 text-bambu-gray hover:text-red-400 transition-colors disabled:opacity-50",title:"Delete",children:a.jsx(an,{className:"w-4 h-4"})})]})]},S.id)})}):a.jsxs("div",{className:"text-center py-8 text-bambu-gray",children:[a.jsx(fc,{className:"w-8 h-8 mx-auto mb-2 opacity-50"}),a.jsx("p",{children:"No external links configured"}),a.jsx("p",{className:"text-sm",children:'Click "Add Link" to add one'})]})]})]}),(e||r)&&a.jsx(OKe,{link:r,onClose:()=>{n(!1),i(null)}}),s&&a.jsx(Zn,{title:"Delete Link",message:`Are you sure you want to delete "${s.name}"? This action cannot be undone.`,confirmText:"Delete",cancelText:"Cancel",variant:"danger",onConfirm:b,onCancel:()=>o(null)})]})}function FKe(){const{t}=On(),e=sn(),{showToast:n}=Hn(),[r,i]=_.useState(!1),[s,o]=_.useState(""),[l,c]=_.useState("immediate"),[u,d]=_.useState("3DPrinter-X1-Carbon"),[h,p]=_.useState(null),[m,x]=_.useState(!1),[y,v]=_.useState(null),{data:b,isLoading:S}=ct({queryKey:["virtual-printer-settings"],queryFn:x1.getSettings,refetchInterval:1e4}),{data:N}=ct({queryKey:["virtual-printer-models"],queryFn:x1.getModels}),{data:T}=ct({queryKey:["printers"],queryFn:ce.getPrinters});_.useEffect(()=>{if(b){i(b.enabled);let U=b.mode==="queue"?"review":b.mode;U!=="immediate"&&U!=="review"&&U!=="print_queue"&&U!=="proxy"&&(U="immediate"),c(U),d(b.model),p(b.target_printer_id)}},[b]);const k=gt({mutationFn:U=>x1.updateSettings(U),onSuccess:()=>{e.invalidateQueries({queryKey:["virtual-printer-settings"]}),n(t("virtualPrinter.toast.updated")),v(null)},onError:U=>{if(n(U.message||t("virtualPrinter.toast.failedToUpdate"),"error"),b){i(b.enabled);const j=b.mode==="queue"?"review":b.mode;c(["immediate","review","print_queue","proxy"].includes(j)?j:"immediate"),d(b.model),p(b.target_printer_id)}v(null)}}),C=()=>{const U=!r;if(U){if(l==="proxy"){if(!h){n(t("virtualPrinter.toast.targetPrinterRequired"),"error");return}}else if(!s&&!b?.access_code_set){n(t("virtualPrinter.toast.accessCodeRequired"),"error");return}}i(U),v("toggle"),k.mutate({enabled:U,access_code:l!=="proxy"&&s||void 0,mode:l,target_printer_id:l==="proxy"?h??void 0:void 0})},E=()=>{if(!s){n(t("virtualPrinter.toast.accessCodeEmpty"),"error");return}if(s.length!==8){n(t("virtualPrinter.toast.accessCodeLength"),"error");return}v("accessCode"),k.mutate({access_code:s}),o("")},P=U=>{c(U),v("mode"),k.mutate({mode:U})},A=U=>{p(U),v("targetPrinter"),k.mutate({target_printer_id:U})},D=U=>{d(U),v("model"),k.mutate({model:U})};if(S)return a.jsx(St,{children:a.jsx(Nt,{className:"py-8 flex justify-center",children:a.jsx(pt,{className:"w-6 h-6 animate-spin text-bambu-green"})})});const I=b?.status,L=I?.running||!1;return a.jsxs("div",{className:"flex flex-col lg:flex-row gap-6 lg:gap-8",children:[a.jsx("div",{className:"space-y-6 lg:w-[480px] lg:flex-shrink-0",children:a.jsxs(St,{children:[a.jsx(Kn,{children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(Ur,{className:"w-5 h-5 text-bambu-green"}),a.jsx("h2",{className:"text-lg font-semibold text-white",children:t("virtualPrinter.title")})]}),I&&a.jsxs("div",{className:`flex items-center gap-2 text-sm ${L?"text-green-400":"text-bambu-gray"}`,children:[a.jsx("span",{className:`w-2 h-2 rounded-full ${L?"bg-green-400 animate-pulse":"bg-gray-500"}`}),t(L?"virtualPrinter.running":"virtualPrinter.stopped")]})]})}),a.jsxs(Nt,{className:"space-y-4",children:[a.jsx("p",{className:"text-sm text-bambu-gray",children:t(l==="proxy"?"virtualPrinter.description.proxy":"virtualPrinter.description.default")}),a.jsxs("div",{className:"flex items-center justify-between py-3 border-t border-bambu-dark-tertiary",children:[a.jsxs("div",{children:[a.jsx("div",{className:"text-white font-medium",children:t("virtualPrinter.enable.title")}),a.jsx("div",{className:"text-sm text-bambu-gray",children:L?l==="proxy"?t("virtualPrinter.enable.proxyingTo",{name:T?.find(U=>U.id===h)?.name||"printer"}):t("virtualPrinter.enable.visibleInSlicer"):t("virtualPrinter.enable.notActive")})]}),a.jsx("button",{onClick:C,disabled:y==="toggle",className:`relative w-12 h-6 rounded-full transition-colors ${r?"bg-bambu-green":"bg-bambu-dark-tertiary"} ${y==="toggle"?"opacity-50":""}`,children:a.jsx("span",{className:`absolute top-1 left-1 w-4 h-4 bg-white rounded-full transition-transform ${r?"translate-x-6":""}`})})]}),l!=="proxy"&&a.jsxs("div",{className:"py-3 border-t border-bambu-dark-tertiary",children:[a.jsx("div",{className:"text-white font-medium mb-2",children:t("virtualPrinter.model.title")}),a.jsx("div",{className:"text-sm text-bambu-gray mb-3",children:t("virtualPrinter.model.description")}),a.jsxs("div",{className:"relative",children:[a.jsx("select",{value:u,onChange:U=>D(U.target.value),disabled:y==="model",className:"w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-2 text-white appearance-none cursor-pointer disabled:opacity-50 disabled:cursor-not-allowed pr-10",children:N?.models&&Object.entries(N.models).sort(([,U],[,j])=>U.localeCompare(j)).map(([U,j])=>a.jsx("option",{value:U,children:j},U))}),a.jsx(Kr,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}),r&&L&&a.jsxs("p",{className:"text-xs text-bambu-gray mt-2",children:[a.jsx(nl,{className:"w-3 h-3 inline mr-1"}),t("virtualPrinter.model.restartWarning")]})]}),l!=="proxy"&&a.jsxs("div",{className:"py-3 border-t border-bambu-dark-tertiary",children:[a.jsx("div",{className:"text-white font-medium mb-2",children:t("virtualPrinter.accessCode.title")}),a.jsx("div",{className:"text-sm text-bambu-gray mb-3",children:b?.access_code_set?a.jsxs("span",{className:"flex items-center gap-1 text-green-400",children:[a.jsx(Wi,{className:"w-4 h-4"}),t("virtualPrinter.accessCode.isSet")]}):a.jsxs("span",{className:"flex items-center gap-1 text-yellow-400",children:[a.jsx(Sn,{className:"w-4 h-4"}),t("virtualPrinter.accessCode.notSet")]})}),a.jsxs("div",{className:"flex gap-2",children:[a.jsxs("div",{className:"relative flex-1",children:[a.jsx("input",{type:m?"text":"password",value:s,onChange:U=>o(U.target.value),placeholder:b?.access_code_set?t("virtualPrinter.accessCode.placeholderChange"):t("virtualPrinter.accessCode.placeholder"),maxLength:8,className:"w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-2 text-white placeholder-bambu-gray pr-10 font-mono"}),a.jsx("button",{onClick:()=>x(!m),className:"absolute right-2 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white",children:m?a.jsx(uM,{className:"w-4 h-4"}):a.jsx(xc,{className:"w-4 h-4"})})]}),a.jsx(Te,{onClick:E,disabled:!s||y==="accessCode",variant:"primary",children:y==="accessCode"?a.jsx(pt,{className:"w-4 h-4 animate-spin"}):t("common.save")})]}),a.jsxs("p",{className:"text-xs text-bambu-gray mt-2",children:[t("virtualPrinter.accessCode.hint"),s&&a.jsxs("span",{className:s.length===8?"text-green-400":"text-yellow-400",children:[" ",t("virtualPrinter.accessCode.charCount",{count:s.length})]})]})]}),l==="proxy"&&a.jsxs("div",{className:"py-3 border-t border-bambu-dark-tertiary",children:[a.jsx("div",{className:"text-white font-medium mb-2",children:t("virtualPrinter.targetPrinter.title")}),a.jsx("div",{className:"text-sm text-bambu-gray mb-3",children:h?a.jsxs("span",{className:"flex items-center gap-1 text-green-400",children:[a.jsx(Wi,{className:"w-4 h-4"}),t("virtualPrinter.targetPrinter.configured")]}):a.jsxs("span",{className:"flex items-center gap-1 text-yellow-400",children:[a.jsx(Sn,{className:"w-4 h-4"}),t("virtualPrinter.targetPrinter.notConfigured")]})}),a.jsxs("div",{className:"relative",children:[a.jsxs("select",{value:h??"",onChange:U=>{const j=parseInt(U.target.value,10);isNaN(j)||A(j)},disabled:y==="targetPrinter",className:"w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-2 text-white appearance-none cursor-pointer disabled:opacity-50 disabled:cursor-not-allowed pr-10",children:[a.jsx("option",{value:"",children:t("virtualPrinter.targetPrinter.placeholder")}),T?.map(U=>a.jsxs("option",{value:U.id,children:[U.name," (",U.ip_address,")"]},U.id))]}),a.jsx(Kr,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}),a.jsx("p",{className:"text-xs text-bambu-gray mt-2",children:t("virtualPrinter.targetPrinter.hint")}),!T?.length&&a.jsxs("p",{className:"text-xs text-yellow-400 mt-2",children:[a.jsx(Sn,{className:"w-3 h-3 inline mr-1"}),t("virtualPrinter.targetPrinter.noPrinters")]})]}),a.jsxs("div",{className:"py-3 border-t border-bambu-dark-tertiary",children:[a.jsx("div",{className:"text-white font-medium mb-2",children:t("virtualPrinter.mode.title")}),a.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[a.jsxs("button",{onClick:()=>P("immediate"),disabled:y==="mode",className:`p-3 rounded-lg border text-left transition-colors ${l==="immediate"?"border-bambu-green bg-bambu-green/10":"border-bambu-dark-tertiary hover:border-bambu-gray"}`,children:[a.jsx("div",{className:"text-white font-medium",children:t("virtualPrinter.mode.archive")}),a.jsx("div",{className:"text-xs text-bambu-gray",children:t("virtualPrinter.mode.archiveDesc")})]}),a.jsxs("button",{onClick:()=>P("review"),disabled:y==="mode",className:`p-3 rounded-lg border text-left transition-colors ${l==="review"?"border-bambu-green bg-bambu-green/10":"border-bambu-dark-tertiary hover:border-bambu-gray"}`,children:[a.jsx("div",{className:"text-white font-medium",children:t("virtualPrinter.mode.review")}),a.jsx("div",{className:"text-xs text-bambu-gray",children:t("virtualPrinter.mode.reviewDesc")})]}),a.jsxs("button",{onClick:()=>P("print_queue"),disabled:y==="mode",className:`p-3 rounded-lg border text-left transition-colors ${l==="print_queue"?"border-bambu-green bg-bambu-green/10":"border-bambu-dark-tertiary hover:border-bambu-gray"}`,children:[a.jsx("div",{className:"text-white font-medium",children:t("virtualPrinter.mode.queue")}),a.jsx("div",{className:"text-xs text-bambu-gray",children:t("virtualPrinter.mode.queueDesc")})]}),a.jsxs("button",{onClick:()=>P("proxy"),disabled:y==="mode",className:`p-3 rounded-lg border text-left transition-colors ${l==="proxy"?"border-blue-500 bg-blue-500/10":"border-bambu-dark-tertiary hover:border-bambu-gray"}`,children:[a.jsxs("div",{className:"flex items-center gap-1.5 text-white font-medium",children:[a.jsx(Iz,{className:"w-4 h-4"}),t("virtualPrinter.mode.proxy")]}),a.jsx("div",{className:"text-xs text-bambu-gray",children:t("virtualPrinter.mode.proxyDesc")})]})]})]})]})]})}),a.jsxs("div",{className:"space-y-6 lg:w-[480px] lg:flex-shrink-0",children:[a.jsx(St,{className:"border-l-4 border-l-yellow-500",children:a.jsx(Nt,{className:"py-4",children:a.jsxs("div",{className:"flex items-start gap-3",children:[a.jsx(Sn,{className:"w-5 h-5 text-yellow-500 flex-shrink-0 mt-0.5"}),a.jsxs("div",{className:"text-sm",children:[a.jsx("p",{className:"text-white font-medium mb-2",children:t("virtualPrinter.setupRequired.title")}),a.jsx("p",{className:"text-bambu-gray mb-3",children:t("virtualPrinter.setupRequired.description")}),a.jsxs("a",{href:"https://wiki.bambuddy.cool/features/virtual-printer/",target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-2 px-4 py-2 bg-yellow-500/20 border border-yellow-500/50 rounded-md text-yellow-400 hover:bg-yellow-500/30 transition-colors",children:[a.jsx(Xr,{className:"w-4 h-4"}),t("virtualPrinter.setupRequired.readGuide")]})]})]})})}),a.jsx(St,{children:a.jsx(Nt,{className:"py-4",children:a.jsxs("div",{className:"flex items-start gap-3",children:[a.jsx(nl,{className:"w-5 h-5 text-blue-400 flex-shrink-0 mt-0.5"}),a.jsxs("div",{className:"text-sm text-bambu-gray",children:[a.jsx("p",{className:"mb-2",children:a.jsxs("strong",{className:"text-white",children:[t(l==="proxy"?"virtualPrinter.howItWorks.titleProxy":"virtualPrinter.howItWorks.title"),":"]})}),l==="proxy"?a.jsxs("ol",{className:"list-decimal list-inside space-y-1",children:[a.jsx("li",{children:t("virtualPrinter.howItWorks.proxyStep1")}),a.jsx("li",{children:t("virtualPrinter.howItWorks.proxyStep2")}),a.jsx("li",{children:t("virtualPrinter.howItWorks.proxyStep3")}),a.jsx("li",{children:t("virtualPrinter.howItWorks.proxyStep4")}),a.jsx("li",{children:t("virtualPrinter.howItWorks.proxyStep5")})]}):a.jsxs("ol",{className:"list-decimal list-inside space-y-1",children:[a.jsx("li",{children:t("virtualPrinter.howItWorks.step1")}),a.jsx("li",{children:t("virtualPrinter.howItWorks.step2")}),a.jsx("li",{children:t("virtualPrinter.howItWorks.step3")}),a.jsx("li",{children:t("virtualPrinter.howItWorks.step4")}),a.jsx("li",{children:t("virtualPrinter.howItWorks.step5")}),a.jsx("li",{children:t("virtualPrinter.howItWorks.step6")})]})]})]})})}),I&&L&&a.jsxs(St,{children:[a.jsx(Kn,{children:a.jsx("h3",{className:"text-md font-semibold text-white",children:t("virtualPrinter.status.title")})}),a.jsx(Nt,{children:I.mode==="proxy"&&I.proxy?a.jsxs("div",{className:"grid grid-cols-2 gap-4 text-sm",children:[a.jsxs("div",{children:[a.jsx("div",{className:"text-bambu-gray",children:t("virtualPrinter.status.targetPrinter")}),a.jsx("div",{className:"text-white",children:T?.find(U=>U.id===h)?.name||I.proxy.target_host}),a.jsx("div",{className:"text-xs text-bambu-gray font-mono",children:I.proxy.target_host})]}),a.jsxs("div",{children:[a.jsx("div",{className:"text-bambu-gray",children:t("virtualPrinter.status.mode")}),a.jsxs("div",{className:"text-white flex items-center gap-1.5",children:[a.jsx(Iz,{className:"w-4 h-4"}),t("virtualPrinter.mode.proxy")]})]}),a.jsxs("div",{children:[a.jsx("div",{className:"text-bambu-gray",children:t("virtualPrinter.status.ftpPort")}),a.jsx("div",{className:"text-white font-mono",children:I.proxy.ftp_port})]}),a.jsxs("div",{children:[a.jsx("div",{className:"text-bambu-gray",children:t("virtualPrinter.status.mqttPort")}),a.jsx("div",{className:"text-white font-mono",children:I.proxy.mqtt_port})]}),a.jsxs("div",{children:[a.jsx("div",{className:"text-bambu-gray",children:t("virtualPrinter.status.ftpConnections")}),a.jsx("div",{className:"text-white",children:I.proxy.ftp_connections})]}),a.jsxs("div",{children:[a.jsx("div",{className:"text-bambu-gray",children:t("virtualPrinter.status.mqttConnections")}),a.jsx("div",{className:"text-white",children:I.proxy.mqtt_connections})]})]}):a.jsxs("div",{className:"grid grid-cols-2 gap-4 text-sm",children:[a.jsxs("div",{children:[a.jsx("div",{className:"text-bambu-gray",children:t("virtualPrinter.status.printerName")}),a.jsx("div",{className:"text-white",children:I.name})]}),a.jsxs("div",{children:[a.jsx("div",{className:"text-bambu-gray",children:t("virtualPrinter.status.model")}),a.jsx("div",{className:"text-white",children:I.model_name||I.model})]}),a.jsxs("div",{children:[a.jsx("div",{className:"text-bambu-gray",children:t("virtualPrinter.status.serialNumber")}),a.jsx("div",{className:"text-white font-mono",children:I.serial})]}),a.jsxs("div",{children:[a.jsx("div",{className:"text-bambu-gray",children:t("virtualPrinter.status.mode")}),a.jsx("div",{className:"text-white capitalize",children:I.mode})]}),a.jsxs("div",{children:[a.jsx("div",{className:"text-bambu-gray",children:t("virtualPrinter.status.pendingFiles")}),a.jsx("div",{className:"text-white",children:I.pending_files})]})]})})]})]})]})}function Sq({status:t}){if(!t)return null;const e={success:"bg-green-500/20 text-green-400",failed:"bg-red-500/20 text-red-400",skipped:"bg-yellow-500/20 text-yellow-400",running:"bg-blue-500/20 text-blue-400"},n={success:a.jsx(Ar,{className:"w-3 h-3"}),failed:a.jsx(Ji,{className:"w-3 h-3"}),skipped:a.jsx(LR,{className:"w-3 h-3"}),running:a.jsx(pt,{className:"w-3 h-3 animate-spin"})};return a.jsxs("span",{className:`inline-flex items-center gap-1 px-2 py-0.5 rounded text-xs font-medium ${e[t]||"bg-gray-500/20 text-gray-400"}`,children:[n[t],t.charAt(0).toUpperCase()+t.slice(1)]})}function IKe(t){return t?new Date(t).toLocaleString():"-"}function Nq(t){if(!t)return"-";const e=new Date(t),n=new Date,r=e.getTime()-n.getTime(),i=Math.round(r/6e4);if(i<0){const s=Math.abs(i);if(s<60)return`${s}m ago`;const o=Math.floor(s/60);return o<24?`${o}h ago`:`${Math.floor(o/24)}d ago`}else{if(i<60)return`in ${i}m`;const s=Math.floor(i/60);return s<24?`in ${s}h`:`in ${Math.floor(s/24)}d`}}function UKe(){const t=sn(),{showToast:e}=Hn(),{t:n}=On(),[r,i]=_.useState(""),[s,o]=_.useState(""),[l,c]=_.useState("main"),[u,d]=_.useState(!1),[h,p]=_.useState("daily"),[m,x]=_.useState(!0),[y,v]=_.useState(!0),[b,S]=_.useState(!1),[N,T]=_.useState(!0),[k,C]=_.useState(!1),[E,P]=_.useState(!1),[A,D]=_.useState(""),[I,L]=_.useState(!1),[U,j]=_.useState(null),[$,K]=_.useState(null),B=_.useRef(null);_.useEffect(()=>{if(k||E){const z=O=>(O.preventDefault(),O.returnValue="A backup operation is in progress. Are you sure you want to leave?",O.returnValue);return window.addEventListener("beforeunload",z),()=>window.removeEventListener("beforeunload",z)}},[k,E]);const[X,Y]=_.useState(!1),[ne,H]=_.useState(null),W=_.useRef(null),re=_.useRef(!1),{data:ie,isLoading:pe}=ct({queryKey:["github-backup-config"],queryFn:ce.getGitHubBackupConfig}),{data:me}=ct({queryKey:["github-backup-status"],queryFn:ce.getGitHubBackupStatus,refetchInterval:te=>te.state.data?.is_running?500:1e4}),{data:de}=ct({queryKey:["github-backup-logs"],queryFn:()=>ce.getGitHubBackupLogs(20)}),{data:Ee}=ct({queryKey:["cloud-status"],queryFn:ce.getCloudStatus}),{data:se}=ct({queryKey:["printers"],queryFn:ce.getPrinters}),Ae=jR({queries:(se??[]).map(te=>({queryKey:["printerStatus",te.id],queryFn:()=>ce.getPrinterStatus(te.id),staleTime:1e4,refetchInterval:3e4}))}),Fe=(se??[]).map((te,z)=>({printer:te,connected:Ae[z]?.data?.connected??!1})),ge=Fe.length,Ze=Fe.filter(te=>te.connected).length,G=ge>0&&Ze===0,Q=Ze>0&&Ze{ie&&(i(ie.repository_url),c(ie.branch),d(ie.schedule_enabled),p(ie.schedule_type),x(ie.backup_kprofiles),v(ie.backup_cloud_profiles),S(ie.backup_settings),T(ie.enabled),o(""),setTimeout(()=>{re.current=!0},100))},[ie]);const he=_.useCallback(async(te=!1)=>{if(ie?.has_token)try{te&&s?(await ce.saveGitHubBackupConfig({repository_url:r,access_token:s,branch:l,schedule_enabled:u,schedule_type:h,backup_kprofiles:m,backup_cloud_profiles:y,backup_settings:b,enabled:N}),o(""),e("Token updated")):(await ce.updateGitHubBackupConfig({repository_url:r,branch:l,schedule_enabled:u,schedule_type:h,backup_kprofiles:m,backup_cloud_profiles:y,backup_settings:b,enabled:N}),e("Settings saved")),t.invalidateQueries({queryKey:["github-backup-config"]}),t.invalidateQueries({queryKey:["github-backup-status"]})}catch(z){e(`Failed to save: ${z.message}`,"error")}},[ie?.has_token,r,s,l,u,h,m,y,b,N,t,e]);_.useEffect(()=>{if(!(!re.current||!ie?.has_token))return W.current&&clearTimeout(W.current),W.current=setTimeout(()=>{he(!1)},500),()=>{W.current&&clearTimeout(W.current)}},[r,l,u,h,m,y,b,N,he,ie?.has_token]),_.useEffect(()=>{if(!(!re.current||!ie?.has_token||!s))return W.current&&clearTimeout(W.current),W.current=setTimeout(()=>{he(!0)},1e3),()=>{W.current&&clearTimeout(W.current)}},[s,he,ie?.has_token]);const q=gt({mutationFn:te=>ce.saveGitHubBackupConfig(te),onSuccess:()=>{t.invalidateQueries({queryKey:["github-backup-config"]}),t.invalidateQueries({queryKey:["github-backup-status"]}),e("GitHub backup enabled"),o(""),re.current=!0},onError:te=>{e(`Failed to save: ${te.message}`,"error")}}),ee=gt({mutationFn:ce.triggerGitHubBackup,onSuccess:te=>{t.invalidateQueries({queryKey:["github-backup-status"]}),t.invalidateQueries({queryKey:["github-backup-logs"]}),te.success?te.files_changed>0?e(`Backup complete - ${te.files_changed} files updated`):e("Backup skipped - no changes"):e(`Backup failed: ${te.message}`,"error")},onError:te=>{e(`Backup failed: ${te.message}`,"error")}}),V=gt({mutationFn:()=>ce.clearGitHubBackupLogs(0),onSuccess:te=>{t.invalidateQueries({queryKey:["github-backup-logs"]}),e(`Cleared ${te.deleted} logs`)},onError:te=>{e(`Failed to clear logs: ${te.message}`,"error")}}),ye=async()=>{Y(!0),H(null);try{let te;if(s){if(!r){e("Enter repository URL","error"),Y(!1);return}te=await ce.testGitHubConnection(r,s)}else if(ie?.has_token)te=await ce.testGitHubStoredConnection();else{e("Enter repository URL and access token","error"),Y(!1);return}H({success:te.success,message:te.message})}catch(te){H({success:!1,message:te.message})}finally{Y(!1)}},je=()=>{if(!r){e("Repository URL is required","error");return}if(!s){e("Access token is required","error");return}q.mutate({repository_url:r,access_token:s,branch:l,schedule_enabled:u,schedule_type:h,backup_kprofiles:m,backup_cloud_profiles:y,backup_settings:b,enabled:N})};return pe?a.jsx("div",{className:"flex items-center justify-center py-12",children:a.jsx(pt,{className:"w-8 h-8 animate-spin text-bambu-green"})}):a.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[a.jsxs("div",{className:"space-y-6",children:[a.jsxs(St,{children:[a.jsx(Kn,{children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(pP,{className:"w-5 h-5 text-gray-400"}),a.jsx("h2",{className:"text-lg font-semibold text-white",children:"GitHub Backup"})]}),ie&&Ee?.is_authenticated&&a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("span",{className:"text-sm text-bambu-gray",children:"Enabled"}),a.jsx(Fn,{checked:N,onChange:T})]})]})}),a.jsx(Nt,{className:"space-y-4",children:Ee?.is_authenticated?a.jsxs(a.Fragment,{children:[a.jsx("p",{className:"text-sm text-bambu-gray",children:"Automatically sync your profiles to a private GitHub repository for backup and version history."}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Repository URL"}),a.jsx("input",{type:"text",value:r,onChange:te=>{i(te.target.value),H(null)},placeholder:"https://github.com/username/bambuddy-backup",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"})]}),a.jsxs("div",{children:[a.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:["Personal Access Token ",ie?.has_token&&a.jsx("span",{className:"text-green-400",children:"(saved)"})]}),a.jsx("input",{type:"password",value:s,onChange:te=>{o(te.target.value),H(null)},placeholder:ie?.has_token?"Enter new token to update":"ghp_xxxxxxxxxxxx",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"}),a.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Fine-grained token with Contents read/write permission"})]}),a.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Branch"}),a.jsx("input",{type:"text",value:l,onChange:te=>c(te.target.value),placeholder:"main",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"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Auto-backup"}),a.jsxs("select",{value:u?h:"disabled",onChange:te=>{te.target.value==="disabled"?d(!1):(d(!0),p(te.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",children:[a.jsx("option",{value:"disabled",children:"Manual only"}),a.jsx("option",{value:"hourly",children:"Hourly"}),a.jsx("option",{value:"daily",children:"Daily"}),a.jsx("option",{value:"weekly",children:"Weekly"})]})]})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-2",children:"Include in backup"}),a.jsxs("div",{className:"space-y-2",children:[a.jsxs("label",{className:`flex items-start gap-2 ${G?"cursor-not-allowed opacity-60":"cursor-pointer"}`,children:[a.jsx("input",{type:"checkbox",checked:m,onChange:te=>x(te.target.checked),className:"w-4 h-4 mt-0.5 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green",disabled:G}),a.jsxs("div",{className:"flex-1",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("span",{className:`text-sm ${G?"text-bambu-gray":"text-white"}`,children:"K-Profiles"}),G&&a.jsxs("span",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-xs bg-yellow-500/20 text-yellow-400",children:[a.jsx(Sn,{className:"w-3 h-3"}),"No printers connected"]}),Q&&a.jsxs("span",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-xs bg-yellow-500/20 text-yellow-400",children:[a.jsx(Sn,{className:"w-3 h-3"}),Ze,"/",ge," connected"]})]}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Pressure advance calibration from connected printers"})]})]}),a.jsxs("label",{className:"flex items-start gap-2 cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:y,onChange:te=>v(te.target.checked),className:"w-4 h-4 mt-0.5 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green",disabled:!Ee?.is_authenticated}),a.jsxs("div",{children:[a.jsx("span",{className:`text-sm ${Ee?.is_authenticated?"text-white":"text-bambu-gray"}`,children:"Cloud Profiles"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Filament, printer, and process presets from Bambu Cloud"})]})]}),a.jsxs("label",{className:"flex items-start gap-2 cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:b,onChange:te=>S(te.target.checked),className:"w-4 h-4 mt-0.5 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),a.jsxs("div",{children:[a.jsx("span",{className:"text-white text-sm",children:"App Settings"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Bambuddy configuration (excludes sensitive data)"})]})]})]})]}),a.jsxs("div",{className:"border-t border-bambu-dark-tertiary pt-4 space-y-3",children:[me?.configured&&a.jsxs("div",{className:"flex items-center justify-between text-sm",children:[a.jsx("div",{className:"flex items-center gap-2 text-bambu-gray",children:me.last_backup_at?a.jsxs(a.Fragment,{children:[a.jsxs("span",{children:["Last backup: ",Nq(me.last_backup_at)]}),a.jsx(Sq,{status:me.last_backup_status})]}):a.jsx("span",{children:"No backups yet"})}),me.next_scheduled_run&&a.jsxs("span",{className:"text-bambu-gray",children:[a.jsx(tr,{className:"w-3 h-3 inline mr-1"}),"Next: ",Nq(me.next_scheduled_run)]})]}),ne&&a.jsxs("div",{className:`text-sm flex items-center gap-1 ${ne.success?"text-green-400":"text-red-400"}`,children:[ne.success?a.jsx(Ar,{className:"w-4 h-4"}):a.jsx(Ji,{className:"w-4 h-4"}),ne.message]}),a.jsx("div",{className:"flex flex-wrap items-center gap-2",children:me?.configured?a.jsx(a.Fragment,{children:ee.isPending||me.is_running?a.jsxs("div",{className:"flex items-center gap-2 text-bambu-green",children:[a.jsx(pt,{className:"w-4 h-4 animate-spin"}),a.jsx("span",{className:"text-sm",children:me.progress||"Starting backup..."})]}):a.jsxs(a.Fragment,{children:[a.jsxs(Te,{variant:"primary",size:"sm",onClick:()=>ee.mutate(),disabled:!ie?.enabled,children:[a.jsx(So,{className:"w-4 h-4"}),"Backup Now"]}),a.jsxs(Te,{variant:"secondary",size:"sm",onClick:ye,disabled:X,children:[X?a.jsx(pt,{className:"w-4 h-4 animate-spin"}):a.jsx(Dr,{className:"w-4 h-4"}),"Test"]})]})}):a.jsxs(a.Fragment,{children:[a.jsxs(Te,{variant:"primary",size:"sm",onClick:je,disabled:q.isPending||!r||!s,children:[q.isPending?a.jsx(pt,{className:"w-4 h-4 animate-spin"}):a.jsx(Ar,{className:"w-4 h-4"}),"Enable Backup"]}),a.jsxs(Te,{variant:"secondary",size:"sm",onClick:ye,disabled:X||!r||!s,children:[X?a.jsx(pt,{className:"w-4 h-4 animate-spin"}):a.jsx(Dr,{className:"w-4 h-4"}),"Test Connection"]})]})})]})]}):a.jsxs("div",{className:"flex items-start gap-2 p-3 bg-yellow-500/10 border border-yellow-500/30 rounded-lg",children:[a.jsx(Sn,{className:"w-4 h-4 text-yellow-400 mt-0.5 flex-shrink-0"}),a.jsx("p",{className:"text-sm text-yellow-400",children:"Bambu Cloud login required. Sign in under Profiles → Cloud Profiles to enable GitHub backup."})]})})]}),de&&de.length>0&&a.jsxs(St,{children:[a.jsx(Kn,{children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(W0,{className:"w-5 h-5 text-gray-400"}),a.jsx("h2",{className:"text-lg font-semibold text-white",children:"History"})]}),a.jsxs(Te,{variant:"ghost",size:"sm",onClick:()=>V.mutate(),disabled:V.isPending,children:[a.jsx(an,{className:"w-4 h-4"}),"Clear"]})]})}),a.jsx(Nt,{children:a.jsx("div",{className:"overflow-x-auto",children:a.jsxs("table",{className:"w-full text-sm",children:[a.jsx("thead",{children:a.jsxs("tr",{className:"text-bambu-gray border-b border-bambu-dark-tertiary",children:[a.jsx("th",{className:"text-left py-2 px-2",children:"Date"}),a.jsx("th",{className:"text-left py-2 px-2",children:"Status"}),a.jsx("th",{className:"text-left py-2 px-2",children:"Commit"})]})}),a.jsx("tbody",{children:de.slice(0,10).map(te=>a.jsxs("tr",{className:"border-b border-bambu-dark-tertiary/50 hover:bg-bambu-dark-secondary",children:[a.jsx("td",{className:"py-2 px-2 text-white",children:IKe(te.started_at)}),a.jsx("td",{className:"py-2 px-2",children:a.jsx(Sq,{status:te.status})}),a.jsx("td",{className:"py-2 px-2",children:te.commit_sha?a.jsxs("a",{href:`${ie?.repository_url}/commit/${te.commit_sha}`,target:"_blank",rel:"noopener noreferrer",className:"text-bambu-green hover:underline inline-flex items-center gap-1",children:[te.commit_sha.substring(0,7),a.jsx(Xr,{className:"w-3 h-3"})]}):a.jsx("span",{className:"text-bambu-gray",children:"-"})})]},te.id))})]})})})]})]}),a.jsx("div",{className:"space-y-6",children:a.jsxs(St,{children:[a.jsx(Kn,{children:a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(Eu,{className:"w-5 h-5 text-gray-400"}),a.jsx("h2",{className:"text-lg font-semibold text-white",children:"Local Backup"})]})}),a.jsxs(Nt,{className:"space-y-4",children:[a.jsx("p",{className:"text-sm text-bambu-gray",children:"Create a complete backup of your Bambuddy data including the database, archives, uploads, and all files."}),a.jsxs("div",{className:"flex items-center justify-between py-3 border-b border-bambu-dark-tertiary",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-white",children:"Download Backup"}),a.jsx("p",{className:"text-sm text-bambu-gray",children:"Complete backup: database + all files (ZIP)"})]}),a.jsxs(Te,{variant:"secondary",size:"sm",disabled:k||E,onClick:async()=>{C(!0),D("Preparing backup...");try{D("Creating backup archive... This may take a while for large archives.");const{blob:te,filename:z}=await ce.exportBackup();D("Downloading backup file...");const O=URL.createObjectURL(te),Z=document.createElement("a");Z.href=O,Z.download=z,Z.click(),URL.revokeObjectURL(O),e("Backup downloaded successfully")}catch(te){e(`Failed to create backup: ${te instanceof Error?te.message:"Unknown error"}`,"error")}finally{C(!1),D("")}},children:[a.jsx(wi,{className:"w-4 h-4"}),"Download"]})]}),a.jsxs("div",{className:"flex items-center justify-between py-3 border-b border-bambu-dark-tertiary",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-white",children:n("backup.restoreBackup")}),a.jsx("p",{className:"text-sm text-bambu-gray",children:n("backup.restoreDescription")}),a.jsx("p",{className:"text-xs text-bambu-gray-light mt-1",children:n("backup.restoreNote")})]}),a.jsx("input",{ref:B,type:"file",accept:".zip",className:"hidden",onChange:te=>{const z=te.target.files?.[0];z&&(j(z),L(!0)),te.target.value=""}}),a.jsxs(Te,{variant:"secondary",size:"sm",disabled:E||k,onClick:()=>B.current?.click(),children:[a.jsx(Ba,{className:"w-4 h-4"}),"Restore"]})]}),$&&a.jsx("div",{className:`p-3 rounded-lg ${$.success?"bg-green-500/10 border border-green-500/30":"bg-red-500/10 border border-red-500/30"}`,children:a.jsxs("div",{className:"flex items-start gap-2 text-sm",children:[$.success?a.jsx(Ar,{className:"w-4 h-4 text-green-400 mt-0.5 flex-shrink-0"}):a.jsx(Ji,{className:"w-4 h-4 text-red-400 mt-0.5 flex-shrink-0"}),a.jsxs("div",{className:$.success?"text-green-200":"text-red-200",children:[$.message,$.success&&a.jsx("div",{className:"mt-2",children:a.jsxs(Te,{size:"sm",onClick:()=>window.location.reload(),children:[a.jsx(Lh,{className:"w-3 h-3"}),"Reload Now"]})})]})]})}),a.jsx("div",{className:"p-3 rounded-lg bg-yellow-500/10 border border-yellow-500/30",children:a.jsxs("div",{className:"flex items-start gap-2 text-sm",children:[a.jsx(Sn,{className:"w-4 h-4 text-yellow-400 mt-0.5 flex-shrink-0"}),a.jsxs("div",{className:"text-yellow-200",children:[a.jsx("span",{className:"font-medium",children:"Restore replaces all data."})," ",a.jsx("span",{className:"text-yellow-200/70",children:"Your current database and files will be completely replaced. A restart is required after restore."})]})]})})]})]})}),I&&U&&a.jsx(Zn,{title:"Restore Backup",message:`Are you sure you want to restore from "${U.name}"? This will completely replace your current database and all files. The application will need to be restarted after restore.`,confirmText:"Restore Backup",variant:"danger",onConfirm:async()=>{L(!1),P(!0),K(null);try{D("Uploading backup file...");const te=await ce.importBackup(U);K(te),te.success?e("Backup restored. Please restart Bambuddy.","success"):e(te.message,"error")}catch(te){const z=te instanceof Error?te.message:"Failed to restore backup";K({success:!1,message:z}),e(z,"error")}finally{P(!1),D(""),j(null)}},onCancel:()=>{L(!1),j(null)}}),(k||E)&&a.jsx("div",{className:"fixed inset-0 bg-black/80 flex items-center justify-center z-[100]",children:a.jsxs("div",{className:"bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl p-8 max-w-md w-full mx-4 text-center",children:[a.jsx("div",{className:"flex justify-center mb-4",children:a.jsxs("div",{className:"relative",children:[a.jsx("div",{className:"w-16 h-16 border-4 border-bambu-dark-tertiary rounded-full"}),a.jsx("div",{className:"w-16 h-16 border-4 border-bambu-green border-t-transparent rounded-full absolute inset-0 animate-spin"})]})}),a.jsx("h3",{className:"text-xl font-semibold text-white mb-2",children:k?"Creating Backup":"Restoring Backup"}),a.jsx("p",{className:"text-bambu-gray mb-4",children:A||(k?"Preparing...":"Processing...")}),a.jsx("div",{className:"p-3 rounded-lg bg-yellow-500/10 border border-yellow-500/30",children:a.jsxs("div",{className:"flex items-start gap-2 text-sm",children:[a.jsx(Sn,{className:"w-4 h-4 text-yellow-400 mt-0.5 flex-shrink-0"}),a.jsx("p",{className:"text-yellow-200 text-left",children:"Please do not close this page or navigate away. This operation may take several minutes for large backups."})]})})]})})]})}const zKe={get:"bg-blue-500/20 text-blue-400 border-blue-500/30",post:"bg-green-500/20 text-green-400 border-green-500/30",put:"bg-yellow-500/20 text-yellow-400 border-yellow-500/30",patch:"bg-orange-500/20 text-orange-400 border-orange-500/30",delete:"bg-red-500/20 text-red-400 border-red-500/30"};function BKe(t,e){const n=e.replace("#/","").split("/");let r=t;for(const i of n)r=r[i];return r}function g0(t,e,n=0){if(n>5)return"...";if(e.$ref)return g0(t,BKe(t,e.$ref),n+1);if(e.allOf){const r={};for(const i of e.allOf){const s=g0(t,i,n+1);typeof s=="object"&&s!==null&&Object.assign(r,s)}return r}if(e.example!==void 0)return e.example;if(e.default!==void 0)return e.default;switch(e.type){case"string":return e.enum?e.enum[0]:"string";case"integer":case"number":return 0;case"boolean":return!1;case"array":return e.items?[g0(t,e.items,n+1)]:[];case"object":if(e.properties){const r={};for(const[i,s]of Object.entries(e.properties))r[i]=g0(t,s,n+1);return r}return{};default:return null}}function HKe({path:t,method:e,spec:n,schema:r,apiKey:i}){const[s,o]=_.useState(!1),[l,c]=_.useState({}),[u,d]=_.useState(""),[h,p]=_.useState(null),[m,x]=_.useState(!1),[y,v]=_.useState(!1);_.useEffect(()=>{if(s&&n.parameters){const P={};for(const A of n.parameters)A.schema?.default!==void 0&&(P[A.name]=String(A.schema.default));c(A=>({...P,...A}))}},[s,n.parameters]),_.useEffect(()=>{if(s&&n.requestBody?.content?.["application/json"]?.schema&&!u){const P=n.requestBody.content["application/json"].schema,A=g0(r,P);d(JSON.stringify(A,null,2))}},[s,n.requestBody,r,u]);const S=(()=>{const P=[];for(const A of n.parameters||[])if(A.in==="path"||A.required){const D=l[A.name];(D===void 0||D==="")&&P.push(A.name)}return P})(),N=async()=>{if(S.length>0){p({status:0,statusText:"Validation Error",headers:{},body:`Missing required parameters: ${S.join(", ")}`,duration:0});return}x(!0),p(null);try{let P=t;const A=new URLSearchParams;for(const ne of n.parameters||[]){const H=l[ne.name];H!==void 0&&H!==""&&(ne.in==="path"?P=P.replace(`{${ne.name}}`,encodeURIComponent(H)):ne.in==="query"&&A.append(ne.name,H))}const D=A.toString(),I=`${P}${D?`?${D}`:""}`,L={"Content-Type":"application/json"};i&&(L["X-API-Key"]=i);const U={method:e.toUpperCase(),headers:L};["post","put","patch"].includes(e)&&u&&(U.body=u);const j=performance.now(),$=await fetch(I,U),K=Math.round(performance.now()-j),B={};$.headers.forEach((ne,H)=>{B[H]=ne});let X;$.headers.get("content-type")?.includes("application/json")?X=await $.json():X=await $.text(),p({status:$.status,statusText:$.statusText,headers:B,body:X,duration:K})}catch(P){p({status:0,statusText:"Network Error",headers:{},body:P instanceof Error?P.message:"Unknown error",duration:0})}finally{x(!1)}},T=async()=>{if(h){const P=typeof h.body=="string"?h.body:JSON.stringify(h.body,null,2);try{await navigator.clipboard.writeText(P),v(!0),setTimeout(()=>v(!1),2e3)}catch{const A=document.createElement("textarea");A.value=P,A.style.position="fixed",A.style.left="-999999px",document.body.appendChild(A),A.select(),document.execCommand("copy"),document.body.removeChild(A),v(!0),setTimeout(()=>v(!1),2e3)}}},k=(n.parameters||[]).filter(P=>P.in==="path"),C=(n.parameters||[]).filter(P=>P.in==="query"),E=["post","put","patch"].includes(e)&&n.requestBody;return a.jsxs("div",{className:"border border-bambu-dark-tertiary rounded-lg overflow-hidden",children:[a.jsxs("button",{onClick:()=>o(!s),className:"w-full flex items-center gap-3 p-3 hover:bg-bambu-dark-tertiary/50 transition-colors text-left",children:[s?a.jsx(Kr,{className:"w-4 h-4 text-bambu-gray flex-shrink-0"}):a.jsx(vs,{className:"w-4 h-4 text-bambu-gray flex-shrink-0"}),a.jsx("span",{className:`px-2 py-0.5 text-xs font-mono font-semibold uppercase rounded border ${zKe[e]||"bg-gray-500/20 text-gray-400"}`,children:e}),a.jsx("code",{className:"text-sm text-white font-mono flex-1 truncate",children:t}),n.summary&&a.jsx("span",{className:"text-sm text-bambu-gray truncate max-w-[40%]",children:n.summary})]}),s&&a.jsxs("div",{className:"border-t border-bambu-dark-tertiary p-4 space-y-4 bg-bambu-dark/50",children:[n.description&&a.jsx("p",{className:"text-sm text-bambu-gray",children:n.description}),k.length>0&&a.jsxs("div",{className:"space-y-2",children:[a.jsx("h4",{className:"text-sm font-medium text-white",children:"Path Parameters"}),a.jsx("div",{className:"space-y-2",children:k.map(P=>a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsxs("label",{className:"text-sm text-bambu-gray w-32 flex-shrink-0",children:[P.name,P.required&&a.jsx("span",{className:"text-red-400 ml-1",children:"*"})]}),a.jsx("input",{type:"text",value:l[P.name]||"",onChange:A=>c(D=>({...D,[P.name]:A.target.value})),placeholder:P.description||P.schema?.type||"value",className:"flex-1 px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm font-mono focus:border-bambu-green focus:outline-none"})]},P.name))})]}),C.length>0&&a.jsxs("div",{className:"space-y-2",children:[a.jsx("h4",{className:"text-sm font-medium text-white",children:"Query Parameters"}),a.jsx("div",{className:"space-y-2",children:C.map(P=>a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsxs("label",{className:"text-sm text-bambu-gray w-32 flex-shrink-0",children:[P.name,P.required&&a.jsx("span",{className:"text-red-400 ml-1",children:"*"})]}),P.schema?.enum?a.jsxs("select",{value:l[P.name]||"",onChange:A=>c(D=>({...D,[P.name]:A.target.value})),className:"flex-1 px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none",children:[a.jsx("option",{value:"",children:"-- Select --"}),P.schema.enum.map(A=>a.jsx("option",{value:A,children:A},A))]}):a.jsx("input",{type:"text",value:l[P.name]||"",onChange:A=>c(D=>({...D,[P.name]:A.target.value})),placeholder:P.description||P.schema?.type||"value",className:"flex-1 px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm font-mono focus:border-bambu-green focus:outline-none"})]},P.name))})]}),E&&a.jsxs("div",{className:"space-y-2",children:[a.jsx("h4",{className:"text-sm font-medium text-white",children:"Request Body"}),a.jsx("textarea",{value:u,onChange:P=>d(P.target.value),rows:8,className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm font-mono focus:border-bambu-green focus:outline-none resize-y",placeholder:"JSON request body..."})]}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsxs(Te,{onClick:N,disabled:m,children:[m?a.jsx(pt,{className:"w-4 h-4 animate-spin"}):a.jsx(So,{className:"w-4 h-4"}),"Execute"]}),S.length>0&&a.jsxs("span",{className:"text-xs text-yellow-400 flex items-center gap-1",children:[a.jsx(Vi,{className:"w-3 h-3"}),"Fill in: ",S.join(", ")]})]}),h&&a.jsxs("div",{className:"space-y-2",children:[a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("h4",{className:"text-sm font-medium text-white flex items-center gap-2",children:["Response",a.jsxs("span",{className:`px-2 py-0.5 text-xs rounded ${h.status>=200&&h.status<300?"bg-green-500/20 text-green-400":h.status>=400?"bg-red-500/20 text-red-400":"bg-yellow-500/20 text-yellow-400"}`,children:[h.status," ",h.statusText]}),a.jsxs("span",{className:"text-xs text-bambu-gray",children:[h.duration,"ms"]})]}),a.jsx(Te,{variant:"secondary",size:"sm",onClick:T,children:y?a.jsx(Ar,{className:"w-3 h-3 text-green-400"}):a.jsx(Ul,{className:"w-3 h-3"})})]}),a.jsx("pre",{className:"p-3 bg-bambu-dark rounded-lg text-sm font-mono text-white overflow-auto max-h-96 border border-bambu-dark-tertiary",children:typeof h.body=="string"?h.body:JSON.stringify(h.body,null,2)})]})]})]})}function $Ke({apiKey:t=""}){const[e,n]=_.useState(null),[r,i]=_.useState(!0),[s,o]=_.useState(null),[l,c]=_.useState(new Set),[u,d]=_.useState("");if(_.useEffect(()=>{async function v(){try{const b=await fetch("/openapi.json");if(!b.ok)throw new Error("Failed to fetch OpenAPI schema");const S=await b.json();n(S)}catch(b){o(b instanceof Error?b.message:"Unknown error")}finally{i(!1)}}v()},[]),r)return a.jsx("div",{className:"flex justify-center py-12",children:a.jsx(pt,{className:"w-8 h-8 text-bambu-green animate-spin"})});if(s||!e)return a.jsx(St,{children:a.jsx(Nt,{className:"py-8",children:a.jsxs("div",{className:"text-center text-red-400",children:[a.jsx(Vi,{className:"w-12 h-12 mx-auto mb-3 opacity-50"}),a.jsx("p",{children:"Failed to load API schema"}),a.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:s})]})})});const h={};for(const[v,b]of Object.entries(e.paths))for(const[S,N]of Object.entries(b)){if(S==="parameters")continue;const T=N.tags||["Other"];for(const k of T)h[k]||(h[k]=[]),h[k].push({path:v,method:S,spec:N})}const p=Object.entries(h).map(([v,b])=>{if(!u)return{tag:v,endpoints:b};const S=b.filter(({path:N,method:T,spec:k})=>{const C=u.toLowerCase();return N.toLowerCase().includes(C)||T.toLowerCase().includes(C)||(k.summary?.toLowerCase()||"").includes(C)||(k.description?.toLowerCase()||"").includes(C)});return{tag:v,endpoints:S}}).filter(({endpoints:v})=>v.length>0).sort((v,b)=>v.tag.localeCompare(b.tag)),m=v=>{c(b=>{const S=new Set(b);return S.has(v)?S.delete(v):S.add(v),S})},x=()=>{c(new Set(p.map(v=>v.tag)))},y=()=>{c(new Set)};return a.jsxs("div",{className:"space-y-4",children:[a.jsxs("div",{className:"flex items-center justify-between gap-4",children:[a.jsx("div",{className:"flex-1",children:a.jsx("input",{type:"text",value:u,onChange:v=>d(v.target.value),placeholder:"Search endpoints...",className:"w-full max-w-md px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(Te,{variant:"secondary",size:"sm",onClick:x,children:"Expand All"}),a.jsx(Te,{variant:"secondary",size:"sm",onClick:y,children:"Collapse All"}),a.jsxs("a",{href:"/docs",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1 text-sm text-bambu-green hover:underline",children:[a.jsx(Xr,{className:"w-4 h-4"}),"Swagger UI"]})]})]}),a.jsxs("p",{className:"text-sm text-bambu-gray",children:[p.reduce((v,b)=>v+b.endpoints.length,0)," endpoints in ",p.length," categories"]}),a.jsx("div",{className:"space-y-3",children:p.map(({tag:v,endpoints:b})=>a.jsxs(St,{children:[a.jsx("button",{onClick:()=>m(v),className:"w-full flex items-center justify-between p-4 hover:bg-bambu-dark-tertiary/30 transition-colors text-left",children:a.jsxs("div",{className:"flex items-center gap-2",children:[l.has(v)?a.jsx(Kr,{className:"w-5 h-5 text-bambu-gray"}):a.jsx(vs,{className:"w-5 h-5 text-bambu-gray"}),a.jsx("h3",{className:"text-base font-semibold text-white capitalize",children:v.replace(/-/g," ")}),a.jsx("span",{className:"text-xs bg-bambu-dark-tertiary px-2 py-0.5 rounded-full text-bambu-gray",children:b.length})]})}),l.has(v)&&a.jsx(Nt,{className:"pt-0 space-y-2",children:b.map(({path:S,method:N,spec:T})=>a.jsx(HKe,{path:S,method:N,spec:T,schema:e,apiKey:t},`${N}-${S}`))})]},v))})]})}const VKe=["general","network","plugs","notifications","filament","apikeys","virtual-printer","users","backup"];function GKe(){const t=sn(),e=Tc(),[n,r]=NR(),{t:i,i18n:s}=On(),{showToast:o}=Hn(),{authEnabled:l,user:c,refreshAuth:u}=Ci(),{mode:d,darkStyle:h,darkBackground:p,darkAccent:m,lightStyle:x,lightBackground:y,lightAccent:v,setDarkStyle:b,setDarkBackground:S,setDarkAccent:N,setLightStyle:T,setLightBackground:k,setLightAccent:C}=Fh(),[E,P]=_.useState(null),[A,D]=_.useState(!1),[I,L]=_.useState(null),[U,j]=_.useState(!1),[$,K]=_.useState(null),[B,X]=_.useState(null),[Y,ne]=_.useState(!1),[H,W]=_.useState(VW()),re=n.get("tab"),ie=re&&VKe.includes(re)?re:"general",[pe,me]=_.useState(ie),de=le=>{me(le),le==="general"?n.delete("tab"):n.set("tab",le),r(n,{replace:!0})},[Ee,se]=_.useState(!1),[Ae,Fe]=_.useState(""),[ge,Ze]=_.useState({can_queue:!0,can_control_printer:!1,can_read_status:!0}),[G,Q]=_.useState(null),[he,q]=_.useState(null),[ee,V]=_.useState(""),[ye,je]=_.useState(!1),[te,z]=_.useState(!1),[O,Z]=_.useState(null),[oe,we]=_.useState(!1),[_e,ae]=_.useState(!1),[Le,Be]=_.useState(!1),[Ve,He]=_.useState({currentPassword:"",newPassword:"",confirmPassword:""}),[xe,Pe]=_.useState(!1),[Ie,Se]=_.useState(!1),[Ke,Me]=_.useState(!1),[it,ke]=_.useState(null),[Xe,ze]=_.useState(null),[ue,$e]=_.useState(null),[be,Je]=_.useState(!1),[at,jt]=_.useState({username:"",password:"",confirmPassword:"",role:"user",group_ids:[]}),[Dt,yn]=_.useState(!1),[cn,rr]=_.useState(null),[Vn,Jn]=_.useState(null),[xn,sr]=_.useState({name:"",description:"",permissions:[]}),[Gn,Xn]=_.useState(new Set),[Nn,hi]=_.useState(null),[ai,Ce]=_.useState(!1),[tt,dt]=_.useState({}),[ht,ut]=_.useState({}),Et=le=>{W(le),Vfe(le),o(i("settings.toast.settingsSaved"),"success")},fe=()=>{localStorage.removeItem("sidebarOrder"),window.location.reload()},{data:Re,isLoading:Ge}=ct({queryKey:["settings"],queryFn:ce.getSettings}),{data:Ne,isLoading:Oe}=ct({queryKey:["smart-plugs"],queryFn:ce.getSmartPlugs}),{data:nt,isLoading:Ye}=ct({queryKey:["smart-plugs-energy",Ne?.map(le=>le.id)],queryFn:async()=>{if(!Ne||Ne.length===0)return null;const le=await Promise.all(Ne.filter(as=>as.enabled).map(async as=>{try{const ss=await ce.getSmartPlugStatus(as.id);return{plug:as,status:ss}}catch{return{plug:as,status:null}}}));let _t=0,Ln=0,er=0,Co=0,ed=0;for(const{plug:as,status:ss}of le){const Gx=as.plug_type==="mqtt"&&ss?.energy?.power!=null;(ss?.reachable||Gx)&&ss?.energy&&(ed++,ss.energy?.power!=null&&(_t+=ss.energy.power),ss.energy?.today!=null&&(Ln+=ss.energy.today),ss.energy?.yesterday!=null&&(er+=ss.energy.yesterday),ss.energy?.total!=null&&(Co+=ss.energy.total))}return{totalPower:_t,totalToday:Ln,totalYesterday:er,totalLifetime:Co,reachableCount:ed,totalPlugs:Ne.filter(as=>as.enabled).length}},enabled:pe==="plugs"&&!!Ne&&Ne.length>0,refetchInterval:pe==="plugs"?1e4:!1}),{data:Tt,isLoading:At}=ct({queryKey:["notification-providers"],queryFn:ce.getNotificationProviders}),{data:It,isLoading:Rt}=ct({queryKey:["api-keys"],queryFn:ce.getAPIKeys}),Mt=gt({mutationFn:le=>ce.createAPIKey(le),onSuccess:le=>{Q(le.key||null),se(!1),Fe(""),t.invalidateQueries({queryKey:["api-keys"]}),o(i("settings.toast.apiKeyCreated"))},onError:le=>{o(`Failed to create API key: ${le.message}`,"error")}}),en=gt({mutationFn:le=>ce.deleteAPIKey(le),onSuccess:()=>{t.invalidateQueries({queryKey:["api-keys"]}),o(i("settings.toast.apiKeyDeleted"))},onError:le=>{o(`Failed to delete API key: ${le.message}`,"error")}}),{data:Ht}=ct({queryKey:["printers"],queryFn:ce.getPrinters}),{data:hn,isLoading:un}=ct({queryKey:["notification-templates"],queryFn:ce.getNotificationTemplates}),{data:Mn}=ct({queryKey:["virtual-printer-settings"],queryFn:x1.getSettings,refetchInterval:1e4}),Gt=Mn?.status?.running??!1,{data:on}=ct({queryKey:["ffmpeg-status"],queryFn:ce.checkFfmpeg}),{data:dn}=ct({queryKey:["version"],queryFn:ce.getVersion}),{data:Yt,refetch:ir,isRefetching:Pn}=ct({queryKey:["updateCheck"],queryFn:ce.checkForUpdates,staleTime:300*1e3}),{data:si,refetch:ar}=ct({queryKey:["updateStatus"],queryFn:ce.getUpdateStatus,refetchInterval:le=>{const _t=le.state.data;return _t?.status==="downloading"||_t?.status==="installing"?1e3:!1}}),{data:dr}=ct({queryKey:["mqtt-status"],queryFn:ce.getMQTTStatus,refetchInterval:pe==="network"?5e3:!1}),{data:rt}=ct({queryKey:["github-backup-status"],queryFn:ce.getGitHubBackupStatus}),{data:Pt}=ct({queryKey:["cloud-status"],queryFn:ce.getCloudStatus}),{hasPermission:qt}=Ci(),{data:vt=[],isLoading:wn}=ct({queryKey:["users"],queryFn:()=>ce.getUsers(),enabled:l&&qt("users:read")}),{data:Fr=[],isLoading:Qr}=ct({queryKey:["groups"],queryFn:()=>ce.getGroups(),enabled:l&&qt("groups:read")}),{data:Br}=ct({queryKey:["permissions"],queryFn:()=>ce.getPermissions(),enabled:l&&qt("groups:read")}),Ys=gt({mutationFn:le=>ce.createUser(le),onSuccess:()=>{t.invalidateQueries({queryKey:["users"]}),t.invalidateQueries({queryKey:["groups"]}),Se(!1),jt({username:"",password:"",confirmPassword:"",role:"user",group_ids:[]}),o(i("settings.toast.userCreated"))},onError:le=>{o(le.message,"error")}}),nn=gt({mutationFn:({id:le,data:_t})=>ce.updateUser(le,_t),onSuccess:()=>{t.invalidateQueries({queryKey:["users"]}),t.invalidateQueries({queryKey:["groups"]}),Me(!1),ke(null),jt({username:"",password:"",confirmPassword:"",role:"user",group_ids:[]}),o(i("settings.toast.userUpdated"))},onError:le=>{o(le.message,"error")}}),ln=gt({mutationFn:({id:le,deleteItems:_t})=>ce.deleteUser(le,_t),onSuccess:()=>{t.invalidateQueries({queryKey:["users"]}),o(i("settings.toast.userDeleted")),ze(null),$e(null)},onError:le=>{o(le.message,"error")}}),Si=async le=>{ze(le),Je(!0);try{const _t=await ce.getUserItemsCount(le);$e(_t)}catch{$e({archives:0,queue_items:0,library_files:0})}finally{Je(!1)}},Es=gt({mutationFn:le=>ce.createGroup(le),onSuccess:()=>{t.invalidateQueries({queryKey:["groups"]}),yn(!1),da(),o(i("settings.toast.groupCreated"))},onError:le=>{o(le.message,"error")}}),Eo=gt({mutationFn:({id:le,data:_t})=>ce.updateGroup(le,_t),onSuccess:()=>{t.invalidateQueries({queryKey:["groups"]}),rr(null),da(),o(i("settings.toast.groupUpdated"))},onError:le=>{o(le.message,"error")}}),To=gt({mutationFn:le=>ce.deleteGroup(le),onSuccess:()=>{t.invalidateQueries({queryKey:["groups"]}),o(i("settings.toast.groupDeleted"))},onError:le=>{o(le.message,"error")}}),Ao=()=>{if(!at.username||!at.password){o(i("settings.toast.fillRequiredFields"),"error");return}if(at.password!==at.confirmPassword){o(i("settings.toast.passwordsDoNotMatch"),"error");return}if(at.password.length<6){o(i("settings.toast.passwordTooShort"),"error");return}Ys.mutate({username:at.username,password:at.password,role:at.role,group_ids:at.group_ids.length>0?at.group_ids:void 0})},Ts=le=>{if(at.password){if(at.password!==at.confirmPassword){o(i("settings.toast.passwordsDoNotMatch"),"error");return}if(at.password.length<6){o(i("settings.toast.passwordTooShort"),"error");return}}const _t={username:at.username||void 0,password:at.password||void 0,role:at.role,group_ids:at.group_ids};_t.password||delete _t.password,nn.mutate({id:le,data:_t})},Ni=le=>{ke(le.id),jt({username:le.username,password:"",confirmPassword:"",role:le.role,group_ids:le.groups?.map(_t=>_t.id)||[]}),Me(!0)},Qs=le=>{jt(_t=>({..._t,group_ids:_t.group_ids.includes(le)?_t.group_ids.filter(Ln=>Ln!==le):[..._t.group_ids,le]}))},da=()=>{sr({name:"",description:"",permissions:[]}),Xn(new Set)},Hr=()=>{if(!xn.name.trim()){o(i("settings.toast.enterGroupName"),"error");return}Es.mutate({name:xn.name,description:xn.description||void 0,permissions:xn.permissions})},Bx=()=>{if(cn){if(!xn.name.trim()){o(i("settings.toast.enterGroupName"),"error");return}Eo.mutate({id:cn.id,data:{name:xn.name!==cn.name?xn.name:void 0,description:xn.description,permissions:xn.permissions}})}},Gh=le=>{rr(le),sr({name:le.name,description:le.description||"",permissions:le.permissions});const _t=new Set;Br?.categories.forEach(Ln=>{Ln.permissions.some(er=>le.permissions.includes(er.value))&&_t.add(Ln.name)}),Xn(_t)},Gl=le=>{Xn(_t=>{const Ln=new Set(_t);return Ln.has(le)?Ln.delete(le):Ln.add(le),Ln})},Hx=le=>{sr(_t=>{const Ln=_t.permissions.includes(le)?_t.permissions.filter(er=>er!==le):[..._t.permissions,le];return{..._t,permissions:Ln}})},Rm=(le,_t)=>{sr(Ln=>{const er=le.permissions.map(as=>as.value),Co=Ln.permissions.filter(as=>!er.includes(as)),ed=_t?[...Co,...er]:Co;return{...Ln,permissions:ed}})},Om=le=>le.permissions.every(_t=>xn.permissions.includes(_t.value)),qh=le=>{const _t=le.permissions.filter(Ln=>xn.permissions.includes(Ln.value));return _t.length>0&&_t.length{le.is_docker?o(le.message,"error"):ar()}}),[Pc,ha]=_.useState(null),bl=gt({mutationFn:ce.testAllNotificationProviders,onSuccess:le=>{ha(le),t.invalidateQueries({queryKey:["notification-providers"]}),le.failed===0?o(`All ${le.tested} providers tested successfully!`,"success"):o(`${le.success}/${le.tested} providers succeeded`,le.failed>0?"error":"success")},onError:le=>{o(`Failed to test providers: ${le.message}`,"error")}}),ql=gt({mutationFn:async le=>{if(!Ne)return{success:0,failed:0};const _t=Ne.filter(er=>er.enabled),Ln=await Promise.all(_t.map(async er=>{try{return await ce.controlSmartPlug(er.id,le),{success:!0}}catch{return{success:!1}}}));return{success:Ln.filter(er=>er.success).length,failed:Ln.filter(er=>!er.success).length}},onSuccess:(le,_t)=>{t.invalidateQueries({queryKey:["smart-plugs"]}),t.invalidateQueries({queryKey:["smart-plugs-energy"]}),le.failed===0?o(`All ${le.success} plugs turned ${_t}`,"success"):o(`${le.success} plugs turned ${_t}, ${le.failed} failed`,"error")},onError:le=>{o(`Failed: ${le.message}`,"error")}}),yl=_.useRef(null),Lm=_.useRef(!1),Fm=_.useRef(!0);_.useEffect(()=>{if(Re&&!E){const le={...Re,external_url:Re.external_url||window.location.origin};P(le),setTimeout(()=>{Fm.current=!1},100)}},[Re,E]);const Im=gt({mutationFn:ce.updateSettings,onSuccess:le=>{t.setQueryData(["settings"],le),P(le),t.invalidateQueries({queryKey:["archiveStats"]}),o(i("settings.toast.settingsSaved"),"success")},onError:le=>{o(`Failed to save: ${le.message}`,"error")},onSettled:()=>{Lm.current=!1}}),Ju=gt({mutationFn:({id:le,data:_t})=>ce.updatePrinter(le,_t),onSuccess:()=>{t.invalidateQueries({queryKey:["printers"]}),o(i("settings.toast.cameraSettingsSaved"),"success")},onError:le=>{o(`Failed to update printer: ${le.message}`,"error")}});_.useEffect(()=>{if(!(Fm.current||!E||!Re||!(Re.auto_archive!==E.auto_archive||Re.save_thumbnails!==E.save_thumbnails||Re.capture_finish_photo!==E.capture_finish_photo||Re.default_filament_cost!==E.default_filament_cost||Re.currency!==E.currency||Re.energy_cost_per_kwh!==E.energy_cost_per_kwh||Re.energy_tracking_mode!==E.energy_tracking_mode||Re.check_updates!==E.check_updates||(Re.check_printer_firmware??!0)!==(E.check_printer_firmware??!0)||Re.notification_language!==E.notification_language||Re.ams_humidity_good!==E.ams_humidity_good||Re.ams_humidity_fair!==E.ams_humidity_fair||Re.ams_temp_good!==E.ams_temp_good||Re.ams_temp_fair!==E.ams_temp_fair||Re.ams_history_retention_days!==E.ams_history_retention_days||Re.per_printer_mapping_expanded!==E.per_printer_mapping_expanded||Re.date_format!==E.date_format||Re.time_format!==E.time_format||Re.default_printer_id!==E.default_printer_id||Re.ftp_retry_enabled!==E.ftp_retry_enabled||Re.ftp_retry_count!==E.ftp_retry_count||Re.ftp_retry_delay!==E.ftp_retry_delay||Re.ftp_timeout!==E.ftp_timeout||Re.mqtt_enabled!==E.mqtt_enabled||Re.mqtt_broker!==E.mqtt_broker||Re.mqtt_port!==E.mqtt_port||Re.mqtt_username!==E.mqtt_username||Re.mqtt_password!==E.mqtt_password||Re.mqtt_topic_prefix!==E.mqtt_topic_prefix||Re.mqtt_use_tls!==E.mqtt_use_tls||Re.external_url!==E.external_url||Re.ha_enabled!==E.ha_enabled||Re.ha_url!==E.ha_url||Re.ha_token!==E.ha_token||(Re.library_archive_mode??"ask")!==(E.library_archive_mode??"ask")||Number(Re.library_disk_warning_gb??5)!==Number(E.library_disk_warning_gb??5)||(Re.camera_view_mode??"window")!==(E.camera_view_mode??"window")||Re.prometheus_enabled!==E.prometheus_enabled||Re.prometheus_token!==E.prometheus_token))&&!Lm.current)return yl.current&&clearTimeout(yl.current),yl.current=setTimeout(()=>{if(Lm.current)return;Lm.current=!0;const _t={auto_archive:E.auto_archive,save_thumbnails:E.save_thumbnails,capture_finish_photo:E.capture_finish_photo,default_filament_cost:E.default_filament_cost,currency:E.currency,energy_cost_per_kwh:E.energy_cost_per_kwh,energy_tracking_mode:E.energy_tracking_mode,check_updates:E.check_updates,check_printer_firmware:E.check_printer_firmware,notification_language:E.notification_language,ams_humidity_good:E.ams_humidity_good,ams_humidity_fair:E.ams_humidity_fair,ams_temp_good:E.ams_temp_good,ams_temp_fair:E.ams_temp_fair,ams_history_retention_days:E.ams_history_retention_days,per_printer_mapping_expanded:E.per_printer_mapping_expanded,date_format:E.date_format,time_format:E.time_format,default_printer_id:E.default_printer_id,ftp_retry_enabled:E.ftp_retry_enabled,ftp_retry_count:E.ftp_retry_count,ftp_retry_delay:E.ftp_retry_delay,ftp_timeout:E.ftp_timeout,mqtt_enabled:E.mqtt_enabled,mqtt_broker:E.mqtt_broker,mqtt_port:E.mqtt_port,mqtt_username:E.mqtt_username,mqtt_password:E.mqtt_password,mqtt_topic_prefix:E.mqtt_topic_prefix,mqtt_use_tls:E.mqtt_use_tls,external_url:E.external_url,ha_enabled:E.ha_enabled,ha_url:E.ha_url,ha_token:E.ha_token,library_archive_mode:E.library_archive_mode,library_disk_warning_gb:E.library_disk_warning_gb,camera_view_mode:E.camera_view_mode,prometheus_enabled:E.prometheus_enabled,prometheus_token:E.prometheus_token};Im.mutate(_t)},500),()=>{yl.current&&clearTimeout(yl.current)}},[E,Re,Im]);const fn=_.useCallback((le,_t)=>{P(Ln=>Ln?{...Ln,[le]:_t}:null)},[]),Mv=async(le,_t,Ln)=>{if(!_t){o(i("settings.toast.enterCameraUrl"),"error");return}ut(er=>({...er,[le]:!0})),dt(er=>({...er,[le]:null}));try{const er=await ce.testExternalCamera(le,_t,Ln);dt(Co=>({...Co,[le]:er})),er.success?o(i("settings.toast.cameraConnected",{resolution:er.resolution||""}),"success"):o(er.error||i("settings.toast.connectionFailed"),"error")}catch(er){const Co=er instanceof Error?er.message:i("settings.toast.testFailed");dt(ed=>({...ed,[le]:{success:!1,error:Co}})),o(Co,"error")}finally{ut(er=>({...er,[le]:!1}))}},[$x,kv]=_.useState({}),Vx=_.useRef({}),Um=_.useRef(new Set);_.useEffect(()=>{if(Ht){const le={};Ht.forEach(_t=>{_t.external_camera_url&&!Um.current.has(_t.id)&&(le[_t.id]=_t.external_camera_url,Um.current.add(_t.id))}),Object.keys(le).length>0&&kv(_t=>({..._t,...le}))}},[Ht]);const W2=(le,_t)=>{kv(Ln=>({...Ln,[le]:_t})),Vx.current[le]&&clearTimeout(Vx.current[le]),Vx.current[le]=setTimeout(()=>{Ju.mutate({id:le,data:{external_camera_url:_t||null}})},800)},Ev=(le,_t)=>{const Ln={};_t.type!==void 0&&(Ln.external_camera_type=_t.type||null),_t.enabled!==void 0&&(Ln.external_camera_enabled=_t.enabled),Ju.mutate({id:le,data:Ln})};return Ge||!E?a.jsx("div",{className:"p-4 md:p-8 flex justify-center",children:a.jsx(pt,{className:"w-8 h-8 text-bambu-green animate-spin"})}):a.jsxs("div",{className:"p-4 md:p-8",children:[a.jsxs("div",{className:"mb-8",children:[a.jsx("h1",{className:"text-2xl font-bold text-white",children:i("settings.title")}),a.jsx("p",{className:"text-bambu-gray",children:i("settings.configureBambuddy")})]}),a.jsxs("div",{className:"flex gap-1 mb-6 border-b border-bambu-dark-tertiary overflow-x-auto",children:[a.jsx("button",{onClick:()=>de("general"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px ${pe==="general"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:i("settings.tabs.general")}),a.jsxs("button",{onClick:()=>de("plugs"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${pe==="plugs"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[a.jsx(al,{className:"w-4 h-4"}),i("settings.tabs.smartPlugs"),Ne&&Ne.length>0&&a.jsx("span",{className:"text-xs bg-bambu-dark-tertiary px-1.5 py-0.5 rounded-full",children:Ne.length})]}),a.jsxs("button",{onClick:()=>de("notifications"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${pe==="notifications"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[a.jsx(Sg,{className:"w-4 h-4"}),i("settings.tabs.notifications"),Tt&&Tt.length>0&&a.jsx("span",{className:"text-xs bg-bambu-dark-tertiary px-1.5 py-0.5 rounded-full",children:Tt.length})]}),a.jsxs("button",{onClick:()=>de("filament"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${pe==="filament"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[a.jsx(Mue,{className:"w-4 h-4"}),i("settings.tabs.filament")]}),a.jsxs("button",{onClick:()=>de("network"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${pe==="network"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[a.jsx(Mg,{className:"w-4 h-4"}),i("settings.tabs.network"),a.jsx("span",{className:`w-2 h-2 rounded-full ${dr?.enabled?"bg-green-400":"bg-gray-500"}`})]}),a.jsxs("button",{onClick:()=>de("apikeys"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${pe==="apikeys"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[a.jsx(Ko,{className:"w-4 h-4"}),i("settings.tabs.apiKeys"),It&&It.length>0&&a.jsx("span",{className:"text-xs bg-bambu-dark-tertiary px-1.5 py-0.5 rounded-full",children:It.length})]}),a.jsxs("button",{onClick:()=>de("virtual-printer"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${pe==="virtual-printer"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[a.jsx(Ur,{className:"w-4 h-4"}),i("settings.tabs.virtualPrinter"),a.jsx("span",{className:`w-2 h-2 rounded-full ${Gt?"bg-green-400":"bg-gray-500"}`})]}),a.jsxs("button",{onClick:()=>de("users"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${pe==="users"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[a.jsx(pg,{className:"w-4 h-4"}),i("settings.tabs.users"),l&&a.jsx("span",{className:`w-2 h-2 rounded-full ${l?"bg-green-400":"bg-gray-500"}`})]}),a.jsxs("button",{onClick:()=>de("backup"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${pe==="backup"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[a.jsx(Eu,{className:"w-4 h-4"}),i("settings.tabs.backup"),a.jsx("span",{className:`w-2 h-2 rounded-full ${Pt?.is_authenticated&&rt?.configured&&rt?.enabled?"bg-green-400":"bg-gray-500"}`})]})]}),pe==="general"&&a.jsxs("div",{className:"flex flex-col lg:flex-row gap-6 lg:gap-8",children:[a.jsxs("div",{className:"space-y-6 flex-1 lg:max-w-xl",children:[a.jsxs(St,{children:[a.jsx(Kn,{children:a.jsx("h2",{className:"text-lg font-semibold text-white",children:i("settings.general")})}),a.jsxs(Nt,{className:"space-y-4",children:[a.jsxs("div",{children:[a.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[a.jsx(oh,{className:"w-4 h-4 inline mr-1"}),i("settings.language")]}),a.jsxs("div",{className:"relative",children:[a.jsx("select",{value:s.language,onChange:le=>{s.changeLanguage(le.target.value),o(i("settings.toast.settingsSaved"),"success")},className:"w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer",children:yz.map(le=>a.jsxs("option",{value:le.code,children:[le.nativeName," (",le.name,")"]},le.code))}),a.jsx(Kr,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}),a.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:i("settings.languageDescription")})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:i("settings.defaultView")}),a.jsxs("div",{className:"relative",children:[a.jsx("select",{value:H,onChange:le=>Et(le.target.value),className:"w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer",children:X0.map(le=>a.jsx("option",{value:le.to,children:i(le.labelKey)},le.id))}),a.jsx(Kr,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}),a.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:i("settings.defaultViewDescription")})]}),a.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Date Format"}),a.jsxs("div",{className:"relative",children:[a.jsxs("select",{value:E.date_format||"system",onChange:le=>fn("date_format",le.target.value),className:"w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer",children:[a.jsx("option",{value:"system",children:i("settings.systemDefault")}),a.jsx("option",{value:"us",children:"US (MM/DD/YYYY)"}),a.jsx("option",{value:"eu",children:"EU (DD/MM/YYYY)"}),a.jsx("option",{value:"iso",children:"ISO (YYYY-MM-DD)"})]}),a.jsx(Kr,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Time Format"}),a.jsxs("div",{className:"relative",children:[a.jsxs("select",{value:E.time_format||"system",onChange:le=>fn("time_format",le.target.value),className:"w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer",children:[a.jsx("option",{value:"system",children:i("settings.systemDefault")}),a.jsx("option",{value:"12h",children:"12-hour (3:30 PM)"}),a.jsx("option",{value:"24h",children:"24-hour (15:30)"})]}),a.jsx(Kr,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]})]})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Default Printer"}),a.jsxs("div",{className:"relative",children:[a.jsxs("select",{value:E.default_printer_id??"",onChange:le=>fn("default_printer_id",le.target.value?Number(le.target.value):null),className:"w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer",children:[a.jsx("option",{value:"",children:i("settings.noDefaultPrinter")}),Ht?.map(le=>a.jsx("option",{value:le.id,children:le.name},le.id))]}),a.jsx(Kr,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}),a.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Pre-select this printer for uploads, reprints, and other operations."})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-white",children:i("settings.sidebarOrder")}),a.jsx("p",{className:"text-sm text-bambu-gray",children:"Drag items in the sidebar to reorder. Reset to default order here."})]}),a.jsxs(Te,{variant:"secondary",size:"sm",onClick:fe,children:[a.jsx(Lh,{className:"w-4 h-4"}),"Reset"]})]})]})]}),a.jsxs(St,{children:[a.jsx(Kn,{children:a.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[a.jsx(PW,{className:"w-5 h-5"}),"Appearance"]})}),a.jsxs(Nt,{className:"space-y-6",children:[a.jsxs("div",{className:`space-y-3 p-4 rounded-lg border ${d==="dark"?"border-bambu-green bg-bambu-green/5":"border-bambu-dark-tertiary"}`,children:[a.jsxs("h3",{className:"text-sm font-medium text-white flex items-center gap-2",children:["Dark Mode",d==="dark"&&a.jsx("span",{className:"text-xs text-bambu-green",children:"(active)"})]}),a.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Background"}),a.jsxs("select",{value:p,onChange:le=>{S(le.target.value),o(i("settings.toast.settingsSaved"),"success")},className:"w-full px-2 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[a.jsx("option",{value:"neutral",children:"Neutral"}),a.jsx("option",{value:"warm",children:"Warm"}),a.jsx("option",{value:"cool",children:"Cool"}),a.jsx("option",{value:"oled",children:"OLED Black"}),a.jsx("option",{value:"slate",children:"Slate Blue"}),a.jsx("option",{value:"forest",children:"Forest Green"})]})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Accent"}),a.jsxs("select",{value:m,onChange:le=>{N(le.target.value),o(i("settings.toast.settingsSaved"),"success")},className:"w-full px-2 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[a.jsx("option",{value:"green",children:"Green"}),a.jsx("option",{value:"teal",children:"Teal"}),a.jsx("option",{value:"blue",children:"Blue"}),a.jsx("option",{value:"orange",children:"Orange"}),a.jsx("option",{value:"purple",children:"Purple"}),a.jsx("option",{value:"red",children:"Red"})]})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Style"}),a.jsxs("select",{value:h,onChange:le=>{b(le.target.value),o(i("settings.toast.settingsSaved"),"success")},className:"w-full px-2 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[a.jsx("option",{value:"classic",children:"Classic"}),a.jsx("option",{value:"glow",children:"Glow"}),a.jsx("option",{value:"vibrant",children:"Vibrant"})]})]})]})]}),a.jsxs("div",{className:`space-y-3 p-4 rounded-lg border ${d==="light"?"border-bambu-green bg-bambu-green/5":"border-bambu-dark-tertiary"}`,children:[a.jsxs("h3",{className:"text-sm font-medium text-white flex items-center gap-2",children:["Light Mode",d==="light"&&a.jsx("span",{className:"text-xs text-bambu-green",children:"(active)"})]}),a.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Background"}),a.jsxs("select",{value:y,onChange:le=>{k(le.target.value),o(i("settings.toast.settingsSaved"),"success")},className:"w-full px-2 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[a.jsx("option",{value:"neutral",children:"Neutral"}),a.jsx("option",{value:"warm",children:"Warm"}),a.jsx("option",{value:"cool",children:"Cool"})]})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Accent"}),a.jsxs("select",{value:v,onChange:le=>{C(le.target.value),o(i("settings.toast.settingsSaved"),"success")},className:"w-full px-2 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[a.jsx("option",{value:"green",children:"Green"}),a.jsx("option",{value:"teal",children:"Teal"}),a.jsx("option",{value:"blue",children:"Blue"}),a.jsx("option",{value:"orange",children:"Orange"}),a.jsx("option",{value:"purple",children:"Purple"}),a.jsx("option",{value:"red",children:"Red"})]})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Style"}),a.jsxs("select",{value:x,onChange:le=>{T(le.target.value),o(i("settings.toast.settingsSaved"),"success")},className:"w-full px-2 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[a.jsx("option",{value:"classic",children:"Classic"}),a.jsx("option",{value:"glow",children:"Glow"}),a.jsx("option",{value:"vibrant",children:"Vibrant"})]})]})]})]}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Toggle between dark and light mode using the sun/moon icon in the sidebar."})]})]}),a.jsxs(St,{children:[a.jsx(Kn,{children:a.jsx("h2",{className:"text-lg font-semibold text-white",children:i("settings.archiveSettings")})}),a.jsxs(Nt,{className:"space-y-4",children:[a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-white",children:"Auto-archive prints"}),a.jsx("p",{className:"text-sm text-bambu-gray",children:"Automatically save 3MF files when prints complete"})]}),a.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:E.auto_archive,onChange:le=>fn("auto_archive",le.target.checked),className:"sr-only peer"}),a.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-white",children:i("settings.saveThumbnails")}),a.jsx("p",{className:"text-sm text-bambu-gray",children:"Extract and save preview images from 3MF files"})]}),a.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:E.save_thumbnails,onChange:le=>fn("save_thumbnails",le.target.checked),className:"sr-only peer"}),a.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-white",children:i("settings.captureFinishPhoto")}),a.jsx("p",{className:"text-sm text-bambu-gray",children:"Take a photo from printer camera when print completes"})]}),a.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:E.capture_finish_photo,onChange:le=>fn("capture_finish_photo",le.target.checked),className:"sr-only peer"}),a.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]}),E.capture_finish_photo&&on&&!on.installed&&a.jsxs("div",{className:"flex items-start gap-2 p-3 bg-yellow-500/10 border border-yellow-500/30 rounded-lg",children:[a.jsx(Sn,{className:"w-5 h-5 text-yellow-500 flex-shrink-0 mt-0.5"}),a.jsxs("div",{className:"text-sm",children:[a.jsx("p",{className:"text-yellow-500 font-medium",children:"ffmpeg not installed"}),a.jsxs("p",{className:"text-bambu-gray mt-1",children:["Camera capture requires ffmpeg. Install it via"," ",a.jsx("code",{className:"bg-bambu-dark-tertiary px-1 rounded",children:"brew install ffmpeg"})," (macOS) or"," ",a.jsx("code",{className:"bg-bambu-dark-tertiary px-1 rounded",children:"apt install ffmpeg"})," (Linux)."]})]})]})]})]})]}),a.jsxs("div",{className:"space-y-6 flex-1 lg:max-w-md",children:[a.jsxs(St,{children:[a.jsx(Kn,{children:a.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[a.jsx(IR,{className:"w-5 h-5 text-bambu-green"}),"Camera"]})}),a.jsxs(Nt,{className:"space-y-4",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Camera View Mode"}),a.jsxs("select",{value:E.camera_view_mode??"window",onChange:le=>fn("camera_view_mode",le.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",children:[a.jsx("option",{value:"window",children:i("settings.newWindow")}),a.jsx("option",{value:"embedded",children:i("settings.embeddedOverlay")})]}),a.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:E.camera_view_mode==="embedded"?"Camera opens in a resizable overlay on the main screen":"Camera opens in a separate browser window"})]}),a.jsxs("div",{className:"border-t border-bambu-dark-tertiary pt-4 mt-4",children:[a.jsx("h3",{className:"text-sm font-medium text-white mb-2",children:i("settings.externalCameras")}),a.jsx("p",{className:"text-xs text-bambu-gray mb-3",children:"Configure external cameras to replace the built-in printer camera. Supports MJPEG streams, RTSP, HTTP snapshots, and USB cameras (V4L2). When enabled, the external camera is used for live view and finish photos."}),Ht&&Ht.length>0?a.jsx("div",{className:"space-y-3",children:Ht.map(le=>a.jsxs("div",{className:"p-3 bg-bambu-dark rounded-lg",children:[a.jsxs("div",{className:"flex items-center justify-between mb-2",children:[a.jsx("span",{className:"text-white font-medium text-sm",children:le.name}),a.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:le.external_camera_enabled,onChange:_t=>Ev(le.id,{enabled:_t.target.checked}),className:"sr-only peer"}),a.jsx("div",{className:"w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green"})]})]}),le.external_camera_enabled&&a.jsxs("div",{className:"space-y-2 mt-2",children:[a.jsx("input",{type:"text",placeholder:le.external_camera_type==="usb"?"Device path (/dev/video0)":"Camera URL (rtsp://... or http://...)",value:$x[le.id]??le.external_camera_url??"",onChange:_t=>W2(le.id,_t.target.value),className:"w-full 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"}),a.jsxs("div",{className:"flex gap-2",children:[a.jsxs("select",{value:le.external_camera_type||"mjpeg",onChange:_t=>Ev(le.id,{type:_t.target.value}),className:"flex-1 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",children:[a.jsx("option",{value:"mjpeg",children:"MJPEG Stream"}),a.jsx("option",{value:"rtsp",children:"RTSP Stream"}),a.jsx("option",{value:"snapshot",children:"HTTP Snapshot"}),a.jsx("option",{value:"usb",children:"USB Camera (V4L2)"})]}),a.jsx(Te,{size:"sm",variant:"secondary",onClick:()=>Mv(le.id,$x[le.id]??le.external_camera_url??"",le.external_camera_type||"mjpeg"),disabled:ht[le.id]||!($x[le.id]??le.external_camera_url),children:ht[le.id]?a.jsx(pt,{className:"w-4 h-4 animate-spin"}):"Test"})]}),tt[le.id]&&a.jsx("div",{className:`text-xs flex items-center gap-1 ${tt[le.id]?.success?"text-green-500":"text-red-500"}`,children:tt[le.id]?.success?a.jsxs(a.Fragment,{children:[a.jsx(Ar,{className:"w-3 h-3"}),"Connected",tt[le.id]?.resolution&&` (${tt[le.id]?.resolution})`]}):a.jsxs(a.Fragment,{children:[a.jsx(Ji,{className:"w-3 h-3"}),tt[le.id]?.error||i("settings.toast.connectionFailed")]})})]})]},le.id))}):a.jsx("p",{className:"text-xs text-bambu-gray italic",children:i("settings.noPrintersConfigured")})]})]})]}),a.jsxs(St,{children:[a.jsx(Kn,{children:a.jsx("h2",{className:"text-lg font-semibold text-white",children:i("settings.costTracking")})}),a.jsxs(Nt,{className:"space-y-4",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Default filament cost (per kg)"}),a.jsx("input",{type:"number",step:"0.01",min:"0",value:E.default_filament_cost,onChange:le=>fn("default_filament_cost",parseFloat(le.target.value)||0),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"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Currency"}),a.jsxs("select",{value:E.currency,onChange:le=>fn("currency",le.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",children:[a.jsx("option",{value:"USD",children:"USD ($)"}),a.jsx("option",{value:"EUR",children:"EUR (€)"}),a.jsx("option",{value:"GBP",children:"GBP (£)"}),a.jsx("option",{value:"CHF",children:"CHF (Fr.)"}),a.jsx("option",{value:"JPY",children:"JPY (¥)"}),a.jsx("option",{value:"CNY",children:"CNY (¥)"}),a.jsx("option",{value:"CAD",children:"CAD ($)"}),a.jsx("option",{value:"AUD",children:"AUD ($)"})]})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Electricity cost per kWh"}),a.jsx("input",{type:"number",step:"0.01",min:"0",value:E.energy_cost_per_kwh,onChange:le=>fn("energy_cost_per_kwh",parseFloat(le.target.value)||0),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"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Energy display mode"}),a.jsxs("select",{value:E.energy_tracking_mode||"total",onChange:le=>fn("energy_tracking_mode",le.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",children:[a.jsx("option",{value:"print",children:i("settings.printsOnly")}),a.jsx("option",{value:"total",children:i("settings.totalConsumption")})]}),a.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:E.energy_tracking_mode==="print"?"Dashboard shows sum of energy used during prints":"Dashboard shows lifetime energy from smart plugs"})]})]})]}),a.jsxs(St,{children:[a.jsx(Kn,{children:a.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[a.jsx(fs,{className:"w-5 h-5 text-bambu-green"}),"File Manager"]})}),a.jsxs(Nt,{className:"space-y-4",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Create Archive Entry When Printing"}),a.jsxs("select",{value:E.library_archive_mode??"ask",onChange:le=>fn("library_archive_mode",le.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",children:[a.jsx("option",{value:"always",children:i("settings.archiveMode.always")}),a.jsx("option",{value:"never",children:i("settings.archiveMode.never")}),a.jsx("option",{value:"ask",children:i("settings.archiveMode.ask")})]}),a.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"When printing from File Manager, optionally create an archive entry"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Low Disk Space Warning"}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("input",{type:"number",min:"0.5",max:"100",step:"0.5",value:E.library_disk_warning_gb??5,onChange:le=>fn("library_disk_warning_gb",parseFloat(le.target.value)||5),className:"w-24 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"}),a.jsx("span",{className:"text-bambu-gray",children:"GB"})]}),a.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Show warning when free disk space falls below this threshold"})]})]})]})]}),a.jsxs("div",{className:"space-y-6 flex-1 lg:max-w-sm",children:[a.jsx(LKe,{}),a.jsxs(St,{children:[a.jsx(Kn,{children:a.jsx("h2",{className:"text-lg font-semibold text-white",children:"Updates"})}),a.jsxs(Nt,{className:"space-y-4",children:[a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-white",children:i("settings.checkForUpdatesLabel")}),a.jsx("p",{className:"text-sm text-bambu-gray",children:"Automatically check for new versions on startup"})]}),a.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:E.check_updates,onChange:le=>fn("check_updates",le.target.checked),className:"sr-only peer"}),a.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-white",children:i("settings.checkPrinterFirmware")}),a.jsx("p",{className:"text-sm text-bambu-gray",children:"Check for printer firmware updates from Bambu Lab"})]}),a.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:E.check_printer_firmware??!0,onChange:le=>fn("check_printer_firmware",le.target.checked),className:"sr-only peer"}),a.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]}),a.jsxs("div",{className:"border-t border-bambu-dark-tertiary pt-4",children:[a.jsxs("div",{className:"flex items-center justify-between mb-2",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-white",children:i("settings.currentVersion")}),a.jsxs("p",{className:"text-sm text-bambu-gray",children:["v",dn?.version||"..."]})]}),a.jsxs(Te,{variant:"secondary",size:"sm",onClick:()=>ir(),disabled:Pn,children:[Pn?a.jsx(pt,{className:"w-4 h-4 animate-spin"}):a.jsx(Dr,{className:"w-4 h-4"}),"Check now"]})]}),Yt?.update_available?a.jsxs("div",{className:"mt-4 p-3 bg-bambu-green/10 border border-bambu-green/30 rounded-lg",children:[a.jsxs("div",{className:"flex items-start justify-between",children:[a.jsxs("div",{children:[a.jsxs("p",{className:"text-bambu-green font-medium",children:["Update available: v",Yt.latest_version]}),Yt.release_name&&Yt.release_name!==Yt.latest_version&&a.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:Yt.release_name})]}),a.jsxs("div",{className:"flex items-center gap-2",children:[Yt.release_notes&&a.jsx("button",{onClick:()=>we(!0),className:"text-bambu-gray hover:text-white transition-colors text-sm underline",children:"Release Notes"}),Yt.release_url&&a.jsx("a",{href:Yt.release_url,target:"_blank",rel:"noopener noreferrer",className:"text-bambu-gray hover:text-white transition-colors",title:i("settings.viewReleaseOnGitHub"),children:a.jsx(Xr,{className:"w-4 h-4"})})]})]}),si?.status==="downloading"||si?.status==="installing"?a.jsxs("div",{className:"mt-3",children:[a.jsxs("div",{className:"flex items-center gap-2 text-sm text-bambu-gray",children:[a.jsx(pt,{className:"w-4 h-4 animate-spin"}),a.jsx("span",{children:si.message})]}),a.jsx("div",{className:"mt-2 w-full bg-bambu-dark-tertiary rounded-full h-2",children:a.jsx("div",{className:"bg-bambu-green h-2 rounded-full transition-all duration-300",style:{width:`${si.progress}%`}})})]}):si?.status==="complete"?a.jsx("div",{className:"mt-3 p-2 bg-bambu-green/20 rounded text-sm text-bambu-green",children:si.message}):si?.status==="error"?a.jsx("div",{className:"mt-3 p-2 bg-red-500/20 rounded text-sm text-red-400",children:si.error||si.message}):Yt?.is_docker?a.jsxs("div",{className:"mt-3 p-3 bg-bambu-dark-tertiary rounded-lg",children:[a.jsx("p",{className:"text-sm text-bambu-gray mb-2",children:"Update via Docker Compose:"}),a.jsx("code",{className:"block text-xs bg-bambu-dark p-2 rounded text-bambu-green font-mono",children:"docker compose pull && docker compose up -d"})]}):a.jsxs(Te,{className:"mt-3",onClick:()=>Zu.mutate(),disabled:Zu.isPending,children:[Zu.isPending?a.jsx(pt,{className:"w-4 h-4 animate-spin"}):a.jsx(wi,{className:"w-4 h-4"}),"Install Update"]})]}):Yt?.error?a.jsxs("div",{className:"mt-2 p-2 bg-red-500/10 border border-red-500/30 rounded text-sm text-red-400",children:["Failed to check for updates: ",Yt.error]}):Yt&&!Yt.update_available?a.jsx("p",{className:"mt-2 text-sm text-bambu-gray",children:"You're running the latest version"}):null]})]})]}),a.jsxs(St,{children:[a.jsx(Kn,{children:a.jsx("h2",{className:"text-lg font-semibold text-white",children:i("settings.dataManagement")})}),a.jsxs(Nt,{className:"space-y-4",children:[a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-white",children:i("settings.clearNotificationLogs")}),a.jsx("p",{className:"text-sm text-bambu-gray",children:i("settings.clearNotificationLogsDescription")})]}),a.jsxs(Te,{variant:"secondary",size:"sm",onClick:()=>je(!0),children:[a.jsx(an,{className:"w-4 h-4"}),i("common.clear")]})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-white",children:i("settings.resetUiPreferences")}),a.jsx("p",{className:"text-sm text-bambu-gray",children:i("settings.resetUiPreferencesDescription")})]}),a.jsxs(Te,{variant:"secondary",size:"sm",onClick:()=>z(!0),children:[a.jsx(an,{className:"w-4 h-4"}),"Reset"]})]}),a.jsxs("div",{className:"flex items-center justify-between pt-4 border-t border-bambu-dark-tertiary",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-white",children:"Backup & Restore"}),a.jsx("p",{className:"text-sm text-bambu-gray",children:"Export/import settings and configure GitHub backup"})]}),a.jsxs(Te,{variant:"secondary",size:"sm",onClick:()=>de("backup"),children:[a.jsx(Eu,{className:"w-4 h-4"}),"Go to Backup"]})]})]})]})]})]}),pe==="network"&&E&&a.jsxs("div",{className:"flex flex-col lg:flex-row gap-6",children:[a.jsxs("div",{className:"flex-1 lg:max-w-xl space-y-4",children:[a.jsxs(St,{children:[a.jsx(Kn,{children:a.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[a.jsx(oh,{className:"w-5 h-5 text-blue-400"}),"External URL"]})}),a.jsxs(Nt,{className:"space-y-4",children:[a.jsx("p",{className:"text-sm text-bambu-gray",children:"The external URL where Bambuddy is accessible. Used for notification images and external integrations."}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Bambuddy URL"}),a.jsx("input",{type:"text",value:E.external_url??"",onChange:le=>fn("external_url",le.target.value),placeholder:"http://192.168.1.100:8000",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"}),a.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Include protocol and port (e.g., http://192.168.1.100:8000)"})]})]})]}),a.jsxs(St,{children:[a.jsx(Kn,{children:a.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[a.jsx(Dr,{className:"w-5 h-5 text-blue-400"}),"FTP Retry"]})}),a.jsxs(Nt,{className:"space-y-4",children:[a.jsx("p",{className:"text-sm text-bambu-gray",children:"Retry FTP operations when printer WiFi is unreliable. Applies to 3MF downloads, print uploads, timelapse downloads, and firmware updates."}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-white",children:i("settings.enableRetry")}),a.jsx("p",{className:"text-sm text-bambu-gray",children:"Automatically retry failed FTP operations"})]}),a.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:E.ftp_retry_enabled??!0,onChange:le=>fn("ftp_retry_enabled",le.target.checked),className:"sr-only peer"}),a.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]}),E.ftp_retry_enabled&&a.jsxs("div",{className:"space-y-4 pt-2 border-t border-bambu-dark-tertiary",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Retry attempts"}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("input",{type:"number",min:"1",max:"10",value:E.ftp_retry_count??3,onChange:le=>fn("ftp_retry_count",Math.min(10,Math.max(1,parseInt(le.target.value)||3))),className:"w-24 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"}),a.jsx("span",{className:"text-bambu-gray",children:"times"})]}),a.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Number of retry attempts before giving up (1-10)"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Retry delay"}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("input",{type:"number",min:"1",max:"30",value:E.ftp_retry_delay??2,onChange:le=>fn("ftp_retry_delay",Math.min(30,Math.max(1,parseInt(le.target.value)||2))),className:"w-24 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"}),a.jsx("span",{className:"text-bambu-gray",children:"seconds"})]}),a.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Wait time between retries (1-30)"})]})]}),a.jsxs("div",{className:"pt-2 border-t border-bambu-dark-tertiary",children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Connection timeout"}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("input",{type:"number",min:"10",max:"120",value:E.ftp_timeout??30,onChange:le=>fn("ftp_timeout",Math.min(120,Math.max(10,parseInt(le.target.value)||30))),className:"w-24 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"}),a.jsx("span",{className:"text-bambu-gray",children:"seconds"})]}),a.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Socket timeout for slow connections. Increase for A1/A1 Mini printers with weak WiFi (10-120)"})]})]})]})]}),a.jsxs("div",{className:"flex-1 lg:max-w-xl space-y-4",children:[a.jsxs(St,{children:[a.jsx(Kn,{children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[a.jsx(Iy,{className:"w-5 h-5 text-bambu-green"}),"Home Assistant"]}),E.ha_enabled&&Nn&&a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("span",{className:`w-2.5 h-2.5 rounded-full ${Nn.success?"bg-green-400":"bg-red-400"}`}),a.jsx("span",{className:`text-sm ${Nn.success?"text-green-400":"text-red-400"}`,children:Nn.success?"Connected":"Disconnected"})]})]})}),a.jsxs(Nt,{className:"space-y-4",children:[a.jsx("p",{className:"text-sm text-bambu-gray",children:"Connect to Home Assistant to control smart plugs via HA's REST API. Supports switch, light, input_boolean, and script entities."}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-white",children:i("settings.enableHomeAssistant")}),a.jsx("p",{className:"text-xs text-bambu-gray",children:i("settings.homeAssistantDescription")})]}),a.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:E.ha_enabled??!1,onChange:le=>fn("ha_enabled",le.target.checked),className:"sr-only peer"}),a.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]}),E.ha_enabled&&a.jsxs(a.Fragment,{children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Home Assistant URL"}),a.jsx("input",{type:"text",value:E.ha_url??"",onChange:le=>fn("ha_url",le.target.value),placeholder:"http://192.168.1.100:8123",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"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Long-Lived Access Token"}),a.jsx("input",{type:"password",value:E.ha_token??"",onChange:le=>fn("ha_token",le.target.value),placeholder:"eyJ0eXAiOiJKV1QiLC...",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"}),a.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Create a token in HA: Profile → Long-Lived Access Tokens → Create Token"})]}),E.ha_url&&E.ha_token&&a.jsx("div",{className:"pt-2 border-t border-bambu-dark-tertiary",children:a.jsxs(Te,{variant:"secondary",size:"sm",disabled:ai,onClick:async()=>{Ce(!0),hi(null);try{const le=await ce.testHAConnection(E.ha_url,E.ha_token);hi(le)}catch(le){hi({success:!1,message:null,error:le instanceof Error?le.message:i("common.unknownError")})}finally{Ce(!1)}},children:[ai?a.jsx(pt,{className:"w-4 h-4 animate-spin"}):a.jsx(Mg,{className:"w-4 h-4"}),i("settings.testConnection")]})})]})]})]}),a.jsxs(St,{children:[a.jsx(Kn,{children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[a.jsx(Mg,{className:"w-5 h-5 text-blue-400"}),"MQTT Publishing"]}),dr?.enabled&&a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("span",{className:`w-2.5 h-2.5 rounded-full ${dr.connected?"bg-green-400":"bg-red-400"}`}),a.jsx("span",{className:`text-sm ${dr.connected?"text-green-400":"text-red-400"}`,children:dr.connected?"Connected":"Disconnected"})]})]})}),a.jsxs(Nt,{className:"space-y-4",children:[a.jsx("p",{className:"text-sm text-bambu-gray",children:"Publish BamBuddy events to an external MQTT broker for integration with Node-RED, Home Assistant, and other automation systems."}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-white",children:i("settings.enableMqtt")}),a.jsx("p",{className:"text-sm text-bambu-gray",children:"Publish events to external MQTT broker"})]}),a.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:E.mqtt_enabled??!1,onChange:le=>fn("mqtt_enabled",le.target.checked),className:"sr-only peer"}),a.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]}),E.mqtt_enabled&&a.jsxs("div",{className:"space-y-4 pt-2 border-t border-bambu-dark-tertiary",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Broker hostname"}),a.jsx("input",{type:"text",value:E.mqtt_broker??"",onChange:le=>fn("mqtt_broker",le.target.value),placeholder:"mqtt.example.com or 192.168.1.100",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"})]}),a.jsxs("div",{className:"flex items-end gap-4",children:[a.jsxs("div",{className:"flex-1",children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Port"}),a.jsx("input",{type:"number",min:"1",max:"65535",value:E.mqtt_port??1883,onChange:le=>fn("mqtt_port",Math.min(65535,Math.max(1,parseInt(le.target.value)||1883))),className:"w-24 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]}),a.jsxs("div",{className:"flex items-center gap-3 pb-2",children:[a.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:E.mqtt_use_tls??!1,onChange:le=>{const _t=le.target.checked;fn("mqtt_use_tls",_t);const Ln=E.mqtt_port??1883;_t&&Ln===1883?fn("mqtt_port",8883):!_t&&Ln===8883&&fn("mqtt_port",1883)},className:"sr-only peer"}),a.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]}),a.jsx("span",{className:"text-white text-sm",children:i("settings.useTls")})]})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Username (optional)"}),a.jsx("input",{type:"text",value:E.mqtt_username??"",onChange:le=>fn("mqtt_username",le.target.value),placeholder:i("settings.leaveEmptyForAnonymous"),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"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Password (optional)"}),a.jsx("input",{type:"password",value:E.mqtt_password??"",onChange:le=>fn("mqtt_password",le.target.value),placeholder:i("settings.leaveEmptyForAnonymous"),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"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Topic prefix"}),a.jsx("input",{type:"text",value:E.mqtt_topic_prefix??"bambuddy",onChange:le=>fn("mqtt_topic_prefix",le.target.value),placeholder:"bambuddy",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"}),a.jsxs("p",{className:"text-xs text-bambu-gray mt-1",children:["Topics will be: ",E.mqtt_topic_prefix||"bambuddy","/printers//status, etc."]})]}),dr&&a.jsx("div",{className:"pt-3 mt-3 border-t border-bambu-dark-tertiary",children:a.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[a.jsx("span",{className:`w-2 h-2 rounded-full ${dr.connected?"bg-green-400":"bg-red-400"}`}),a.jsx("span",{className:"text-bambu-gray",children:dr.connected?a.jsxs(a.Fragment,{children:[i("settings.mqttConnectedTo")," ",a.jsxs("span",{className:"text-white",children:[dr.broker,":",dr.port]})]}):i("settings.spoolmanDisconnected")})]})})]})]})]})]}),a.jsx("div",{className:"flex-1 lg:max-w-md space-y-4",children:a.jsxs(St,{children:[a.jsx(Kn,{children:a.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[a.jsx(wP,{className:"w-5 h-5 text-orange-400"}),"Prometheus Metrics"]})}),a.jsxs(Nt,{className:"space-y-4",children:[a.jsxs("p",{className:"text-sm text-bambu-gray",children:["Expose printer metrics at ",a.jsx("code",{className:"bg-bambu-dark px-1 rounded",children:"/api/v1/metrics"})," for Prometheus/Grafana monitoring."]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-white",children:i("settings.enableMetricsEndpoint")}),a.jsx("p",{className:"text-xs text-bambu-gray",children:i("settings.prometheusDescription")})]}),a.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:E.prometheus_enabled??!1,onChange:le=>fn("prometheus_enabled",le.target.checked),className:"sr-only peer"}),a.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]}),E.prometheus_enabled&&a.jsxs("div",{className:"space-y-4 pt-2 border-t border-bambu-dark-tertiary",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Bearer Token (optional)"}),a.jsx("input",{type:"password",value:E.prometheus_token??"",onChange:le=>fn("prometheus_token",le.target.value),placeholder:i("settings.leaveEmptyForNoAuth"),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"}),a.jsxs("p",{className:"text-xs text-bambu-gray mt-1",children:["If set, requests must include ",a.jsx("code",{className:"bg-bambu-dark px-1 rounded",children:"Authorization: Bearer "})]})]}),a.jsxs("div",{className:"pt-2 border-t border-bambu-dark-tertiary",children:[a.jsx("p",{className:"text-sm text-white mb-2",children:i("settings.availableMetrics")}),a.jsxs("div",{className:"text-xs text-bambu-gray space-y-1",children:[a.jsxs("p",{children:[a.jsx("code",{className:"text-orange-400",children:"bambuddy_printer_connected"})," - Connection status"]}),a.jsxs("p",{children:[a.jsx("code",{className:"text-orange-400",children:"bambuddy_printer_state"})," - Printer state (idle/printing/etc)"]}),a.jsxs("p",{children:[a.jsx("code",{className:"text-orange-400",children:"bambuddy_print_progress"})," - Print progress 0-100%"]}),a.jsxs("p",{children:[a.jsx("code",{className:"text-orange-400",children:"bambuddy_bed_temp_celsius"})," - Bed temperature"]}),a.jsxs("p",{children:[a.jsx("code",{className:"text-orange-400",children:"bambuddy_nozzle_temp_celsius"})," - Nozzle temperature"]}),a.jsxs("p",{children:[a.jsx("code",{className:"text-orange-400",children:"bambuddy_prints_total"})," - Total prints by result"]}),a.jsx("p",{className:"text-bambu-gray/70 italic",children:"...and more (layers, fans, queue, filament usage)"})]})]})]})]})]})})]}),Nn&&a.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50",children:a.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg p-6 max-w-md w-full mx-4",children:[a.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[Nn.success?a.jsx(Ar,{className:"w-8 h-8 text-green-400"}):a.jsx(Ji,{className:"w-8 h-8 text-red-400"}),a.jsx("h3",{className:"text-lg font-medium text-white",children:Nn.success?"Connection Successful":"Connection Failed"})]}),a.jsx("p",{className:"text-bambu-gray mb-6",children:Nn.success?Nn.message||"Successfully connected to Home Assistant.":Nn.error||"Failed to connect to Home Assistant."}),a.jsx("div",{className:"flex justify-end",children:a.jsx(Te,{variant:"primary",onClick:()=>hi(null),children:"OK"})})]})}),pe==="plugs"&&a.jsxs("div",{className:"max-w-4xl",children:[a.jsxs("div",{className:"flex items-start justify-between mb-6",children:[a.jsxs("div",{children:[a.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[a.jsx(al,{className:"w-5 h-5 text-bambu-green"}),"Smart Plugs"]}),a.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:"Connect smart plugs (Tasmota or Home Assistant) to automate power control and track energy usage for your printers."})]}),a.jsxs("div",{className:"flex items-center gap-2 pt-1 shrink-0",children:[Ne&&Ne.filter(le=>le.enabled).length>1&&a.jsxs(a.Fragment,{children:[a.jsxs(Te,{variant:"secondary",size:"sm",className:"whitespace-nowrap",onClick:()=>Z("on"),disabled:ql.isPending,title:i("settings.turnAllPlugsOn"),children:[ql.isPending?a.jsx(pt,{className:"w-4 h-4 animate-spin"}):a.jsx(qu,{className:"w-4 h-4 text-bambu-green"}),"All On"]}),a.jsxs(Te,{variant:"secondary",size:"sm",className:"whitespace-nowrap",onClick:()=>Z("off"),disabled:ql.isPending,title:i("settings.turnAllPlugsOff"),children:[ql.isPending?a.jsx(pt,{className:"w-4 h-4 animate-spin"}):a.jsx(bM,{className:"w-4 h-4 text-red-400"}),"All Off"]})]}),a.jsxs(Te,{className:"whitespace-nowrap",onClick:()=>{L(null),D(!0)},children:[a.jsx(fr,{className:"w-4 h-4"}),"Add Smart Plug"]})]})]}),Ne&&Ne.length>0&&a.jsxs(St,{className:"mb-6",children:[a.jsx(Kn,{children:a.jsxs("h3",{className:"text-base font-semibold text-white flex items-center gap-2",children:[a.jsx(_h,{className:"w-4 h-4 text-yellow-400"}),"Energy Summary",Ye&&a.jsx(pt,{className:"w-4 h-4 animate-spin text-bambu-gray ml-2"})]})}),a.jsx(Nt,{children:nt?a.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[a.jsxs("div",{className:"bg-bambu-dark rounded-lg p-3",children:[a.jsxs("div",{className:"flex items-center gap-2 text-bambu-gray text-xs mb-1",children:[a.jsx(_h,{className:"w-3 h-3"}),"Current Power"]}),a.jsxs("div",{className:"text-xl font-bold text-white",children:[nt.totalPower.toFixed(1),a.jsx("span",{className:"text-sm font-normal text-bambu-gray ml-1",children:"W"})]}),a.jsxs("div",{className:"text-xs text-bambu-gray mt-1",children:[nt.reachableCount,"/",nt.totalPlugs," plugs online"]})]}),a.jsxs("div",{className:"bg-bambu-dark rounded-lg p-3",children:[a.jsxs("div",{className:"flex items-center gap-2 text-bambu-gray text-xs mb-1",children:[a.jsx(ti,{className:"w-3 h-3"}),"Today"]}),a.jsxs("div",{className:"text-xl font-bold text-white",children:[nt.totalToday.toFixed(2),a.jsx("span",{className:"text-sm font-normal text-bambu-gray ml-1",children:"kWh"})]}),E&&E.energy_cost_per_kwh>0&&a.jsxs("div",{className:"text-xs text-bambu-gray mt-1",children:["~",(nt.totalToday*E.energy_cost_per_kwh).toFixed(2)," ",E.currency]})]}),a.jsxs("div",{className:"bg-bambu-dark rounded-lg p-3",children:[a.jsxs("div",{className:"flex items-center gap-2 text-bambu-gray text-xs mb-1",children:[a.jsx(wP,{className:"w-3 h-3"}),"Yesterday"]}),a.jsxs("div",{className:"text-xl font-bold text-white",children:[nt.totalYesterday.toFixed(2),a.jsx("span",{className:"text-sm font-normal text-bambu-gray ml-1",children:"kWh"})]}),E&&E.energy_cost_per_kwh>0&&a.jsxs("div",{className:"text-xs text-bambu-gray mt-1",children:["~",(nt.totalYesterday*E.energy_cost_per_kwh).toFixed(2)," ",E.currency]})]}),a.jsxs("div",{className:"bg-bambu-dark rounded-lg p-3",children:[a.jsxs("div",{className:"flex items-center gap-2 text-bambu-gray text-xs mb-1",children:[a.jsx(mP,{className:"w-3 h-3"}),"Total"]}),a.jsxs("div",{className:"text-xl font-bold text-white",children:[nt.totalLifetime.toFixed(1),a.jsx("span",{className:"text-sm font-normal text-bambu-gray ml-1",children:"kWh"})]}),E&&E.energy_cost_per_kwh>0&&a.jsxs("div",{className:"text-xs text-bambu-gray mt-1",children:["~",(nt.totalLifetime*E.energy_cost_per_kwh).toFixed(2)," ",E.currency]})]})]}):Ye?null:a.jsx("p",{className:"text-sm text-bambu-gray",children:"Enable plugs to see energy summary"})})]}),Oe?a.jsx("div",{className:"flex justify-center py-12",children:a.jsx(pt,{className:"w-8 h-8 text-bambu-green animate-spin"})}):Ne&&Ne.length>0?a.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:Ne.map(le=>a.jsx(NKe,{plug:le,onEdit:_t=>{L(_t),D(!0)}},le.id))}):a.jsx(St,{children:a.jsx(Nt,{className:"py-12",children:a.jsxs("div",{className:"text-center text-bambu-gray",children:[a.jsx(al,{className:"w-16 h-16 mx-auto mb-4 opacity-30"}),a.jsx("p",{className:"text-lg font-medium text-white mb-2",children:i("settings.noSmartPlugsTitle")}),a.jsx("p",{className:"text-sm mb-4",children:i("settings.noSmartPlugsDescription")}),a.jsxs(Te,{onClick:()=>{L(null),D(!0)},children:[a.jsx(fr,{className:"w-4 h-4"}),i("settings.addFirstSmartPlug")]})]})})})]}),pe==="notifications"&&a.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-8",children:[a.jsxs("div",{children:[a.jsxs("div",{className:"flex items-center justify-between mb-4",children:[a.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[a.jsx(Sg,{className:"w-5 h-5 text-bambu-green"}),i("settings.providers")]}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsxs(Te,{size:"sm",variant:"secondary",onClick:()=>ne(!0),children:[a.jsx(W0,{className:"w-4 h-4"}),i("settings.log")]}),Tt&&Tt.length>0&&a.jsxs(Te,{size:"sm",variant:"secondary",onClick:()=>{ha(null),bl.mutate()},disabled:bl.isPending,children:[bl.isPending?a.jsx(pt,{className:"w-4 h-4 animate-spin"}):a.jsx(OR,{className:"w-4 h-4"}),i("settings.testAll")]}),a.jsxs(Te,{size:"sm",onClick:()=>{K(null),j(!0)},children:[a.jsx(fr,{className:"w-4 h-4"}),"Add"]})]})]}),a.jsx(St,{className:"mb-4",children:a.jsx(Nt,{className:"py-3",children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-white text-sm font-medium",children:i("settings.notificationLanguage")}),a.jsx("p",{className:"text-xs text-bambu-gray",children:i("settings.notificationLanguageDescription")})]}),a.jsx("select",{value:E.notification_language||"en",onChange:le=>fn("notification_language",le.target.value),className:"px-2 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm focus:outline-none focus:ring-1 focus:ring-bambu-green",children:yz.map(le=>a.jsx("option",{value:le.code,children:le.nativeName},le.code))})]})})}),Pc&&a.jsx(St,{className:"mb-4",children:a.jsxs(Nt,{className:"py-3",children:[a.jsxs("div",{className:"flex items-center justify-between mb-2",children:[a.jsx("span",{className:"text-sm font-medium text-white",children:i("settings.testResults")}),a.jsx("button",{onClick:()=>ha(null),className:"text-bambu-gray hover:text-white text-xs",children:i("common.dismiss")})]}),a.jsxs("div",{className:"flex items-center gap-4 text-sm mb-2",children:[a.jsxs("span",{className:"flex items-center gap-1 text-bambu-green",children:[a.jsx(Ar,{className:"w-4 h-4"}),i("settings.testPassedCount",{count:Pc.success})]}),Pc.failed>0&&a.jsxs("span",{className:"flex items-center gap-1 text-red-400",children:[a.jsx(Ji,{className:"w-4 h-4"}),i("settings.testFailedCount",{count:Pc.failed})]})]}),Pc.results.filter(le=>!le.success).length>0&&a.jsx("div",{className:"space-y-1 mt-2 pt-2 border-t border-bambu-dark-tertiary",children:Pc.results.filter(le=>!le.success).map(le=>a.jsxs("div",{className:"text-xs text-red-400",children:[a.jsxs("span",{className:"font-medium",children:[le.provider_name,":"]})," ",le.message]},le.provider_id))})]})}),At?a.jsx("div",{className:"flex justify-center py-12",children:a.jsx(pt,{className:"w-6 h-6 text-bambu-green animate-spin"})}):Tt&&Tt.length>0?a.jsx("div",{className:"space-y-3",children:Tt.map(le=>a.jsx(EKe,{provider:le,onEdit:_t=>{K(_t),j(!0)}},le.id))}):a.jsx(St,{children:a.jsx(Nt,{className:"py-8",children:a.jsxs("div",{className:"text-center text-bambu-gray",children:[a.jsx(Sg,{className:"w-12 h-12 mx-auto mb-3 opacity-30"}),a.jsx("p",{className:"text-sm font-medium text-white mb-2",children:i("settings.noProvidersTitle")}),a.jsx("p",{className:"text-xs mb-3",children:i("settings.noProvidersDescription")}),a.jsxs(Te,{size:"sm",onClick:()=>{K(null),j(!0)},children:[a.jsx(fr,{className:"w-4 h-4"}),i("settings.addProvider")]})]})})})]}),a.jsxs("div",{children:[a.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2 mb-4",children:[a.jsx(fs,{className:"w-5 h-5 text-bambu-green"}),i("settings.messageTemplates")]}),a.jsx("p",{className:"text-sm text-bambu-gray mb-4",children:i("settings.messageTemplatesDescription")}),un?a.jsx("div",{className:"flex justify-center py-8",children:a.jsx(pt,{className:"w-6 h-6 text-bambu-green animate-spin"})}):hn&&hn.length>0?a.jsx("div",{className:"space-y-2",children:hn.map(le=>a.jsx(St,{className:"cursor-pointer hover:border-bambu-green/50 transition-colors",onClick:()=>X(le),children:a.jsx(Nt,{className:"py-2.5 px-3",children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{className:"min-w-0 flex-1",children:[a.jsx("p",{className:"text-white font-medium text-sm truncate",children:le.name}),a.jsx("p",{className:"text-bambu-gray text-xs truncate mt-0.5",children:le.title_template})]}),a.jsx("button",{className:"p-1.5 hover:bg-bambu-dark-tertiary rounded transition-colors shrink-0 ml-2",onClick:_t=>{_t.stopPropagation(),X(le)},children:a.jsx(mg,{className:"w-4 h-4 text-bambu-gray"})})]})})},le.id))}):a.jsx(St,{children:a.jsx(Nt,{className:"py-8",children:a.jsxs("div",{className:"text-center text-bambu-gray",children:[a.jsx(fs,{className:"w-12 h-12 mx-auto mb-3 opacity-30"}),a.jsx("p",{className:"text-sm",children:i("settings.noTemplatesAvailable")})]})})})]})]}),pe==="apikeys"&&a.jsxs("div",{className:"grid grid-cols-1 xl:grid-cols-2 gap-8",children:[a.jsxs("div",{children:[a.jsxs("div",{className:"flex items-start justify-between gap-4 mb-6",children:[a.jsxs("div",{className:"flex-1",children:[a.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[a.jsx(Ko,{className:"w-5 h-5 text-bambu-green"}),i("settings.apiKeys")]}),a.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:i("settings.apiKeysDescription")})]}),a.jsxs(Te,{size:"sm",onClick:()=>se(!0),className:"flex-shrink-0",children:[a.jsx(fr,{className:"w-4 h-4"}),i("settings.createKey")]})]}),G&&a.jsx(St,{className:"mb-6 border-bambu-green",children:a.jsx(Nt,{className:"py-4",children:a.jsxs("div",{className:"flex items-start gap-3",children:[a.jsx(Ar,{className:"w-5 h-5 text-bambu-green flex-shrink-0 mt-0.5"}),a.jsxs("div",{className:"flex-1",children:[a.jsx("p",{className:"text-white font-medium mb-1",children:i("settings.apiKeyCreated")}),a.jsx("p",{className:"text-sm text-bambu-gray mb-2",children:i("settings.apiKeyCopyWarning")}),a.jsxs("div",{className:"flex items-center gap-2 bg-bambu-dark rounded-lg p-2",children:[a.jsx("code",{className:"flex-1 text-sm text-bambu-green font-mono break-all",children:G}),a.jsx(Te,{variant:"secondary",size:"sm",onClick:async()=>{try{if(navigator.clipboard&&navigator.clipboard.writeText)await navigator.clipboard.writeText(G);else{const le=document.createElement("textarea");le.value=G,le.style.position="fixed",le.style.left="-999999px",document.body.appendChild(le),le.select(),document.execCommand("copy"),document.body.removeChild(le)}o(i("settings.toast.keyCopied"))}catch{o(i("settings.toast.copyFailed"),"error")}},children:a.jsx(Ul,{className:"w-4 h-4"})})]}),a.jsxs("div",{className:"flex gap-2 mt-3",children:[a.jsx(Te,{variant:"secondary",size:"sm",onClick:()=>{V(G),o(i("settings.toast.keyAddedToBrowser"))},children:i("settings.useInApiBrowser")}),a.jsx(Te,{variant:"secondary",size:"sm",onClick:()=>Q(null),children:i("common.dismiss")})]})]})]})})}),Ee&&a.jsxs(St,{className:"mb-6",children:[a.jsx(Kn,{children:a.jsx("h3",{className:"text-base font-semibold text-white",children:i("settings.createNewApiKey")})}),a.jsxs(Nt,{className:"space-y-4",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:i("settings.keyName")}),a.jsx("input",{type:"text",value:Ae,onChange:le=>Fe(le.target.value),placeholder:i("settings.keyNamePlaceholder"),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"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-2",children:i("common.permissions")}),a.jsxs("div",{className:"space-y-2",children:[a.jsxs("label",{className:"flex items-center gap-3 cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:ge.can_read_status,onChange:le=>Ze(_t=>({..._t,can_read_status:le.target.checked})),className:"w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green"}),a.jsxs("div",{children:[a.jsx("span",{className:"text-white",children:i("settings.readStatus")}),a.jsx("p",{className:"text-xs text-bambu-gray",children:i("settings.readStatusDescription")})]})]}),a.jsxs("label",{className:"flex items-center gap-3 cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:ge.can_queue,onChange:le=>Ze(_t=>({..._t,can_queue:le.target.checked})),className:"w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green"}),a.jsxs("div",{children:[a.jsx("span",{className:"text-white",children:i("settings.manageQueue")}),a.jsx("p",{className:"text-xs text-bambu-gray",children:i("settings.manageQueueDescription")})]})]}),a.jsxs("label",{className:"flex items-center gap-3 cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:ge.can_control_printer,onChange:le=>Ze(_t=>({..._t,can_control_printer:le.target.checked})),className:"w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green"}),a.jsxs("div",{children:[a.jsx("span",{className:"text-white",children:i("settings.controlPrinter")}),a.jsx("p",{className:"text-xs text-bambu-gray",children:i("settings.controlPrinterDescription")})]})]})]})]}),a.jsxs("div",{className:"flex items-center gap-2 pt-2",children:[a.jsxs(Te,{onClick:()=>Mt.mutate({name:Ae||i("settings.unnamedKey"),...ge}),disabled:Mt.isPending,children:[Mt.isPending?a.jsx(pt,{className:"w-4 h-4 animate-spin"}):a.jsx(fr,{className:"w-4 h-4"}),i("settings.createKey")]}),a.jsx(Te,{variant:"secondary",onClick:()=>se(!1),children:i("common.cancel")})]})]})]}),Rt?a.jsx("div",{className:"flex justify-center py-12",children:a.jsx(pt,{className:"w-8 h-8 text-bambu-green animate-spin"})}):It&&It.length>0?a.jsx("div",{className:"space-y-3",children:It.map(le=>a.jsx(St,{children:a.jsx(Nt,{className:"py-3",children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{className:"flex items-center gap-3",children:[a.jsx(Ko,{className:`w-5 h-5 ${le.enabled?"text-bambu-green":"text-bambu-gray"}`}),a.jsxs("div",{children:[a.jsx("p",{className:"text-white font-medium",children:le.name}),a.jsxs("p",{className:"text-xs text-bambu-gray",children:[le.key_prefix,"••••••••",le.last_used&&` · ${i("settings.lastUsed")}: ${$g(le.last_used)}`]})]})]}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsxs("div",{className:"flex gap-1 text-xs",children:[le.can_read_status&&a.jsx("span",{className:"px-1.5 py-0.5 bg-blue-500/20 text-blue-400 rounded",children:i("settings.read")}),le.can_queue&&a.jsx("span",{className:"px-1.5 py-0.5 bg-green-500/20 text-green-400 rounded",children:i("queue.title")}),le.can_control_printer&&a.jsx("span",{className:"px-1.5 py-0.5 bg-orange-500/20 text-orange-400 rounded",children:i("settings.control")})]}),a.jsx(Te,{variant:"secondary",size:"sm",onClick:()=>q(le.id),children:a.jsx(an,{className:"w-4 h-4 text-red-400"})})]})]})})},le.id))}):a.jsx(St,{children:a.jsx(Nt,{className:"py-12",children:a.jsxs("div",{className:"text-center text-bambu-gray",children:[a.jsx(Ko,{className:"w-16 h-16 mx-auto mb-4 opacity-30"}),a.jsx("p",{className:"text-lg font-medium text-white mb-2",children:i("settings.apiKeysEmptyTitle")}),a.jsx("p",{className:"text-sm mb-4",children:i("settings.apiKeysEmptyDescription")}),a.jsxs(Te,{onClick:()=>se(!0),children:[a.jsx(fr,{className:"w-4 h-4"}),i("settings.createFirstKey")]})]})})}),a.jsxs(St,{className:"mt-6",children:[a.jsx(Kn,{children:a.jsx("h3",{className:"text-base font-semibold text-white",children:i("settings.webhookEndpoints")})}),a.jsxs(Nt,{className:"space-y-3 text-sm",children:[a.jsx("p",{className:"text-bambu-gray",children:i("settings.webhookApiKeyHint")}),a.jsxs("div",{className:"space-y-2 font-mono text-xs",children:[a.jsxs("div",{className:"p-2 bg-bambu-dark rounded",children:[a.jsx("span",{className:"text-blue-400",children:"GET"})," ",a.jsx("span",{className:"text-white",children:"/api/v1/webhook/status"}),a.jsxs("span",{className:"text-bambu-gray",children:[" - ",i("settings.webhook.getAllStatus")]})]}),a.jsxs("div",{className:"p-2 bg-bambu-dark rounded",children:[a.jsx("span",{className:"text-blue-400",children:"GET"})," ",a.jsx("span",{className:"text-white",children:"/api/v1/webhook/status/:id"}),a.jsxs("span",{className:"text-bambu-gray",children:[" - ",i("settings.webhook.getSpecificStatus")]})]}),a.jsxs("div",{className:"p-2 bg-bambu-dark rounded",children:[a.jsx("span",{className:"text-green-400",children:"POST"})," ",a.jsx("span",{className:"text-white",children:"/api/v1/webhook/queue"}),a.jsxs("span",{className:"text-bambu-gray",children:[" - ",i("settings.webhook.addToQueue")]})]}),a.jsxs("div",{className:"p-2 bg-bambu-dark rounded",children:[a.jsx("span",{className:"text-orange-400",children:"POST"})," ",a.jsx("span",{className:"text-white",children:"/api/v1/webhook/printer/:id/pause"}),a.jsxs("span",{className:"text-bambu-gray",children:[" - ",i("settings.webhook.pausePrint")]})]}),a.jsxs("div",{className:"p-2 bg-bambu-dark rounded",children:[a.jsx("span",{className:"text-orange-400",children:"POST"})," ",a.jsx("span",{className:"text-white",children:"/api/v1/webhook/printer/:id/resume"}),a.jsxs("span",{className:"text-bambu-gray",children:[" - ",i("settings.webhook.resumePrint")]})]}),a.jsxs("div",{className:"p-2 bg-bambu-dark rounded",children:[a.jsx("span",{className:"text-red-400",children:"POST"})," ",a.jsx("span",{className:"text-white",children:"/api/v1/webhook/printer/:id/stop"}),a.jsxs("span",{className:"text-bambu-gray",children:[" - ",i("settings.webhook.stopPrint")]})]})]})]})]})]}),a.jsxs("div",{children:[a.jsxs("div",{className:"mb-6",children:[a.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[a.jsx(oh,{className:"w-5 h-5 text-bambu-green"}),i("settings.apiBrowser")]}),a.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:i("settings.apiBrowserDescription")})]}),a.jsx(St,{className:"mb-4",children:a.jsxs(Nt,{className:"py-3",children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-2",children:i("settings.apiKeyForTesting")}),a.jsx("input",{type:"text",value:ee,onChange:le=>V(le.target.value),placeholder:i("settings.apiKeyPlaceholder"),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white font-mono text-sm focus:border-bambu-green focus:outline-none"}),a.jsx("p",{className:"text-xs text-bambu-gray mt-2",children:i("settings.apiKeyHint")})]})}),a.jsx($Ke,{apiKey:ee})]})]}),pe==="virtual-printer"&&a.jsx(FKe,{}),pe==="filament"&&E&&a.jsxs("div",{className:"flex flex-col lg:flex-row gap-6 lg:gap-8",children:[a.jsx("div",{className:"flex-1 lg:max-w-xl",children:a.jsxs(St,{children:[a.jsx(Kn,{children:a.jsx("h2",{className:"text-lg font-semibold text-white",children:i("settings.amsDisplayThresholds")})}),a.jsxs(Nt,{className:"space-y-4",children:[a.jsx("p",{className:"text-sm text-bambu-gray",children:i("settings.amsThresholdsDescription")}),a.jsxs("div",{className:"space-y-3",children:[a.jsxs("div",{className:"flex items-center gap-2 text-white",children:[a.jsx(DR,{className:"w-4 h-4 text-blue-400"}),a.jsx("span",{className:"font-medium",children:i("settings.humidity")})]}),a.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[a.jsxs("div",{children:[a.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[i("settings.goodGreen")," ≤"]}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("input",{type:"number",min:"0",max:"100",value:E.ams_humidity_good??40,onChange:le=>fn("ams_humidity_good",parseInt(le.target.value)||40),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"}),a.jsx("span",{className:"text-bambu-gray",children:"%"})]})]}),a.jsxs("div",{children:[a.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[i("settings.fairOrange")," ≤"]}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("input",{type:"number",min:"0",max:"100",value:E.ams_humidity_fair??60,onChange:le=>fn("ams_humidity_fair",parseInt(le.target.value)||60),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"}),a.jsx("span",{className:"text-bambu-gray",children:"%"})]})]})]}),a.jsx("p",{className:"text-xs text-bambu-gray",children:i("settings.aboveFairBad")})]}),a.jsxs("div",{className:"space-y-3 pt-2 border-t border-bambu-dark-tertiary",children:[a.jsxs("div",{className:"flex items-center gap-2 text-white",children:[a.jsx(vM,{className:"w-4 h-4 text-orange-400"}),a.jsx("span",{className:"font-medium",children:i("settings.temperature")})]}),a.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[a.jsxs("div",{children:[a.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[i("settings.goodBlue")," ≤"]}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("input",{type:"number",step:"0.5",min:"0",max:"60",value:E.ams_temp_good??28,onChange:le=>fn("ams_temp_good",parseFloat(le.target.value)||28),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"}),a.jsx("span",{className:"text-bambu-gray",children:"°C"})]})]}),a.jsxs("div",{children:[a.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[i("settings.fairOrange")," ≤"]}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("input",{type:"number",step:"0.5",min:"0",max:"60",value:E.ams_temp_fair??35,onChange:le=>fn("ams_temp_fair",parseFloat(le.target.value)||35),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"}),a.jsx("span",{className:"text-bambu-gray",children:"°C"})]})]})]}),a.jsx("p",{className:"text-xs text-bambu-gray",children:i("settings.aboveFairHot")})]}),a.jsxs("div",{className:"space-y-3 pt-4 border-t border-bambu-dark-tertiary",children:[a.jsxs("div",{className:"flex items-center gap-2 text-white",children:[a.jsx(Eu,{className:"w-4 h-4 text-purple-400"}),a.jsx("span",{className:"font-medium",children:i("settings.historyRetention")})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:i("settings.keepSensorHistory")}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("input",{type:"number",min:"1",max:"365",value:E.ams_history_retention_days??30,onChange:le=>fn("ams_history_retention_days",parseInt(le.target.value)||30),className:"w-24 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"}),a.jsx("span",{className:"text-bambu-gray",children:i("common.days")})]})]}),a.jsx("p",{className:"text-xs text-bambu-gray",children:i("settings.historyRetentionDescription")})]}),a.jsxs("div",{className:"space-y-3 pt-4 border-t border-bambu-dark-tertiary",children:[a.jsxs("div",{className:"flex items-center gap-2 text-white",children:[a.jsx(Ur,{className:"w-4 h-4 text-bambu-green"}),a.jsx("span",{className:"font-medium",children:i("settings.printModal")})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-white",children:i("settings.expandCustomMapping")}),a.jsx("p",{className:"text-xs text-bambu-gray mt-0.5",children:i("settings.expandCustomMappingDescription")})]}),a.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:E.per_printer_mapping_expanded??!1,onChange:le=>fn("per_printer_mapping_expanded",le.target.checked),className:"sr-only peer"}),a.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]})]})]})]})}),a.jsx("div",{className:"flex-1 lg:max-w-xl",children:a.jsx(RKe,{})})]}),he!==null&&a.jsx(Zn,{title:i("settings.deleteApiKeyTitle"),message:i("settings.deleteApiKeyMessage"),confirmText:i("settings.deleteKey"),variant:"danger",onConfirm:()=>{en.mutate(he),q(null)},onCancel:()=>q(null)}),A&&a.jsx(MKe,{plug:I,onClose:()=>{D(!1),L(null)}}),U&&a.jsx(TKe,{provider:$,onClose:()=>{j(!1),K(null)}}),B&&a.jsx(AKe,{template:B,onClose:()=>X(null)}),Y&&a.jsx(PKe,{onClose:()=>ne(!1)}),ye&&a.jsx(Zn,{title:i("settings.clearNotificationLogs"),message:i("settings.clearLogsMessage"),confirmText:i("settings.clearLogs"),variant:"warning",onConfirm:async()=>{je(!1);try{const le=await ce.clearNotificationLogs(30);o(le.message,"success")}catch{o(i("settings.toast.clearLogsFailed"),"error")}},onCancel:()=>je(!1)}),te&&a.jsx(Zn,{title:i("settings.resetUiPreferences"),message:i("settings.resetUiPreferencesMessage"),confirmText:i("settings.resetPreferences"),variant:"default",onConfirm:()=>{z(!1),localStorage.clear(),o(i("settings.toast.uiPreferencesReset"),"success"),setTimeout(()=>window.location.reload(),1e3)},onCancel:()=>z(!1)}),O&&a.jsx(Zn,{title:`Turn All Plugs ${O==="on"?"On":"Off"}`,message:`This will turn ${O==="on"?"ON":"OFF"} all ${Ne?.filter(le=>le.enabled).length||0} enabled smart plugs. ${O==="off"?"Any running printers may be affected!":""}`,confirmText:`Turn All ${O==="on"?"On":"Off"}`,variant:O==="off"?"danger":"warning",onConfirm:()=>{const le=O;Z(null),ql.mutate(le)},onCancel:()=>Z(null)}),oe&&Yt?.release_notes&&a.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",onClick:()=>we(!1),children:a.jsxs(St,{className:"w-full max-w-2xl max-h-[80vh] flex flex-col",onClick:le=>le.stopPropagation(),children:[a.jsxs(Kn,{className:"flex flex-row items-center justify-between shrink-0",children:[a.jsxs("div",{children:[a.jsxs("h2",{className:"text-lg font-semibold text-white",children:["Release Notes - v",Yt.latest_version]}),Yt.release_name&&Yt.release_name!==Yt.latest_version&&a.jsx("p",{className:"text-sm text-bambu-gray",children:Yt.release_name})]}),a.jsx("button",{onClick:()=>we(!1),className:"p-1 rounded hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white",children:a.jsx(Lt,{className:"w-5 h-5"})})]}),a.jsx(Nt,{className:"overflow-y-auto flex-1",children:a.jsx("pre",{className:"text-sm text-bambu-gray whitespace-pre-wrap font-sans",children:Yt.release_notes})}),a.jsxs("div",{className:"p-4 border-t border-bambu-dark-tertiary shrink-0 flex gap-2",children:[Yt.release_url&&a.jsx("a",{href:Yt.release_url,target:"_blank",rel:"noopener noreferrer",className:"flex-1",children:a.jsxs(Te,{variant:"secondary",className:"w-full",children:[a.jsx(Xr,{className:"w-4 h-4"}),"View on GitHub"]})}),a.jsx(Te,{onClick:()=>we(!1),className:"flex-1",children:"Close"})]})]})}),pe==="users"&&a.jsxs("div",{className:"space-y-6",children:[a.jsx(St,{children:a.jsx(Nt,{className:"py-4",children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{className:"flex items-center gap-3",children:[a.jsx("div",{className:`w-10 h-10 rounded-full flex items-center justify-center ${l?"bg-green-500/20":"bg-gray-500/20"}`,children:l?a.jsx(iT,{className:"w-5 h-5 text-green-400"}):a.jsx(rT,{className:"w-5 h-5 text-gray-400"})}),a.jsxs("div",{children:[a.jsx("h3",{className:"text-white font-medium",children:i("settings.authentication")}),a.jsx("p",{className:"text-sm text-bambu-gray",children:i(l?"settings.authEnabledDescription":"settings.authDisabledDescription")})]})]}),l?c?.is_admin&&a.jsxs(Te,{variant:"secondary",onClick:()=>ae(!0),children:[a.jsx(rT,{className:"w-4 h-4"}),i("common.disable")]}):a.jsxs(Te,{onClick:()=>e("/setup"),children:[a.jsx(iT,{className:"w-4 h-4"}),i("common.enable")]})]})})}),l&&a.jsxs("div",{className:"grid grid-cols-1 xl:grid-cols-2 gap-6",children:[a.jsxs("div",{className:"space-y-6",children:[c&&a.jsxs(St,{children:[a.jsx(Kn,{children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("h3",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[a.jsx(pg,{className:"w-5 h-5 text-bambu-green"}),i("settings.currentUser")]}),a.jsxs(Te,{size:"sm",variant:"ghost",onClick:()=>Be(!0),children:[a.jsx(Ko,{className:"w-4 h-4"}),i("settings.changePassword")]})]})}),a.jsx(Nt,{children:a.jsx("div",{className:"flex items-center justify-between",children:a.jsxs("div",{children:[a.jsx("p",{className:"text-white font-medium text-lg",children:c.username}),a.jsxs("div",{className:"flex flex-wrap gap-1 mt-2",children:[c.is_admin&&a.jsx("span",{className:"px-2 py-0.5 rounded-full text-xs font-medium bg-purple-500/20 text-purple-300",children:i("settings.admin")}),c.groups?.map(le=>a.jsx("span",{className:`px-2 py-0.5 rounded-full text-xs font-medium ${le.name==="Administrators"?"bg-purple-500/20 text-purple-300":le.name==="Operators"?"bg-blue-500/20 text-blue-300":le.name==="Viewers"?"bg-green-500/20 text-green-300":"bg-gray-500/20 text-gray-300"}`,children:le.name},le.id))]})]})})})]}),a.jsxs(St,{children:[a.jsx(Kn,{children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("h3",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[a.jsx(pg,{className:"w-5 h-5 text-bambu-green"}),i("settings.users")]}),qt("users:create")&&a.jsxs(Te,{size:"sm",onClick:()=>{Se(!0),jt({username:"",password:"",confirmPassword:"",role:"user",group_ids:[]})},children:[a.jsx(fr,{className:"w-4 h-4"}),i("settings.addUser")]})]})}),a.jsx(Nt,{children:wn?a.jsx("div",{className:"flex items-center justify-center py-8",children:a.jsx(pt,{className:"w-6 h-6 text-bambu-green animate-spin"})}):vt.length===0?a.jsx("p",{className:"text-center text-bambu-gray py-8",children:i("settings.noUsersFound")}):a.jsx("div",{className:"divide-y divide-bambu-dark-tertiary",children:vt.map(le=>a.jsxs("div",{className:"py-3 flex items-center justify-between",children:[a.jsxs("div",{className:"flex-1 min-w-0",children:[a.jsx("p",{className:"text-white font-medium truncate",children:le.username}),a.jsxs("div",{className:"flex flex-wrap gap-1 mt-1",children:[le.is_admin&&a.jsx("span",{className:"px-2 py-0.5 rounded-full text-xs font-medium bg-purple-500/20 text-purple-300",children:i("settings.admin")}),le.groups?.map(_t=>a.jsx("span",{className:`px-2 py-0.5 rounded-full text-xs font-medium ${_t.name==="Administrators"?"bg-purple-500/20 text-purple-300":_t.name==="Operators"?"bg-blue-500/20 text-blue-300":_t.name==="Viewers"?"bg-green-500/20 text-green-300":"bg-gray-500/20 text-gray-300"}`,children:_t.name},_t.id))]})]}),a.jsxs("div",{className:"flex items-center gap-1 ml-4",children:[qt("users:update")&&a.jsx(Te,{size:"sm",variant:"ghost",onClick:()=>Ni(le),children:a.jsx(mg,{className:"w-4 h-4"})}),qt("users:delete")&&le.id!==c?.id&&a.jsx(Te,{size:"sm",variant:"ghost",onClick:()=>Si(le.id),children:a.jsx(an,{className:"w-4 h-4"})})]})]},le.id))})})]})]}),a.jsx("div",{children:a.jsxs(St,{children:[a.jsx(Kn,{children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("h3",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[a.jsx(aT,{className:"w-5 h-5 text-bambu-green"}),i("settings.groups")]}),qt("groups:create")&&a.jsxs(Te,{size:"sm",onClick:()=>{yn(!0),da()},children:[a.jsx(fr,{className:"w-4 h-4"}),i("settings.addGroup")]})]})}),a.jsx(Nt,{children:Qr?a.jsx("div",{className:"flex items-center justify-center py-8",children:a.jsx(pt,{className:"w-6 h-6 text-bambu-green animate-spin"})}):Fr.length===0?a.jsx("p",{className:"text-center text-bambu-gray py-8",children:i("settings.noGroupsFound")}):a.jsx("div",{className:"divide-y divide-bambu-dark-tertiary",children:Fr.map(le=>a.jsxs("div",{className:"py-3",children:[a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(aT,{className:`w-4 h-4 ${le.name==="Administrators"?"text-purple-400":le.name==="Operators"?"text-blue-400":le.name==="Viewers"?"text-green-400":"text-bambu-gray"}`}),a.jsx("span",{className:"text-white font-medium",children:le.name}),le.is_system&&a.jsx("span",{className:"px-2 py-0.5 rounded text-xs bg-yellow-500/20 text-yellow-400",children:i("settings.system")})]}),a.jsxs("div",{className:"flex items-center gap-1",children:[qt("groups:update")&&a.jsx(Te,{size:"sm",variant:"ghost",onClick:()=>Gh(le),children:a.jsx(mg,{className:"w-4 h-4"})}),qt("groups:delete")&&!le.is_system&&a.jsx(Te,{size:"sm",variant:"ghost",onClick:()=>Jn(le.id),children:a.jsx(an,{className:"w-4 h-4"})})]})]}),a.jsx("p",{className:"text-sm text-bambu-gray mt-1 ml-6",children:le.description||i("settings.noDescription")}),a.jsxs("div",{className:"flex items-center gap-4 mt-2 ml-6 text-xs text-bambu-gray",children:[a.jsx("span",{children:i("settings.userCount",{count:le.user_count})}),a.jsx("span",{children:i("settings.permissionCount",{count:le.permissions.length})})]})]},le.id))})})]})})]}),!l&&a.jsx(St,{children:a.jsx(Nt,{className:"py-6",children:a.jsxs("div",{className:"text-center",children:[a.jsx(rT,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),a.jsx("h3",{className:"text-lg font-medium text-white mb-2",children:i("settings.authDisabledTitle")}),a.jsx("p",{className:"text-sm text-bambu-gray mb-4 max-w-md mx-auto",children:i("settings.authDisabledMessage")}),a.jsxs("ul",{className:"space-y-2 text-sm text-bambu-gray mb-6 text-left max-w-xs mx-auto",children:[a.jsxs("li",{className:"flex items-start gap-2",children:[a.jsx(Ar,{className:"w-4 h-4 text-bambu-green mt-0.5 flex-shrink-0"}),a.jsx("span",{children:i("settings.authDisabledFeature1")})]}),a.jsxs("li",{className:"flex items-start gap-2",children:[a.jsx(Ar,{className:"w-4 h-4 text-bambu-green mt-0.5 flex-shrink-0"}),a.jsx("span",{children:i("settings.authDisabledFeature2")})]}),a.jsxs("li",{className:"flex items-start gap-2",children:[a.jsx(Ar,{className:"w-4 h-4 text-bambu-green mt-0.5 flex-shrink-0"}),a.jsx("span",{children:i("settings.authDisabledFeature3")})]})]}),a.jsxs(Te,{onClick:()=>e("/setup"),children:[a.jsx(iT,{className:"w-4 h-4"}),i("settings.enableAuthentication")]})]})})})]}),Ie&&a.jsx("div",{className:"fixed inset-0 bg-black flex items-center justify-center z-50 p-4",onClick:()=>{Se(!1),jt({username:"",password:"",confirmPassword:"",role:"user",group_ids:[]})},children:a.jsxs(St,{className:"w-full max-w-md",onClick:le=>le.stopPropagation(),children:[a.jsx(Kn,{children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(pg,{className:"w-5 h-5 text-bambu-green"}),a.jsx("h2",{className:"text-lg font-semibold text-white",children:i("settings.createUser")})]}),a.jsx(Te,{variant:"ghost",size:"sm",onClick:()=>{Se(!1),jt({username:"",password:"",confirmPassword:"",role:"user",group_ids:[]})},children:a.jsx(Lt,{className:"w-5 h-5"})})]})}),a.jsxs(Nt,{children:[a.jsxs("div",{className:"space-y-4",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:i("settings.username")}),a.jsx("input",{type:"text",value:at.username,onChange:le=>jt({...at,username:le.target.value}),className:"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:i("settings.enterUsername"),autoComplete:"username"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:i("settings.password")}),a.jsx("input",{type:"password",value:at.password,onChange:le=>jt({...at,password:le.target.value}),className:"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:i("settings.enterPassword"),autoComplete:"new-password",minLength:6})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:i("settings.confirmPassword")}),a.jsx("input",{type:"password",value:at.confirmPassword,onChange:le=>jt({...at,confirmPassword:le.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors ${at.confirmPassword&&at.password!==at.confirmPassword?"border-red-500":"border-bambu-dark-tertiary"}`,placeholder:i("settings.confirmPasswordPlaceholder"),autoComplete:"new-password",minLength:6}),at.confirmPassword&&at.password!==at.confirmPassword&&a.jsx("p",{className:"text-red-400 text-xs mt-1",children:i("settings.passwordsDoNotMatch")})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:"Groups"}),a.jsxs("div",{className:"space-y-2 max-h-40 overflow-y-auto p-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg",children:[Fr.map(le=>a.jsxs("label",{className:"flex items-center gap-3 px-2 py-1.5 rounded hover:bg-bambu-dark-tertiary cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:at.group_ids.includes(le.id),onChange:()=>Qs(le.id),className:"w-4 h-4 rounded border-bambu-gray text-bambu-green focus:ring-bambu-green focus:ring-offset-0 bg-bambu-dark"}),a.jsx("span",{className:"text-sm text-white",children:le.name}),le.is_system&&a.jsx("span",{className:"text-xs text-yellow-400",children:"(System)"})]},le.id)),Fr.length===0&&a.jsx("p",{className:"text-sm text-bambu-gray",children:i("settings.noGroupsAvailable")})]})]})]}),a.jsxs("div",{className:"mt-6 flex justify-end gap-3",children:[a.jsx(Te,{variant:"secondary",onClick:()=>{Se(!1),jt({username:"",password:"",confirmPassword:"",role:"user",group_ids:[]})},children:"Cancel"}),a.jsx(Te,{onClick:Ao,disabled:Ys.isPending||!at.username||!at.password||at.password!==at.confirmPassword||at.password.length<6,children:Ys.isPending?a.jsxs(a.Fragment,{children:[a.jsx(pt,{className:"w-4 h-4 animate-spin"}),"Creating..."]}):a.jsxs(a.Fragment,{children:[a.jsx(fr,{className:"w-4 h-4"}),"Create User"]})})]})]})]})}),Ke&&it!==null&&a.jsx("div",{className:"fixed inset-0 bg-black flex items-center justify-center z-50 p-4",onClick:()=>{Me(!1),ke(null),jt({username:"",password:"",confirmPassword:"",role:"user",group_ids:[]})},children:a.jsxs(St,{className:"w-full max-w-md",onClick:le=>le.stopPropagation(),children:[a.jsx(Kn,{children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(mg,{className:"w-5 h-5 text-bambu-green"}),a.jsx("h2",{className:"text-lg font-semibold text-white",children:i("settings.editUser")})]}),a.jsx(Te,{variant:"ghost",size:"sm",onClick:()=>{Me(!1),ke(null),jt({username:"",password:"",confirmPassword:"",role:"user",group_ids:[]})},children:a.jsx(Lt,{className:"w-5 h-5"})})]})}),a.jsxs(Nt,{children:[a.jsxs("div",{className:"space-y-4",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:i("settings.username")}),a.jsx("input",{type:"text",value:at.username,onChange:le=>jt({...at,username:le.target.value}),className:"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:i("settings.enterUsername"),autoComplete:"username"})]}),a.jsxs("div",{children:[a.jsxs("label",{className:"block text-sm font-medium text-white mb-2",children:["Password ",a.jsx("span",{className:"text-bambu-gray font-normal",children:"(leave blank to keep current)"})]}),a.jsx("input",{type:"password",value:at.password,onChange:le=>jt({...at,password:le.target.value,confirmPassword:""}),className:"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:i("settings.enterNewPassword"),autoComplete:"new-password",minLength:6})]}),at.password&&a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:i("settings.confirmPassword")}),a.jsx("input",{type:"password",value:at.confirmPassword,onChange:le=>jt({...at,confirmPassword:le.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors ${at.confirmPassword&&at.password!==at.confirmPassword?"border-red-500":"border-bambu-dark-tertiary"}`,placeholder:i("settings.confirmNewPassword"),autoComplete:"new-password",minLength:6}),at.confirmPassword&&at.password!==at.confirmPassword&&a.jsx("p",{className:"text-red-400 text-xs mt-1",children:i("settings.passwordsDoNotMatch")})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:"Groups"}),a.jsx("div",{className:"space-y-2 max-h-40 overflow-y-auto p-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg",children:Fr.map(le=>a.jsxs("label",{className:"flex items-center gap-3 px-2 py-1.5 rounded hover:bg-bambu-dark-tertiary cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:at.group_ids.includes(le.id),onChange:()=>Qs(le.id),className:"w-4 h-4 rounded border-bambu-gray text-bambu-green focus:ring-bambu-green focus:ring-offset-0 bg-bambu-dark"}),a.jsx("span",{className:"text-sm text-white",children:le.name}),le.is_system&&a.jsx("span",{className:"text-xs text-yellow-400",children:"(System)"})]},le.id))})]})]}),a.jsxs("div",{className:"mt-6 flex justify-end gap-3",children:[a.jsx(Te,{variant:"secondary",onClick:()=>{Me(!1),ke(null),jt({username:"",password:"",confirmPassword:"",role:"user",group_ids:[]})},children:"Cancel"}),a.jsx(Te,{onClick:()=>Ts(it),disabled:nn.isPending||!at.username||!!(at.password&&(at.password!==at.confirmPassword||at.password.length<6)),children:nn.isPending?a.jsxs(a.Fragment,{children:[a.jsx(pt,{className:"w-4 h-4 animate-spin"}),"Saving..."]}):a.jsxs(a.Fragment,{children:[a.jsx(ms,{className:"w-4 h-4"}),"Save Changes"]})})]})]})]})}),Xe!==null&&a.jsx("div",{className:"fixed inset-0 bg-black/80 flex items-center justify-center z-50 p-4",onClick:()=>{ze(null),$e(null)},children:a.jsxs(St,{className:"w-full max-w-md",onClick:le=>le.stopPropagation(),children:[a.jsx(Kn,{children:a.jsxs("div",{className:"flex items-center gap-2 text-red-400",children:[a.jsx(an,{className:"w-5 h-5"}),a.jsx("h3",{className:"text-lg font-semibold",children:i("settings.deleteUserTitle")})]})}),a.jsx(Nt,{className:"space-y-4",children:be?a.jsx("div",{className:"flex items-center justify-center py-4",children:a.jsx("div",{className:"animate-spin rounded-full h-6 w-6 border-2 border-bambu-green border-t-transparent"})}):ue&&ue.archives+ue.queue_items+ue.library_files>0?a.jsxs(a.Fragment,{children:[a.jsx("p",{className:"text-white",children:i("settings.userHasCreated")}),a.jsxs("ul",{className:"list-disc list-inside text-bambu-gray space-y-1",children:[ue.archives>0&&a.jsxs("li",{children:[ue.archives," archive",ue.archives!==1?"s":""]}),ue.queue_items>0&&a.jsxs("li",{children:[ue.queue_items," queue item",ue.queue_items!==1?"s":""]}),ue.library_files>0&&a.jsxs("li",{children:[ue.library_files," library file",ue.library_files!==1?"s":""]})]}),a.jsx("p",{className:"text-bambu-gray text-sm",children:i("settings.userItemsQuestion")}),a.jsxs("div",{className:"flex flex-col gap-2",children:[a.jsx(Te,{variant:"danger",onClick:()=>ln.mutate({id:Xe,deleteItems:!0}),disabled:ln.isPending,className:"justify-center",children:"Delete user AND their items"}),a.jsx(Te,{variant:"secondary",onClick:()=>ln.mutate({id:Xe,deleteItems:!1}),disabled:ln.isPending,className:"justify-center",children:"Delete user, keep items (become ownerless)"}),a.jsx(Te,{variant:"ghost",onClick:()=>{ze(null),$e(null)},disabled:ln.isPending,className:"justify-center",children:"Cancel"})]})]}):a.jsxs(a.Fragment,{children:[a.jsx("p",{className:"text-white",children:i("settings.deleteUserConfirm")}),a.jsx("p",{className:"text-bambu-gray text-sm",children:i("settings.actionCannotBeUndone")}),a.jsxs("div",{className:"flex gap-2 justify-end",children:[a.jsx(Te,{variant:"ghost",onClick:()=>{ze(null),$e(null)},disabled:ln.isPending,children:"Cancel"}),a.jsx(Te,{variant:"danger",onClick:()=>ln.mutate({id:Xe,deleteItems:!1}),disabled:ln.isPending,children:"Delete User"})]})]})})]})}),(Dt||cn)&&a.jsx("div",{className:"fixed inset-0 bg-black flex items-center justify-center z-50 p-4",onClick:()=>{yn(!1),rr(null),da()},children:a.jsxs(St,{className:"w-full max-w-2xl max-h-[90vh] overflow-y-auto",onClick:le=>le.stopPropagation(),children:[a.jsx(Kn,{children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(aT,{className:"w-5 h-5 text-bambu-green"}),a.jsx("h2",{className:"text-lg font-semibold text-white",children:cn?"Edit Group":"Create Group"})]}),a.jsx(Te,{variant:"ghost",size:"sm",onClick:()=>{yn(!1),rr(null),da()},children:a.jsx(Lt,{className:"w-5 h-5"})})]})}),a.jsxs(Nt,{children:[a.jsxs("div",{className:"space-y-4",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:i("settings.groupName")}),a.jsx("input",{type:"text",value:xn.name,onChange:le=>sr({...xn,name:le.target.value}),disabled:cn?.is_system,className:"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 disabled:opacity-50",placeholder:i("settings.enterGroupName")}),cn?.is_system&&a.jsx("p",{className:"text-xs text-yellow-400 mt-1",children:i("settings.systemGroupWarning")})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:"Description"}),a.jsx("textarea",{value:xn.description,onChange:le=>sr({...xn,description:le.target.value}),rows:2,className:"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 resize-none",placeholder:i("settings.enterDescriptionOptional")})]}),a.jsxs("div",{children:[a.jsxs("label",{className:"block text-sm font-medium text-white mb-2",children:["Permissions (",xn.permissions.length," selected)"]}),a.jsx("div",{className:"space-y-2 max-h-96 overflow-y-auto",children:Br?.categories.map(le=>a.jsxs("div",{className:"border border-bambu-dark-tertiary rounded-lg overflow-hidden",children:[a.jsxs("div",{className:"flex items-center justify-between px-4 py-2 bg-bambu-dark-secondary cursor-pointer hover:bg-bambu-dark-tertiary transition-colors",onClick:()=>Gl(le.name),children:[a.jsxs("div",{className:"flex items-center gap-3",children:[a.jsx("button",{type:"button",onClick:_t=>{_t.stopPropagation(),Rm(le,!Om(le))},className:`w-5 h-5 rounded border flex items-center justify-center transition-colors ${Om(le)?"bg-bambu-green border-bambu-green":qh(le)?"bg-bambu-green/50 border-bambu-green":"border-bambu-gray hover:border-white"}`,children:(Om(le)||qh(le))&&a.jsx(Wi,{className:"w-3 h-3 text-white"})}),a.jsx("span",{className:"text-white font-medium",children:le.name}),a.jsxs("span",{className:"text-xs text-bambu-gray",children:["(",le.permissions.filter(_t=>xn.permissions.includes(_t.value)).length,"/",le.permissions.length,")"]})]}),Gn.has(le.name)?a.jsx(Kr,{className:"w-4 h-4 text-bambu-gray"}):a.jsx(vs,{className:"w-4 h-4 text-bambu-gray"})]}),Gn.has(le.name)&&a.jsx("div",{className:"p-3 bg-bambu-dark space-y-2",children:le.permissions.map(_t=>a.jsxs("label",{className:"flex items-center gap-3 px-2 py-1.5 rounded hover:bg-bambu-dark-secondary cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:xn.permissions.includes(_t.value),onChange:()=>Hx(_t.value),className:"w-4 h-4 rounded border-bambu-gray text-bambu-green focus:ring-bambu-green focus:ring-offset-0 bg-bambu-dark-secondary"}),a.jsx("span",{className:"text-sm text-bambu-gray",children:_t.label})]},_t.value))})]},le.name))})]})]}),a.jsxs("div",{className:"mt-6 flex justify-end gap-3",children:[a.jsx(Te,{variant:"secondary",onClick:()=>{yn(!1),rr(null),da()},children:"Cancel"}),a.jsx(Te,{onClick:cn?Bx:Hr,disabled:Es.isPending||Eo.isPending||!xn.name.trim(),children:Es.isPending||Eo.isPending?a.jsxs(a.Fragment,{children:[a.jsx(pt,{className:"w-4 h-4 animate-spin"}),cn?"Saving...":"Creating..."]}):a.jsxs(a.Fragment,{children:[a.jsx(ms,{className:"w-4 h-4"}),cn?"Save Changes":"Create Group"]})})]})]})]})}),Vn!==null&&a.jsx(Zn,{title:i("settings.deleteGroupTitle"),message:i("settings.deleteGroupMessage"),confirmText:i("settings.deleteGroup"),variant:"danger",onConfirm:()=>{To.mutate(Vn),Jn(null)},onCancel:()=>Jn(null)}),pe==="backup"&&a.jsx(UKe,{}),_e&&a.jsx(Zn,{title:i("settings.disableAuthenticationTitle"),message:i("settings.disableAuthenticationMessage"),confirmText:i("settings.disableAuthentication"),variant:"danger",onConfirm:async()=>{try{await ce.disableAuth(),o(i("settings.toast.authDisabled"),"success"),await u(),ae(!1),window.location.href="/"}catch(le){const _t=le instanceof Error?le.message:i("settings.toast.authDisableFailed");o(_t,"error")}},onCancel:()=>ae(!1)}),Le&&a.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",onClick:()=>{Be(!1),He({currentPassword:"",newPassword:"",confirmPassword:""})},children:a.jsxs(St,{className:"w-full max-w-md",onClick:le=>le.stopPropagation(),children:[a.jsx(Kn,{children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(Ko,{className:"w-5 h-5 text-bambu-green"}),a.jsx("h2",{className:"text-lg font-semibold text-white",children:i("settings.changePassword")})]}),a.jsx(Te,{variant:"ghost",size:"sm",onClick:()=>{Be(!1),He({currentPassword:"",newPassword:"",confirmPassword:""})},children:a.jsx(Lt,{className:"w-5 h-5"})})]})}),a.jsxs(Nt,{children:[a.jsxs("div",{className:"space-y-4",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:"Current Password"}),a.jsx("input",{type:"password",value:Ve.currentPassword,onChange:le=>He({...Ve,currentPassword:le.target.value}),className:"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:i("settings.enterCurrentPassword"),autoComplete:"current-password"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:"New Password"}),a.jsx("input",{type:"password",value:Ve.newPassword,onChange:le=>He({...Ve,newPassword:le.target.value}),className:"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:i("settings.enterNewPasswordMin6"),autoComplete:"new-password",minLength:6})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:"Confirm New Password"}),a.jsx("input",{type:"password",value:Ve.confirmPassword,onChange:le=>He({...Ve,confirmPassword:le.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors ${Ve.confirmPassword&&Ve.newPassword!==Ve.confirmPassword?"border-red-500":"border-bambu-dark-tertiary"}`,placeholder:i("settings.confirmNewPassword"),autoComplete:"new-password",minLength:6}),Ve.confirmPassword&&Ve.newPassword!==Ve.confirmPassword&&a.jsx("p",{className:"text-red-400 text-xs mt-1",children:i("settings.passwordsDoNotMatch")})]})]}),a.jsxs("div",{className:"mt-6 flex justify-end gap-3",children:[a.jsx(Te,{variant:"secondary",onClick:()=>{Be(!1),He({currentPassword:"",newPassword:"",confirmPassword:""})},children:"Cancel"}),a.jsx(Te,{onClick:async()=>{if(Ve.newPassword!==Ve.confirmPassword){o(i("settings.toast.passwordsDoNotMatch"),"error");return}if(Ve.newPassword.length<6){o(i("settings.toast.passwordTooShort"),"error");return}Pe(!0);try{await ce.changePassword(Ve.currentPassword,Ve.newPassword),o(i("settings.toast.passwordChanged"),"success"),Be(!1),He({currentPassword:"",newPassword:"",confirmPassword:""})}catch(le){const _t=le instanceof Error?le.message:"Failed to change password";o(_t,"error")}finally{Pe(!1)}},disabled:xe||!Ve.currentPassword||!Ve.newPassword||Ve.newPassword!==Ve.confirmPassword||Ve.newPassword.length<6,children:xe?a.jsxs(a.Fragment,{children:[a.jsx(pt,{className:"w-4 h-4 animate-spin"}),"Changing..."]}):a.jsxs(a.Fragment,{children:[a.jsx(Ko,{className:"w-4 h-4"}),"Change Password"]})})]})]})]})})]})}const Wre=t=>{const e=parseFloat(t);return(Math.trunc(e*1e3)/1e3).toFixed(3)},qKe=t=>t.startsWith("HH")?"HF":"S",WKe=t=>{const e=t.match(/^([A-Z]{2}\d{2})/);return e?e[1]:"HH00"},fR=t=>{const e=["High Flow_","High Flow ","Standard_","Standard ","HF_","HF ","S_","S "];for(const r of e)if(t.startsWith(r))return t.slice(r.length);const n=t.indexOf("_");return n>0?t.slice(n+1):t};function Gj({profile:t,onEdit:e,onCopy:n,selectionMode:r,isSelected:i,onToggleSelect:s,note:o}){const l=qKe(t.nozzle_id),c=t.nozzle_diameter,u=()=>{r&&s?s():e()};return a.jsxs("div",{className:"flex items-center gap-2",children:[r&&a.jsx("button",{onClick:s,className:"text-bambu-gray hover:text-white transition-colors p-1",children:i?a.jsx(Gs,{className:"w-4 h-4 text-bambu-green"}):a.jsx(cl,{className:"w-4 h-4"})}),a.jsxs("button",{onClick:u,className:`flex-1 text-left px-3 py-2 bg-bambu-dark rounded hover:bg-bambu-dark-tertiary transition-colors ${i?"ring-1 ring-bambu-green":""}`,children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("span",{className:"text-bambu-green font-mono text-sm font-bold whitespace-nowrap",children:Wre(t.k_value)}),a.jsx("span",{className:"text-white text-sm truncate flex-1",title:t.name,children:t.name||"Unnamed"}),o&&a.jsx("span",{title:"Has note",children:a.jsx(OW,{className:"w-3 h-3 text-yellow-500"})}),a.jsxs("span",{className:"text-xs text-bambu-gray whitespace-nowrap",children:[l," ",c]})]}),o&&a.jsxs("div",{className:"text-xs mt-0.5 truncate text-yellow-500/70",title:o,children:["Note: ",o.length>50?o.substring(0,50)+"...":o]})]}),!r&&n&&a.jsx("button",{onClick:d=>{d.stopPropagation(),n()},className:"text-bambu-gray hover:text-white transition-colors p-1",title:"Copy profile",children:a.jsx(Ul,{className:"w-4 h-4"})})]})}function qj({profile:t,printerId:e,nozzleDiameter:n,existingProfiles:r=[],isDualNozzle:i=!1,initialNote:s="",initialNoteKey:o=null,onClose:l,onSave:c,onSaveNote:u,hasPermission:d}){const{t:h}=On(),{showToast:p}=Hn(),[m,x]=_.useState(t?.name||""),[y,v]=_.useState(t?.k_value?Wre(t.k_value):"0.020"),[b,S]=_.useState(t?.filament_id||""),[N,T]=_.useState(t?.nozzle_id?WKe(t.nozzle_id):"HH00"),[k,C]=_.useState(t?.nozzle_diameter||n),[E,P]=_.useState(t?[t.extruder_id]:i?[0,1]:[0]),[A,D]=_.useState(!1),[I,L]=_.useState({current:0,total:0}),[U,j]=_.useState(s),$=ei.useMemo(()=>{const W=new Map;for(const re of r)if(re.filament_id&&!W.has(re.filament_id)){const ie=fR(re.name||"");W.set(re.filament_id,{id:re.filament_id,name:ie||re.filament_id})}return Array.from(W.values()).sort((re,ie)=>re.name.localeCompare(ie.name))},[r]),K=gt({mutationFn:W=>(console.log("[KProfile] Calling API..."),ce.setKProfile(e,W)),onSuccess:W=>{if(console.log("[KProfile] Save success:",W),p(h("kProfiles.toast.profileSaved")),u&&U!==s){let re;U===""&&o?re=o:t&&t.slot_id>0?re=t.setting_id||`slot_${t.slot_id}_${t.filament_id}_${t.extruder_id}`:re=`name_${m}_${b}`,u(re,U)}D(!0),setTimeout(()=>{D(!1),c()},2500)},onError:W=>{console.error("[KProfile] Save error:",W),p(W.message,"error"),D(!1)}}),B=gt({mutationFn:W=>(console.log("[KProfile] Deleting profile..."),ce.deleteKProfile(e,W)),onSuccess:W=>{console.log("[KProfile] Delete success:",W),p(h("kProfiles.toast.profileDeleted")),D(!0),setTimeout(()=>{D(!1),l()},4e3)},onError:W=>{console.error("[KProfile] Delete error:",W),p(W.message,"error"),D(!1)}}),[X,Y]=_.useState(!1),ne=()=>{t&&B.mutate({slot_id:t.slot_id,extruder_id:t.extruder_id,nozzle_id:t.nozzle_id,nozzle_diameter:t.nozzle_diameter,filament_id:t.filament_id,setting_id:t.setting_id})},H=async W=>{if(W.preventDefault(),i&&!t&&E.length===0){p(h("kProfiles.toast.selectAtLeastOneExtruder"),"error");return}const re=parseFloat(y).toFixed(6),ie=`${N}-${k}`;if(t||E.length===1){const me={name:m,k_value:re,filament_id:b,nozzle_id:ie,nozzle_diameter:k,extruder_id:t?t.extruder_id:E[0],setting_id:t?.setting_id,slot_id:t?.slot_id??0};console.log("[KProfile] Saving profile:",me),K.mutate(me);return}D(!0),L({current:1,total:E.length});const pe=E.map(me=>({name:m,k_value:re,filament_id:b,nozzle_id:ie,nozzle_diameter:k,extruder_id:me,setting_id:void 0,slot_id:0}));console.log(`[KProfile] Saving ${pe.length} profiles in batch:`,pe);try{if(await ce.setKProfilesBatch(e,pe),p(h("kProfiles.toast.profilesSaved",{count:E.length})),u&&U){const me=`name_${m}_${b}`;u(me,U)}}catch(me){console.error("[KProfile] Failed to save batch:",me),p(h("kProfiles.toast.failedToSaveBatch"),"error"),D(!1),L({current:0,total:0});return}L({current:E.length,total:E.length}),setTimeout(()=>{D(!1),L({current:0,total:0}),c()},3e3)};return a.jsxs("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",children:[a.jsxs(St,{className:"w-full max-w-md relative",children:[A&&a.jsxs("div",{className:"absolute inset-0 bg-bambu-dark-secondary/90 flex flex-col items-center justify-center z-10 rounded-lg",children:[a.jsx(pt,{className:"w-8 h-8 text-bambu-green animate-spin mb-3"}),a.jsx("p",{className:"text-white font-medium",children:I.total>1?h("kProfiles.modal.savingExtruder",{current:I.current,total:I.total}):h("kProfiles.modal.syncing")}),a.jsx("p",{className:"text-bambu-gray text-sm mt-1",children:h("kProfiles.modal.pleaseWait")})]}),a.jsxs(Nt,{className:"p-0",children:[a.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[a.jsx("h2",{className:"text-xl font-semibold text-white",children:h(t?"kProfiles.modal.editTitle":"kProfiles.modal.addTitle")}),a.jsx("button",{onClick:l,className:"text-bambu-gray hover:text-white transition-colors",disabled:A,children:a.jsx(Lt,{className:"w-5 h-5"})})]}),a.jsxs("form",{onSubmit:H,className:"p-4 space-y-4",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:h("kProfiles.modal.profileName")}),a.jsx("input",{type:"text",value:m,onChange:W=>x(W.target.value),disabled:!!t,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 ${t?"opacity-60 cursor-not-allowed":""}`,placeholder:h("kProfiles.modal.profileNamePlaceholder"),required:!t})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:h("kProfiles.modal.kValue")}),a.jsx("input",{type:"text",inputMode:"decimal",value:y,onChange:W=>{const re=W.target.value;(re===""||/^\d*\.?\d*$/.test(re))&&v(re)},onBlur:W=>{const re=parseFloat(W.target.value);isNaN(re)||v((Math.trunc(re*1e3)/1e3).toFixed(3))},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 font-mono",placeholder:h("kProfiles.modal.kValuePlaceholder"),required:!0}),a.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:h("kProfiles.modal.kValueHelp")})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:h("kProfiles.modal.filament")}),a.jsxs("select",{value:b,onChange:W=>{const re=W.target.value;if(S(re),!t&&re&&!m){const ie=$.find(pe=>pe.id===re);ie&&x(`${N==="HH00"?"HF":"S"} ${ie.name}`)}},disabled:!!t,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 ${t?"opacity-60 cursor-not-allowed":""}`,required:!t,children:[a.jsx("option",{value:"",children:h("kProfiles.modal.selectFilament")}),t?.filament_id&&a.jsx("option",{value:t.filament_id,children:$.find(W=>W.id===t.filament_id)?.name||t.filament_id},t.filament_id),!t&&$.map(W=>a.jsx("option",{value:W.id,children:W.name},W.id))]}),!t&&$.length===0&&a.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:h("kProfiles.modal.noFilamentsHelp")})]}),a.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:h("kProfiles.modal.flowType")}),a.jsxs("select",{value:N,onChange:W=>{const re=W.target.value;if(T(re),!t&&b&&!m){const ie=$.find(pe=>pe.id===b);ie&&x(`${re==="HS00"?"HF":"S"} ${ie.name}`)}},disabled:!!t,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 ${t?"opacity-60 cursor-not-allowed":""}`,children:[a.jsx("option",{value:"HH00",children:h("kProfiles.modal.highFlow")}),a.jsx("option",{value:"HS00",children:h("kProfiles.modal.standard")})]})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:h("kProfiles.modal.nozzleSize")}),a.jsxs("select",{value:k,onChange:W=>C(W.target.value),disabled:!!t,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 ${t?"opacity-60 cursor-not-allowed":""}`,children:[a.jsx("option",{value:"0.2",children:"0.2mm"}),a.jsx("option",{value:"0.4",children:"0.4mm"}),a.jsx("option",{value:"0.6",children:"0.6mm"}),a.jsx("option",{value:"0.8",children:"0.8mm"})]})]})]}),i&&a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:h(t?"kProfiles.modal.extruder":"kProfiles.modal.extruders")}),t?a.jsx("div",{className:"px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white opacity-60",children:t.extruder_id===1?h("kProfiles.modal.left"):h("kProfiles.modal.right")}):a.jsxs("div",{className:"flex gap-4",children:[a.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:E.includes(1),onChange:W=>{W.target.checked?P([...E,1]):P(E.filter(re=>re!==1))},className:"w-4 h-4 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green focus:ring-offset-0 accent-bambu-green"}),a.jsx("span",{className:"text-white",children:h("kProfiles.modal.left")})]}),a.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:E.includes(0),onChange:W=>{W.target.checked?P([...E,0]):P(E.filter(re=>re!==0))},className:"w-4 h-4 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green focus:ring-offset-0 accent-bambu-green"}),a.jsx("span",{className:"text-white",children:h("kProfiles.modal.right")})]})]})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:h("kProfiles.modal.notes")}),a.jsx("textarea",{value:U,onChange:W=>j(W.target.value),placeholder:h("kProfiles.modal.notesPlaceholder"),rows:2,className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none resize-none"}),a.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:h("kProfiles.modal.notesHelp")})]}),a.jsxs("div",{className:"flex gap-2 pt-4",children:[t&&a.jsx(Te,{type:"button",variant:"secondary",onClick:()=>Y(!0),disabled:B.isPending||A||!d("kprofiles:delete"),title:d("kprofiles:delete")?void 0:h("kProfiles.permission.noDelete"),className:"text-red-500 hover:bg-red-500/10",children:B.isPending?a.jsx(pt,{className:"w-4 h-4 animate-spin"}):a.jsx(an,{className:"w-4 h-4"})}),a.jsx(Te,{type:"button",variant:"secondary",onClick:l,disabled:A,className:"flex-1",children:h("common.cancel")}),a.jsxs(Te,{type:"submit",disabled:K.isPending||A||!d(t?"kprofiles:update":"kprofiles:create"),title:d(t?"kprofiles:update":"kprofiles:create")?void 0:h(t?"kProfiles.permission.noUpdate":"kProfiles.permission.noCreate"),className:"flex-1",children:[K.isPending?a.jsx(pt,{className:"w-4 h-4 animate-spin"}):a.jsx(fM,{className:"w-4 h-4"}),h("common.save")]})]})]})]})]}),X&&a.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-[60]",children:a.jsx(St,{className:"w-full max-w-sm",children:a.jsxs(Nt,{className:"p-6",children:[a.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[a.jsx("div",{className:"w-10 h-10 rounded-full bg-red-500/20 flex items-center justify-center",children:a.jsx(an,{className:"w-5 h-5 text-red-500"})}),a.jsxs("div",{children:[a.jsx("h3",{className:"text-lg font-semibold text-white",children:h("kProfiles.deleteConfirm.title")}),a.jsx("p",{className:"text-sm text-bambu-gray",children:h("kProfiles.deleteConfirm.cannotUndo")})]})]}),a.jsx("p",{className:"text-bambu-gray mb-6",children:h("kProfiles.deleteConfirm.message",{name:t?.name})}),a.jsxs("div",{className:"flex gap-3",children:[a.jsx(Te,{variant:"secondary",onClick:()=>Y(!1),className:"flex-1",children:h("common.cancel")}),a.jsxs(Te,{onClick:()=>{Y(!1),ne()},disabled:B.isPending,className:"flex-1 bg-red-500 hover:bg-red-600 text-white",children:[B.isPending?a.jsx(pt,{className:"w-4 h-4 animate-spin"}):a.jsx(an,{className:"w-4 h-4"}),h("common.delete")]})]})]})})})]})}const m1={NOZZLE_DIAMETER:"bambusy_kprofiles_nozzle",SORT_OPTION:"bambusy_kprofiles_sort"};function KKe(){const{t}=On(),{showToast:e}=Hn(),{hasPermission:n}=Ci(),[r,i]=_.useState(null),[s,o]=_.useState(()=>localStorage.getItem(m1.NOZZLE_DIAMETER)||"0.4"),[l,c]=_.useState(null),[u,d]=_.useState(!1),[h,p]=_.useState(null),[m,x]=_.useState(""),[y,v]=_.useState("all"),[b,S]=_.useState("all"),[N,T]=_.useState(()=>localStorage.getItem(m1.SORT_OPTION)||"name"),[k,C]=_.useState(!1),[E,P]=_.useState(new Set),[A,D]=_.useState(!1),[I,L]=_.useState(!1),U=_.useCallback(V=>`${V.slot_id}_${V.extruder_id}`,[]);_.useEffect(()=>{localStorage.setItem(m1.NOZZLE_DIAMETER,s)},[s]),_.useEffect(()=>{localStorage.setItem(m1.SORT_OPTION,N)},[N]);const{data:j,isLoading:$}=ct({queryKey:["printers"],queryFn:ce.getPrinters}),{data:K,isLoading:B,isFetching:X,error:Y,refetch:ne}=ct({queryKey:["kprofiles",r,s],queryFn:async()=>{console.log("[KProfiles] Fetching profiles for printer",r,"nozzle",s);const V=await ce.getKProfiles(r,s);return console.log("[KProfiles] Received profiles:",V?.profiles?.length||0,"profiles"),V},enabled:!!r,retry:!1,staleTime:0,gcTime:0,refetchOnMount:"always"}),{data:H}=ct({queryKey:["kprofiles",r,"0.4"],queryFn:()=>ce.getKProfiles(r,"0.4"),enabled:!!r,staleTime:6e4}),{data:W,refetch:re}=ct({queryKey:["kprofile-notes",r],queryFn:()=>ce.getKProfileNotes(r),enabled:!!r,staleTime:3e4}),ie=Y?.message?.includes("not connected");_.useEffect(()=>{if(!r&&j&&j.length>0){const V=j.find(ye=>ye.is_active);V&&i(V.id)}},[r,j]),_.useEffect(()=>{if(r){const V=setTimeout(()=>{ne()},150);return()=>clearTimeout(V)}},[r,s]);const pe=j?.filter(V=>V.is_active)||[],me=ei.useMemo(()=>K?.profiles?K.profiles.filter(ye=>{const je=m.toLowerCase(),te=!je||ye.name.toLowerCase().includes(je)||ye.filament_id.toLowerCase().includes(je),z=y==="all"||y==="left"&&ye.extruder_id===1||y==="right"&&ye.extruder_id===0,O=b==="all"||b==="hf"&&ye.nozzle_id.startsWith("HH")||b==="s"&&ye.nozzle_id.startsWith("HS");return te&&z&&O}).sort((ye,je)=>{switch(N){case"k_value":return parseFloat(ye.k_value)-parseFloat(je.k_value);case"filament":return fR(ye.name).localeCompare(fR(je.name));case"name":default:return ye.name.localeCompare(je.name)}}):[],[K?.profiles,m,y,b,N]),de=j?.find(V=>V.id===r),Ee=de?.nozzle_count===2;_.useEffect(()=>{const V=ye=>{ye.target instanceof HTMLInputElement||ye.target instanceof HTMLTextAreaElement||ye.target instanceof HTMLSelectElement||l||u||h||(ye.key==="r"||ye.key==="R"?(ye.preventDefault(),ne()):ye.key==="n"||ye.key==="N"?(ye.preventDefault(),d(!0)):ye.key==="Escape"&&k&&(ye.preventDefault(),C(!1),P(new Set)))};return window.addEventListener("keydown",V),()=>window.removeEventListener("keydown",V)},[l,u,h,k,ne]);const se=_.useCallback(()=>{if(!K?.profiles||K.profiles.length===0){e(t("kProfiles.toast.noProfilesToExport"),"error");return}const V={version:1,exported_at:new Date().toISOString(),printer:de?.name||"Unknown",nozzle_diameter:s,profiles:K.profiles.map(z=>({name:z.name,k_value:z.k_value,filament_id:z.filament_id,nozzle_id:z.nozzle_id,nozzle_diameter:z.nozzle_diameter,extruder_id:z.extruder_id}))},ye=new Blob([JSON.stringify(V,null,2)],{type:"application/json"}),je=URL.createObjectURL(ye),te=document.createElement("a");te.href=je,te.download=`kprofiles_${de?.name||"printer"}_${s}mm_${new Date().toISOString().split("T")[0]}.json`,document.body.appendChild(te),te.click(),document.body.removeChild(te),URL.revokeObjectURL(je),e(t("kProfiles.toast.exportedProfiles",{count:K.profiles.length}))},[K?.profiles,de,s,e,t]),Ae=_.useCallback(()=>{const V=document.createElement("input");V.type="file",V.accept=".json",V.onchange=async ye=>{const je=ye.target.files?.[0];if(je)try{const te=await je.text(),z=JSON.parse(te);if(!z.profiles||!Array.isArray(z.profiles)){e(t("kProfiles.toast.invalidFileFormat"),"error");return}let O=0;for(const Z of z.profiles)if(!(!Z.name||!Z.k_value||!Z.filament_id))try{await ce.setKProfile(r,{name:Z.name,k_value:parseFloat(Z.k_value).toFixed(6),filament_id:Z.filament_id,nozzle_id:Z.nozzle_id||`HH00-${s}`,nozzle_diameter:Z.nozzle_diameter||s,extruder_id:Z.extruder_id??0,slot_id:0}),O++,await new Promise(oe=>setTimeout(oe,500))}catch(oe){console.error("Failed to import profile:",Z.name,oe)}e(t("kProfiles.toast.importedProfiles",{count:O,total:z.profiles.length})),ne()}catch(te){console.error("Import error:",te),e(t("kProfiles.toast.failedToParseImport"),"error")}},V.click()},[r,s,e,ne,t]),Fe=_.useCallback(V=>{P(ye=>{const je=new Set(ye);return je.has(V)?je.delete(V):je.add(V),je})},[]),ge=_.useCallback(()=>{P(new Set(me.map(V=>U(V))))},[me,U]),Ze=_.useCallback(()=>{E.size!==0&&D(!0)},[E.size]),G=_.useCallback(async()=>{const V=me.filter(je=>E.has(U(je)));L(!0);let ye=0;for(const je of V)try{await ce.deleteKProfile(r,{slot_id:je.slot_id,extruder_id:je.extruder_id,nozzle_id:je.nozzle_id,nozzle_diameter:je.nozzle_diameter,filament_id:je.filament_id,setting_id:je.setting_id}),ye++,await new Promise(te=>setTimeout(te,300))}catch(te){console.error("Failed to delete profile:",je.name,te)}e(t("kProfiles.toast.profilesDeleted",{count:ye})),L(!1),D(!1),C(!1),P(new Set),ne()},[r,E,me,e,ne,U,t]),Q=_.useCallback(V=>{const ye=[];return V.setting_id&&ye.push(V.setting_id),ye.push(`slot_${V.slot_id}_${V.filament_id}_${V.extruder_id}`),ye.push(`name_${V.name}_${V.filament_id}`),ye},[]),he=_.useCallback(async(V,ye)=>{if(r)try{await ce.setKProfileNote(r,V,ye),re()}catch(je){console.error("Failed to save note:",je),e(t("kProfiles.toast.failedToSaveNote"),"error")}},[r,re,e,t]),q=_.useCallback(V=>{if(!W?.notes)return{note:"",key:null};const ye=Q(V);for(const je of ye)if(W.notes[je])return{note:W.notes[je],key:je};return{note:"",key:null}},[W,Q]),ee=_.useCallback(V=>q(V).note,[q]);return $?a.jsx("div",{className:"flex justify-center py-12",children:a.jsx(pt,{className:"w-8 h-8 text-bambu-green animate-spin"})}):!j||j.length===0?a.jsx(St,{children:a.jsxs(Nt,{className:"py-12 text-center",children:[a.jsx(Vi,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),a.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:t("kProfiles.noPrintersConfigured")}),a.jsx("p",{className:"text-bambu-gray",children:t("kProfiles.addPrinterInSettings")})]})}):pe.length===0?a.jsx(St,{children:a.jsxs(Nt,{className:"py-12 text-center",children:[a.jsx(Ur,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),a.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:t("kProfiles.noActivePrinters")}),a.jsx("p",{className:"text-bambu-gray",children:t("kProfiles.enablePrinterConnection")})]})}):a.jsxs(a.Fragment,{children:[X&&!B&&a.jsxs("div",{className:"fixed inset-0 bg-black/50 flex flex-col items-center justify-center z-40",children:[a.jsx(pt,{className:"w-10 h-10 text-bambu-green animate-spin mb-3"}),a.jsx("p",{className:"text-white font-medium",children:t("kProfiles.loadingProfiles")})]}),a.jsxs("div",{className:"flex flex-wrap gap-4 mb-6",children:[a.jsxs("div",{className:"flex-1 min-w-48",children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:t("kProfiles.printer")}),a.jsx("select",{value:r||"",onChange:V=>i(parseInt(V.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",children:pe.map(V=>a.jsx("option",{value:V.id,children:V.name},V.id))})]}),a.jsxs("div",{className:"w-32",children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:t("kProfiles.nozzle")}),a.jsxs("select",{value:s,onChange:V=>o(V.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",children:[a.jsx("option",{value:"0.2",children:"0.2mm"}),a.jsx("option",{value:"0.4",children:"0.4mm"}),a.jsx("option",{value:"0.6",children:"0.6mm"}),a.jsx("option",{value:"0.8",children:"0.8mm"})]})]}),a.jsxs("div",{className:"flex items-end gap-2",children:[a.jsxs(Te,{variant:"secondary",onClick:()=>ne(),disabled:X||!n("kprofiles:read"),title:n("kprofiles:read")?void 0:t("kProfiles.permission.noRead"),children:[a.jsx(Dr,{className:`w-4 h-4 ${X?"animate-spin":""}`}),t("kProfiles.refresh")]}),a.jsxs(Te,{onClick:()=>d(!0),disabled:!n("kprofiles:create"),title:n("kprofiles:create")?void 0:t("kProfiles.permission.noCreate"),children:[a.jsx(fr,{className:"w-4 h-4"}),t("kProfiles.addProfile")]})]})]}),a.jsxs("div",{className:"flex flex-wrap gap-4 mb-4",children:[a.jsxs("div",{className:"flex-1 min-w-48 relative",children:[a.jsx(wa,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray"}),a.jsx("input",{type:"text",value:m,onChange:V=>x(V.target.value),placeholder:t("kProfiles.searchPlaceholder"),className:"w-full pl-10 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none"})]}),Ee&&a.jsx("div",{className:"w-36",children:a.jsxs("select",{value:y,onChange:V=>v(V.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",children:[a.jsx("option",{value:"all",children:t("kProfiles.allExtruders")}),a.jsx("option",{value:"left",children:t("kProfiles.leftOnly")}),a.jsx("option",{value:"right",children:t("kProfiles.rightOnly")})]})}),a.jsx("div",{className:"w-32",children:a.jsxs("select",{value:b,onChange:V=>S(V.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",children:[a.jsx("option",{value:"all",children:t("kProfiles.allFlow")}),a.jsx("option",{value:"hf",children:t("kProfiles.hfOnly")}),a.jsx("option",{value:"s",children:t("kProfiles.sOnly")})]})}),a.jsx("div",{className:"w-32",children:a.jsxs("select",{value:N,onChange:V=>T(V.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",children:[a.jsx("option",{value:"name",children:t("kProfiles.sortName")}),a.jsx("option",{value:"k_value",children:t("kProfiles.sortKValue")}),a.jsx("option",{value:"filament",children:t("kProfiles.sortFilament")})]})})]}),a.jsxs("div",{className:"flex flex-wrap gap-2 mb-6",children:[a.jsxs(Te,{variant:"secondary",onClick:se,disabled:!K?.profiles?.length||!n("kprofiles:read"),title:n("kprofiles:read")?void 0:t("kProfiles.permission.noExport"),children:[a.jsx(wi,{className:"w-4 h-4"}),t("kProfiles.export")]}),a.jsxs(Te,{variant:"secondary",onClick:Ae,disabled:!n("kprofiles:create"),title:n("kprofiles:create")?void 0:t("kProfiles.permission.noImport"),children:[a.jsx(Ba,{className:"w-4 h-4"}),t("kProfiles.import")]}),a.jsx("div",{className:"flex-1"}),k?a.jsxs(a.Fragment,{children:[a.jsxs(Te,{variant:"secondary",onClick:ge,children:[a.jsx(Gs,{className:"w-4 h-4"}),t("kProfiles.selectAll")]}),a.jsxs(Te,{variant:"secondary",onClick:Ze,disabled:E.size===0||!n("kprofiles:delete"),className:"text-red-500 hover:bg-red-500/10",title:n("kprofiles:delete")?void 0:t("kProfiles.permission.noDelete"),children:[a.jsx(an,{className:"w-4 h-4"}),t("kProfiles.delete")," (",E.size,")"]}),a.jsxs(Te,{variant:"secondary",onClick:()=>{C(!1),P(new Set)},children:[a.jsx(Lt,{className:"w-4 h-4"}),t("common.cancel")]})]}):a.jsxs(Te,{variant:"secondary",onClick:()=>C(!0),disabled:!me.length||!n("kprofiles:delete"),title:n("kprofiles:delete")?void 0:t("kProfiles.permission.noDelete"),children:[a.jsx(Gs,{className:"w-4 h-4"}),t("kProfiles.select")]})]}),B?a.jsx("div",{className:"flex justify-center py-12",children:a.jsx(pt,{className:"w-8 h-8 text-bambu-green animate-spin"})}):ie?a.jsx(St,{children:a.jsxs(Nt,{className:"py-12 text-center",children:[a.jsx(lm,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),a.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:t("kProfiles.printerOffline")}),a.jsx("p",{className:"text-bambu-gray mb-4",children:t("kProfiles.printerOfflineDesc")}),a.jsxs(Te,{variant:"secondary",onClick:()=>ne(),children:[a.jsx(Dr,{className:"w-4 h-4"}),t("common.refresh")]})]})}):me.length>0?Ee?a.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[a.jsxs("div",{children:[a.jsx("h3",{className:"text-sm font-medium text-bambu-gray mb-2 px-1",children:t("kProfiles.leftExtruder")}),a.jsx("div",{className:"space-y-1",children:me.filter(V=>V.extruder_id===1).map(V=>a.jsx(Gj,{profile:V,onEdit:()=>c(V),onCopy:()=>p(V),selectionMode:k,isSelected:E.has(U(V)),onToggleSelect:()=>Fe(U(V)),note:ee(V)},U(V)))})]}),a.jsxs("div",{children:[a.jsx("h3",{className:"text-sm font-medium text-bambu-gray mb-2 px-1",children:t("kProfiles.rightExtruder")}),a.jsx("div",{className:"space-y-1",children:me.filter(V=>V.extruder_id===0).map(V=>a.jsx(Gj,{profile:V,onEdit:()=>c(V),onCopy:()=>p(V),selectionMode:k,isSelected:E.has(U(V)),onToggleSelect:()=>Fe(U(V)),note:ee(V)},U(V)))})]})]}):a.jsx("div",{className:"space-y-1",children:me.map(V=>a.jsx(Gj,{profile:V,onEdit:()=>c(V),onCopy:()=>p(V),selectionMode:k,isSelected:E.has(U(V)),onToggleSelect:()=>Fe(U(V)),note:ee(V)},U(V)))}):m||y!=="all"||b!=="all"?a.jsx(St,{children:a.jsxs(Nt,{className:"py-12 text-center",children:[a.jsx(wa,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),a.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:t("kProfiles.noMatchingProfiles")}),a.jsx("p",{className:"text-bambu-gray",children:t("kProfiles.noMatchingProfilesDesc")})]})}):a.jsx(St,{children:a.jsxs(Nt,{className:"py-12 text-center",children:[a.jsx(fM,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),a.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:t("kProfiles.noKProfiles")}),a.jsx("p",{className:"text-bambu-gray mb-4",children:t("kProfiles.noKProfilesDesc",{diameter:s})}),a.jsxs(Te,{onClick:()=>d(!0),children:[a.jsx(fr,{className:"w-4 h-4"}),t("kProfiles.createFirstProfile")]})]})}),l&&r&&(()=>{const{note:V,key:ye}=q(l);return a.jsx(qj,{profile:l,printerId:r,nozzleDiameter:s,existingProfiles:H?.profiles||K?.profiles,isDualNozzle:Ee,initialNote:V,initialNoteKey:ye,onSaveNote:he,hasPermission:n,onClose:()=>{console.log("[KProfiles] Edit modal onClose - refetching profiles..."),c(null),ne()},onSave:()=>{c(null),ne()}})})(),u&&r&&a.jsx(qj,{printerId:r,nozzleDiameter:s,existingProfiles:H?.profiles||K?.profiles,isDualNozzle:Ee,onSaveNote:he,hasPermission:n,onClose:()=>{d(!1),ne()},onSave:()=>{d(!1),ne()}}),h&&r&&a.jsx(qj,{printerId:r,nozzleDiameter:s,existingProfiles:H?.profiles||K?.profiles,isDualNozzle:Ee,onSaveNote:he,hasPermission:n,profile:{...h,slot_id:0,name:`${h.name} (Copy)`},onClose:()=>{p(null),ne()},onSave:()=>{p(null),ne()}}),A&&a.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",children:a.jsx(St,{className:"w-full max-w-sm",children:a.jsxs(Nt,{className:"p-6",children:[a.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[a.jsx("div",{className:"w-10 h-10 rounded-full bg-red-500/20 flex items-center justify-center",children:a.jsx(an,{className:"w-5 h-5 text-red-500"})}),a.jsxs("div",{children:[a.jsx("h3",{className:"text-lg font-semibold text-white",children:t("kProfiles.bulkDelete.title")}),a.jsx("p",{className:"text-sm text-bambu-gray",children:t("kProfiles.bulkDelete.cannotUndo")})]})]}),a.jsx("p",{className:"text-bambu-gray mb-6",children:t("kProfiles.bulkDelete.message",{count:E.size})}),a.jsxs("div",{className:"flex gap-3",children:[a.jsx(Te,{variant:"secondary",onClick:()=>D(!1),disabled:I,className:"flex-1",children:t("common.cancel")}),a.jsxs(Te,{onClick:G,disabled:I,className:"flex-1 bg-red-500 hover:bg-red-600 text-white",children:[I?a.jsx(pt,{className:"w-4 h-4 animate-spin"}):a.jsx(an,{className:"w-4 h-4"}),t("common.delete")]})]})]})})})]})}function mF(t,e){const n=`${t} ${e||""}`,r=n.match(/@?\s*(?:BBL\s+)?(?:Bambu\s+Lab\s+)?([XPAH][1-9][A-Z]?(?:\s*(?:Carbon|mini))?|H2D)/i),i=r?r[1].trim():null,s=n.match(/(\d+\.?\d*)\s*(?:mm\s*)?nozzle|nozzle\s*(\d+\.?\d*)/i),o=s?(s[1]||s[2])+"mm":null,l=n.match(/(\d+\.?\d*)mm\s*(?:Standard|Fine|Extra Fine|Draft|Quality)?/i),c=l?l[1]+"mm":null,u=n.match(/\b(PLA|PETG|ABS|ASA|TPU|PC|PA|PVA|HIPS|PP|PET(?:-?CF)?|PA(?:-?CF)?|PLA(?:-?CF)?)\b/i),d=u?u[1].toUpperCase():null;return{printer:i,nozzle:o,layerHeight:c,filamentType:d}}function Oy(t){return/^(P[FPM]US|PF\d|PP\d)/.test(t)}function XKe(t,e){const n=zi(t);if(!n)return"";const i=new Date().getTime()-n.getTime(),s=Math.floor(i/6e4),o=Math.floor(i/36e5),l=Math.floor(i/864e5);return s<1?e("profiles.time.justNow"):s<60?e("profiles.time.minsAgo",{count:s}):o<24?e("profiles.time.hoursAgo",{count:o}):l<7?e("profiles.time.daysAgo",{count:l}):n.toLocaleDateString()}function YKe({onSuccess:t,t:e}){const{showToast:n}=Hn(),[r,i]=_.useState("email"),[s,o]=_.useState(""),[l,c]=_.useState(""),[u,d]=_.useState(""),[h,p]=_.useState(""),[m,x]=_.useState("global"),[y,v]=_.useState(null),[b,S]=_.useState(null),N=gt({mutationFn:()=>ce.cloudLogin(s,l,m),onSuccess:P=>{P.success?(n(e("profiles.login.toast.loggedIn")),t()):P.needs_verification?(v(P.verification_type||"email"),S(P.tfa_key||null),P.verification_type==="totp"?n(e("profiles.login.toast.enterTotp")):n(e("profiles.login.toast.codeSent")),i("code")):n(P.message,"error")},onError:P=>n(P.message,"error")}),T=gt({mutationFn:()=>ce.cloudVerify(s,u,b||void 0),onSuccess:P=>{P.success?(n(e("profiles.login.toast.loggedIn")),t()):n(P.message,"error")},onError:P=>n(P.message,"error")}),k=gt({mutationFn:()=>ce.cloudSetToken(h),onSuccess:()=>{n(e("profiles.login.toast.tokenSet")),t()},onError:P=>n(P.message,"error")}),C=P=>{P.preventDefault(),r==="email"?N.mutate():r==="code"?T.mutate():r==="token"&&k.mutate()},E=N.isPending||T.isPending||k.isPending;return a.jsx(St,{className:"max-w-md mx-auto",children:a.jsxs(Nt,{children:[a.jsxs("div",{className:"text-center mb-6",children:[a.jsx("div",{className:"inline-flex items-center justify-center w-12 h-12 rounded-xl bg-bambu-green/20 mb-3",children:a.jsx(cM,{className:"w-6 h-6 text-bambu-green"})}),a.jsx("h2",{className:"text-xl font-semibold text-white",children:e("profiles.login.title")}),a.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:e("profiles.login.subtitle")})]}),a.jsxs("form",{onSubmit:C,className:"space-y-4",children:[r==="email"&&a.jsxs(a.Fragment,{children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:e("profiles.login.email")}),a.jsx("input",{type:"email",value:s,onChange:P=>o(P.target.value),className:"w-full px-3 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",placeholder:"your@email.com",required:!0})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:e("profiles.login.password")}),a.jsx("input",{type:"password",value:l,onChange:P=>c(P.target.value),className:"w-full px-3 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",placeholder:"••••••••",required:!0})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:e("profiles.login.region")}),a.jsxs("select",{value:m,onChange:P=>x(P.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",children:[a.jsx("option",{value:"global",children:e("profiles.login.regionGlobal")}),a.jsx("option",{value:"china",children:e("profiles.login.regionChina")})]})]})]}),r==="code"&&a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:e(y==="totp"?"profiles.login.totpCode":"profiles.login.verificationCode")}),a.jsx("p",{className:"text-xs text-bambu-gray mb-2",children:y==="totp"?e("profiles.login.enterTotpHint"):e("profiles.login.checkEmail",{email:s})}),a.jsx("input",{type:"text",value:u,onChange:P=>d(P.target.value.replace(/\D/g,"").slice(0,6)),className:"w-full px-3 py-3 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-center text-2xl tracking-widest font-mono focus:border-bambu-green focus:outline-none",placeholder:"000000",maxLength:6,required:!0})]}),r==="token"&&a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:e("profiles.login.accessToken")}),a.jsx("p",{className:"text-xs text-bambu-gray mb-2",children:e("profiles.login.accessTokenHint")}),a.jsx("textarea",{value:h,onChange:P=>p(P.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-xs font-mono placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none resize-none",placeholder:"eyJ...",rows:4,required:!0})]}),a.jsxs("div",{className:"flex gap-2",children:[r==="code"&&a.jsx(Te,{type:"button",variant:"secondary",onClick:()=>i("email"),className:"flex-1",children:e("profiles.login.back")}),a.jsxs(Te,{type:"submit",disabled:E,className:"flex-1",children:[E?a.jsx(pt,{className:"w-4 h-4 animate-spin"}):a.jsx(Uz,{className:"w-4 h-4"}),e(r==="email"?"profiles.login.loginButton":r==="code"?"profiles.login.verifyButton":"profiles.login.setTokenButton")]})]}),r==="email"&&a.jsx("div",{className:"pt-4 border-t border-bambu-dark-tertiary",children:a.jsxs("button",{type:"button",onClick:()=>i("token"),className:"text-sm text-bambu-gray hover:text-white flex items-center gap-2 transition-colors",children:[a.jsx(Ko,{className:"w-4 h-4"}),e("profiles.login.useToken")]})}),r==="token"&&a.jsx("div",{className:"pt-4 border-t border-bambu-dark-tertiary",children:a.jsxs("button",{type:"button",onClick:()=>i("email"),className:"text-sm text-bambu-gray hover:text-white flex items-center gap-2 transition-colors",children:[a.jsx(Uz,{className:"w-4 h-4"}),e("profiles.login.useEmail")]})})]})]})})}function ig({label:t,value:e,options:n,onChange:r}){const[i,s]=_.useState(!1),o=n.find(l=>l.value===e);return a.jsxs("div",{className:"relative",children:[a.jsxs("button",{onClick:()=>s(!i),className:"flex items-center gap-2 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-sm text-white hover:border-bambu-gray-dark transition-colors",children:[a.jsxs("span",{className:"text-bambu-gray",children:[t,":"]}),a.jsx("span",{children:o?.label||"All"}),a.jsx(Kr,{className:`w-4 h-4 text-bambu-gray transition-transform ${i?"rotate-180":""}`})]}),i&&a.jsxs(a.Fragment,{children:[a.jsx("div",{className:"fixed inset-0 z-10",onClick:()=>s(!1)}),a.jsx("div",{className:"absolute top-full left-0 mt-1 min-w-[160px] bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl z-20 py-1 max-h-60 overflow-y-auto",children:n.map(l=>a.jsxs("button",{onClick:()=>{r(l.value),s(!1)},className:`w-full px-3 py-2 text-left text-sm flex items-center justify-between hover:bg-bambu-dark-tertiary transition-colors ${e===l.value?"text-bambu-green":"text-white"}`,children:[a.jsx("span",{children:l.label}),l.count!==void 0&&a.jsx("span",{className:"text-bambu-gray text-xs",children:l.count})]},l.value))})]})]})}function QKe(){const[t,e]=_.useState(!1);_.useEffect(()=>{const r=()=>{e(window.scrollY>300)};return window.addEventListener("scroll",r),()=>window.removeEventListener("scroll",r)},[]);const n=()=>{window.scrollTo({top:0,behavior:"smooth"})};return t?a.jsx("button",{onClick:n,className:"fixed bottom-6 right-6 p-3 bg-bambu-green hover:bg-bambu-green-light text-white rounded-full shadow-lg shadow-bambu-green/25 transition-all z-40","aria-label":"Scroll to top",children:a.jsx(zg,{className:"w-5 h-5"})}):null}function Wj({setting:t,onClick:e,onDuplicate:n,compareMode:r,isCompareSelected:i,compareIndex:s,compareDisabled:o,t:l}){const c=mF(t.name),u=Oy(t.setting_id);return a.jsxs("div",{className:"flex items-center gap-2 group",children:[a.jsx("button",{onClick:e,disabled:o,className:`flex-1 text-left px-3 py-2 rounded transition-colors ${i?"bg-blue-500/20 border border-blue-500/50":o?"bg-bambu-dark/50 opacity-40 cursor-not-allowed":"bg-bambu-dark hover:bg-bambu-dark-tertiary"} ${r&&!o?"cursor-pointer":""}`,children:a.jsxs("div",{className:"flex items-center gap-2",children:[i&&s!==void 0&&a.jsx("span",{className:"flex-shrink-0 w-5 h-5 rounded-full bg-blue-500 text-white text-xs flex items-center justify-center font-medium",children:s+1}),!i&&u&&a.jsx("span",{className:"flex-shrink-0 w-1.5 h-1.5 rounded-full bg-bambu-green",title:l("profiles.presets.myPreset")}),a.jsx("span",{className:"text-white text-sm truncate flex-1",title:t.name,children:t.name}),c.filamentType&&t.type==="filament"&&a.jsx("span",{className:"text-xs text-bambu-gray whitespace-nowrap",children:c.filamentType}),c.layerHeight&&t.type==="process"&&a.jsx("span",{className:"text-xs text-bambu-gray whitespace-nowrap",children:c.layerHeight}),c.printer&&a.jsx("span",{className:"text-xs text-bambu-gray whitespace-nowrap",children:c.printer})]})}),a.jsx("button",{onClick:d=>{d.stopPropagation(),n()},className:"opacity-0 group-hover:opacity-100 text-bambu-gray hover:text-white transition-all p-1",title:l("profiles.presets.duplicate"),children:a.jsx(Ul,{className:"w-4 h-4"})})]})}function mR(t,e=0){const n=" ".repeat(e);if(t===null)return"null";if(t===void 0)return"undefined";if(typeof t=="string"){if(t.includes("\\n")||t.includes(`
`)){const i=t.replace(/\\n/g,`
`).replace(/\\"/g,'"').replace(/\\t/g," ").split(`
`);if(i.length>1)return`"""
diff --git a/static/index.html b/static/index.html
index 4a2ce9fac..faabb05c2 100644
--- a/static/index.html
+++ b/static/index.html
@@ -23,7 +23,7 @@
-
+