From 179499359df5411703ae2ea5bb079048c67bf640 Mon Sep 17 00:00:00 2001 From: maziggy Date: Fri, 23 Jan 2026 10:10:13 +0100 Subject: [PATCH] Rearranged network setting cards --- frontend/src/pages/SettingsPage.tsx | 10 ++++++---- static/assets/{index-DbOfgMyu.js => index-CPB3KMs0.js} | 2 +- static/index.html | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) rename static/assets/{index-DbOfgMyu.js => index-CPB3KMs0.js} (97%) diff --git a/frontend/src/pages/SettingsPage.tsx b/frontend/src/pages/SettingsPage.tsx index 98e624ef8..eebd58bdc 100644 --- a/frontend/src/pages/SettingsPage.tsx +++ b/frontend/src/pages/SettingsPage.tsx @@ -1331,7 +1331,7 @@ export function SettingsPage() { {/* Network Tab */} {activeTab === 'network' && localSettings && (
- {/* Left Column - FTP Retry & Home Assistant */} + {/* Left Column - External URL & FTP Retry */}
{/* External URL */} @@ -1459,6 +1459,10 @@ export function SettingsPage() { +
+ + {/* Right Column - Home Assistant & MQTT Publishing */} +
{/* Home Assistant Integration */} @@ -1557,10 +1561,8 @@ export function SettingsPage() { )} -
- {/* Right Column - MQTT Publishing */} -
+ {/* MQTT Publishing */}
diff --git a/static/assets/index-DbOfgMyu.js b/static/assets/index-CPB3KMs0.js similarity index 97% rename from static/assets/index-DbOfgMyu.js rename to static/assets/index-CPB3KMs0.js index 386508171..6b7d05053 100644 --- a/static/assets/index-DbOfgMyu.js +++ b/static/assets/index-CPB3KMs0.js @@ -8648,7 +8648,7 @@ Accuracy: ${t.time_accuracy.toFixed(0)}%`:t.actual_time_seconds?`Actual: ${mb(t. transition-all duration-200 hover:border-bambu-dark-tertiary/80 ${x?"opacity-50 scale-[1.02] shadow-xl z-50":""} ${b?"border-blue-500/30 bg-gradient-to-r from-blue-500/5 to-transparent":""} - `,children:s.jsxs("div",{className:"flex items-center gap-4 p-4",children:[v?s.jsx("div",{...u,...d,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:s.jsx(Qp,{className:"w-6 h-6 md:w-4 md:h-4 text-bambu-gray"})}):e!==void 0?s.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]}):s.jsx("div",{className:"w-8"}),s.jsx("div",{className:"w-14 h-14 flex-shrink-0 bg-bambu-dark rounded-lg overflow-hidden",children:t.archive_thumbnail?s.jsx("img",{src:pe.getArchiveThumbnail(t.archive_id),alt:"",className:"w-full h-full object-cover"}):t.library_file_thumbnail?s.jsx("img",{src:pe.getLibraryFileThumbnailUrl(t.library_file_id),alt:"",className:"w-full h-full object-cover"}):s.jsx("div",{className:"w-full h-full flex items-center justify-center text-bambu-gray",children:s.jsx(nl,{className:"w-6 h-6"})})}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[s.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?s.jsx(ls,{to:`/archives?highlight=${t.archive_id}`,className:"text-bambu-gray hover:text-bambu-green transition-colors flex-shrink-0",title:"View archive",children:s.jsx(Lr,{className:"w-3.5 h-3.5"})}):t.library_file_id?s.jsx(ls,{to:`/library?highlight=${t.library_file_id}`,className:"text-bambu-gray hover:text-bambu-green transition-colors flex-shrink-0",title:"View in File Manager",children:s.jsx(Lr,{className:"w-3.5 h-3.5"})}):null]}),s.jsxs("div",{className:"flex items-center gap-3 text-sm text-bambu-gray",children:[s.jsxs("span",{className:`flex items-center gap-1.5 ${t.printer_id===null?"text-orange-400":""}`,children:[s.jsx(Ir,{className:"w-3.5 h-3.5"}),t.printer_id===null?"Unassigned":t.printer_name||`Printer #${t.printer_id}`]}),t.print_time_seconds&&s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx(md,{className:"w-3.5 h-3.5"}),dre(t.print_time_seconds)]}),v&&!t.manual_start&&s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx(Gn,{className:"w-3.5 h-3.5"}),gqe(t.scheduled_time,c)]})]}),s.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[t.manual_start&&s.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:[s.jsx(qW,{className:"w-3 h-3"}),"Staged"]}),t.require_previous_success&&s.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:"Requires previous success"}),t.auto_off_after&&s.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:[s.jsx(uu,{className:"w-3 h-3"}),"Auto power off"]})]}),b&&s.jsxs("div",{className:"mt-3",children:[s.jsx("div",{className:"h-2 bg-bambu-dark rounded-full overflow-hidden",children:s.jsx("div",{className:"h-full bg-gradient-to-r from-blue-500 to-blue-400 animate-pulse w-full opacity-50"})}),s.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Printing in progress..."})]}),t.error_message&&s.jsxs("p",{className:"text-xs text-red-400 mt-2 flex items-center gap-1",children:[s.jsx(ea,{className:"w-3 h-3"}),t.error_message]})]}),s.jsx(xqe,{status:t.status}),s.jsxs("div",{className:"flex items-center gap-1",children:[b&&s.jsx(Se,{variant:"ghost",size:"sm",onClick:a,title:"Stop Print",className:"text-red-400 hover:text-red-300 hover:bg-red-500/10",children:s.jsx(kce,{className:"w-4 h-4"})}),v&&s.jsxs(s.Fragment,{children:[t.manual_start&&s.jsx(Se,{variant:"ghost",size:"sm",onClick:l,title:"Start Print",className:"text-bambu-green hover:text-bambu-green-light hover:bg-bambu-green/10",children:s.jsx(rl,{className:"w-4 h-4"})}),s.jsx(Se,{variant:"ghost",size:"sm",onClick:n,title:"Edit",children:s.jsx(Ga,{className:"w-4 h-4"})}),s.jsx(Se,{variant:"ghost",size:"sm",onClick:r,title:"Cancel",className:"text-red-400 hover:text-red-300 hover:bg-red-500/10",children:s.jsx(Ut,{className:"w-4 h-4"})})]}),M&&s.jsxs(s.Fragment,{children:[s.jsx(Se,{variant:"ghost",size:"sm",onClick:o,title:"Re-queue",className:"text-bambu-green hover:text-bambu-green/80 hover:bg-bambu-green/10",children:s.jsx(yr,{className:"w-4 h-4"})}),s.jsx(Se,{variant:"ghost",size:"sm",onClick:i,title:"Remove",children:s.jsx(an,{className:"w-4 h-4"})})]})]})]})})}function bqe(){const t=tn(),{showToast:e}=$n(),[n,r]=w.useState(null),[i,a]=w.useState(""),[o,l]=w.useState(!1),[c,u]=w.useState(null),[d,f]=w.useState(null),[m,g]=w.useState(null),[x,y]=w.useState(()=>localStorage.getItem("queue.historySortBy")||"date"),[b,v]=w.useState(()=>{const J=localStorage.getItem("queue.historySortAsc");return J!==null?J==="true":!1}),[M,S]=w.useState(()=>localStorage.getItem("queue.pendingSortBy")||"position"),[A,E]=w.useState(()=>{const J=localStorage.getItem("queue.pendingSortAsc");return J!==null?J==="true":!0});w.useEffect(()=>{localStorage.setItem("queue.historySortBy",x)},[x]),w.useEffect(()=>{localStorage.setItem("queue.historySortAsc",String(b))},[b]),w.useEffect(()=>{localStorage.setItem("queue.pendingSortBy",M)},[M]),w.useEffect(()=>{localStorage.setItem("queue.pendingSortAsc",String(A))},[A]);const k=zne(y2(lN,{activationConstraint:{distance:8}}),y2(oN,{coordinateGetter:cre})),{data:C}=ct({queryKey:["settings"],queryFn:pe.getSettings}),R=C?.time_format||"system",{data:T,isLoading:P}=ct({queryKey:["queue",n,i],queryFn:()=>pe.getQueue(n||void 0,i||void 0),refetchInterval:5e3}),{data:F}=ct({queryKey:["printers"],queryFn:()=>pe.getPrinters()}),L=ft({mutationFn:J=>pe.cancelQueueItem(J),onSuccess:()=>{t.invalidateQueries({queryKey:["queue"]}),e("Queue item cancelled")},onError:()=>e("Failed to cancel item","error")}),X=ft({mutationFn:J=>pe.removeFromQueue(J),onSuccess:()=>{t.invalidateQueries({queryKey:["queue"]}),e("Queue item removed")},onError:()=>e("Failed to remove item","error")}),D=ft({mutationFn:J=>pe.stopQueueItem(J),onSuccess:()=>{t.invalidateQueries({queryKey:["queue"]}),e("Print stopped")},onError:()=>e("Failed to stop print","error")}),K=ft({mutationFn:J=>pe.startQueueItem(J),onSuccess:()=>{t.invalidateQueries({queryKey:["queue"]}),e("Print released to queue")},onError:()=>e("Failed to start print","error")}),Y=ft({mutationFn:J=>pe.reorderQueue(J),onSuccess:()=>{t.invalidateQueries({queryKey:["queue"]})},onError:()=>e("Failed to reorder queue","error")}),q=ft({mutationFn:async()=>{const J=T?.filter(te=>["completed","failed","skipped","cancelled"].includes(te.status))||[];for(const te of J)await pe.removeFromQueue(te.id);return J.length},onSuccess:J=>{t.invalidateQueries({queryKey:["queue"]}),e(`Cleared ${J} history item${J!==1?"s":""}`)},onError:()=>e("Failed to clear history","error")}),Z=w.useMemo(()=>{const J=T?.filter(ae=>ae.status==="pending")||[],te=ae=>{if(!ae.scheduled_time)return 0;const de=new Date(ae.scheduled_time).getTime(),fe=Date.now()+4320*60*60*1e3;return de>fe?0:de};return[...J].sort((ae,de)=>{let fe;if(M==="name"){const Ae=ae.archive_name||ae.library_file_name||"",ge=de.archive_name||de.library_file_name||"";fe=Ae.localeCompare(ge)}else M==="printer"?fe=(ae.printer_name||"").localeCompare(de.printer_name||""):M==="time"?fe=te(ae)-te(de):fe=ae.position-de.position;return A?fe:-fe})},[T,M,A]),re=T?.filter(J=>J.status==="printing")||[],oe=w.useMemo(()=>[...T?.filter(te=>["completed","failed","skipped","cancelled"].includes(te.status))||[]].sort((te,ae)=>{let de;if(x==="name"){const fe=te.archive_name||te.library_file_name||"",Ae=ae.archive_name||ae.library_file_name||"";de=fe.localeCompare(Ae)}else x==="printer"?de=(te.printer_name||"").localeCompare(ae.printer_name||""):de=new Date(ae.completed_at||ae.created_at).getTime()-new Date(te.completed_at||te.created_at).getTime();return b?-de:de}),[T,x,b]),B=w.useMemo(()=>Z.reduce((J,te)=>J+(te.print_time_seconds||0),0),[Z]),G=J=>{const{active:te,over:ae}=J;if(!ae||te.id===ae.id)return;const de=Z.findIndex(Ae=>Ae.id===te.id),fe=Z.findIndex(Ae=>Ae.id===ae.id);if(de!==-1&&fe!==-1){const ge=dN(Z,de,fe).map((Me,je)=>({id:Me.id,position:je+1}));Y.mutate(ge)}};return s.jsxs("div",{className:"p-4 md:p-8",children:[s.jsx("div",{className:"flex items-center justify-between mb-8",children:s.jsxs("div",{children:[s.jsxs("h1",{className:"text-2xl font-bold text-white flex items-center gap-3",children:[s.jsx(KW,{className:"w-7 h-7 text-bambu-green"}),"Print Queue"]}),s.jsx("p",{className:"text-bambu-gray mt-1",children:"Schedule and manage your print jobs"})]})}),s.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-4 gap-4 mb-8",children:[s.jsx(Mt,{className:"bg-gradient-to-br from-blue-500/10 to-transparent border-blue-500/20",children:s.jsx(Et,{className:"p-4",children:s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("div",{className:"w-10 h-10 rounded-lg bg-blue-500/20 flex items-center justify-center",children:s.jsx(rl,{className:"w-5 h-5 text-blue-400"})}),s.jsxs("div",{children:[s.jsx("p",{className:"text-2xl font-bold text-white",children:re.length}),s.jsx("p",{className:"text-sm text-bambu-gray",children:"Printing"})]})]})})}),s.jsx(Mt,{className:"bg-gradient-to-br from-yellow-500/10 to-transparent border-yellow-500/20",children:s.jsx(Et,{className:"p-4",children:s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("div",{className:"w-10 h-10 rounded-lg bg-yellow-500/20 flex items-center justify-center",children:s.jsx(Gn,{className:"w-5 h-5 text-yellow-400"})}),s.jsxs("div",{children:[s.jsx("p",{className:"text-2xl font-bold text-white",children:Z.length}),s.jsx("p",{className:"text-sm text-bambu-gray",children:"Queued"})]})]})})}),s.jsx(Mt,{className:"bg-gradient-to-br from-bambu-green/10 to-transparent border-bambu-green/20",children:s.jsx(Et,{className:"p-4",children:s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("div",{className:"w-10 h-10 rounded-lg bg-bambu-green/20 flex items-center justify-center",children:s.jsx(md,{className:"w-5 h-5 text-bambu-green"})}),s.jsxs("div",{children:[s.jsx("p",{className:"text-2xl font-bold text-white",children:dre(B)}),s.jsx("p",{className:"text-sm text-bambu-gray",children:"Total Queue Time"})]})]})})}),s.jsx(Mt,{className:"bg-gradient-to-br from-gray-500/10 to-transparent border-gray-500/20",children:s.jsx(Et,{className:"p-4",children:s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("div",{className:"w-10 h-10 rounded-lg bg-gray-500/20 flex items-center justify-center",children:s.jsx(Dn,{className:"w-5 h-5 text-gray-400"})}),s.jsxs("div",{children:[s.jsx("p",{className:"text-2xl font-bold text-white",children:oe.length}),s.jsx("p",{className:"text-sm text-bambu-gray",children:"History"})]})]})})})]}),s.jsxs("div",{className:"flex items-center gap-4 mb-6",children:[s.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:n===-1?"unassigned":n||"",onChange:J=>{const te=J.target.value;r(te==="unassigned"?-1:te===""?null:Number(te))},children:[s.jsx("option",{value:"",children:"All Printers"}),s.jsx("option",{value:"unassigned",children:"Unassigned"}),F?.map(J=>s.jsx("option",{value:J.id,children:J.name},J.id))]}),s.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:i,onChange:J=>a(J.target.value),children:[s.jsx("option",{value:"",children:"All Status"}),s.jsx("option",{value:"pending",children:"Pending"}),s.jsx("option",{value:"printing",children:"Printing"}),s.jsx("option",{value:"completed",children:"Completed"}),s.jsx("option",{value:"failed",children:"Failed"}),s.jsx("option",{value:"skipped",children:"Skipped"}),s.jsx("option",{value:"cancelled",children:"Cancelled"})]}),s.jsx("div",{className:"flex-1"}),oe.length>0&&s.jsxs(Se,{variant:"secondary",size:"sm",onClick:()=>l(!0),children:[s.jsx(an,{className:"w-4 h-4"}),"Clear History"]})]}),P?s.jsx("div",{className:"text-center py-12 text-bambu-gray",children:"Loading..."}):T?.length===0?s.jsxs(Mt,{className:"p-12 text-center border-dashed",children:[s.jsx(Qr,{className:"w-16 h-16 text-bambu-gray mx-auto mb-4 opacity-50"}),s.jsx("h3",{className:"text-xl font-medium text-white mb-2",children:"No prints scheduled"}),s.jsx("p",{className:"text-bambu-gray max-w-md mx-auto",children:'Schedule a print from the Archives page using the "Schedule" option in the context menu, or drag and drop files to get started.'})]}):s.jsxs("div",{className:"space-y-8",children:[re.length>0&&s.jsxs("div",{children:[s.jsxs("h2",{className:"text-lg font-semibold text-white mb-4 flex items-center gap-2",children:[s.jsx("div",{className:"w-2 h-2 rounded-full bg-blue-400 animate-pulse"}),"Currently Printing"]}),s.jsx("div",{className:"space-y-3",children:re.map(J=>s.jsx(pj,{item:J,onEdit:()=>{},onCancel:()=>{},onRemove:()=>{},onStop:()=>g({type:"stop",item:J}),onRequeue:()=>{},onStart:()=>{},timeFormat:R},J.id))})]}),Z.length>0&&s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center justify-between mb-4",children:[s.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[s.jsx(Gn,{className:"w-5 h-5 text-yellow-400"}),"Queued",s.jsxs("span",{className:"text-sm font-normal text-bambu-gray",children:["(",Z.length," item",Z.length!==1?"s":"",")"]}),s.jsx("span",{className:"text-xs text-bambu-gray ml-2",title:"Position only affects ASAP items. Scheduled items run at their set time.",children:"Drag to reorder (ASAP only)"})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.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:M,onChange:J=>S(J.target.value),children:[s.jsx("option",{value:"position",children:"Sort by Position"}),s.jsx("option",{value:"name",children:"Sort by Name"}),s.jsx("option",{value:"printer",children:"Sort by Printer"}),s.jsx("option",{value:"time",children:"Sort by Schedule"})]}),s.jsx(Se,{variant:"ghost",size:"sm",onClick:()=>E(!A),title:A?"Ascending":"Descending",className:"px-2",children:A?s.jsx(Kp,{className:"w-4 h-4"}):s.jsx(i0,{className:"w-4 h-4"})})]})]}),s.jsx(rre,{sensors:k,collisionDetection:Vne,onDragEnd:G,children:s.jsx(sre,{items:Z.map(J=>J.id),strategy:aqe,children:s.jsx("div",{className:"space-y-3",children:Z.map((J,te)=>s.jsx(pj,{item:J,position:te+1,onEdit:()=>u(J),onCancel:()=>g({type:"cancel",item:J}),onRemove:()=>{},onStop:()=>{},onRequeue:()=>{},onStart:()=>K.mutate(J.id),timeFormat:R},J.id))})})})]}),oe.length>0&&s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center justify-between mb-4",children:[s.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[s.jsx(Dn,{className:"w-5 h-5 text-bambu-gray"}),"History",s.jsxs("span",{className:"text-sm font-normal text-bambu-gray",children:["(",oe.length," item",oe.length!==1?"s":"",")"]})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.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:x,onChange:J=>y(J.target.value),children:[s.jsx("option",{value:"date",children:"Sort by Date"}),s.jsx("option",{value:"name",children:"Sort by Name"}),s.jsx("option",{value:"printer",children:"Sort by Printer"})]}),s.jsx(Se,{variant:"ghost",size:"sm",onClick:()=>v(!b),title:b?"Ascending (oldest first)":"Descending (newest first)",className:"px-2",children:b?s.jsx(Kp,{className:"w-4 h-4"}):s.jsx(i0,{className:"w-4 h-4"})})]})]}),s.jsx("div",{className:"space-y-3",children:oe.slice(0,20).map((J,te)=>s.jsx(pj,{item:J,position:te+1,onEdit:()=>{},onCancel:()=>{},onRemove:()=>g({type:"remove",item:J}),onStop:()=>{},onRequeue:()=>f(J),onStart:()=>{},timeFormat:R},J.id))})]})]}),c&&s.jsx(Wd,{mode:"edit-queue-item",archiveId:c.archive_id??void 0,libraryFileId:c.library_file_id??void 0,archiveName:c.archive_name||c.library_file_name||`File #${c.archive_id||c.library_file_id}`,queueItem:c,onClose:()=>u(null)}),d&&s.jsx(Wd,{mode:"add-to-queue",archiveId:d.archive_id??void 0,libraryFileId:d.library_file_id??void 0,archiveName:d.archive_name||d.library_file_name||`File #${d.archive_id||d.library_file_id}`,onClose:()=>f(null)}),m&&s.jsx(Ln,{title:m.type==="cancel"?"Cancel Scheduled Print":m.type==="stop"?"Stop Print":"Remove from History",message:m.type==="cancel"?`Are you sure you want to cancel "${m.item.archive_name||m.item.library_file_name||"this print"}"?`:m.type==="stop"?`Are you sure you want to stop the current print "${m.item.archive_name||m.item.library_file_name||"this print"}"? This will cancel the print job on the printer.`:`Are you sure you want to remove "${m.item.archive_name||m.item.library_file_name||"this item"}" from the queue history?`,confirmText:m.type==="cancel"?"Cancel Print":m.type==="stop"?"Stop Print":"Remove",variant:"danger",onConfirm:()=>{m.type==="cancel"?L.mutate(m.item.id):m.type==="stop"?D.mutate(m.item.id):X.mutate(m.item.id),g(null)},onCancel:()=>g(null)}),o&&s.jsx(Ln,{title:"Clear History",message:`Are you sure you want to remove all ${oe.length} item${oe.length!==1?"s":""} from the history?`,confirmText:"Clear History",variant:"danger",onConfirm:()=>{q.mutate(),l(!1)},onCancel:()=>l(!1)})]})}function yqe({printDates:t,months:e=3}){const n=w.useRef(null),[r,i]=w.useState(0);w.useEffect(()=>{const M=n.current;if(!M)return;const S=new ResizeObserver(A=>{const E=A[0]?.contentRect.width||0;i(E)});return S.observe(M),()=>S.disconnect()},[]);const{weeks:a,monthLabels:o,printCounts:l}=w.useMemo(()=>{const M={};t.forEach(F=>{const L=F.split("T")[0];M[L]=(M[L]||0)+1});const S=new Date,A=new Date(S);A.setMonth(A.getMonth()-e),A.setDate(A.getDate()-A.getDay());const E=[],k=[];let C=[],R=-1;const T=new Date(A);let P=0;for(;T<=S;)T.getDay()===0&&C.length>0&&(E.push(C),C=[],P++),T.getMonth()!==R&&(k.push({month:T.toLocaleDateString("en-US",{month:"short"}),weekIndex:P}),R=T.getMonth()),C.push(new Date(T)),T.setDate(T.getDate()+1);return C.length>0&&E.push(C),{weeks:E,monthLabels:k,printCounts:M}},[t,e]),c=Math.max(1,...Object.values(l)),u=M=>{if(M===0)return"bg-bambu-dark";const S=M/c;return S<=.25?"bg-bambu-green/30":S<=.5?"bg-bambu-green/50":S<=.75?"bg-bambu-green/75":"bg-bambu-green"},d=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],f=a.length,m=32,g=2,x=r-m-16,y=f>0?Math.floor((x-(f-1)*g)/f):12,b=Math.max(8,Math.min(20,y)),v=b<=10?10:12;return s.jsx("div",{ref:n,className:"w-full flex justify-center",children:r>0&&s.jsxs("div",{children:[s.jsx("div",{className:"flex mb-1",style:{marginLeft:m+4},children:o.map(({month:M,weekIndex:S},A)=>s.jsx("div",{className:"text-bambu-gray",style:{fontSize:v,marginLeft:A===0?0:`${(S-(o[A-1]?.weekIndex||0))*(b+g)-24}px`},children:M},A))}),s.jsxs("div",{className:"flex",style:{gap:g},children:[s.jsx("div",{className:"flex flex-col",style:{gap:g,marginRight:4,width:m},children:d.map((M,S)=>s.jsx("div",{className:"text-bambu-gray flex items-center",style:{width:m,height:b,fontSize:v,visibility:S%2===1?"visible":"hidden"},children:M},M))}),a.map((M,S)=>s.jsx("div",{className:"flex flex-col",style:{gap:g},children:[0,1,2,3,4,5,6].map(A=>{const E=M.find(T=>T.getDay()===A);if(!E)return s.jsx("div",{style:{width:b,height:b}},A);const k=E.toISOString().split("T")[0],C=l[k]||0,R=k===new Date().toISOString().split("T")[0];return s.jsx("div",{className:`rounded-sm ${u(C)} ${R?"ring-1 ring-white":""}`,style:{width:b,height:b},title:`${E.toLocaleDateString()}: ${C} print${C!==1?"s":""}`},A)})},S))]}),s.jsxs("div",{className:"flex items-center gap-2 mt-3 text-bambu-gray",style:{fontSize:v},children:[s.jsx("span",{children:"Less"}),s.jsxs("div",{className:"flex",style:{gap:g},children:[s.jsx("div",{className:"rounded-sm bg-bambu-dark",style:{width:b,height:b}}),s.jsx("div",{className:"rounded-sm bg-bambu-green/30",style:{width:b,height:b}}),s.jsx("div",{className:"rounded-sm bg-bambu-green/50",style:{width:b,height:b}}),s.jsx("div",{className:"rounded-sm bg-bambu-green/75",style:{width:b,height:b}}),s.jsx("div",{className:"rounded-sm bg-bambu-green",style:{width:b,height:b}})]}),s.jsx("span",{children:"More"})]})]})})}const A1=["#00ae42","#3b82f6","#f59e0b","#ef4444","#8b5cf6","#ec4899","#14b8a6","#f97316"];function vqe(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 _qe({archives:t,currency:e="$"}){const[n,r]=w.useState("30d"),i=w.useMemo(()=>{const m=vqe(n);return t.filter(g=>(mi(g.completed_at||g.created_at)||new Date(0))>=m)},[t,n]),a=w.useMemo(()=>{const m=new Map;return i.forEach(g=>{const x=mi(g.completed_at||g.created_at)||new Date,y=`${x.getFullYear()}-${String(x.getMonth()+1).padStart(2,"0")}-${String(x.getDate()).padStart(2,"0")}`,b=m.get(y)||{date:y,filament:0,cost:0,prints:0};b.filament+=g.filament_used_grams||0,b.cost+=g.cost||0,b.prints+=1,m.set(y,b)}),Array.from(m.values()).sort((g,x)=>g.date.localeCompare(x.date)).map(g=>({...g,dateLabel:new Date(g.date).toLocaleDateString("en-US",{month:"short",day:"numeric"})}))},[i]),o=w.useMemo(()=>{if(n==="7d"||n==="30d")return a;const m=new Map;return i.forEach(g=>{const x=mi(g.completed_at||g.created_at)||new Date,y=new Date(x);y.setDate(x.getDate()-x.getDay());const b=`${y.getFullYear()}-${String(y.getMonth()+1).padStart(2,"0")}-${String(y.getDate()).padStart(2,"0")}`,v=m.get(b)||{week:b,filament:0,cost:0,prints:0};v.filament+=g.filament_used_grams||0,v.cost+=g.cost||0,v.prints+=1,m.set(b,v)}),Array.from(m.values()).sort((g,x)=>g.week.localeCompare(x.week)).map(g=>({date:g.week,dateLabel:`Week of ${new Date(g.week).toLocaleDateString("en-US",{month:"short",day:"numeric"})}`,...g}))},[i,a,n]),l=w.useMemo(()=>{const m=new Map;return i.forEach(g=>{const y=(g.filament_type||"Unknown").split(", ");y.forEach(b=>{const v=(g.filament_used_grams||0)/y.length;m.set(b,(m.get(b)||0)+v)})}),Array.from(m.entries()).map(([g,x])=>({name:g,value:Math.round(x)})).sort((g,x)=>x.value-g.value)},[i]),c=w.useMemo(()=>{const m=new Date,g=[];for(let x=5;x>=0;x--){const y=new Date(m.getFullYear(),m.getMonth()-x,1),b=new Date(m.getFullYear(),m.getMonth()-x+1,0),v=y.toLocaleDateString("en-US",{month:"short",year:"2-digit"}),M=t.filter(S=>{const A=mi(S.completed_at||S.created_at)||new Date(0);return A>=y&&A<=b});g.push({month:v,filament:Math.round(M.reduce((S,A)=>S+(A.filament_used_grams||0),0)),cost:M.reduce((S,A)=>S+(A.cost||0),0),prints:M.length})}return g},[t]),u=n==="7d"||n==="30d"?a:o,d=i.reduce((m,g)=>m+(g.filament_used_grams||0),0),f=i.reduce((m,g)=>m+(g.cost||0),0);return s.jsxs("div",{className:"space-y-6",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("h3",{className:"text-lg font-semibold text-white",children:"Filament Usage Trends"}),s.jsx("div",{className:"flex gap-1 bg-bambu-dark rounded-lg p-1",children:["7d","30d","90d","365d","all"].map(m=>s.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))})]}),s.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[s.jsxs("div",{className:"bg-bambu-dark rounded-lg p-4",children:[s.jsx("p",{className:"text-sm text-bambu-gray",children:"Period Filament"}),s.jsxs("p",{className:"text-2xl font-bold text-white",children:[(d/1e3).toFixed(2),"kg"]}),s.jsxs("p",{className:"text-xs text-bambu-gray",children:[d.toFixed(0),"g total"]})]}),s.jsxs("div",{className:"bg-bambu-dark rounded-lg p-4",children:[s.jsx("p",{className:"text-sm text-bambu-gray",children:"Period Cost"}),s.jsxs("p",{className:"text-2xl font-bold text-white",children:[e,f.toFixed(2)]}),s.jsxs("p",{className:"text-xs text-bambu-gray",children:[i.length," prints"]})]}),s.jsxs("div",{className:"bg-bambu-dark rounded-lg p-4",children:[s.jsx("p",{className:"text-sm text-bambu-gray",children:"Avg per Print"}),s.jsxs("p",{className:"text-2xl font-bold text-white",children:[i.length>0?(d/i.length).toFixed(0):0,"g"]}),s.jsxs("p",{className:"text-xs text-bambu-gray",children:[e,i.length>0?(f/i.length).toFixed(2):"0.00"," avg"]})]})]}),u.length>0?s.jsxs("div",{className:"bg-bambu-dark rounded-lg p-4",children:[s.jsx("h4",{className:"text-sm font-medium text-bambu-gray mb-4",children:"Usage Over Time"}),s.jsx(F1,{width:"100%",height:250,children:s.jsxs(bke,{data:u,children:[s.jsx("defs",{children:s.jsxs("linearGradient",{id:"colorFilament",x1:"0",y1:"0",x2:"0",y2:"1",children:[s.jsx("stop",{offset:"5%",stopColor:"#00ae42",stopOpacity:.3}),s.jsx("stop",{offset:"95%",stopColor:"#00ae42",stopOpacity:0})]})}),s.jsx(lS,{strokeDasharray:"3 3",stroke:"#3d3d3d"}),s.jsx(uS,{dataKey:"dateLabel",stroke:"#9ca3af",tick:{fontSize:12},interval:"preserveStartEnd"}),s.jsx(dS,{stroke:"#9ca3af",tick:{fontSize:12},tickFormatter:m=>`${m}g`}),s.jsx(z1,{contentStyle:{backgroundColor:"#2d2d2d",border:"1px solid #3d3d3d",borderRadius:"8px"},labelStyle:{color:"#fff"},formatter:m=>[`${m.toFixed(0)}g`,"Filament"]}),s.jsx(cZ,{type:"monotone",dataKey:"filament",stroke:"#00ae42",strokeWidth:2,fillOpacity:1,fill:"url(#colorFilament)"})]})})]}):s.jsx("div",{className:"bg-bambu-dark rounded-lg p-8 text-center text-bambu-gray",children:"No data for selected time range"}),s.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[s.jsxs("div",{className:"bg-bambu-dark rounded-lg p-4",children:[s.jsx("h4",{className:"text-sm font-medium text-bambu-gray mb-4",children:"By Filament Type"}),l.length>0?s.jsxs("div",{className:"flex items-center gap-4",children:[s.jsx(F1,{width:160,height:160,children:s.jsxs(gke,{children:[s.jsx(RQ,{data:l,cx:"50%",cy:"50%",innerRadius:40,outerRadius:70,paddingAngle:2,dataKey:"value",children:l.map((m,g)=>s.jsx(wy,{fill:A1[g%A1.length]},`cell-${g}`))}),s.jsx(z1,{contentStyle:{backgroundColor:"#2d2d2d",border:"1px solid #3d3d3d",borderRadius:"8px"},formatter:m=>[`${m}g`,"Usage"]})]})}),s.jsx("div",{className:"flex-1 space-y-2 overflow-hidden",children:l.map((m,g)=>{const x=l.reduce((b,v)=>b+v.value,0),y=x>0?(m.value/x*100).toFixed(0):0;return s.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[s.jsx("div",{className:"w-3 h-3 rounded-sm flex-shrink-0",style:{backgroundColor:A1[g%A1.length]}}),s.jsx("span",{className:"text-white truncate flex-1",children:m.name}),s.jsxs("span",{className:"text-bambu-gray flex-shrink-0",children:[y,"%"]})]},m.name)})})]}):s.jsx("div",{className:"h-[160px] flex items-center justify-center text-bambu-gray",children:"No filament data"})]}),s.jsxs("div",{className:"bg-bambu-dark rounded-lg p-4",children:[s.jsx("h4",{className:"text-sm font-medium text-bambu-gray mb-4",children:"Monthly Comparison"}),s.jsx(F1,{width:"100%",height:200,children:s.jsxs(ike,{data:c,children:[s.jsx(lS,{strokeDasharray:"3 3",stroke:"#3d3d3d"}),s.jsx(uS,{dataKey:"month",stroke:"#9ca3af",tick:{fontSize:12}}),s.jsx(dS,{stroke:"#9ca3af",tick:{fontSize:12},tickFormatter:m=>`${m}g`}),s.jsx(z1,{contentStyle:{backgroundColor:"#2d2d2d",border:"1px solid #3d3d3d",borderRadius:"8px"},formatter:(m,g)=>[g==="filament"?`${m}g`:g==="cost"?`${e}${m.toFixed(2)}`:m,g==="filament"?"Filament":g==="cost"?"Cost":"Prints"]}),s.jsx(OD,{}),s.jsx(UQ,{dataKey:"filament",name:"Filament (g)",fill:"#00ae42",radius:[4,4,0,0]})]})})]})]})]})}function wqe({id:t,title:e,component:n,isHidden:r,size:i,onToggleVisibility:a,onToggleSize:o}){const{attributes:l,listeners:c,setNodeRef:u,transform:d,transition:f,isDragging:m}=lre({id:t}),g={transform:Eg.Transform.toString(d),transition:f,opacity:m?.5:1};return r?null:s.jsxs("div",{ref:u,style:{...g,gridColumn:`span ${i}`},className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary overflow-hidden ${m?"ring-2 ring-bambu-green shadow-lg":""}`,children:[s.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-bambu-dark-tertiary bg-bambu-dark/30",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.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:s.jsx(Qp,{className:"w-6 h-6 md:w-4 md:h-4 text-bambu-gray"})}),s.jsx("h3",{className:"text-sm font-medium text-white",children:e})]}),s.jsxs("div",{className:"flex items-center gap-1",children:[s.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?s.jsx(YW,{className:"w-4 h-4 text-bambu-gray hover:text-white"}):s.jsx(XW,{className:"w-4 h-4 text-bambu-gray hover:text-white"})}),s.jsx("button",{onClick:a,className:"p-1 hover:bg-bambu-dark-tertiary rounded transition-colors",title:"Hide widget",children:s.jsx(T2,{className:"w-4 h-4 text-bambu-gray hover:text-white"})})]})]}),s.jsx("div",{className:"p-4",children:typeof n=="function"?n(i):n})]})}function Sqe({widgets:t,storageKey:e,columns:n=4,hideControls:r=!1,onResetLayout:i,renderControls:a}){const o=()=>{const A={};return t.forEach(E=>{A[E.id]=E.defaultSize||4}),A},[l,c]=w.useState(()=>{const A=localStorage.getItem(e);if(A)try{const E=JSON.parse(A);return E.sizes||(E.sizes=o()),E}catch{}return{order:t.map(E=>E.id),hidden:t.filter(E=>E.defaultVisible===!1).map(E=>E.id),sizes:o()}}),[u,d]=w.useState(!1);w.useEffect(()=>{const A=()=>d(E=>!E);return window.addEventListener("toggle-hidden-panel",A),()=>window.removeEventListener("toggle-hidden-panel",A)},[]),w.useEffect(()=>{localStorage.setItem(e,JSON.stringify(l))},[l,e]),w.useEffect(()=>{const E=t.map(k=>k.id).filter(k=>!l.order.includes(k));E.length>0&&c(k=>({...k,order:[...k.order,...E]}))},[t,l.order]);const f=zne(y2(lN,{activationConstraint:{distance:8}}),y2(oN,{coordinateGetter:cre})),m=A=>{const{active:E,over:k}=A;k&&E.id!==k.id&&c(C=>{const R=C.order.indexOf(E.id),T=C.order.indexOf(k.id);return{...C,order:dN(C.order,R,T)}})},g=A=>{c(E=>({...E,hidden:E.hidden.includes(A)?E.hidden.filter(k=>k!==A):[...E.hidden,A]}))},x=A=>{c(E=>{const k=E.sizes[A]||4,C=k===1?2:k===2?4:1;return{...E,sizes:{...E.sizes,[A]:C}}})},y=()=>{const A={order:t.map(E=>E.id),hidden:t.filter(E=>E.defaultVisible===!1).map(E=>E.id),sizes:o()};c(A),i?.()},b=l.order.map(A=>t.find(E=>E.id===A)).filter(Boolean),v=b.filter(A=>!l.hidden.includes(A.id)),M=b.filter(A=>l.hidden.includes(A.id)),S=a?.({hiddenCount:M.length,showHiddenPanel:u,setShowHiddenPanel:d,resetLayout:y});return s.jsxs("div",{className:"space-y-4",children:[S,!r&&!a&&s.jsxs("div",{className:"flex items-center justify-end gap-2",children:[s.jsxs(Se,{variant:"secondary",size:"sm",onClick:y,children:[s.jsx(Vf,{className:"w-4 h-4"}),"Reset Layout"]}),M.length>0&&s.jsxs(Se,{variant:"secondary",size:"sm",onClick:()=>d(!u),children:[s.jsx(_f,{className:"w-4 h-4"}),M.length," Hidden"]})]}),u&&M.length>0&&s.jsxs("div",{className:"p-4 bg-bambu-dark rounded-xl border border-bambu-dark-tertiary",children:[s.jsx("p",{className:"text-sm text-bambu-gray mb-3",children:"Hidden widgets (click to show):"}),s.jsx("div",{className:"flex flex-wrap gap-2",children:M.map(A=>s.jsxs("button",{onClick:()=>g(A.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:[s.jsx(_f,{className:"w-3 h-3"}),A.title]},A.id))})]}),s.jsx(rre,{sensors:f,collisionDetection:Vne,onDragEnd:m,children:s.jsx(sre,{items:v.map(A=>A.id),strategy:PL,children:s.jsx("div",{className:"grid gap-6",style:{gridTemplateColumns:`repeat(${n}, minmax(0, 1fr))`},children:v.map(A=>s.jsx(wqe,{id:A.id,title:A.title,component:A.component,isHidden:l.hidden.includes(A.id),size:l.sizes[A.id]||2,onToggleVisibility:()=>g(A.id),onToggleSize:()=>x(A.id)},A.id))})})}),v.length===0&&s.jsxs("div",{className:"text-center py-12 text-bambu-gray",children:[s.jsx("p",{children:"All widgets are hidden."}),s.jsx(Se,{className:"mt-4",onClick:y,children:"Reset Layout"})]})]})}function Mqe({stats:t,currency:e}){return s.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-3 gap-4",children:[s.jsxs("div",{className:"flex items-start gap-3",children:[s.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark text-bambu-green",children:s.jsx(Dl,{className:"w-5 h-5"})}),s.jsxs("div",{children:[s.jsx("p",{className:"text-xs text-bambu-gray",children:"Total Prints"}),s.jsx("p",{className:"text-xl font-bold text-white",children:t?.total_prints||0})]})]}),s.jsxs("div",{className:"flex items-start gap-3",children:[s.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark text-blue-400",children:s.jsx(Gn,{className:"w-5 h-5"})}),s.jsxs("div",{children:[s.jsx("p",{className:"text-xs text-bambu-gray",children:"Print Time"}),s.jsxs("p",{className:"text-xl font-bold text-white",children:[t?.total_print_time_hours.toFixed(1)||0,"h"]})]})]}),s.jsxs("div",{className:"flex items-start gap-3",children:[s.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark text-orange-400",children:s.jsx(Dl,{className:"w-5 h-5"})}),s.jsxs("div",{children:[s.jsx("p",{className:"text-xs text-bambu-gray",children:"Filament Used"}),s.jsxs("p",{className:"text-xl font-bold text-white",children:[((t?.total_filament_grams||0)/1e3).toFixed(2),"kg"]})]})]}),s.jsxs("div",{className:"flex items-start gap-3",children:[s.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark text-green-400",children:s.jsx(Uj,{className:"w-5 h-5"})}),s.jsxs("div",{children:[s.jsx("p",{className:"text-xs text-bambu-gray",children:"Filament Cost"}),s.jsxs("p",{className:"text-xl font-bold text-white",children:[e," ",t?.total_cost.toFixed(2)||"0.00"]})]})]}),s.jsxs("div",{className:"flex items-start gap-3",children:[s.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark text-yellow-400",children:s.jsx(Mf,{className:"w-5 h-5"})}),s.jsxs("div",{children:[s.jsx("p",{className:"text-xs text-bambu-gray",children:"Energy Used"}),s.jsxs("p",{className:"text-xl font-bold text-white",children:[t?.total_energy_kwh.toFixed(2)||"0.00"," kWh"]})]})]}),s.jsxs("div",{className:"flex items-start gap-3",children:[s.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark text-yellow-500",children:s.jsx(Uj,{className:"w-5 h-5"})}),s.jsxs("div",{children:[s.jsx("p",{className:"text-xs text-bambu-gray",children:"Energy Cost"}),s.jsxs("p",{className:"text-xl font-bold text-white",children:[e," ",t?.total_energy_cost.toFixed(2)||"0.00"]})]})]})]})}function Nqe({stats:t,printerMap:e,size:n=1}){const r=t?.total_prints?Math.round(t.successful_prints/t.total_prints*100):0,i=n===1?112:n===2?128:144,a=i/2-8,o=a*2*Math.PI;return s.jsxs("div",{className:"flex items-center gap-6",children:[s.jsxs("div",{className:"relative flex-shrink-0",style:{width:i,height:i},children:[s.jsxs("svg",{className:"w-full h-full -rotate-90",children:[s.jsx("circle",{cx:i/2,cy:i/2,r:a,fill:"none",stroke:"#3d3d3d",strokeWidth:"10"}),s.jsx("circle",{cx:i/2,cy:i/2,r:a,fill:"none",stroke:"#00ae42",strokeWidth:"10",strokeLinecap:"round",strokeDasharray:`${r/100*o} ${o}`})]}),s.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:s.jsxs("span",{className:`font-bold text-white ${n>=2?"text-2xl":"text-xl"}`,children:[r,"%"]})})]}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Dn,{className:"w-4 h-4 text-bambu-green flex-shrink-0"}),s.jsx("span",{className:"text-sm text-bambu-gray",children:"Successful:"}),s.jsx("span",{className:"text-sm text-white font-medium",children:t?.successful_prints||0})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(qi,{className:"w-4 h-4 text-red-400 flex-shrink-0"}),s.jsx("span",{className:"text-sm text-bambu-gray",children:"Failed:"}),s.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&&s.jsxs("div",{className:"mt-4 pt-4 border-t border-bambu-dark-tertiary",children:[s.jsx("p",{className:"text-xs text-bambu-gray font-medium mb-2",children:"Prints by Printer"}),s.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(([l,c])=>s.jsxs("div",{className:"flex items-center gap-3 text-sm",children:[s.jsx("span",{className:"text-bambu-gray truncate max-w-[120px]",children:e.get(l)||`Printer ${l}`}),s.jsx("span",{className:"text-white font-medium",children:c})]},l))})]})]})]})}function Eqe({stats:t,printerMap:e,size:n=1}){const r=t?.average_time_accuracy;if(r==null)return s.jsx("div",{className:"flex items-center justify-center h-full",children:s.jsx("p",{className:"text-bambu-gray text-center py-4",children:"No time accuracy data yet"})});const a=(Math.min(150,Math.max(50,r))-50)/100*100,l=(x=>x>=95&&x<=105?"#00ae42":x>105?"#3b82f6":"#f97316")(r),c=r-100,u=n===1?112:n===2?128:144,d=u/2-8,f=d*2*Math.PI,m=n===1?3:n===2?6:999,g=t?.time_accuracy_by_printer?Object.entries(t.time_accuracy_by_printer).slice(0,m):[];return s.jsxs("div",{className:"flex items-center gap-6",children:[s.jsxs("div",{className:"relative flex-shrink-0",style:{width:u,height:u},children:[s.jsxs("svg",{className:"w-full h-full -rotate-90",children:[s.jsx("circle",{cx:u/2,cy:u/2,r:d,fill:"none",stroke:"#3d3d3d",strokeWidth:"10"}),s.jsx("circle",{cx:u/2,cy:u/2,r:d,fill:"none",stroke:l,strokeWidth:"10",strokeLinecap:"round",strokeDasharray:`${a/100*f} ${f}`})]}),s.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center",children:[s.jsxs("span",{className:`font-bold text-white ${n>=2?"text-2xl":"text-xl"}`,children:[r.toFixed(0),"%"]}),s.jsxs("span",{className:`text-xs ${c>=0?"text-blue-400":"text-orange-400"}`,children:[c>=0?"+":"",c.toFixed(0),"%"]})]})]}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsxs("div",{className:"flex items-center gap-2 text-xs text-bambu-gray",children:[s.jsx(nq,{className:"w-3 h-3 flex-shrink-0"}),s.jsx("span",{children:"100% = perfect estimate"})]}),g.length>0&&s.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:g.map(([x,y])=>s.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[s.jsx("span",{className:"text-bambu-gray truncate max-w-[100px]",children:e.get(x)||`Printer ${x}`}),s.jsxs("span",{className:`font-medium ${y>=95&&y<=105?"text-bambu-green":y>105?"text-blue-400":"text-orange-400"}`,children:[y.toFixed(0),"%"]})]},x))})]})]})}function Aqe({stats:t,size:e=1}){if(!t?.prints_by_filament_type||Object.keys(t.prints_by_filament_type).length===0)return s.jsx("p",{className:"text-bambu-gray text-center py-4",children:"No filament data available"});const n=Object.entries(t.prints_by_filament_type).sort(([,o],[,l])=>l-o),r=e===1?5:e===2?8:999,i=n.slice(0,r),a=n.length>r;return e===4&&i.length>4?s.jsx("div",{className:"grid grid-cols-2 lg:grid-cols-3 gap-4",children:i.map(([o,l])=>{const c=Math.round(l/(t.total_prints||1)*100);return s.jsxs("div",{children:[s.jsxs("div",{className:"flex justify-between text-sm mb-1",children:[s.jsx("span",{className:"text-white truncate max-w-[120px]",children:o}),s.jsx("span",{className:"text-bambu-gray",children:l})]}),s.jsx("div",{className:"h-2 bg-bambu-dark rounded-full",children:s.jsx("div",{className:"h-full bg-bambu-green rounded-full transition-all",style:{width:`${c}%`}})})]},o)})}):s.jsxs("div",{className:"space-y-3",children:[i.map(([o,l])=>{const c=Math.round(l/(t.total_prints||1)*100);return s.jsxs("div",{children:[s.jsxs("div",{className:"flex justify-between text-sm mb-1",children:[s.jsx("span",{className:"text-white",children:o}),s.jsxs("span",{className:"text-bambu-gray",children:[l," prints"]})]}),s.jsx("div",{className:"h-2 bg-bambu-dark rounded-full",children:s.jsx("div",{className:"h-full bg-bambu-green rounded-full transition-all",style:{width:`${c}%`}})})]},o)}),a&&s.jsxs("p",{className:"text-xs text-bambu-gray text-center pt-1",children:["+",n.length-r," more types"]})]})}function Tqe({printDates:t,size:e=2}){const n=e===1?3:e===2?6:12;return s.jsx(yqe,{printDates:t,months:n})}function Cqe({stats:t,printerMap:e}){return!t?.prints_by_printer||Object.keys(t.prints_by_printer).length===0?s.jsx("p",{className:"text-bambu-gray text-center py-4",children:"No printer data available"}):s.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:Object.entries(t.prints_by_printer).map(([n,r])=>s.jsxs("div",{className:"flex items-center gap-3 p-3 bg-bambu-dark rounded-lg",children:[s.jsx("div",{className:"p-2 bg-bambu-dark-tertiary rounded-lg",children:s.jsx(Ir,{className:"w-4 h-4 text-bambu-green"})}),s.jsxs("div",{children:[s.jsx("p",{className:"text-white font-medium text-sm",children:e.get(n)||`Printer ${n}`}),s.jsxs("p",{className:"text-xs text-bambu-gray",children:[r," prints"]})]})]},n))})}function kqe({archives:t,currency:e}){return!t||t.length===0?s.jsx("p",{className:"text-bambu-gray text-center py-4",children:"No print data available"}):s.jsx(_qe,{archives:t,currency:e})}function jqe({size:t=1}){const{data:e,isLoading:n}=ct({queryKey:["failureAnalysis"],queryFn:()=>pe.getFailureAnalysis({days:30})});if(n)return s.jsx("div",{className:"flex justify-center py-4",children:s.jsx(mt,{className:"w-6 h-6 text-bambu-green animate-spin"})});if(!e||e.total_prints===0)return s.jsx("p",{className:"text-bambu-gray text-center py-4",children:"No print data in the last 30 days"});const r=t===1?5:t===2?8:999,i=Object.entries(e.failures_by_reason).sort(([,l],[,c])=>c-l),a=i.slice(0,r),o=i.length>r;return s.jsxs("div",{className:`${t>=2?"flex gap-8":"space-y-4"}`,children:[s.jsxs("div",{className:t>=2?"flex-shrink-0":"",children:[s.jsx("div",{className:"flex items-center gap-4",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Cn,{className:`w-5 h-5 ${e.failure_rate>20?"text-red-400":e.failure_rate>10?"text-yellow-400":"text-bambu-green"}`}),s.jsxs("span",{className:`font-bold text-white ${t>=2?"text-3xl":"text-2xl"}`,children:[e.failure_rate.toFixed(1),"%"]})]})}),s.jsxs("div",{className:"text-sm text-bambu-gray mt-1",children:[e.failed_prints," / ",e.total_prints," prints failed"]}),e.trend&&e.trend.length>=2&&s.jsx("div",{className:`${t>=2?"mt-4":"mt-2 pt-2 border-t border-bambu-dark-tertiary"}`,children:s.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[s.jsx(iq,{className:`w-4 h-4 ${e.trend[e.trend.length-1].failure_rate0&&s.jsxs("div",{className:`flex-1 ${t>=2?"border-l border-bambu-dark-tertiary pl-8":"pt-2"}`,children:[s.jsx("p",{className:"text-xs text-bambu-gray font-medium mb-2",children:t>=2?"Failure Reasons":"Top Failure Reasons"}),s.jsx("div",{className:`${t===4?"grid grid-cols-2 gap-x-6 gap-y-1":"space-y-1"}`,children:a.map(([l,c])=>s.jsxs("div",{className:"flex items-center justify-between text-sm",children:[s.jsx("span",{className:`text-white truncate ${t===4?"max-w-[200px]":"max-w-[160px]"}`,children:l||"Unknown"}),s.jsx("span",{className:"text-bambu-gray ml-2",children:c})]},l))}),o&&s.jsxs("p",{className:"text-xs text-bambu-gray mt-2",children:["+",i.length-r," more reasons"]})]})]})}function Pqe(){const{showToast:t}=$n(),[e,n]=w.useState(!1),[r,i]=w.useState(!1),[a,o]=w.useState(0),[l,c]=w.useState(0);w.useEffect(()=>{const S=()=>{try{const E=localStorage.getItem("bambusy-dashboard-layout");if(E){const k=JSON.parse(E);c(k.hidden?.length||0)}}catch{c(0)}};S(),window.addEventListener("storage",S);const A=setInterval(S,500);return()=>{window.removeEventListener("storage",S),clearInterval(A)}},[a]);const{data:u,isLoading:d}=ct({queryKey:["archiveStats"],queryFn:pe.getArchiveStats}),{data:f}=ct({queryKey:["printers"],queryFn:pe.getPrinters}),{data:m}=ct({queryKey:["archives"],queryFn:()=>pe.getArchives(void 0,void 0,1e3,0)}),{data:g}=ct({queryKey:["settings"],queryFn:pe.getSettings}),x=async S=>{i(!1),n(!0);try{const{blob:A,filename:E}=await pe.exportStats({format:S,days:90}),k=URL.createObjectURL(A),C=document.createElement("a");C.href=k,C.download=E,C.click(),URL.revokeObjectURL(k),t("Export downloaded")}catch{t("Export failed","error")}finally{n(!1)}},y=g?.currency||"$",b=new Map(f?.map(S=>[String(S.id),S.name])||[]),v=m?.map(S=>S.created_at)||[];if(d)return s.jsx("div",{className:"p-4 md:p-8",children:s.jsx("div",{className:"text-center py-12 text-bambu-gray",children:"Loading statistics..."})});const M=[{id:"quick-stats",title:"Quick Stats",component:s.jsx(Mqe,{stats:u,currency:y}),defaultSize:2},{id:"success-rate",title:"Success Rate",component:S=>s.jsx(Nqe,{stats:u,printerMap:b,size:S}),defaultSize:1},{id:"time-accuracy",title:"Time Accuracy",component:S=>s.jsx(Eqe,{stats:u,printerMap:b,size:S}),defaultSize:1},{id:"filament-types",title:"Filament Types",component:S=>s.jsx(Aqe,{stats:u,size:S}),defaultSize:1},{id:"failure-analysis",title:"Failure Analysis (30 days)",component:S=>s.jsx(jqe,{size:S}),defaultSize:1},{id:"print-activity",title:"Print Activity",component:S=>s.jsx(Tqe,{printDates:v,size:S}),defaultSize:2},{id:"prints-by-printer",title:"Prints by Printer",component:s.jsx(Cqe,{stats:u,printerMap:b}),defaultSize:2},{id:"filament-trends",title:"Filament Usage Trends",component:s.jsx(kqe,{archives:m||[],currency:y}),defaultSize:4}];return s.jsxs("div",{className:"p-4 md:p-8",children:[s.jsxs("div",{className:"flex items-center justify-between mb-6",children:[s.jsxs("div",{children:[s.jsx("h1",{className:"text-2xl font-bold text-white",children:"Dashboard"}),s.jsx("p",{className:"text-bambu-gray",children:"Drag widgets to rearrange. Click the eye icon to hide."})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[l>0&&s.jsxs(Se,{variant:"secondary",onClick:()=>{window.dispatchEvent(new CustomEvent("toggle-hidden-panel"))},children:[s.jsx(_f,{className:"w-4 h-4"}),l," Hidden"]}),s.jsxs(Se,{variant:"secondary",onClick:()=>{localStorage.removeItem("bambusy-dashboard-layout"),o(S=>S+1),t("Layout reset")},children:[s.jsx(Vf,{className:"w-4 h-4"}),"Reset Layout"]}),s.jsxs("div",{className:"relative",children:[s.jsxs(Se,{variant:"secondary",onClick:()=>i(!r),disabled:e,children:[e?s.jsx(mt,{className:"w-4 h-4 animate-spin"}):s.jsx(dw,{className:"w-4 h-4"}),"Export Stats"]}),r&&s.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:[s.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:()=>x("csv"),children:[s.jsx(za,{className:"w-4 h-4"}),"Export as CSV"]}),s.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:()=>x("xlsx"),children:[s.jsx(dw,{className:"w-4 h-4"}),"Export as Excel"]})]})]})]})]}),s.jsx(Sqe,{widgets:M,storageKey:"bambusy-dashboard-layout",hideControls:!0},a)]})}function Rqe({plug:t,onEdit:e}){const n=tn(),{showToast:r}=$n(),[i,a]=w.useState(!1),[o,l]=w.useState(!1),[c,u]=w.useState(!1),[d,f]=w.useState(!1),{data:m,isLoading:g}=ct({queryKey:["smart-plug-status",t.id],queryFn:()=>pe.getSmartPlugStatus(t.id),refetchInterval:3e4}),{data:x}=ct({queryKey:["printers"],queryFn:pe.getPrinters}),y=x?.find(R=>R.id===t.printer_id),b=ft({mutationFn:R=>pe.controlSmartPlug(t.id,R),onMutate:async R=>{await n.cancelQueries({queryKey:["smart-plug-status",t.id]});const T=n.getQueryData(["smart-plug-status",t.id]),P=R==="on"?"ON":R==="off"||m?.state==="ON"?"OFF":"ON";return n.setQueryData(["smart-plug-status",t.id],F=>({...F,state:P})),{previousStatus:T}},onError:(R,T,P)=>{P?.previousStatus&&n.setQueryData(["smart-plug-status",t.id],P.previousStatus),r(`Failed to turn ${T} "${t.name}"`,"error")},onSettled:()=>{setTimeout(()=>{n.invalidateQueries({queryKey:["smart-plug-status",t.id]}),n.invalidateQueries({queryKey:["smart-plugs"]})},1e3)}}),v=ft({mutationFn:R=>pe.updateSmartPlug(t.id,R),onSuccess:()=>{n.invalidateQueries({queryKey:["smart-plugs"]}),t.printer_id&&n.invalidateQueries({queryKey:["smartPlugByPrinter",t.printer_id]})}}),M=ft({mutationFn:()=>pe.deleteSmartPlug(t.id),onSuccess:()=>{n.invalidateQueries({queryKey:["smart-plugs"]})}}),S=m?.state==="ON",A=m?.reachable??!1,E=b.isPending,C=(()=>{if(t.plug_type!=="tasmota"||!t.ip_address)return null;const R=t.ip_address;return t.username&&t.password?`http://${encodeURIComponent(t.username)}:${encodeURIComponent(t.password)}@${R}/`:`http://${R}/`})();return s.jsxs(s.Fragment,{children:[s.jsx(Mt,{className:"relative",children:s.jsxs(Et,{className:"p-4",children:[s.jsxs("div",{className:"flex items-start justify-between mb-3",children:[s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("div",{className:`p-2 rounded-lg ${A?S?"bg-bambu-green/20":"bg-bambu-dark":"bg-red-500/20"}`,children:t.plug_type==="homeassistant"?s.jsx(R2,{className:`w-5 h-5 ${A?S?"text-bambu-green":"text-bambu-gray":"text-red-400"}`}):s.jsx(Us,{className:`w-5 h-5 ${A?S?"text-bambu-green":"text-bambu-gray":"text-red-400"}`})}),s.jsxs("div",{children:[s.jsx("h3",{className:"font-medium text-white",children:t.name}),s.jsx("p",{className:"text-sm text-bambu-gray",children:t.plug_type==="homeassistant"?t.ha_entity_id:t.ip_address})]})]}),s.jsxs("div",{className:"flex flex-col items-end gap-1",children:[g?s.jsx(mt,{className:"w-4 h-4 text-bambu-gray animate-spin"}):A?s.jsxs("div",{className:"flex items-center gap-1 text-sm",children:[s.jsx(Dp,{className:"w-4 h-4 text-bambu-green"}),s.jsx("span",{className:S?"text-bambu-green":"text-bambu-gray",children:m?.state||"Unknown"})]}):s.jsxs("div",{className:"flex items-center gap-1 text-sm text-red-400",children:[s.jsx(Pg,{className:"w-4 h-4"}),s.jsx("span",{children:"Offline"})]}),C&&s.jsxs("a",{href:C,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:[s.jsx(Lr,{className:"w-3 h-3"}),"Admin"]})]})]}),y&&s.jsxs("div",{className:"mb-3 px-2 py-1.5 bg-bambu-dark rounded-lg",children:[s.jsx("span",{className:"text-xs text-bambu-gray",children:"Linked to: "}),s.jsx("span",{className:"text-sm text-white",children:y.name})]}),(t.power_alert_enabled||t.schedule_enabled)&&s.jsxs("div",{className:"flex flex-wrap gap-1.5 mb-3",children:[t.power_alert_enabled&&s.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:[s.jsx(tf,{className:"w-3 h-3"}),"Alerts"]}),t.schedule_enabled&&s.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:[s.jsx(Qr,{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}`]})]}),s.jsxs("div",{className:"flex gap-2 mb-3",children:[s.jsxs(Se,{size:"sm",variant:S?"primary":"secondary",disabled:!A||E,onClick:()=>l(!0),className:"flex-1",children:[E?s.jsx(mt,{className:"w-4 h-4 animate-spin"}):s.jsx(uu,{className:"w-4 h-4"}),"On"]}),s.jsxs(Se,{size:"sm",variant:S?"secondary":"primary",disabled:!A||E,onClick:()=>u(!0),className:"flex-1",children:[E?s.jsx(mt,{className:"w-4 h-4 animate-spin"}):s.jsx(I2,{className:"w-4 h-4"}),"Off"]})]}),s.jsxs("button",{onClick:()=>f(!d),className:"w-full flex items-center justify-between py-2 text-sm text-bambu-gray hover:text-white transition-colors",children:[s.jsxs("span",{className:"flex items-center gap-2",children:[s.jsx(Dd,{className:"w-4 h-4"}),"Automation Settings"]}),s.jsx("span",{children:d?"-":"+"})]}),d&&s.jsxs("div",{className:"pt-3 border-t border-bambu-dark-tertiary space-y-4",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(D2,{className:"w-4 h-4 text-bambu-green"}),s.jsxs("div",{children:[s.jsx("p",{className:"text-sm text-white",children:"Show in Switchbar"}),s.jsx("p",{className:"text-xs text-bambu-gray",children:"Quick access from sidebar"})]})]}),s.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[s.jsx("input",{type:"checkbox",checked:t.show_in_switchbar,onChange:R=>v.mutate({show_in_switchbar:R.target.checked}),className:"sr-only peer"}),s.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"})]})]}),s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{children:[s.jsx("p",{className:"text-sm text-white",children:"Enabled"}),s.jsx("p",{className:"text-xs text-bambu-gray",children:"Enable automation for this plug"})]}),s.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[s.jsx("input",{type:"checkbox",checked:t.enabled,onChange:R=>v.mutate({enabled:R.target.checked}),className:"sr-only peer"}),s.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"})]})]}),s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{children:[s.jsx("p",{className:"text-sm text-white",children:"Auto On"}),s.jsx("p",{className:"text-xs text-bambu-gray",children:"Turn on when print starts"})]}),s.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[s.jsx("input",{type:"checkbox",checked:t.auto_on,onChange:R=>v.mutate({auto_on:R.target.checked}),className:"sr-only peer"}),s.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"})]})]}),s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{children:[s.jsx("p",{className:"text-sm text-white",children:"Auto Off"}),s.jsx("p",{className:"text-xs text-bambu-gray",children:"Turn off when print completes (one-shot)"})]}),s.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[s.jsx("input",{type:"checkbox",checked:t.auto_off,onChange:R=>v.mutate({auto_off:R.target.checked}),className:"sr-only peer"}),s.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&&s.jsxs("div",{className:"space-y-3 pl-4 border-l-2 border-bambu-dark-tertiary",children:[s.jsxs("div",{children:[s.jsx("p",{className:"text-sm text-white mb-2",children:"Turn Off Delay Mode"}),s.jsxs("div",{className:"flex gap-2",children:[s.jsxs("button",{onClick:()=>v.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:[s.jsx(Gn,{className:"w-4 h-4"}),"Time"]}),s.jsxs("button",{onClick:()=>v.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:[s.jsx(U2,{className:"w-4 h-4"}),"Temp"]})]})]}),t.off_delay_mode==="time"?s.jsxs("div",{children:[s.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Delay (minutes)"}),s.jsx("input",{type:"number",min:"1",max:"60",value:t.off_delay_minutes,onChange:R=>v.mutate({off_delay_minutes:parseInt(R.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"})]}):s.jsxs("div",{children:[s.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Temperature threshold (C)"}),s.jsx("input",{type:"number",min:"30",max:"100",value:t.off_temp_threshold,onChange:R=>v.mutate({off_temp_threshold:parseInt(R.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"}),s.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Turns off when nozzle cools below this temperature"})]})]}),s.jsxs("div",{className:"flex gap-2 pt-2",children:[s.jsxs(Se,{size:"sm",variant:"secondary",onClick:()=>e(t),className:"flex-1",children:[s.jsx(L2,{className:"w-4 h-4"}),"Edit"]}),s.jsx(Se,{size:"sm",variant:"secondary",onClick:()=>a(!0),className:"text-red-400 hover:text-red-300",children:s.jsx(an,{className:"w-4 h-4"})})]})]})]})}),i&&s.jsx(Ln,{title:"Delete Smart Plug",message:`Are you sure you want to delete "${t.name}"? This cannot be undone.`,confirmText:"Delete",variant:"danger",onConfirm:()=>{M.mutate(),a(!1)},onCancel:()=>a(!1)}),o&&s.jsx(Ln,{title:"Turn On Smart Plug",message:`Are you sure you want to turn on "${t.name}"?`,confirmText:"Turn On",variant:"default",onConfirm:()=>{b.mutate("on"),l(!1)},onCancel:()=>l(!1)}),c&&s.jsx(Ln,{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:()=>{b.mutate("off"),u(!1)},onCancel:()=>u(!1)})]})}function Dqe({plug:t,onClose:e}){const n=tn(),r=!!t,[i,a]=w.useState(t?.plug_type||"tasmota"),[o,l]=w.useState(t?.name||""),[c,u]=w.useState(t?.ip_address||""),[d,f]=w.useState(t?.username||""),[m,g]=w.useState(t?.password||""),[x,y]=w.useState(t?.ha_entity_id||""),[b,v]=w.useState(t?.ha_power_entity||""),[M,S]=w.useState(t?.ha_energy_today_entity||""),[A,E]=w.useState(t?.ha_energy_total_entity||""),[k,C]=w.useState(""),[R,T]=w.useState(""),[P,F]=w.useState(!1),L=w.useRef(null),[X,D]=w.useState(""),[K,Y]=w.useState(!1),q=w.useRef(null),[Z,re]=w.useState(""),[oe,B]=w.useState(!1),G=w.useRef(null),[J,te]=w.useState(""),[ae,de]=w.useState(!1),fe=w.useRef(null),[Ae,ge]=w.useState(t?.printer_id||null),[Me,je]=w.useState(null),[ne,Ke]=w.useState(null),[$,z]=w.useState(t?.power_alert_enabled||!1),[W,U]=w.useState(t?.power_alert_high?.toString()||""),[V,Q]=w.useState(t?.power_alert_low?.toString()||""),[Ee,Ce]=w.useState(t?.schedule_enabled||!1),[Ne,H]=w.useState(t?.schedule_on_time||""),[O,ie]=w.useState(t?.schedule_off_time||""),[ye,_e]=w.useState(t?.show_in_switchbar||!1),[le,ke]=w.useState(!1),[Oe,Ze]=w.useState({scanned:0,total:0}),[ht,We]=w.useState([]),he=w.useRef(null),{data:rt}=ct({queryKey:["printers"],queryFn:pe.getPrinters}),{data:qe}=ct({queryKey:["smart-plugs"],queryFn:pe.getSmartPlugs}),{data:Je}=ct({queryKey:["settings"],queryFn:pe.getSettings}),ot=!!(Je?.ha_enabled&&Je?.ha_url&&Je?.ha_token);w.useEffect(()=>{const pt=setTimeout(()=>{T(k)},300);return()=>clearTimeout(pt)},[k]),w.useEffect(()=>{const pt=$t=>{L.current&&!L.current.contains($t.target)&&F(!1),q.current&&!q.current.contains($t.target)&&Y(!1),G.current&&!G.current.contains($t.target)&&B(!1),fe.current&&!fe.current.contains($t.target)&&de(!1)};return document.addEventListener("mousedown",pt),()=>document.removeEventListener("mousedown",pt)},[]);const{data:se,isLoading:$e,error:be}=ct({queryKey:["ha-entities",R],queryFn:()=>pe.getHAEntities(R||void 0),enabled:i==="homeassistant"&&ot,retry:!1,staleTime:0}),{data:Fe}=ct({queryKey:["ha-sensor-entities"],queryFn:pe.getHASensorEntities,enabled:i==="homeassistant"&&ot,retry:!1,staleTime:0});w.useEffect(()=>{const pt=$t=>{$t.key==="Escape"&&e()};return window.addEventListener("keydown",pt),()=>{window.removeEventListener("keydown",pt),he.current&&clearInterval(he.current)}},[e]);const De=async()=>{ke(!0),We([]),Ze({scanned:0,total:0}),Ke(null);try{await pe.startTasmotaScan();const pt=async()=>{try{const $t=await pe.getTasmotaScanStatus();Ze({scanned:$t.scanned,total:$t.total});const qt=await pe.getDiscoveredTasmotaDevices();We(qt),$t.running||(ke(!1),he.current&&(clearInterval(he.current),he.current=null))}catch($t){console.error("Polling error:",$t)}};await pt(),he.current=setInterval(pt,500)}catch(pt){ke(!1);const $t=pt instanceof Error?pt.message:typeof pt=="string"?pt:JSON.stringify(pt);Ke($t||"Failed to start scan")}},ve=async()=>{try{await pe.stopTasmotaScan()}catch{}ke(!1),he.current&&(clearInterval(he.current),he.current=null)},He=pt=>{u(pt.ip_address),l(pt.name),je(null)},dt=ft({mutationFn:()=>pe.testSmartPlugConnection(c,d||null,m||null),onSuccess:pt=>{je(pt),Ke(null),!o&&pt.device_name&&l(pt.device_name)},onError:pt=>{je(null),Ke(pt.message)}}),kt=ft({mutationFn:pt=>pe.createSmartPlug(pt),onSuccess:()=>{n.invalidateQueries({queryKey:["smart-plugs"]}),e()},onError:pt=>{Ke(pt.message)}}),jt=ft({mutationFn:pt=>pe.updateSmartPlug(t.id,pt),onSuccess:()=>{n.invalidateQueries({queryKey:["smart-plugs"]}),e()},onError:pt=>{Ke(pt.message)}}),Zt=rt?.filter(pt=>!qe?.some(qt=>qt.printer_id===pt.id&&qt.id!==t?.id)),Rt=pt=>{if(pt.preventDefault(),Ke(null),!o.trim()){Ke("Name is required");return}if(i==="tasmota"&&!c.trim()){Ke("IP address is required for Tasmota plugs");return}if(i==="homeassistant"&&!x){Ke("Entity is required for Home Assistant plugs");return}const $t={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"&&b||null,ha_energy_today_entity:i==="homeassistant"&&M||null,ha_energy_total_entity:i==="homeassistant"&&A||null,username:i==="tasmota"&&d.trim()||null,password:i==="tasmota"&&m.trim()||null,printer_id:Ae,power_alert_enabled:$,power_alert_high:W?parseFloat(W):null,power_alert_low:V?parseFloat(V):null,schedule_enabled:Ee,schedule_on_time:Ne||null,schedule_off_time:O||null,show_in_switchbar:ye};r?jt.mutate($t):kt.mutate($t)},nn=kt.isPending||jt.isPending;return s.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",onClick:e,children:s.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:pt=>pt.stopPropagation(),children:[s.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary flex-shrink-0",children:[s.jsx("h2",{className:"text-lg font-semibold text-white",children:r?"Edit Smart Plug":"Add Smart Plug"}),s.jsx("button",{onClick:e,className:"text-bambu-gray hover:text-white transition-colors",children:s.jsx(Ut,{className:"w-5 h-5"})})]}),s.jsxs("form",{onSubmit:Rt,className:"p-6 space-y-4 overflow-y-auto",children:[ne&&s.jsx("div",{className:"p-3 bg-red-500/20 border border-red-500/50 rounded-lg text-sm text-red-400",children:ne}),!r&&s.jsxs("div",{className:"flex gap-2 mb-2",children:[s.jsxs("button",{type:"button",onClick:()=>{a("tasmota"),je(null),Ke(null)},className:`flex-1 flex items-center justify-center gap-2 px-4 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:[s.jsx(Us,{className:"w-4 h-4"}),"Tasmota"]}),s.jsxs("button",{type:"button",onClick:()=>{a("homeassistant"),je(null),Ke(null)},className:`flex-1 flex items-center justify-center gap-2 px-4 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:[s.jsx(R2,{className:"w-4 h-4"}),"Home Assistant"]})]}),!r&&i==="tasmota"&&s.jsxs("div",{className:"space-y-3",children:[le?s.jsxs(Se,{type:"button",variant:"secondary",onClick:ve,className:"w-full",children:[s.jsx(Ut,{className:"w-4 h-4"}),"Stop Scanning"]}):s.jsxs(Se,{type:"button",variant:"primary",onClick:De,className:"w-full",children:[s.jsx(xa,{className:"w-4 h-4"}),"Discover Tasmota Devices"]}),le&&Oe.total>0&&s.jsxs("div",{className:"space-y-1",children:[s.jsxs("div",{className:"flex justify-between text-xs text-bambu-gray",children:[s.jsx("span",{children:"Scanning network..."}),s.jsxs("span",{children:[Oe.scanned," / ",Oe.total]})]}),s.jsx("div",{className:"w-full bg-bambu-dark-tertiary rounded-full h-2",children:s.jsx("div",{className:"bg-bambu-green h-2 rounded-full transition-all duration-300",style:{width:`${Oe.scanned/Oe.total*100}%`}})})]}),ht.length>0&&s.jsxs("div",{className:"space-y-2",children:[s.jsxs("p",{className:"text-xs text-bambu-gray",children:["Found ",ht.length," device(s) - click to select:"]}),s.jsx("div",{className:"max-h-40 overflow-y-auto space-y-1",children:ht.map(pt=>s.jsxs("button",{type:"button",onClick:()=>He(pt),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:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Us,{className:"w-4 h-4 text-bambu-green"}),s.jsxs("div",{children:[s.jsx("p",{className:"text-sm text-white",children:pt.name}),s.jsx("p",{className:"text-xs text-bambu-gray",children:pt.ip_address})]})]}),pt.state&&s.jsxs("span",{className:`flex items-center gap-1 text-xs ${pt.state==="ON"?"text-bambu-green":"text-bambu-gray"}`,children:[s.jsx(uu,{className:"w-3 h-3"}),pt.state]})]},pt.ip_address))})]}),!le&&ht.length===0&&Oe.total>0&&s.jsx("p",{className:"text-xs text-bambu-gray text-center py-2",children:"No Tasmota devices found on your network"})]}),i==="homeassistant"&&s.jsxs("div",{className:"space-y-3",children:[!ot&&s.jsxs("div",{className:"space-y-3",children:[s.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"," ",s.jsx("span",{className:"font-medium",children:"Settings → Network → Home Assistant"})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1 opacity-50",children:"Select Entity *"}),s.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:s.jsx("option",{children:"Choose an entity..."})})]})]}),ot&&s.jsxs(s.Fragment,{children:[$e&&s.jsxs("div",{className:"flex items-center justify-center py-4 text-bambu-gray",children:[s.jsx(mt,{className:"w-5 h-5 animate-spin mr-2"}),"Loading entities..."]}),be&&s.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: ",be.message]}),(()=>{const pt=qe?.filter(wt=>wt.ha_entity_id&&wt.id!==t?.id).map(wt=>wt.ha_entity_id)||[],$t=(se||[]).filter(wt=>!pt.includes(wt.entity_id)),qt=se?.find(wt=>wt.entity_id===x);return s.jsxs("div",{ref:L,className:"relative",children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Select Entity *"}),s.jsxs("div",{className:"relative",children:[s.jsx(xa,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"}),s.jsx("input",{type:"text",value:P?k:qt?`${qt.friendly_name} (${qt.entity_id})`:"",onChange:wt=>{C(wt.target.value),P||F(!0)},onFocus:()=>{F(!0),C("")},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&&!P&&s.jsx("button",{type:"button",onClick:()=>{y(""),C("")},className:"absolute right-2 top-1/2 -translate-y-1/2 p-1 hover:bg-bambu-dark-tertiary rounded",children:s.jsx(Ut,{className:"w-4 h-4 text-bambu-gray hover:text-white"})}),$e&&s.jsx(mt,{className:"absolute right-2 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray animate-spin"})]}),P&&s.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:[$e&&s.jsxs("div",{className:"px-3 py-2 text-sm text-bambu-gray flex items-center gap-2",children:[s.jsx(mt,{className:"w-4 h-4 animate-spin"}),"Loading..."]}),!$e&&$t.length===0&&s.jsx("div",{className:"px-3 py-2 text-sm text-bambu-gray",children:R?`No entities found matching "${R}"`:"No entities available"}),!$e&&$t.map(wt=>s.jsxs("button",{type:"button",onClick:()=>{y(wt.entity_id),F(!1),C(""),o||l(wt.friendly_name)},className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary transition-colors ${wt.entity_id===x?"bg-bambu-green/20 text-bambu-green":"text-white"}`,children:[s.jsx("div",{className:"font-medium",children:wt.friendly_name}),s.jsxs("div",{className:"text-xs text-bambu-gray flex items-center justify-between",children:[s.jsx("span",{children:wt.entity_id}),s.jsx("span",{className:wt.state==="on"?"text-bambu-green":"",children:wt.state})]})]},wt.entity_id))]}),s.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:R?`Searching all entities (${$t.length} found)`:`Showing switch, light, input_boolean (${$t.length} available)`})]})})(),x&&Fe&&Fe.length>0&&s.jsxs("div",{className:"border-t border-bambu-dark-tertiary pt-4 mt-4 space-y-3",children:[s.jsxs("div",{children:[s.jsx("p",{className:"text-white font-medium mb-1",children:"Energy Monitoring (Optional)"}),s.jsx("p",{className:"text-xs text-bambu-gray mb-3",children:"Search and select sensors that provide power/energy data."})]}),(()=>{const pt=Fe.filter(wt=>wt.unit_of_measurement==="W"||wt.unit_of_measurement==="kW"||wt.unit_of_measurement==="mW"),$t=X?pt.filter(wt=>wt.entity_id.toLowerCase().includes(X.toLowerCase())||wt.friendly_name.toLowerCase().includes(X.toLowerCase())):pt,qt=Fe.find(wt=>wt.entity_id===b);return s.jsxs("div",{ref:q,className:"relative",children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Power Sensor (W)"}),s.jsxs("div",{className:"relative",children:[s.jsx(xa,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"}),s.jsx("input",{type:"text",value:K?X:qt?`${qt.friendly_name} (${qt.state} ${qt.unit_of_measurement})`:"",onChange:wt=>{D(wt.target.value),K||Y(!0)},onFocus:()=>{Y(!0),D("")},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"}),b&&!K&&s.jsx("button",{type:"button",onClick:()=>{v(""),D("")},className:"absolute right-2 top-1/2 -translate-y-1/2 p-1 hover:bg-bambu-dark-tertiary rounded",children:s.jsx(Ut,{className:"w-4 h-4 text-bambu-gray hover:text-white"})})]}),K&&s.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:[s.jsx("button",{type:"button",onClick:()=>{v(""),Y(!1),D("")},className:"w-full px-3 py-2 text-left text-sm text-bambu-gray hover:bg-bambu-dark-tertiary",children:"None"}),$t.map(wt=>s.jsxs("button",{type:"button",onClick:()=>{v(wt.entity_id),Y(!1),D("")},className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary ${wt.entity_id===b?"bg-bambu-green/20 text-bambu-green":"text-white"}`,children:[s.jsx("div",{className:"font-medium",children:wt.friendly_name}),s.jsxs("div",{className:"text-xs text-bambu-gray",children:[wt.entity_id," • ",wt.state," ",wt.unit_of_measurement]})]},wt.entity_id)),$t.length===0&&s.jsx("div",{className:"px-3 py-2 text-sm text-bambu-gray",children:"No matching sensors"})]})]})})(),(()=>{const pt=Fe.filter(wt=>wt.unit_of_measurement==="kWh"||wt.unit_of_measurement==="Wh"||wt.unit_of_measurement==="MWh"),$t=Z?pt.filter(wt=>wt.entity_id.toLowerCase().includes(Z.toLowerCase())||wt.friendly_name.toLowerCase().includes(Z.toLowerCase())):pt,qt=Fe.find(wt=>wt.entity_id===M);return s.jsxs("div",{ref:G,className:"relative",children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Energy Today (kWh)"}),s.jsxs("div",{className:"relative",children:[s.jsx(xa,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"}),s.jsx("input",{type:"text",value:oe?Z:qt?`${qt.friendly_name} (${qt.state} ${qt.unit_of_measurement})`:"",onChange:wt=>{re(wt.target.value),oe||B(!0)},onFocus:()=>{B(!0),re("")},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"}),M&&!oe&&s.jsx("button",{type:"button",onClick:()=>{S(""),re("")},className:"absolute right-2 top-1/2 -translate-y-1/2 p-1 hover:bg-bambu-dark-tertiary rounded",children:s.jsx(Ut,{className:"w-4 h-4 text-bambu-gray hover:text-white"})})]}),oe&&s.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:[s.jsx("button",{type:"button",onClick:()=>{S(""),B(!1),re("")},className:"w-full px-3 py-2 text-left text-sm text-bambu-gray hover:bg-bambu-dark-tertiary",children:"None"}),$t.map(wt=>s.jsxs("button",{type:"button",onClick:()=>{S(wt.entity_id),B(!1),re("")},className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary ${wt.entity_id===M?"bg-bambu-green/20 text-bambu-green":"text-white"}`,children:[s.jsx("div",{className:"font-medium",children:wt.friendly_name}),s.jsxs("div",{className:"text-xs text-bambu-gray",children:[wt.entity_id," • ",wt.state," ",wt.unit_of_measurement]})]},wt.entity_id)),$t.length===0&&s.jsx("div",{className:"px-3 py-2 text-sm text-bambu-gray",children:"No matching sensors"})]})]})})(),(()=>{const pt=Fe.filter(wt=>wt.unit_of_measurement==="kWh"||wt.unit_of_measurement==="Wh"||wt.unit_of_measurement==="MWh"),$t=J?pt.filter(wt=>wt.entity_id.toLowerCase().includes(J.toLowerCase())||wt.friendly_name.toLowerCase().includes(J.toLowerCase())):pt,qt=Fe.find(wt=>wt.entity_id===A);return s.jsxs("div",{ref:fe,className:"relative",children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Total Energy (kWh)"}),s.jsxs("div",{className:"relative",children:[s.jsx(xa,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"}),s.jsx("input",{type:"text",value:ae?J:qt?`${qt.friendly_name} (${qt.state} ${qt.unit_of_measurement})`:"",onChange:wt=>{te(wt.target.value),ae||de(!0)},onFocus:()=>{de(!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"}),A&&!ae&&s.jsx("button",{type:"button",onClick:()=>{E(""),te("")},className:"absolute right-2 top-1/2 -translate-y-1/2 p-1 hover:bg-bambu-dark-tertiary rounded",children:s.jsx(Ut,{className:"w-4 h-4 text-bambu-gray hover:text-white"})})]}),ae&&s.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:[s.jsx("button",{type:"button",onClick:()=>{E(""),de(!1),te("")},className:"w-full px-3 py-2 text-left text-sm text-bambu-gray hover:bg-bambu-dark-tertiary",children:"None"}),$t.map(wt=>s.jsxs("button",{type:"button",onClick:()=>{E(wt.entity_id),de(!1),te("")},className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary ${wt.entity_id===A?"bg-bambu-green/20 text-bambu-green":"text-white"}`,children:[s.jsx("div",{className:"font-medium",children:wt.friendly_name}),s.jsxs("div",{className:"text-xs text-bambu-gray",children:[wt.entity_id," • ",wt.state," ",wt.unit_of_measurement]})]},wt.entity_id)),$t.length===0&&s.jsx("div",{className:"px-3 py-2 text-sm text-bambu-gray",children:"No matching sensors"})]})]})})()]})]})]}),i==="tasmota"&&s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"IP Address *"}),s.jsxs("div",{className:"flex gap-2",children:[s.jsx("input",{type:"text",value:c,onChange:pt=>{u(pt.target.value),je(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"}),s.jsxs(Se,{type:"button",variant:"secondary",onClick:()=>dt.mutate(),disabled:!c.trim()||dt.isPending,children:[dt.isPending?s.jsx(mt,{className:"w-4 h-4 animate-spin"}):s.jsx(Dp,{className:"w-4 h-4"}),"Test"]})]})]}),i==="tasmota"&&Me&&s.jsx("div",{className:`p-3 rounded-lg flex items-center gap-2 ${Me.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:Me.success?s.jsxs(s.Fragment,{children:[s.jsx(Dn,{className:"w-5 h-5"}),s.jsxs("div",{children:[s.jsx("p",{className:"font-medium",children:"Connected!"}),s.jsxs("p",{className:"text-sm opacity-80",children:[Me.device_name&&`Device: ${Me.device_name} - `,"State: ",Me.state]})]})]}):s.jsxs(s.Fragment,{children:[s.jsx(Pg,{className:"w-5 h-5"}),s.jsx("span",{children:"Connection failed"})]})}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Name *"}),s.jsx("input",{type:"text",value:o,onChange:pt=>l(pt.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"&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Username"}),s.jsx("input",{type:"text",value:d,onChange:pt=>f(pt.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"})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Password"}),s.jsx("input",{type:"password",value:m,onChange:pt=>g(pt.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"})]})]}),s.jsx("p",{className:"text-xs text-bambu-gray -mt-2",children:"Leave empty if your Tasmota device doesn't require authentication"})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Link to Printer"}),s.jsxs("select",{value:Ae??"",onChange:pt=>ge(pt.target.value?Number(pt.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:[s.jsx("option",{value:"",children:"No printer (manual control only)"}),Zt?.map(pt=>s.jsx("option",{value:pt.id,children:pt.name},pt.id))]}),s.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Linking enables automatic on/off when prints start/complete"})]}),s.jsxs("div",{className:"border-t border-bambu-dark-tertiary pt-4",children:[s.jsxs("div",{className:"flex items-center justify-between mb-3",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(tf,{className:"w-4 h-4 text-bambu-green"}),s.jsx("span",{className:"text-white font-medium",children:"Power Alerts"})]}),s.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[s.jsx("input",{type:"checkbox",checked:$,onChange:pt=>z(pt.target.checked),className:"sr-only peer"}),s.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"})]})]}),$&&s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Alert if above (W)"}),s.jsx("input",{type:"number",value:W,onChange:pt=>U(pt.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"})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Alert if below (W)"}),s.jsx("input",{type:"number",value:V,onChange:pt=>Q(pt.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"})]})]}),s.jsx("p",{className:"text-xs text-bambu-gray",children:"Get notified when power consumption crosses these thresholds. Leave empty to disable that direction."})]})]}),s.jsxs("div",{className:"border-t border-bambu-dark-tertiary pt-4",children:[s.jsxs("div",{className:"flex items-center justify-between mb-3",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Gn,{className:"w-4 h-4 text-bambu-green"}),s.jsx("span",{className:"text-white font-medium",children:"Daily Schedule"})]}),s.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[s.jsx("input",{type:"checkbox",checked:Ee,onChange:pt=>Ce(pt.target.checked),className:"sr-only peer"}),s.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"})]})]}),Ee&&s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Turn On at"}),s.jsx("input",{type:"time",value:Ne,onChange:pt=>H(pt.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"})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Turn Off at"}),s.jsx("input",{type:"time",value:O,onChange:pt=>ie(pt.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"})]})]}),s.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."})]})]}),s.jsx("div",{className:"border-t border-bambu-dark-tertiary pt-4",children:s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(D2,{className:"w-4 h-4 text-bambu-green"}),s.jsxs("div",{children:[s.jsx("span",{className:"text-white font-medium",children:"Show in Switchbar"}),s.jsx("p",{className:"text-xs text-bambu-gray",children:"Quick access from sidebar"})]})]}),s.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[s.jsx("input",{type:"checkbox",checked:ye,onChange:pt=>_e(pt.target.checked),className:"sr-only peer"}),s.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"})]})]})}),s.jsxs("div",{className:"flex gap-3 pt-2",children:[s.jsx(Se,{type:"button",variant:"secondary",onClick:e,className:"flex-1",children:"Cancel"}),s.jsxs(Se,{type:"submit",disabled:nn,className:"flex-1",children:[nn?s.jsx(mt,{className:"w-4 h-4 animate-spin"}):s.jsx(ds,{className:"w-4 h-4"}),r?"Save":"Add"]})]})]})]})})}function Vn({checked:t,onChange:e,disabled:n}){const r=i=>{i.preventDefault(),i.stopPropagation(),n||e(!t)};return s.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:s.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 Oqe={callmebot:"CallMeBot/WhatsApp",ntfy:"ntfy",pushover:"Pushover",telegram:"Telegram",email:"Email",discord:"Discord",webhook:"Webhook"};function Lqe({provider:t,onEdit:e}){const n=tn(),[r,i]=w.useState(!1),[a,o]=w.useState(!1),[l,c]=w.useState(null),{data:u}=ct({queryKey:["printers"],queryFn:pe.getPrinters}),d=u?.find(y=>y.id===t.printer_id),f=ft({mutationFn:y=>pe.updateNotificationProvider(t.id,y),onSuccess:()=>{n.invalidateQueries({queryKey:["notification-providers"]})}}),m=ft({mutationFn:()=>pe.deleteNotificationProvider(t.id),onSuccess:()=>{n.invalidateQueries({queryKey:["notification-providers"]})}}),g=ft({mutationFn:()=>pe.testNotificationProvider(t.id),onSuccess:y=>{c(y),n.invalidateQueries({queryKey:["notification-providers"]})},onError:y=>{c({success:!1,message:y.message})}}),x=y=>y||"";return s.jsxs(s.Fragment,{children:[s.jsx(Mt,{className:"relative",children:s.jsxs(Et,{className:"p-4",children:[s.jsxs("div",{className:"flex items-start justify-between mb-3",children:[s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("div",{className:`p-2 rounded-lg ${t.enabled?"bg-bambu-green/20":"bg-bambu-dark"}`,children:s.jsx(tf,{className:`w-5 h-5 ${t.enabled?"text-bambu-green":"text-bambu-gray"}`})}),s.jsxs("div",{children:[s.jsx("h3",{className:"font-medium text-white",children:t.name}),s.jsx("p",{className:"text-sm text-bambu-gray",children:Oqe[t.provider_type]||t.provider_type})]})]}),s.jsxs("div",{className:"flex items-center gap-3",children:[t.last_success&&s.jsxs("span",{className:"text-xs text-bambu-green hidden sm:inline",children:["Last: ",Jp(t.last_success)]}),t.last_error&&t.last_error_at&&(!t.last_success||(mi(t.last_error_at)?.getTime()||0)>(mi(t.last_success)?.getTime()||0))&&s.jsx("span",{className:"text-xs text-red-400",title:t.last_error,children:"Error"}),s.jsx(Vn,{checked:t.enabled,onChange:y=>f.mutate({enabled:y})})]})]}),d&&s.jsxs("div",{className:"mb-3 px-2 py-1.5 bg-bambu-dark rounded-lg",children:[s.jsx("span",{className:"text-xs text-bambu-gray",children:"Printer: "}),s.jsx("span",{className:"text-sm text-white",children:d.name})]}),!d&&!t.printer_id&&s.jsx("div",{className:"mb-3 px-2 py-1.5 bg-bambu-dark rounded-lg",children:s.jsx("span",{className:"text-xs text-bambu-gray",children:"All printers"})}),s.jsxs("div",{className:"mb-3 flex flex-wrap gap-1",children:[t.on_print_start&&s.jsx("span",{className:"px-2 py-0.5 bg-blue-500/20 text-blue-400 text-xs rounded",children:"Start"}),t.on_print_complete&&s.jsx("span",{className:"px-2 py-0.5 bg-bambu-green/20 text-bambu-green text-xs rounded",children:"Complete"}),t.on_print_failed&&s.jsx("span",{className:"px-2 py-0.5 bg-red-500/20 text-red-400 text-xs rounded",children:"Failed"}),t.on_print_stopped&&s.jsx("span",{className:"px-2 py-0.5 bg-orange-500/20 text-orange-400 text-xs rounded",children:"Stopped"}),t.on_print_progress&&s.jsx("span",{className:"px-2 py-0.5 bg-yellow-500/20 text-yellow-400 text-xs rounded",children:"Progress"}),t.on_printer_offline&&s.jsx("span",{className:"px-2 py-0.5 bg-gray-500/20 text-gray-400 text-xs rounded",children:"Offline"}),t.on_printer_error&&s.jsx("span",{className:"px-2 py-0.5 bg-rose-500/20 text-rose-400 text-xs rounded",children:"Error"}),t.on_filament_low&&s.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&&s.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&&s.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&&s.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&&s.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&&s.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&&s.jsxs("span",{className:"px-2 py-0.5 bg-indigo-500/20 text-indigo-400 text-xs rounded flex items-center gap-1",children:[s.jsx(fw,{className:"w-3 h-3"}),"Quiet"]}),t.daily_digest_enabled&&s.jsxs("span",{className:"px-2 py-0.5 bg-emerald-500/20 text-emerald-400 text-xs rounded flex items-center gap-1",children:[s.jsx(Qr,{className:"w-3 h-3"}),"Digest ",t.daily_digest_time]})]}),s.jsx("div",{className:"mb-3",children:s.jsxs(Se,{size:"sm",variant:"secondary",disabled:g.isPending,onClick:()=>{c(null),g.mutate()},className:"w-full",children:[g.isPending?s.jsx(mt,{className:"w-4 h-4 animate-spin"}):s.jsx(iD,{className:"w-4 h-4"}),"Send Test Notification"]})}),l&&s.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?s.jsx(Dn,{className:"w-4 h-4"}):s.jsx(qi,{className:"w-4 h-4"}),s.jsx("span",{children:l.message})]}),s.jsxs("button",{onClick:()=>o(!a),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:[s.jsxs("span",{className:"flex items-center gap-2",children:[s.jsx(Dd,{className:"w-4 h-4"}),"Event Settings"]}),a?s.jsx(Jc,{className:"w-4 h-4"}):s.jsx(Ji,{className:"w-4 h-4"})]}),a&&s.jsxs("div",{className:"pt-3 border-t border-bambu-dark-tertiary space-y-4",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{children:[s.jsx("p",{className:"text-sm text-white",children:"Enabled"}),s.jsx("p",{className:"text-xs text-bambu-gray",children:"Send notifications from this provider"})]}),s.jsx(Vn,{checked:t.enabled,onChange:y=>f.mutate({enabled:y})})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsx("p",{className:"text-xs text-bambu-gray uppercase tracking-wide",children:"Print Events"}),s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("p",{className:"text-sm text-white",children:"Print Started"}),s.jsx(Vn,{checked:t.on_print_start,onChange:y=>f.mutate({on_print_start:y})})]}),s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("p",{className:"text-sm text-white",children:"Print Completed"}),s.jsx(Vn,{checked:t.on_print_complete,onChange:y=>f.mutate({on_print_complete:y})})]}),s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("p",{className:"text-sm text-white",children:"Print Failed"}),s.jsx(Vn,{checked:t.on_print_failed,onChange:y=>f.mutate({on_print_failed:y})})]}),s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("p",{className:"text-sm text-white",children:"Print Stopped"}),s.jsx(Vn,{checked:t.on_print_stopped,onChange:y=>f.mutate({on_print_stopped:y})})]}),s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{children:[s.jsx("p",{className:"text-sm text-white",children:"Progress Milestones"}),s.jsx("p",{className:"text-xs text-bambu-gray",children:"Notify at 25%, 50%, 75%"})]}),s.jsx(Vn,{checked:t.on_print_progress,onChange:y=>f.mutate({on_print_progress:y})})]})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsx("p",{className:"text-xs text-bambu-gray uppercase tracking-wide",children:"Printer Status"}),s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("p",{className:"text-sm text-white",children:"Printer Offline"}),s.jsx(Vn,{checked:t.on_printer_offline,onChange:y=>f.mutate({on_printer_offline:y})})]}),s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("p",{className:"text-sm text-white",children:"Printer Error"}),s.jsx(Vn,{checked:t.on_printer_error,onChange:y=>f.mutate({on_printer_error:y})})]}),s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("p",{className:"text-sm text-white",children:"Low Filament"}),s.jsx(Vn,{checked:t.on_filament_low,onChange:y=>f.mutate({on_filament_low:y})})]}),s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{children:[s.jsx("p",{className:"text-sm text-white",children:"Maintenance Due"}),s.jsx("p",{className:"text-xs text-bambu-gray",children:"Notify when maintenance is needed"})]}),s.jsx(Vn,{checked:t.on_maintenance_due??!1,onChange:y=>f.mutate({on_maintenance_due:y})})]})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsx("p",{className:"text-xs text-bambu-gray uppercase tracking-wide",children:"AMS Alarms"}),s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{children:[s.jsx("p",{className:"text-sm text-white",children:"AMS Humidity High"}),s.jsx("p",{className:"text-xs text-bambu-gray",children:"Regular AMS humidity exceeds threshold"})]}),s.jsx(Vn,{checked:t.on_ams_humidity_high??!1,onChange:y=>f.mutate({on_ams_humidity_high:y})})]}),s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{children:[s.jsx("p",{className:"text-sm text-white",children:"AMS Temperature High"}),s.jsx("p",{className:"text-xs text-bambu-gray",children:"Regular AMS temperature exceeds threshold"})]}),s.jsx(Vn,{checked:t.on_ams_temperature_high??!1,onChange:y=>f.mutate({on_ams_temperature_high:y})})]})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsx("p",{className:"text-xs text-bambu-gray uppercase tracking-wide",children:"AMS-HT Alarms"}),s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{children:[s.jsx("p",{className:"text-sm text-white",children:"AMS-HT Humidity High"}),s.jsx("p",{className:"text-xs text-bambu-gray",children:"AMS-HT humidity exceeds threshold"})]}),s.jsx(Vn,{checked:t.on_ams_ht_humidity_high??!1,onChange:y=>f.mutate({on_ams_ht_humidity_high:y})})]}),s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{children:[s.jsx("p",{className:"text-sm text-white",children:"AMS-HT Temperature High"}),s.jsx("p",{className:"text-xs text-bambu-gray",children:"AMS-HT temperature exceeds threshold"})]}),s.jsx(Vn,{checked:t.on_ams_ht_temperature_high??!1,onChange:y=>f.mutate({on_ams_ht_temperature_high:y})})]})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(fw,{className:"w-4 h-4 text-purple-400"}),s.jsx("p",{className:"text-sm text-white",children:"Quiet Hours"})]}),s.jsx(Vn,{checked:t.quiet_hours_enabled,onChange:y=>f.mutate({quiet_hours_enabled:y})})]}),t.quiet_hours_enabled&&s.jsxs("div",{className:"pl-4 border-l-2 border-bambu-dark-tertiary space-y-2",children:[s.jsx("p",{className:"text-xs text-bambu-gray",children:"No notifications during these hours"}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Gn,{className:"w-4 h-4 text-bambu-gray"}),s.jsxs("span",{className:"text-sm text-white",children:[x(t.quiet_hours_start)||"22:00"," - ",x(t.quiet_hours_end)||"07:00"]})]}),s.jsx("p",{className:"text-xs text-bambu-gray",children:"Edit provider to change quiet hours"})]})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Qr,{className:"w-4 h-4 text-emerald-400"}),s.jsx("p",{className:"text-sm text-white",children:"Daily Digest"})]}),s.jsx(Vn,{checked:t.daily_digest_enabled,onChange:y=>f.mutate({daily_digest_enabled:y})})]}),t.daily_digest_enabled&&s.jsxs("div",{className:"pl-4 border-l-2 border-bambu-dark-tertiary space-y-2",children:[s.jsx("p",{className:"text-xs text-bambu-gray",children:"Batch notifications into a single daily summary"}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Gn,{className:"w-4 h-4 text-bambu-gray"}),s.jsxs("span",{className:"text-sm text-white",children:["Send at ",x(t.daily_digest_time)||"08:00"]})]}),s.jsx("p",{className:"text-xs text-bambu-gray",children:"Edit provider to change digest time"})]})]}),s.jsxs("div",{className:"flex gap-2 pt-2",children:[s.jsxs(Se,{size:"sm",variant:"secondary",onClick:()=>e(t),className:"flex-1",children:[s.jsx(L2,{className:"w-4 h-4"}),"Edit"]}),s.jsx(Se,{size:"sm",variant:"secondary",onClick:()=>i(!0),className:"text-red-400 hover:text-red-300",children:s.jsx(an,{className:"w-4 h-4"})})]})]})]})}),r&&s.jsx(Ln,{title:"Delete Notification Provider",message:`Are you sure you want to delete "${t.name}"? This cannot be undone.`,confirmText:"Delete",variant:"danger",onConfirm:()=>{m.mutate(),i(!1)},onCancel:()=>i(!1)})]})}const GG=[{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 Iqe({provider:t,onClose:e}){const n=tn(),r=!!t,[i,a]=w.useState(t?.name||""),[o,l]=w.useState(t?.provider_type||"email"),[c,u]=w.useState(t?.printer_id||null),[d,f]=w.useState(t?.quiet_hours_enabled||!1),[m,g]=w.useState(t?.quiet_hours_start||"22:00"),[x,y]=w.useState(t?.quiet_hours_end||"07:00"),[b,v]=w.useState(t?.daily_digest_enabled||!1),[M,S]=w.useState(t?.daily_digest_time||"08:00"),[A,E]=w.useState(t?.on_print_start??!1),[k,C]=w.useState(t?.on_print_complete??!0),[R,T]=w.useState(t?.on_print_failed??!0),[P,F]=w.useState(t?.on_print_stopped??!0),[L,X]=w.useState(t?.on_print_progress??!1),[D,K]=w.useState(t?.on_printer_offline??!1),[Y,q]=w.useState(t?.on_printer_error??!1),[Z,re]=w.useState(t?.on_filament_low??!1),[oe,B]=w.useState(t?.on_maintenance_due??!1),[G,J]=w.useState(t?.config?Object.fromEntries(Object.entries(t.config).map(([U,V])=>[U,String(V)])):{}),[te,ae]=w.useState(null),[de,fe]=w.useState(null),{data:Ae}=ct({queryKey:["printers"],queryFn:pe.getPrinters});w.useEffect(()=>{const U=V=>{V.key==="Escape"&&e()};return window.addEventListener("keydown",U),()=>window.removeEventListener("keydown",U)},[e]);const ge=ft({mutationFn:()=>pe.testNotificationConfig({provider_type:o,config:G}),onSuccess:U=>{ae(U),fe(null)},onError:U=>{ae({success:!1,message:U.message})}}),Me=ft({mutationFn:U=>pe.createNotificationProvider(U),onSuccess:()=>{n.invalidateQueries({queryKey:["notification-providers"]}),e()},onError:U=>{fe(U.message)}}),je=ft({mutationFn:U=>pe.updateNotificationProvider(t.id,U),onSuccess:()=>{n.invalidateQueries({queryKey:["notification-providers"]}),e()},onError:U=>{fe(U.message)}}),ne=U=>{if(U.preventDefault(),fe(null),!i.trim()){fe("Name is required");return}const V=z(o);for(const Ee of V)if(!G[Ee.key]?.trim()){fe(`${Ee.label} is required`);return}const Q={name:i.trim(),provider_type:o,config:G,printer_id:c,quiet_hours_enabled:d,quiet_hours_start:d?m:null,quiet_hours_end:d?x:null,daily_digest_enabled:b,daily_digest_time:b?M:null,on_print_start:A,on_print_complete:k,on_print_failed:R,on_print_stopped:P,on_print_progress:L,on_printer_offline:D,on_printer_error:Y,on_filament_low:Z,on_maintenance_due:oe};r?je.mutate(Q):Me.mutate(Q)},Ke=Me.isPending||je.isPending,$=U=>{switch(U){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:V=>V.payload_format!=="slack"},{key:"field_message",label:"Message Field Name",placeholder:"message",type:"text",required:!1,showIf:V=>V.payload_format!=="slack"}];default:return[]}},z=U=>$(U).filter(V=>V.required),W=$(o);return s.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4 overflow-y-auto",onClick:e,children:s.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:U=>U.stopPropagation(),children:[s.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary",children:[s.jsx("h2",{className:"text-lg font-semibold text-white",children:r?"Edit Notification Provider":"Add Notification Provider"}),s.jsx("button",{onClick:e,className:"text-bambu-gray hover:text-white transition-colors",children:s.jsx(Ut,{className:"w-5 h-5"})})]}),s.jsxs("form",{onSubmit:ne,className:"p-6 space-y-4",children:[de&&s.jsx("div",{className:"p-3 bg-red-500/20 border border-red-500/50 rounded-lg text-sm text-red-400",children:de}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Name *"}),s.jsx("input",{type:"text",value:i,onChange:U=>a(U.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"})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Provider Type *"}),s.jsx("select",{value:o,onChange:U=>{l(U.target.value),J({}),ae(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:GG.map(U=>s.jsx("option",{value:U.value,children:U.label},U.value))}),s.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:GG.find(U=>U.value===o)?.description})]}),s.jsxs("div",{className:"space-y-3",children:[s.jsx("p",{className:"text-sm text-bambu-gray",children:"Configuration"}),W.filter(U=>!("showIf"in U)||U.showIf?.(G)!==!1).map(U=>s.jsxs("div",{children:[s.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[U.label," ",U.required&&"*"]}),U.type==="select"&&"options"in U&&U.options?s.jsx("select",{value:G[U.key]||U.options[0]?.value||"",onChange:V=>{J({...G,[U.key]:V.target.value}),ae(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:U.options.map(V=>s.jsx("option",{value:V.value,children:V.label},V.value))}):s.jsx("input",{type:U.type,value:G[U.key]||"",onChange:V=>{J({...G,[U.key]:V.target.value}),ae(null)},placeholder:U.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"})]},U.key))]}),s.jsx("div",{className:"flex gap-2",children:s.jsxs(Se,{type:"button",variant:"secondary",onClick:()=>{ae(null),ge.mutate()},disabled:ge.isPending||!G[z(o)[0]?.key],className:"flex-1",children:[ge.isPending?s.jsx(mt,{className:"w-4 h-4 animate-spin"}):s.jsx(iD,{className:"w-4 h-4"}),"Test Configuration"]})}),te&&s.jsx("div",{className:`p-3 rounded-lg flex items-center gap-2 ${te.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:te.success?s.jsxs(s.Fragment,{children:[s.jsx(Dn,{className:"w-5 h-5"}),s.jsx("span",{children:te.message})]}):s.jsxs(s.Fragment,{children:[s.jsx(qi,{className:"w-5 h-5"}),s.jsx("span",{children:te.message})]})}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Printer Filter"}),s.jsxs("select",{value:c??"",onChange:U=>u(U.target.value?Number(U.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:[s.jsx("option",{value:"",children:"All printers"}),Ae?.map(U=>s.jsx("option",{value:U.id,children:U.name},U.id))]}),s.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Only send notifications for events from this printer"})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("label",{className:"text-sm text-white",children:"Quiet Hours (Do Not Disturb)"}),s.jsx(Vn,{checked:d,onChange:f})]}),d&&s.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[s.jsxs("div",{children:[s.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Start"}),s.jsx("input",{type:"time",value:m,onChange:U=>g(U.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"})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"End"}),s.jsx("input",{type:"time",value:x,onChange:U=>y(U.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"})]})]})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{children:[s.jsx("label",{className:"text-sm text-white",children:"Daily Digest"}),s.jsx("p",{className:"text-xs text-bambu-gray",children:"Batch notifications into a single daily summary"})]}),s.jsx(Vn,{checked:b,onChange:v})]}),b&&s.jsxs("div",{children:[s.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Send digest at"}),s.jsx("input",{type:"time",value:M,onChange:U=>S(U.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"}),s.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Events will be collected and sent as a single summary at this time"})]})]}),s.jsxs("div",{className:"space-y-3",children:[s.jsx("p",{className:"text-sm text-bambu-gray",children:"Notification Events"}),s.jsxs("div",{className:"space-y-2 p-3 bg-bambu-dark rounded-lg",children:[s.jsx("p",{className:"text-xs text-bambu-gray uppercase tracking-wide mb-2",children:"Print Events"}),s.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("span",{className:"text-sm text-white",children:"Start"}),s.jsx(Vn,{checked:A,onChange:E})]}),s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("span",{className:"text-sm text-white",children:"Complete"}),s.jsx(Vn,{checked:k,onChange:C})]}),s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("span",{className:"text-sm text-white",children:"Failed"}),s.jsx(Vn,{checked:R,onChange:T})]}),s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("span",{className:"text-sm text-white",children:"Stopped"}),s.jsx(Vn,{checked:P,onChange:F})]}),s.jsxs("div",{className:"flex items-center justify-between col-span-2",children:[s.jsxs("div",{children:[s.jsx("span",{className:"text-sm text-white",children:"Progress"}),s.jsx("span",{className:"text-xs text-bambu-gray ml-1",children:"(25%, 50%, 75%)"})]}),s.jsx(Vn,{checked:L,onChange:X})]})]})]}),s.jsxs("div",{className:"space-y-2 p-3 bg-bambu-dark rounded-lg",children:[s.jsx("p",{className:"text-xs text-bambu-gray uppercase tracking-wide mb-2",children:"Printer Status"}),s.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("span",{className:"text-sm text-white",children:"Offline"}),s.jsx(Vn,{checked:D,onChange:K})]}),s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("span",{className:"text-sm text-white",children:"Error"}),s.jsx(Vn,{checked:Y,onChange:q})]}),s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("span",{className:"text-sm text-white",children:"Low Filament"}),s.jsx(Vn,{checked:Z,onChange:re})]}),s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("span",{className:"text-sm text-white",children:"Maintenance"}),s.jsx(Vn,{checked:oe,onChange:B})]})]})]})]}),s.jsxs("div",{className:"flex gap-3 pt-2",children:[s.jsx(Se,{type:"button",variant:"secondary",onClick:e,className:"flex-1",children:"Cancel"}),s.jsxs(Se,{type:"submit",disabled:Ke,className:"flex-1",children:[Ke?s.jsx(mt,{className:"w-4 h-4 animate-spin"}):s.jsx(ds,{className:"w-4 h-4"}),r?"Save":"Add"]})]})]})]})})}function Fqe({template:t,onClose:e}){const n=tn(),r=w.useRef(null),[i,a]=w.useState(t.title_template),[o,l]=w.useState(t.body_template),[c,u]=w.useState(null),[d,f]=w.useState(!0),{data:m}=ct({queryKey:["template-variables"],queryFn:pe.getTemplateVariables}),g=m?.find(E=>E.event_type===t.event_type),{data:x,isLoading:y}=ct({queryKey:["template-preview",t.event_type,i,o],queryFn:()=>pe.previewTemplate({event_type:t.event_type,title_template:i,body_template:o}),enabled:d&&i.length>0&&o.length>0});w.useEffect(()=>{const E=k=>{k.key==="Escape"&&e()};return window.addEventListener("keydown",E),()=>window.removeEventListener("keydown",E)},[e]);const b=ft({mutationFn:E=>pe.updateNotificationTemplate(t.id,E),onSuccess:()=>{n.invalidateQueries({queryKey:["notification-templates"]}),e()},onError:E=>{u(E.message)}}),v=ft({mutationFn:()=>pe.resetNotificationTemplate(t.id),onSuccess:E=>{a(E.title_template),l(E.body_template),n.invalidateQueries({queryKey:["notification-templates"]})},onError:E=>{u(E.message)}}),M=E=>{if(E.preventDefault(),u(null),!i.trim()){u("Title is required");return}if(!o.trim()){u("Body is required");return}b.mutate({title_template:i,body_template:o})},S=E=>{const k=r.current;if(!k)return;const C=k.selectionStart,R=k.selectionEnd,T=o,P=T.substring(0,C),F=T.substring(R),L=P+`{${E}}`+F;l(L),setTimeout(()=>{k.focus();const X=C+E.length+2;k.setSelectionRange(X,X)},0)},A=i!==t.title_template||o!==t.body_template;return s.jsx("div",{className:"fixed inset-0 bg-black/80 flex items-center justify-center z-50 p-4",children:s.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg w-full max-w-2xl max-h-[90vh] flex flex-col",children:[s.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary shrink-0",children:[s.jsxs("h2",{className:"text-lg font-semibold text-white",children:["Edit Template: ",t.name]}),s.jsx("button",{onClick:e,className:"p-1 hover:bg-bambu-dark-tertiary rounded transition-colors",children:s.jsx(Ut,{className:"w-5 h-5 text-bambu-gray"})})]}),s.jsxs("form",{onSubmit:M,className:"flex-1 overflow-y-auto p-4 space-y-4",children:[c&&s.jsx("div",{className:"p-3 bg-red-500/20 border border-red-500/50 rounded text-red-400 text-sm",children:c}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm font-medium text-bambu-gray mb-1",children:"Title"}),s.jsx("input",{type:"text",value:i,onChange:E=>a(E.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..."})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm font-medium text-bambu-gray mb-1",children:"Body"}),s.jsx("textarea",{ref:r,value:o,onChange:E=>l(E.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..."})]}),g&&s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm font-medium text-bambu-gray mb-2",children:"Available Variables"}),s.jsx("div",{className:"flex flex-wrap gap-2",children:g.variables.map(E=>s.jsxs("button",{type:"button",onClick:()=>S(E),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:[s.jsx(Kn,{className:"w-3 h-3"}),E]},E))}),s.jsx("p",{className:"text-xs text-bambu-gray/60 mt-1",children:"Click to insert at cursor position in body"})]}),s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center justify-between mb-2",children:[s.jsxs("label",{className:"text-sm font-medium text-bambu-gray flex items-center gap-2",children:[s.jsx(_f,{className:"w-4 h-4"}),"Live Preview"]}),s.jsx("button",{type:"button",onClick:()=>f(!d),className:"text-xs text-bambu-green hover:text-bambu-green-light",children:d?"Hide":"Show"})]}),d&&s.jsx("div",{className:"bg-bambu-dark border border-bambu-dark-tertiary rounded p-3 space-y-2",children:y?s.jsxs("div",{className:"flex items-center gap-2 text-bambu-gray text-sm",children:[s.jsx(mt,{className:"w-4 h-4 animate-spin"}),"Loading preview..."]}):x?s.jsxs(s.Fragment,{children:[s.jsxs("div",{children:[s.jsx("span",{className:"text-xs text-bambu-gray",children:"Title:"}),s.jsx("div",{className:"text-white font-medium",children:x.title})]}),s.jsxs("div",{children:[s.jsx("span",{className:"text-xs text-bambu-gray",children:"Body:"}),s.jsx("div",{className:"text-white whitespace-pre-wrap text-sm",children:x.body})]})]}):s.jsx("div",{className:"text-bambu-gray text-sm",children:"Enter template content to see preview"})})]})]}),s.jsxs("div",{className:"flex items-center justify-between p-4 border-t border-bambu-dark-tertiary shrink-0",children:[s.jsxs(Se,{type:"button",variant:"ghost",onClick:()=>v.mutate(),disabled:v.isPending,className:"text-orange-400 hover:text-orange-300",children:[v.isPending?s.jsx(mt,{className:"w-4 h-4 animate-spin mr-2"}):s.jsx(Vf,{className:"w-4 h-4 mr-2"}),"Reset to Default"]}),s.jsxs("div",{className:"flex gap-2",children:[s.jsx(Se,{type:"button",variant:"secondary",onClick:e,children:"Cancel"}),s.jsxs(Se,{onClick:M,disabled:b.isPending||!A,children:[b.isPending?s.jsx(mt,{className:"w-4 h-4 animate-spin mr-2"}):s.jsx(ds,{className:"w-4 h-4 mr-2"}),"Save"]})]})]})]})})}const Uqe={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"},zqe={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 Bqe({onClose:t}){const e=tn(),{showToast:n}=$n(),[r,i]=w.useState(7),[a,o]=w.useState(null),[l,c]=w.useState(!1),{data:u}=ct({queryKey:["settings"],queryFn:pe.getSettings}),d=u?.time_format||"system",{data:f,isLoading:m,refetch:g,isRefetching:x}=ct({queryKey:["notification-logs",r,l],queryFn:()=>pe.getNotificationLogs({days:r,limit:100,success:l?!1:void 0})}),{data:y}=ct({queryKey:["notification-log-stats",r],queryFn:()=>pe.getNotificationLogStats(r)}),b=ft({mutationFn:()=>pe.clearNotificationLogs(30),onSuccess:M=>{n(M.message,"success"),e.invalidateQueries({queryKey:["notification-logs"]}),e.invalidateQueries({queryKey:["notification-log-stats"]})},onError:M=>{n(`Failed to clear logs: ${M.message}`,"error")}}),v=M=>{const S=mi(M);if(!S)return"";const E=new Date().getTime()-S.getTime();return E<6e4?"Just now":E<36e5?`${Math.floor(E/6e4)}m ago`:E<864e5?`${Math.floor(E/36e5)}h ago`:S.toLocaleDateString()+" "+lfe(S,d)};return s.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",children:s.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:[s.jsxs("div",{className:"p-4 border-b border-bambu-dark-tertiary flex items-center justify-between",children:[s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx(hw,{className:"w-5 h-5 text-bambu-green"}),s.jsx("h2",{className:"text-lg font-semibold text-white",children:"Notification Log"})]}),s.jsx("button",{onClick:t,className:"text-bambu-gray hover:text-white transition-colors",children:"×"})]}),y&&s.jsx("div",{className:"px-4 py-3 border-b border-bambu-dark-tertiary bg-bambu-dark/50",children:s.jsxs("div",{className:"flex items-center gap-6 text-sm",children:[s.jsxs("span",{className:"text-bambu-gray",children:["Last ",r," days: ",s.jsx("span",{className:"text-white font-medium",children:y.total})," notifications"]}),s.jsxs("span",{className:"flex items-center gap-1 text-bambu-green",children:[s.jsx(Dn,{className:"w-4 h-4"}),y.success_count," sent"]}),y.failure_count>0&&s.jsxs("span",{className:"flex items-center gap-1 text-red-400",children:[s.jsx(qi,{className:"w-4 h-4"}),y.failure_count," failed"]})]})}),s.jsxs("div",{className:"px-4 py-3 border-b border-bambu-dark-tertiary flex items-center gap-4",children:[s.jsxs("select",{value:r,onChange:M=>i(Number(M.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:[s.jsx("option",{value:1,children:"Last 24 hours"}),s.jsx("option",{value:7,children:"Last 7 days"}),s.jsx("option",{value:30,children:"Last 30 days"}),s.jsx("option",{value:90,children:"Last 90 days"})]}),s.jsxs("label",{className:"flex items-center gap-2 text-sm text-bambu-gray cursor-pointer",children:[s.jsx("input",{type:"checkbox",checked:l,onChange:M=>c(M.target.checked),className:"rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),"Show failed only"]}),s.jsx("div",{className:"flex-1"}),s.jsxs(Se,{size:"sm",variant:"secondary",onClick:()=>g(),disabled:x,children:[x?s.jsx(mt,{className:"w-4 h-4 animate-spin"}):s.jsx(yr,{className:"w-4 h-4"}),"Refresh"]}),s.jsxs(Se,{size:"sm",variant:"secondary",onClick:()=>b.mutate(),disabled:b.isPending,className:"text-red-400 hover:text-red-300",children:[b.isPending?s.jsx(mt,{className:"w-4 h-4 animate-spin"}):s.jsx(an,{className:"w-4 h-4"}),"Clear Old"]})]}),s.jsx("div",{className:"flex-1 overflow-y-auto p-4",children:m?s.jsx("div",{className:"flex justify-center py-12",children:s.jsx(mt,{className:"w-6 h-6 text-bambu-green animate-spin"})}):f&&f.length>0?s.jsx("div",{className:"space-y-2",children:f.map(M=>s.jsx($qe,{log:M,isExpanded:a===M.id,onToggle:()=>o(a===M.id?null:M.id),formatDate:v,formatFullDate:S=>eg(S,d)},M.id))}):s.jsxs("div",{className:"text-center py-12 text-bambu-gray",children:[s.jsx(hw,{className:"w-12 h-12 mx-auto mb-3 opacity-30"}),s.jsx("p",{className:"text-sm",children:l?"No failed notifications":"No notifications logged"})]})})]})})}function $qe({log:t,isExpanded:e,onToggle:n,formatDate:r,formatFullDate:i}){return s.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:[s.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?s.jsx(Dn,{className:"w-4 h-4 text-bambu-green shrink-0"}):s.jsx(qi,{className:"w-4 h-4 text-red-400 shrink-0"}),s.jsx("span",{className:`text-xs font-medium ${zqe[t.event_type]||"text-bambu-gray"}`,children:Uqe[t.event_type]||t.event_type}),s.jsx("span",{className:"text-sm text-white truncate flex-1",children:t.provider_name||"Unknown Provider"}),t.printer_name&&s.jsx("span",{className:"text-xs text-bambu-gray",children:t.printer_name}),s.jsx("span",{className:"text-xs text-bambu-gray shrink-0",children:r(t.created_at)}),e?s.jsx(Jc,{className:"w-4 h-4 text-bambu-gray shrink-0"}):s.jsx(Ji,{className:"w-4 h-4 text-bambu-gray shrink-0"})]}),e&&s.jsxs("div",{className:"px-3 py-2 border-t border-bambu-dark-tertiary bg-bambu-dark/20 space-y-2",children:[s.jsxs("div",{children:[s.jsx("p",{className:"text-xs text-bambu-gray mb-1",children:"Title"}),s.jsx("p",{className:"text-sm text-white",children:t.title})]}),s.jsxs("div",{children:[s.jsx("p",{className:"text-xs text-bambu-gray mb-1",children:"Message"}),s.jsx("p",{className:"text-sm text-white whitespace-pre-wrap",children:t.message})]}),!t.success&&t.error_message&&s.jsxs("div",{children:[s.jsx("p",{className:"text-xs text-red-400 mb-1",children:"Error"}),s.jsx("p",{className:"text-sm text-red-300",children:t.error_message})]}),s.jsxs("div",{className:"flex gap-4 text-xs text-bambu-gray pt-1",children:[s.jsxs("span",{children:["Provider: ",t.provider_type]}),s.jsxs("span",{children:["Time: ",i(t.created_at)]})]})]})]})}const T1=[{id:"settings",labelKey:"backup.categories.settings",defaultLabel:"App Settings",icon:s.jsx(F2,{className:"w-4 h-4"}),default:!0,description:"Language, theme, update preferences"},{id:"notifications",labelKey:"backup.categories.notifications",defaultLabel:"Notification Providers",icon:s.jsx(tf,{className:"w-4 h-4"}),default:!0,description:"ntfy, Pushover, Discord, etc."},{id:"templates",labelKey:"backup.categories.templates",defaultLabel:"Notification Templates",icon:s.jsx(za,{className:"w-4 h-4"}),default:!0,description:"Custom message templates"},{id:"smart_plugs",labelKey:"backup.categories.smartPlugs",defaultLabel:"Smart Plugs",icon:s.jsx(Us,{className:"w-4 h-4"}),default:!0,description:"Tasmota plug configurations"},{id:"external_links",labelKey:"backup.categories.externalLinks",defaultLabel:"External Links",icon:s.jsx(Y0,{className:"w-4 h-4"}),default:!0,description:"Sidebar links to external services"},{id:"printers",labelKey:"backup.categories.printers",defaultLabel:"Printers",icon:s.jsx(Ir,{className:"w-4 h-4"}),default:!1,description:"Printer info (access codes excluded)"},{id:"filaments",labelKey:"backup.categories.filaments",defaultLabel:"Filament Inventory",icon:s.jsx(nD,{className:"w-4 h-4"}),default:!1,description:"Filament types and costs"},{id:"maintenance",labelKey:"backup.categories.maintenance",defaultLabel:"Maintenance Types",icon:s.jsx(Od,{className:"w-4 h-4"}),default:!1,description:"Custom maintenance schedules"},{id:"archives",labelKey:"backup.categories.archives",defaultLabel:"Print Archives",icon:s.jsx(Ha,{className:"w-4 h-4"}),default:!1,description:"All print data + files (3MF, thumbnails, photos)"},{id:"projects",labelKey:"backup.categories.projects",defaultLabel:"Projects",icon:s.jsx(ba,{className:"w-4 h-4"}),default:!1,description:"Projects, BOM items, and attachments"},{id:"pending_uploads",labelKey:"backup.categories.pendingUploads",defaultLabel:"Pending Uploads",icon:s.jsx(bi,{className:"w-4 h-4"}),default:!1,description:"Virtual printer uploads awaiting review"},{id:"api_keys",labelKey:"backup.categories.apiKeys",defaultLabel:"API Keys",icon:s.jsx(Gh,{className:"w-4 h-4"}),default:!1,description:"Webhook API keys (new keys generated on import)"}];function Hqe({onClose:t,onExport:e}){const{t:n}=Tg(),[r,i]=w.useState(()=>{const x={};return T1.forEach(y=>{x[y.id]=y.default}),x}),[a,o]=w.useState(!1),[l,c]=w.useState(!1);w.useEffect(()=>{const x=y=>{y.key==="Escape"&&t()};return window.addEventListener("keydown",x),()=>window.removeEventListener("keydown",x)},[t]);const u=x=>{i(y=>({...y,[x]:!y[x]}))},d=()=>{const x={};T1.forEach(y=>{x[y.id]=!0}),i(x)},f=()=>{const x={};T1.forEach(y=>{x[y.id]=!1}),i(x)},m=Object.values(r).filter(Boolean).length,g=async()=>{c(!0);try{await e({...r,access_codes:a&&r.printers})}finally{c(!1)}};return s.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",onClick:l?void 0:t,children:s.jsx(Mt,{className:"w-full max-w-lg",onClick:x=>x.stopPropagation(),children:s.jsxs(Et,{className:"p-0",children:[s.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("div",{className:"p-2 rounded-full bg-bambu-green/20 text-bambu-green",children:s.jsx(Jr,{className:"w-5 h-5"})}),s.jsxs("div",{children:[s.jsx("h3",{className:"text-lg font-semibold text-white",children:n("backup.exportTitle",{defaultValue:"Export Backup"})}),s.jsx("p",{className:"text-sm text-bambu-gray",children:n("backup.selectCategories",{defaultValue:"Select data to include"})})]})]}),s.jsx("button",{onClick:t,className:"p-2 hover:bg-bambu-dark-tertiary rounded-lg transition-colors",children:s.jsx(Ut,{className:"w-5 h-5"})})]}),s.jsxs("div",{className:"flex gap-2 px-4 pt-4",children:[s.jsx("button",{onClick:d,disabled:l,className:"text-sm text-bambu-green hover:text-bambu-green/80 disabled:opacity-50 disabled:cursor-not-allowed",children:n("common.selectAll",{defaultValue:"Select All"})}),s.jsx("span",{className:"text-bambu-gray",children:"|"}),s.jsx("button",{onClick:f,disabled:l,className:"text-sm text-bambu-gray hover:text-white disabled:opacity-50 disabled:cursor-not-allowed",children:n("common.selectNone",{defaultValue:"Select None"})})]}),s.jsx("div",{className:`p-4 space-y-2 max-h-[400px] overflow-y-auto ${l?"opacity-50 pointer-events-none":""}`,children:T1.map(x=>s.jsxs("label",{className:`flex items-center gap-3 p-3 rounded-lg cursor-pointer transition-colors ${r[x.id]?"bg-bambu-green/10 border border-bambu-green/30":"bg-bambu-dark hover:bg-bambu-dark-tertiary border border-transparent"}`,children:[s.jsx("input",{type:"checkbox",checked:r[x.id],onChange:()=>u(x.id),disabled:l,className:"w-4 h-4 rounded border-bambu-gray bg-bambu-dark text-bambu-green focus:ring-bambu-green focus:ring-offset-0"}),s.jsx("div",{className:`${r[x.id]?"text-bambu-green":"text-bambu-gray"}`,children:x.icon}),s.jsxs("div",{className:"flex-1",children:[s.jsx("div",{className:"text-white text-sm font-medium",children:n(x.labelKey,{defaultValue:x.defaultLabel})}),s.jsx("div",{className:"text-xs text-bambu-gray",children:x.description})]})]},x.id))}),r.archives&&s.jsx("div",{className:"mx-4 mb-2 p-3 rounded-lg bg-yellow-500/10 border border-yellow-500/30",children:s.jsxs("div",{className:"flex items-start gap-2 text-sm",children:[s.jsx(Ha,{className:"w-4 h-4 text-yellow-500 mt-0.5 flex-shrink-0"}),s.jsxs("div",{className:"text-yellow-200 dark:text-yellow-200 text-yellow-700",children:[s.jsx("span",{className:"font-medium",children:"ZIP file will be created."}),s.jsx("span",{className:"text-yellow-600 dark:text-yellow-200/70",children:" Includes all 3MF files, thumbnails, timelapses, and photos. This may take a while and result in a large file."})]})]})}),r.printers&&s.jsxs("div",{className:"mx-4 mb-2 p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsx(Gh,{className:"w-4 h-4 text-orange-500 dark:text-orange-400 mt-0.5 flex-shrink-0"}),s.jsxs("div",{children:[s.jsx("p",{className:"text-sm font-medium text-white",children:"Include Access Codes"}),s.jsx("p",{className:"text-xs text-bambu-gray",children:"For transferring to another machine"})]})]}),s.jsx(Vn,{checked:a,onChange:o})]}),a&&s.jsx("div",{className:"mt-2 p-2 rounded bg-orange-500/10 border border-orange-500/30",children:s.jsxs("div",{className:"flex items-start gap-2 text-xs",children:[s.jsx(Cn,{className:"w-3 h-3 text-orange-500 dark:text-orange-400 mt-0.5 flex-shrink-0"}),s.jsx("span",{className:"text-orange-700 dark:text-orange-200",children:"Access codes will be included in plain text. Keep this backup file secure!"})]})})]}),s.jsxs("div",{className:"flex items-center justify-between p-4 border-t border-bambu-dark-tertiary",children:[s.jsx("span",{className:"text-sm text-bambu-gray",children:n("backup.selectedCount",{count:m,defaultValue:`${m} categories selected`})}),s.jsxs("div",{className:"flex gap-3",children:[s.jsx(Se,{variant:"secondary",onClick:t,disabled:l,children:n("common.cancel",{defaultValue:"Cancel"})}),s.jsx(Se,{onClick:g,disabled:m===0||l,className:"bg-bambu-green hover:bg-bambu-green-dark disabled:opacity-50 disabled:cursor-not-allowed min-w-[100px]",children:l?s.jsxs(s.Fragment,{children:[s.jsx(mt,{className:"w-4 h-4 mr-2 animate-spin"}),n("backup.exporting",{defaultValue:"Exporting..."})]}):s.jsxs(s.Fragment,{children:[s.jsx(Jr,{className:"w-4 h-4 mr-2"}),n("backup.export",{defaultValue:"Export"})]})})]})]})]})})})}const WG={settings:"Settings",notification_providers:"Notification Providers",notification_templates:"Notification Templates",smart_plugs:"Smart Plugs",printers:"Printers",filaments:"Filaments",maintenance_types:"Maintenance Types",archives:"Archives",projects:"Projects",pending_uploads:"Pending Uploads",external_links:"External Links",api_keys:"API Keys"};function Vqe({onClose:t,onRestore:e,onSuccess:n}){const[r,i]=w.useState("options"),[a,o]=w.useState(!1),[l,c]=w.useState(null),[u,d]=w.useState(null),[f,m]=w.useState(new Set),g=w.useRef(null);w.useEffect(()=>{const A=E=>{E.key==="Escape"&&r!=="restoring"&&(r==="result"&&u?.success&&n(),t())};return window.addEventListener("keydown",A),()=>window.removeEventListener("keydown",A)},[t,n,r,u]);const x=A=>{const E=A.target.files?.[0];E&&c(E)},y=async()=>{if(l){i("restoring");try{const A=await e(l,a);d(A),i("result")}catch{d({success:!1,message:"Failed to restore backup. Please check the file format."}),i("result")}}},b=()=>{u?.success&&n(),t()},v=A=>{m(E=>{const k=new Set(E);return k.has(A)?k.delete(A):k.add(A),k})},M=u?.restored?Object.values(u.restored).reduce((A,E)=>A+E,0)+(u.files_restored||0):0,S=u?.total_skipped||0;return s.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",onMouseDown:A=>{A.target===A.currentTarget&&r!=="restoring"&&t()},children:s.jsx(Mt,{className:"w-full max-w-lg",children:s.jsxs(Et,{className:"p-0",children:[s.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("div",{className:`p-2 rounded-full ${r==="result"&&u?.success?"bg-bambu-green/20 text-bambu-green":r==="result"&&!u?.success?"bg-red-500/20 text-red-500":"bg-blue-500/20 text-blue-500"}`,children:r==="result"&&u?.success?s.jsx(Dn,{className:"w-5 h-5"}):r==="result"&&!u?.success?s.jsx(Cn,{className:"w-5 h-5"}):s.jsx(bi,{className:"w-5 h-5"})}),s.jsxs("div",{children:[s.jsxs("h3",{className:"text-lg font-semibold text-white",children:[r==="options"&&"Restore Backup",r==="restoring"&&"Restoring...",r==="result"&&(u?.success?"Restore Complete":"Restore Failed")]}),s.jsxs("p",{className:"text-sm text-bambu-gray",children:[r==="options"&&"Import settings from a backup file",r==="restoring"&&"Please wait while your data is being restored",r==="result"&&u?.message]})]})]}),r!=="restoring"&&s.jsx("button",{onClick:b,className:"p-2 hover:bg-bambu-dark-tertiary rounded-lg transition-colors",children:s.jsx(Ut,{className:"w-5 h-5"})})]}),r==="options"&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"p-4 space-y-4",children:[s.jsxs("div",{children:[s.jsx("input",{ref:g,type:"file",accept:".json,.zip",className:"hidden",onChange:x}),s.jsx("button",{type:"button",onClick:()=>g.current?.click(),className:`w-full p-4 border-2 border-dashed rounded-lg transition-colors ${l?"border-bambu-green bg-bambu-green/10":"border-bambu-dark-tertiary hover:border-bambu-gray"}`,children:l?s.jsxs("div",{className:"flex items-center justify-center gap-2 text-bambu-green",children:[s.jsx(Dn,{className:"w-5 h-5"}),s.jsx("span",{className:"font-medium",children:l.name})]}):s.jsxs("div",{className:"flex flex-col items-center gap-2 text-bambu-gray",children:[s.jsx(bi,{className:"w-8 h-8"}),s.jsx("span",{children:"Click to select backup file (.json or .zip)"})]})})]}),s.jsx("div",{className:"p-3 rounded-lg bg-blue-500/10 border border-blue-500/30",children:s.jsxs("div",{className:"flex items-start gap-2 text-sm",children:[s.jsx(Cn,{className:"w-4 h-4 text-blue-500 dark:text-blue-400 mt-0.5 flex-shrink-0"}),s.jsxs("div",{className:"text-blue-700 dark:text-blue-200",children:[s.jsx("p",{className:"font-medium mb-1",children:"How duplicate handling works:"}),s.jsxs("ul",{className:"text-blue-600 dark:text-blue-200/80 space-y-1 text-xs",children:[s.jsxs("li",{children:[s.jsx("strong",{children:"Printers"})," - matched by serial number"]}),s.jsxs("li",{children:[s.jsx("strong",{children:"Smart Plugs"})," - matched by IP address"]}),s.jsxs("li",{children:[s.jsx("strong",{children:"Notification Providers"})," - matched by name"]}),s.jsxs("li",{children:[s.jsx("strong",{children:"Filaments"})," - matched by name + type + brand"]}),s.jsxs("li",{children:[s.jsx("strong",{children:"Archives"})," - matched by content hash (always skipped)"]}),s.jsxs("li",{children:[s.jsx("strong",{children:"Pending Uploads"})," - matched by filename"]}),s.jsxs("li",{children:[s.jsx("strong",{children:"Settings & Templates"})," - always overwritten"]})]})]})]})}),s.jsx("div",{className:"p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary",children:s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{children:[s.jsxs("p",{className:"text-white font-medium flex items-center gap-2",children:[a?s.jsx(yr,{className:"w-4 h-4 text-orange-400"}):s.jsx(mw,{className:"w-4 h-4 text-bambu-gray"}),a?"Replace existing data":"Keep existing data"]}),s.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:a?"Overwrite items that already exist with backup data":"Only restore items that don't already exist"})]}),s.jsx(Vn,{checked:a,onChange:o})]})}),a&&s.jsx("div",{className:"p-3 rounded-lg bg-orange-500/10 border border-orange-500/30",children:s.jsxs("div",{className:"flex items-start gap-2 text-sm",children:[s.jsx(Cn,{className:"w-4 h-4 text-orange-500 dark:text-orange-400 mt-0.5 flex-shrink-0"}),s.jsxs("div",{className:"text-orange-700 dark:text-orange-200",children:[s.jsx("span",{className:"font-medium",children:"Caution:"})," Overwriting will replace your current configurations with data from the backup. Printer access codes are never overwritten for security."]})]})})]}),s.jsxs("div",{className:"flex items-center justify-end gap-3 p-4 border-t border-bambu-dark-tertiary",children:[s.jsx(Se,{type:"button",variant:"secondary",onClick:t,children:"Cancel"}),s.jsxs(Se,{type:"button",onClick:y,disabled:!l,className:"bg-bambu-green hover:bg-bambu-green-dark disabled:opacity-50",children:[s.jsx(bi,{className:"w-4 h-4 mr-2"}),"Restore"]})]})]}),r==="restoring"&&s.jsxs("div",{className:"p-8 flex flex-col items-center gap-4",children:[s.jsx(mt,{className:"w-12 h-12 text-bambu-green animate-spin"}),s.jsx("p",{className:"text-bambu-gray",children:"Processing backup file..."})]}),r==="result"&&u&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"p-4 space-y-4 max-h-[400px] overflow-y-auto",children:[s.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[s.jsxs("div",{className:"p-3 rounded-lg bg-bambu-green/10 border border-bambu-green/30",children:[s.jsx("div",{className:"text-2xl font-bold text-bambu-green",children:M}),s.jsx("div",{className:"text-sm text-bambu-gray",children:"Items Restored"})]}),s.jsxs("div",{className:"p-3 rounded-lg bg-yellow-500/10 border border-yellow-500/30",children:[s.jsx("div",{className:"text-2xl font-bold text-yellow-500",children:S}),s.jsx("div",{className:"text-sm text-bambu-gray",children:"Items Skipped"})]})]}),u.restored&&Object.entries(u.restored).some(([,A])=>A>0)&&s.jsxs("div",{className:"space-y-2",children:[s.jsxs("h4",{className:"text-sm font-medium text-bambu-gray flex items-center gap-2",children:[s.jsx(Dn,{className:"w-4 h-4 text-bambu-green"}),"Restored"]}),s.jsxs("div",{className:"space-y-1",children:[Object.entries(u.restored).filter(([,A])=>A>0).map(([A,E])=>s.jsxs("div",{className:"flex items-center justify-between text-sm p-2 rounded bg-bambu-dark",children:[s.jsx("span",{className:"text-white",children:WG[A]||A}),s.jsx("span",{className:"text-bambu-green font-medium",children:E})]},A)),(u.files_restored||0)>0&&s.jsxs("div",{className:"flex items-center justify-between text-sm p-2 rounded bg-bambu-dark",children:[s.jsx("span",{className:"text-white",children:"Files (3MF, thumbnails, etc.)"}),s.jsx("span",{className:"text-bambu-green font-medium",children:u.files_restored})]})]})]}),u.skipped&&Object.entries(u.skipped).some(([,A])=>A>0)&&s.jsxs("div",{className:"space-y-2",children:[s.jsxs("h4",{className:"text-sm font-medium text-bambu-gray flex items-center gap-2",children:[s.jsx(mw,{className:"w-4 h-4 text-yellow-500"}),"Skipped (already exist)"]}),s.jsx("div",{className:"space-y-1",children:Object.entries(u.skipped).filter(([,A])=>A>0).map(([A,E])=>{const k=u.skipped_details?.[A]||[],C=f.has(A);return s.jsxs("div",{children:[s.jsxs("button",{onClick:()=>k.length>0&&v(A),className:`w-full flex items-center justify-between text-sm p-2 rounded bg-bambu-dark ${k.length>0?"hover:bg-bambu-dark-tertiary cursor-pointer":""}`,children:[s.jsxs("span",{className:"text-white flex items-center gap-2",children:[WG[A]||A,k.length>0&&(C?s.jsx(Jc,{className:"w-3 h-3"}):s.jsx(Ji,{className:"w-3 h-3"}))]}),s.jsx("span",{className:"text-yellow-500 font-medium",children:E})]}),C&&k.length>0&&s.jsxs("div",{className:"mt-1 ml-4 p-2 rounded bg-bambu-dark-tertiary text-xs text-bambu-gray space-y-1",children:[k.slice(0,10).map((R,T)=>s.jsx("div",{children:R},T)),k.length>10&&s.jsxs("div",{className:"text-bambu-gray/60",children:["...and ",k.length-10," more"]})]})]},A)})})]}),u.new_api_keys&&u.new_api_keys.length>0&&s.jsxs("div",{className:"space-y-2",children:[s.jsxs("h4",{className:"text-sm font-medium text-bambu-gray flex items-center gap-2",children:[s.jsx(Cn,{className:"w-4 h-4 text-orange-500"}),"New API Keys Generated"]}),s.jsxs("div",{className:"p-3 rounded bg-orange-500/10 border border-orange-500/30",children:[s.jsx("p",{className:"text-xs text-orange-200 mb-2",children:"These keys are only shown once. Copy them now!"}),s.jsx("div",{className:"space-y-2",children:u.new_api_keys.map((A,E)=>s.jsxs("div",{className:"p-2 rounded bg-bambu-dark",children:[s.jsx("div",{className:"text-sm text-white font-medium mb-1",children:A.name}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("code",{className:"text-xs text-bambu-green bg-bambu-dark-tertiary px-2 py-1 rounded font-mono flex-1 break-all",children:A.key}),s.jsx("button",{onClick:()=>navigator.clipboard.writeText(A.key),className:"text-xs text-bambu-gray hover:text-white px-2 py-1 rounded bg-bambu-dark-tertiary",children:"Copy"})]})]},E))})]})]}),M===0&&S===0&&s.jsx("div",{className:"p-4 text-center text-bambu-gray",children:"No data was found to restore in the backup file."})]}),s.jsx("div",{className:"flex items-center justify-end gap-3 p-4 border-t border-bambu-dark-tertiary",children:s.jsx(Se,{onClick:b,children:"Close"})})]})]})})})}async function Gqe(){const t=await fetch("/api/v1/settings/spoolman");if(!t.ok)throw new Error("Failed to load Spoolman settings");return t.json()}async function Wqe(t){const e=await fetch("/api/v1/settings/spoolman",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!e.ok)throw new Error("Failed to save Spoolman settings");return e.json()}function qqe(){const t=tn(),[e,n]=w.useState(!1),[r,i]=w.useState(""),[a,o]=w.useState("auto"),[l,c]=w.useState(!1),[u,d]=w.useState("all"),[f,m]=w.useState(!1),[g,x]=w.useState(!1),{data:y,isLoading:b}=ct({queryKey:["spoolman-settings"],queryFn:Gqe}),{data:v,isLoading:M,refetch:S}=ct({queryKey:["spoolman-status"],queryFn:pe.getSpoolmanStatus,refetchInterval:3e4}),{data:A}=ct({queryKey:["printers"],queryFn:pe.getPrinters});w.useEffect(()=>{y&&(n(y.spoolman_enabled==="true"),i(y.spoolman_url||""),o(y.spoolman_sync_mode||"auto"),m(!0))},[y]),w.useEffect(()=>{if(!f||!y)return;if(y.spoolman_enabled==="true"!==e||(y.spoolman_url||"")!==r||(y.spoolman_sync_mode||"auto")!==a){const K=setTimeout(()=>{E.mutate()},500);return()=>clearTimeout(K)}},[e,r,a,f]);const E=ft({mutationFn:()=>Wqe({spoolman_enabled:e?"true":"false",spoolman_url:r,spoolman_sync_mode:a}),onSuccess:()=>{t.invalidateQueries({queryKey:["spoolman-settings"]}),t.invalidateQueries({queryKey:["spoolman-status"]}),c(!0),setTimeout(()=>c(!1),2e3)}}),k=ft({mutationFn:pe.connectSpoolman,onSuccess:()=>{S()}}),C=ft({mutationFn:pe.disconnectSpoolman,onSuccess:()=>{S()}}),R=ft({mutationFn:pe.syncAllPrintersAms,onSuccess:D=>{D.success}}),T=ft({mutationFn:D=>pe.syncPrinterAms(D),onSuccess:D=>{D.success}}),P=()=>{u==="all"?R.mutate():T.mutate(u)},F=R.isPending||T.isPending,L=u==="all"?R.data:T.data,X=u==="all"?R.isSuccess:T.isSuccess;return b?s.jsxs(Mt,{children:[s.jsx(mr,{children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Yp,{className:"w-5 h-5 text-bambu-green"}),s.jsx("h2",{className:"text-lg font-semibold text-white",children:"Spoolman Integration"})]})}),s.jsx(Et,{children:s.jsx("div",{className:"flex justify-center py-8",children:s.jsx(mt,{className:"w-6 h-6 text-bambu-green animate-spin"})})})]}):s.jsxs(Mt,{children:[s.jsx(mr,{children:s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Yp,{className:"w-5 h-5 text-bambu-green"}),s.jsx("h2",{className:"text-lg font-semibold text-white",children:"Spoolman Integration"})]}),E.isPending&&s.jsx(mt,{className:"w-4 h-4 text-bambu-green animate-spin"}),l&&s.jsx(xs,{className:"w-4 h-4 text-bambu-green"})]})}),s.jsxs(Et,{className:"space-y-4",children:[s.jsx("p",{className:"text-sm text-bambu-gray",children:"Connect to Spoolman for filament inventory tracking. AMS data will sync automatically."}),s.jsx("div",{className:"p-3 bg-blue-500/10 border border-blue-500/30 rounded-lg",children:s.jsxs("div",{className:"flex gap-2",children:[s.jsx(tl,{className:"w-4 h-4 text-blue-400 flex-shrink-0 mt-0.5"}),s.jsxs("div",{className:"text-xs text-blue-300",children:[s.jsx("p",{className:"font-medium mb-1",children:"How Sync Works"}),s.jsxs("ul",{className:"list-disc list-inside space-y-0.5 text-blue-300/80",children:[s.jsx("li",{children:"Only official Bambu Lab spools with RFID are synced"}),s.jsx("li",{children:"New spools are auto-created in Spoolman on first sync"}),s.jsx("li",{children:"Non-Bambu Lab spools (third-party, refilled) are skipped"})]}),s.jsx("p",{className:"font-medium mt-2 mb-1",children:"Linking Existing Spools"}),s.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".'})]})]})}),s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{children:[s.jsx("p",{className:"text-white",children:"Enable Spoolman"}),s.jsx("p",{className:"text-sm text-bambu-gray",children:"Sync filament data with Spoolman server"})]}),s.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[s.jsx("input",{type:"checkbox",checked:e,onChange:D=>n(D.target.checked),className:"sr-only peer"}),s.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"})]})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Spoolman URL"}),s.jsx("input",{type:"text",placeholder:"http://192.168.1.100:7912",value:r,onChange:D=>i(D.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"}),s.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"URL of your Spoolman server (e.g., http://localhost:7912)"})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Sync Mode"}),s.jsxs("select",{value:a,onChange:D=>o(D.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:[s.jsx("option",{value:"auto",children:"Automatic"}),s.jsx("option",{value:"manual",children:"Manual Only"})]}),s.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:a==="auto"?"AMS data syncs automatically when changes are detected":"Only sync when manually triggered"})]}),e&&s.jsxs("div",{className:"pt-2 border-t border-bambu-dark-tertiary",children:[s.jsxs("div",{className:"flex items-center justify-between mb-3",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"text-sm text-bambu-gray",children:"Status:"}),M?s.jsx(mt,{className:"w-4 h-4 text-bambu-gray animate-spin"}):v?.connected?s.jsxs("span",{className:"flex items-center gap-1 text-sm text-green-500",children:[s.jsx(xs,{className:"w-4 h-4"}),"Connected"]}):s.jsxs("span",{className:"flex items-center gap-1 text-sm text-red-500",children:[s.jsx(Ut,{className:"w-4 h-4"}),"Disconnected"]})]}),s.jsx("div",{className:"flex gap-2",children:v?.connected?s.jsxs(Se,{variant:"secondary",size:"sm",onClick:()=>C.mutate(),disabled:C.isPending,children:[C.isPending?s.jsx(mt,{className:"w-4 h-4 animate-spin"}):s.jsx(Que,{className:"w-4 h-4"}),"Disconnect"]}):s.jsxs(Se,{size:"sm",onClick:()=>k.mutate(),disabled:k.isPending||!r,children:[k.isPending?s.jsx(mt,{className:"w-4 h-4 animate-spin"}):s.jsx(kl,{className:"w-4 h-4"}),"Connect"]})})]}),k.isError&&s.jsx("div",{className:"mb-3 p-2 bg-red-500/20 border border-red-500/50 rounded text-sm text-red-400",children:k.error.message}),v?.connected&&s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{children:[s.jsx("p",{className:"text-sm text-white",children:"Sync AMS Data"}),s.jsx("p",{className:"text-xs text-bambu-gray",children:"Manually sync printer AMS data to Spoolman"})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs("div",{className:"relative flex-1",children:[s.jsxs("select",{value:u,onChange:D=>d(D.target.value==="all"?"all":Number(D.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:[s.jsx("option",{value:"all",children:"All Printers"}),A?.map(D=>s.jsx("option",{value:D.id,children:D.name},D.id))]}),s.jsx(Ji,{className:"absolute right-2 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}),s.jsxs(Se,{variant:"secondary",size:"sm",onClick:P,disabled:F,children:[F?s.jsx(mt,{className:"w-4 h-4 animate-spin"}):s.jsx(yr,{className:"w-4 h-4"}),"Sync"]})]})]}),X&&L&&s.jsxs("div",{className:"mt-3 space-y-2",children:[s.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&&s.jsxs("div",{className:"p-2 bg-amber-500/10 border border-amber-500/30 rounded text-sm",children:[s.jsxs("div",{className:"flex items-center justify-between text-amber-400 mb-1",children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(Cn,{className:"w-3.5 h-3.5"}),s.jsxs("span",{className:"font-medium",children:[L.skipped_count," spool",L.skipped_count!==1?"s":""," skipped"]})]}),L.skipped_count>5&&s.jsx("button",{onClick:()=>x(!g),className:"text-xs text-amber-400 hover:text-amber-300 underline",children:g?"Show less":"Show all"})]}),s.jsxs("ul",{className:"text-xs text-amber-300/80 space-y-0.5",children:[(g?L.skipped:L.skipped.slice(0,5)).map((D,K)=>s.jsxs("li",{className:"flex items-center gap-2",children:[D.color&&s.jsx("span",{className:"w-3 h-3 rounded-full border border-white/20",style:{backgroundColor:`#${D.color}`}}),s.jsx("span",{children:D.location}),s.jsxs("span",{className:"text-amber-300/60",children:["- ",D.reason]})]},K)),!g&&L.skipped_count>5&&s.jsxs("li",{className:"text-amber-300/60 italic",children:["...and ",L.skipped_count-5," more"]})]})]}),L.errors.length>0&&s.jsxs("div",{className:"p-2 bg-red-500/10 border border-red-500/30 rounded text-sm",children:[s.jsx("div",{className:"text-red-400 font-medium mb-1",children:"Errors:"}),s.jsx("ul",{className:"text-xs text-red-300/80 space-y-0.5",children:L.errors.map((D,K)=>s.jsx("li",{children:D},K))})]})]})]})]})]})}function Kqe({link:t,onClose:e}){const n=tn(),{mode:r}=Xd(),i=!!t,a=w.useRef(null),[o,l]=w.useState(t?.name||""),[c,u]=w.useState(t?.url||""),[d,f]=w.useState(t?.icon||"link"),[m,g]=w.useState(!!t?.custom_icon),[x,y]=w.useState(t?.custom_icon?pe.getExternalLinkIconUrl(t.id):null),[b,v]=w.useState(null),[M,S]=w.useState(null);w.useEffect(()=>{const F=L=>{L.key==="Escape"&&e()};return window.addEventListener("keydown",F),()=>window.removeEventListener("keydown",F)},[e]);const A=ft({mutationFn:async F=>{const L=await pe.createExternalLink(F);return b?await pe.uploadExternalLinkIcon(L.id,b):L},onSuccess:()=>{n.invalidateQueries({queryKey:["external-links"]}),e()},onError:F=>{S(F.message)}}),E=ft({mutationFn:async F=>{let L=await pe.updateExternalLink(t.id,F);return b?L=await pe.uploadExternalLinkIcon(t.id,b):!m&&t?.custom_icon&&(L=await pe.deleteExternalLinkIcon(t.id)),L},onSuccess:()=>{n.invalidateQueries({queryKey:["external-links"]}),e()},onError:F=>{S(F.message)}}),k=F=>{const L=F.target.files?.[0];if(L){if(!["image/png","image/jpeg","image/gif","image/svg+xml","image/webp","image/x-icon"].includes(L.type)){S("Please select a valid image file (PNG, JPG, GIF, SVG, WebP, or ICO)");return}if(L.size>1024*1024){S("Image file must be less than 1MB");return}v(L),g(!0);const D=new FileReader;D.onload=K=>{y(K.target?.result)},D.readAsDataURL(L)}},C=()=>{v(null),y(null),g(!1),a.current&&(a.current.value="")},R=F=>{if(F.preventDefault(),S(null),!o.trim()){S("Name is required");return}if(!c.trim()){S("URL is required");return}if(!c.startsWith("http://")&&!c.startsWith("https://")){S("URL must start with http:// or https://");return}const L={name:o.trim(),url:c.trim(),icon:d};i?E.mutate(L):A.mutate(L)},T=A.isPending||E.isPending,P=z2(d);return s.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",onClick:e,children:s.jsxs("div",{className:"bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-md",onClick:F=>F.stopPropagation(),children:[s.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary",children:[s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("div",{className:"p-2 rounded-full bg-bambu-green/20 text-bambu-green",children:m&&x?s.jsx("img",{src:x,alt:"",className:`w-5 h-5 rounded ${r==="dark"?"invert opacity-[0.65]":"opacity-60"}`}):s.jsx(P,{className:"w-5 h-5"})}),s.jsx("h2",{className:"text-lg font-semibold text-white",children:i?"Edit Link":"Add External Link"})]}),s.jsx("button",{onClick:e,className:"text-bambu-gray hover:text-white transition-colors",children:s.jsx(Ut,{className:"w-5 h-5"})})]}),s.jsxs("form",{onSubmit:R,className:"p-6 space-y-4",children:[M&&s.jsx("div",{className:"p-3 bg-red-500/20 border border-red-500/50 rounded-lg text-sm text-red-400",children:M}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Name *"}),s.jsx("input",{type:"text",value:o,onChange:F=>l(F.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"})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"URL *"}),s.jsx("input",{type:"text",value:c,onChange:F=>u(F.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"})]}),s.jsxs("div",{className:"space-y-3",children:[s.jsx("label",{className:"block text-sm text-bambu-gray",children:"Icon"}),s.jsxs("div",{className:"p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary",children:[s.jsxs("div",{className:"flex items-center justify-between mb-2",children:[s.jsx("span",{className:"text-sm text-white",children:"Custom Icon"}),s.jsx("input",{ref:a,type:"file",accept:"image/png,image/jpeg,image/gif,image/svg+xml,image/webp,image/x-icon",className:"hidden",onChange:k}),m&&x?s.jsxs("div",{className:"flex items-center gap-2",children:[s.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"}`}),s.jsx("button",{type:"button",onClick:C,className:"p-1 text-red-400 hover:text-red-300 transition-colors",title:"Remove custom icon",children:s.jsx(an,{className:"w-4 h-4"})})]}):s.jsxs(Se,{type:"button",variant:"secondary",size:"sm",onClick:()=>a.current?.click(),children:[s.jsx(bi,{className:"w-4 h-4"}),"Upload"]})]}),s.jsx("p",{className:"text-xs text-bambu-gray",children:"PNG, JPG, GIF, SVG, WebP, or ICO. Max 1MB."})]}),!m&&s.jsxs("div",{children:[s.jsx("span",{className:"text-sm text-bambu-gray block mb-2",children:"Or choose a preset icon"}),s.jsx(nfe,{value:d,onChange:f})]})]}),s.jsxs("div",{className:"flex gap-3 pt-2",children:[s.jsx(Se,{type:"button",variant:"secondary",onClick:e,className:"flex-1",children:"Cancel"}),s.jsxs(Se,{type:"submit",disabled:T,className:"flex-1",children:[T?s.jsx(mt,{className:"w-4 h-4 animate-spin"}):s.jsx(ds,{className:"w-4 h-4"}),i?"Save":"Add"]})]})]})]})})}function Xqe(){const t=tn(),[e,n]=w.useState(!1),[r,i]=w.useState(null),[a,o]=w.useState(null),[l,c]=w.useState(null),{data:u,isLoading:d}=ct({queryKey:["external-links"],queryFn:pe.getExternalLinks}),f=ft({mutationFn:M=>pe.deleteExternalLink(M),onSuccess:()=>{t.invalidateQueries({queryKey:["external-links"]})}}),m=ft({mutationFn:M=>pe.reorderExternalLinks(M),onSuccess:()=>{t.invalidateQueries({queryKey:["external-links"]})}}),g=(M,S)=>{c(S),M.dataTransfer.effectAllowed="move"},x=M=>{M.preventDefault(),M.dataTransfer.dropEffect="move"},y=(M,S)=>{if(M.preventDefault(),l===null||l===S||!u)return;const A=u.map(R=>R.id),E=A.indexOf(l),k=A.indexOf(S);if(E===-1||k===-1)return;const C=[...A];C.splice(E,1),C.splice(k,0,l),m.mutate(C),c(null)},b=M=>{o(M)},v=()=>{a&&(f.mutate(a.id),o(null))};return s.jsxs(s.Fragment,{children:[s.jsxs(Mt,{children:[s.jsx(mr,{children:s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(kl,{className:"w-5 h-5 text-bambu-green"}),s.jsx("h2",{className:"text-lg font-semibold text-white",children:"Sidebar Links"})]}),s.jsxs(Se,{size:"sm",onClick:()=>n(!0),children:[s.jsx(Kn,{className:"w-4 h-4"}),"Add Link"]})]})}),s.jsxs(Et,{children:[s.jsx("p",{className:"text-sm text-bambu-gray mb-4",children:"Add external links to the sidebar navigation. Drag to reorder."}),d?s.jsx("div",{className:"flex justify-center py-8",children:s.jsx(mt,{className:"w-6 h-6 text-bambu-green animate-spin"})}):u&&u.length>0?s.jsx("div",{className:"space-y-2",children:u.map(M=>{const S=z2(M.icon);return s.jsxs("div",{draggable:!0,onDragStart:A=>g(A,M.id),onDragOver:x,onDrop:A=>y(A,M.id),className:`flex items-center gap-3 p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary transition-colors ${l===M.id?"opacity-50":""}`,children:[s.jsx(Qp,{className:"w-6 h-6 md:w-4 md:h-4 text-bambu-gray cursor-grab flex-shrink-0"}),s.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark-tertiary text-bambu-gray",children:s.jsx(S,{className:"w-4 h-4"})}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"text-white font-medium truncate",children:M.name}),s.jsx(Lr,{className:"w-3 h-3 text-bambu-gray flex-shrink-0"})]}),s.jsx("span",{className:"text-sm text-bambu-gray truncate block",children:M.url})]}),s.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[s.jsx("button",{onClick:()=>i(M),className:"p-2 rounded-lg hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white transition-colors",title:"Edit",children:s.jsx(Ga,{className:"w-4 h-4"})}),s.jsx("button",{onClick:()=>b(M),disabled:f.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:s.jsx(an,{className:"w-4 h-4"})})]})]},M.id)})}):s.jsxs("div",{className:"text-center py-8 text-bambu-gray",children:[s.jsx(kl,{className:"w-8 h-8 mx-auto mb-2 opacity-50"}),s.jsx("p",{children:"No external links configured"}),s.jsx("p",{className:"text-sm",children:'Click "Add Link" to add one'})]})]})]}),(e||r)&&s.jsx(Kqe,{link:r,onClose:()=>{n(!1),i(null)}}),a&&s.jsx(Ln,{title:"Delete Link",message:`Are you sure you want to delete "${a.name}"? This action cannot be undone.`,confirmText:"Delete",cancelText:"Cancel",variant:"danger",onConfirm:v,onCancel:()=>o(null)})]})}function Yqe(){const t=tn(),{showToast:e}=$n(),[n,r]=w.useState(!1),[i,a]=w.useState(""),[o,l]=w.useState("immediate"),[c,u]=w.useState("3DPrinter-X1-Carbon"),[d,f]=w.useState(!1),[m,g]=w.useState(null),{data:x,isLoading:y}=ct({queryKey:["virtual-printer-settings"],queryFn:R1.getSettings,refetchInterval:1e4}),{data:b}=ct({queryKey:["virtual-printer-models"],queryFn:R1.getModels});w.useEffect(()=>{if(x){r(x.enabled);let R=x.mode==="queue"?"review":x.mode;R!=="immediate"&&R!=="review"&&R!=="print_queue"&&(R="immediate"),l(R),u(x.model)}},[x]);const v=ft({mutationFn:R=>R1.updateSettings(R),onSuccess:()=>{t.invalidateQueries({queryKey:["virtual-printer-settings"]}),e("Virtual printer settings updated"),g(null)},onError:R=>{if(e(R.message||"Failed to update settings","error"),x){r(x.enabled);const T=x.mode==="queue"?"review":x.mode;l(T==="print_queue"||T==="review"?T:"immediate"),u(x.model)}g(null)}}),M=()=>{const R=!n;if(R&&!i&&!x?.access_code_set){e("Please set an access code first","error");return}r(R),g("toggle"),v.mutate({enabled:R,access_code:i||void 0,mode:o})},S=()=>{if(!i){e("Access code cannot be empty","error");return}if(i.length!==8){e("Access code must be exactly 8 characters","error");return}g("accessCode"),v.mutate({access_code:i}),a("")},A=R=>{l(R),g("mode"),v.mutate({mode:R})},E=R=>{u(R),g("model"),v.mutate({model:R})};if(y)return s.jsx(Mt,{children:s.jsx(Et,{className:"py-8 flex justify-center",children:s.jsx(mt,{className:"w-6 h-6 animate-spin text-bambu-green"})})});const k=x?.status,C=k?.running||!1;return s.jsxs("div",{className:"flex flex-col lg:flex-row gap-6 lg:gap-8",children:[s.jsx("div",{className:"space-y-6 lg:w-[480px] lg:flex-shrink-0",children:s.jsxs(Mt,{children:[s.jsx(mr,{children:s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Ir,{className:"w-5 h-5 text-bambu-green"}),s.jsx("h2",{className:"text-lg font-semibold text-white",children:"Virtual Printer"})]}),k&&s.jsxs("div",{className:`flex items-center gap-2 text-sm ${C?"text-green-400":"text-bambu-gray"}`,children:[s.jsx("span",{className:`w-2 h-2 rounded-full ${C?"bg-green-400 animate-pulse":"bg-gray-500"}`}),C?"Running":"Stopped"]})]})}),s.jsxs(Et,{className:"space-y-4",children:[s.jsx("p",{className:"text-sm text-bambu-gray",children:"Enable a virtual printer that appears in Bambu Studio and OrcaSlicer. Files sent to this printer will be archived directly without printing."}),s.jsxs("div",{className:"flex items-center justify-between py-3 border-t border-bambu-dark-tertiary",children:[s.jsxs("div",{children:[s.jsx("div",{className:"text-white font-medium",children:"Enable Virtual Printer"}),s.jsx("div",{className:"text-sm text-bambu-gray",children:C?'Visible as "Bambuddy" in slicer discovery':"Not visible to slicers"})]}),s.jsx("button",{onClick:M,disabled:m==="toggle",className:`relative w-12 h-6 rounded-full transition-colors ${n?"bg-bambu-green":"bg-bambu-dark-tertiary"} ${m==="toggle"?"opacity-50":""}`,children:s.jsx("span",{className:`absolute top-1 left-1 w-4 h-4 bg-white rounded-full transition-transform ${n?"translate-x-6":""}`})})]}),s.jsxs("div",{className:"py-3 border-t border-bambu-dark-tertiary",children:[s.jsx("div",{className:"text-white font-medium mb-2",children:"Printer Model"}),s.jsx("div",{className:"text-sm text-bambu-gray mb-3",children:"Select which printer model to emulate."}),s.jsxs("div",{className:"relative",children:[s.jsx("select",{value:c,onChange:R=>E(R.target.value),disabled:m==="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:b?.models&&Object.entries(b.models).sort(([,R],[,T])=>R.localeCompare(T)).map(([R,T])=>s.jsx("option",{value:R,children:T},R))}),s.jsx(Ji,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}),n&&C&&s.jsxs("p",{className:"text-xs text-bambu-gray mt-2",children:[s.jsx(tl,{className:"w-3 h-3 inline mr-1"}),"Changing the model will restart the virtual printer"]})]}),s.jsxs("div",{className:"py-3 border-t border-bambu-dark-tertiary",children:[s.jsx("div",{className:"text-white font-medium mb-2",children:"Access Code"}),s.jsx("div",{className:"text-sm text-bambu-gray mb-3",children:x?.access_code_set?s.jsxs("span",{className:"flex items-center gap-1 text-green-400",children:[s.jsx(xs,{className:"w-4 h-4"}),"Access code is set"]}):s.jsxs("span",{className:"flex items-center gap-1 text-yellow-400",children:[s.jsx(Cn,{className:"w-4 h-4"}),"No access code set - required to enable"]})}),s.jsxs("div",{className:"flex gap-2",children:[s.jsxs("div",{className:"relative flex-1",children:[s.jsx("input",{type:d?"text":"password",value:i,onChange:R=>a(R.target.value),placeholder:x?.access_code_set?"Enter new code to change":"Enter 8-char code",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"}),s.jsx("button",{onClick:()=>f(!d),className:"absolute right-2 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white",children:d?s.jsx(T2,{className:"w-4 h-4"}):s.jsx(_f,{className:"w-4 h-4"})})]}),s.jsx(Se,{onClick:S,disabled:!i||m==="accessCode",variant:"primary",children:m==="accessCode"?s.jsx(mt,{className:"w-4 h-4 animate-spin"}):"Save"})]}),s.jsxs("p",{className:"text-xs text-bambu-gray mt-2",children:["Must be exactly 8 characters. Used by slicers to authenticate.",i&&s.jsxs("span",{className:i.length===8?"text-green-400":"text-yellow-400",children:[" ","(",i.length,"/8)"]})]})]}),s.jsxs("div",{className:"py-3 border-t border-bambu-dark-tertiary",children:[s.jsx("div",{className:"text-white font-medium mb-2",children:"Mode"}),s.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[s.jsxs("button",{onClick:()=>A("immediate"),disabled:m==="mode",className:`p-3 rounded-lg border text-left transition-colors ${o==="immediate"?"border-bambu-green bg-bambu-green/10":"border-bambu-dark-tertiary hover:border-bambu-gray"}`,children:[s.jsx("div",{className:"text-white font-medium",children:"Archive"}),s.jsx("div",{className:"text-xs text-bambu-gray",children:"Archive files immediately"})]}),s.jsxs("button",{onClick:()=>A("review"),disabled:m==="mode",className:`p-3 rounded-lg border text-left transition-colors ${o==="review"?"border-bambu-green bg-bambu-green/10":"border-bambu-dark-tertiary hover:border-bambu-gray"}`,children:[s.jsx("div",{className:"text-white font-medium",children:"Review"}),s.jsx("div",{className:"text-xs text-bambu-gray",children:"Review and tag before archiving"})]}),s.jsxs("button",{onClick:()=>A("print_queue"),disabled:m==="mode",className:`p-3 rounded-lg border text-left transition-colors ${o==="print_queue"?"border-bambu-green bg-bambu-green/10":"border-bambu-dark-tertiary hover:border-bambu-gray"}`,children:[s.jsx("div",{className:"text-white font-medium",children:"Queue"}),s.jsx("div",{className:"text-xs text-bambu-gray",children:"Archive and add to print queue"})]})]})]})]})]})}),s.jsxs("div",{className:"space-y-6 lg:w-[480px] lg:flex-shrink-0",children:[s.jsx(Mt,{className:"border-l-4 border-l-yellow-500",children:s.jsx(Et,{className:"py-4",children:s.jsxs("div",{className:"flex items-start gap-3",children:[s.jsx(Cn,{className:"w-5 h-5 text-yellow-500 flex-shrink-0 mt-0.5"}),s.jsxs("div",{className:"text-sm",children:[s.jsx("p",{className:"text-white font-medium mb-2",children:"Setup Required"}),s.jsx("p",{className:"text-bambu-gray mb-3",children:"The virtual printer feature requires additional system configuration before it will work. This includes port forwarding, firewall rules, and platform-specific settings."}),s.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:[s.jsx(Lr,{className:"w-4 h-4"}),"Read the setup guide before enabling"]})]})]})})}),s.jsx(Mt,{children:s.jsx(Et,{className:"py-4",children:s.jsxs("div",{className:"flex items-start gap-3",children:[s.jsx(tl,{className:"w-5 h-5 text-blue-400 flex-shrink-0 mt-0.5"}),s.jsxs("div",{className:"text-sm text-bambu-gray",children:[s.jsx("p",{className:"mb-2",children:s.jsx("strong",{className:"text-white",children:"How it works:"})}),s.jsxs("ol",{className:"list-decimal list-inside space-y-1",children:[s.jsx("li",{children:"Complete the setup guide for your platform"}),s.jsx("li",{children:"Enable the virtual printer and set an access code"}),s.jsx("li",{children:'In Bambu Studio or OrcaSlicer, go to "Add Printer"'}),s.jsx("li",{children:'The "Bambuddy" printer should appear in the discovery list'}),s.jsx("li",{children:"Connect using the access code you set"}),s.jsx("li",{children:'When you "print" to Bambuddy, the 3MF file is archived instead'})]})]})]})})}),k&&C&&s.jsxs(Mt,{children:[s.jsx(mr,{children:s.jsx("h3",{className:"text-md font-semibold text-white",children:"Status Details"})}),s.jsx(Et,{children:s.jsxs("div",{className:"grid grid-cols-2 gap-4 text-sm",children:[s.jsxs("div",{children:[s.jsx("div",{className:"text-bambu-gray",children:"Printer Name"}),s.jsx("div",{className:"text-white",children:k.name})]}),s.jsxs("div",{children:[s.jsx("div",{className:"text-bambu-gray",children:"Model"}),s.jsx("div",{className:"text-white",children:k.model_name||k.model})]}),s.jsxs("div",{children:[s.jsx("div",{className:"text-bambu-gray",children:"Serial Number"}),s.jsx("div",{className:"text-white font-mono",children:k.serial})]}),s.jsxs("div",{children:[s.jsx("div",{className:"text-bambu-gray",children:"Mode"}),s.jsx("div",{className:"text-white capitalize",children:k.mode})]}),s.jsxs("div",{children:[s.jsx("div",{className:"text-bambu-gray",children:"Pending Files"}),s.jsx("div",{className:"text-white",children:k.pending_files})]})]})})]})]})]})}const Qqe={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 Zqe(t,e){const n=e.replace("#/","").split("/");let r=t;for(const i of n)r=r[i];return r}function Tb(t,e,n=0){if(n>5)return"...";if(e.$ref)return Tb(t,Zqe(t,e.$ref),n+1);if(e.allOf){const r={};for(const i of e.allOf){const a=Tb(t,i,n+1);typeof a=="object"&&a!==null&&Object.assign(r,a)}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?[Tb(t,e.items,n+1)]:[];case"object":if(e.properties){const r={};for(const[i,a]of Object.entries(e.properties))r[i]=Tb(t,a,n+1);return r}return{};default:return null}}function Jqe({path:t,method:e,spec:n,schema:r,apiKey:i}){const[a,o]=w.useState(!1),[l,c]=w.useState({}),[u,d]=w.useState(""),[f,m]=w.useState(null),[g,x]=w.useState(!1),[y,b]=w.useState(!1);w.useEffect(()=>{if(a&&n.parameters){const R={};for(const T of n.parameters)T.schema?.default!==void 0&&(R[T.name]=String(T.schema.default));c(T=>({...R,...T}))}},[a,n.parameters]),w.useEffect(()=>{if(a&&n.requestBody?.content?.["application/json"]?.schema&&!u){const R=n.requestBody.content["application/json"].schema,T=Tb(r,R);d(JSON.stringify(T,null,2))}},[a,n.requestBody,r,u]);const M=(()=>{const R=[];for(const T of n.parameters||[])if(T.in==="path"||T.required){const P=l[T.name];(P===void 0||P==="")&&R.push(T.name)}return R})(),S=async()=>{if(M.length>0){m({status:0,statusText:"Validation Error",headers:{},body:`Missing required parameters: ${M.join(", ")}`,duration:0});return}x(!0),m(null);try{let R=t;const T=new URLSearchParams;for(const oe of n.parameters||[]){const B=l[oe.name];B!==void 0&&B!==""&&(oe.in==="path"?R=R.replace(`{${oe.name}}`,encodeURIComponent(B)):oe.in==="query"&&T.append(oe.name,B))}const P=T.toString(),F=`${R}${P?`?${P}`:""}`,L={"Content-Type":"application/json"};i&&(L["X-API-Key"]=i);const X={method:e.toUpperCase(),headers:L};["post","put","patch"].includes(e)&&u&&(X.body=u);const D=performance.now(),K=await fetch(F,X),Y=Math.round(performance.now()-D),q={};K.headers.forEach((oe,B)=>{q[B]=oe});let Z;K.headers.get("content-type")?.includes("application/json")?Z=await K.json():Z=await K.text(),m({status:K.status,statusText:K.statusText,headers:q,body:Z,duration:Y})}catch(R){m({status:0,statusText:"Network Error",headers:{},body:R instanceof Error?R.message:"Unknown error",duration:0})}finally{x(!1)}},A=async()=>{if(f){const R=typeof f.body=="string"?f.body:JSON.stringify(f.body,null,2);try{await navigator.clipboard.writeText(R),b(!0),setTimeout(()=>b(!1),2e3)}catch{const T=document.createElement("textarea");T.value=R,T.style.position="fixed",T.style.left="-999999px",document.body.appendChild(T),T.select(),document.execCommand("copy"),document.body.removeChild(T),b(!0),setTimeout(()=>b(!1),2e3)}}},E=(n.parameters||[]).filter(R=>R.in==="path"),k=(n.parameters||[]).filter(R=>R.in==="query"),C=["post","put","patch"].includes(e)&&n.requestBody;return s.jsxs("div",{className:"border border-bambu-dark-tertiary rounded-lg overflow-hidden",children:[s.jsxs("button",{onClick:()=>o(!a),className:"w-full flex items-center gap-3 p-3 hover:bg-bambu-dark-tertiary/50 transition-colors text-left",children:[a?s.jsx(Ji,{className:"w-4 h-4 text-bambu-gray flex-shrink-0"}):s.jsx(Gs,{className:"w-4 h-4 text-bambu-gray flex-shrink-0"}),s.jsx("span",{className:`px-2 py-0.5 text-xs font-mono font-semibold uppercase rounded border ${Qqe[e]||"bg-gray-500/20 text-gray-400"}`,children:e}),s.jsx("code",{className:"text-sm text-white font-mono flex-1 truncate",children:t}),n.summary&&s.jsx("span",{className:"text-sm text-bambu-gray truncate max-w-[40%]",children:n.summary})]}),a&&s.jsxs("div",{className:"border-t border-bambu-dark-tertiary p-4 space-y-4 bg-bambu-dark/50",children:[n.description&&s.jsx("p",{className:"text-sm text-bambu-gray",children:n.description}),E.length>0&&s.jsxs("div",{className:"space-y-2",children:[s.jsx("h4",{className:"text-sm font-medium text-white",children:"Path Parameters"}),s.jsx("div",{className:"space-y-2",children:E.map(R=>s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs("label",{className:"text-sm text-bambu-gray w-32 flex-shrink-0",children:[R.name,R.required&&s.jsx("span",{className:"text-red-400 ml-1",children:"*"})]}),s.jsx("input",{type:"text",value:l[R.name]||"",onChange:T=>c(P=>({...P,[R.name]:T.target.value})),placeholder:R.description||R.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"})]},R.name))})]}),k.length>0&&s.jsxs("div",{className:"space-y-2",children:[s.jsx("h4",{className:"text-sm font-medium text-white",children:"Query Parameters"}),s.jsx("div",{className:"space-y-2",children:k.map(R=>s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs("label",{className:"text-sm text-bambu-gray w-32 flex-shrink-0",children:[R.name,R.required&&s.jsx("span",{className:"text-red-400 ml-1",children:"*"})]}),R.schema?.enum?s.jsxs("select",{value:l[R.name]||"",onChange:T=>c(P=>({...P,[R.name]:T.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:[s.jsx("option",{value:"",children:"-- Select --"}),R.schema.enum.map(T=>s.jsx("option",{value:T,children:T},T))]}):s.jsx("input",{type:"text",value:l[R.name]||"",onChange:T=>c(P=>({...P,[R.name]:T.target.value})),placeholder:R.description||R.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"})]},R.name))})]}),C&&s.jsxs("div",{className:"space-y-2",children:[s.jsx("h4",{className:"text-sm font-medium text-white",children:"Request Body"}),s.jsx("textarea",{value:u,onChange:R=>d(R.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..."})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs(Se,{onClick:S,disabled:g,children:[g?s.jsx(mt,{className:"w-4 h-4 animate-spin"}):s.jsx(rl,{className:"w-4 h-4"}),"Execute"]}),M.length>0&&s.jsxs("span",{className:"text-xs text-yellow-400 flex items-center gap-1",children:[s.jsx(ea,{className:"w-3 h-3"}),"Fill in: ",M.join(", ")]})]}),f&&s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("h4",{className:"text-sm font-medium text-white flex items-center gap-2",children:["Response",s.jsxs("span",{className:`px-2 py-0.5 text-xs rounded ${f.status>=200&&f.status<300?"bg-green-500/20 text-green-400":f.status>=400?"bg-red-500/20 text-red-400":"bg-yellow-500/20 text-yellow-400"}`,children:[f.status," ",f.statusText]}),s.jsxs("span",{className:"text-xs text-bambu-gray",children:[f.duration,"ms"]})]}),s.jsx(Se,{variant:"secondary",size:"sm",onClick:A,children:y?s.jsx(Dn,{className:"w-3 h-3 text-green-400"}):s.jsx(Jo,{className:"w-3 h-3"})})]}),s.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 f.body=="string"?f.body:JSON.stringify(f.body,null,2)})]})]})]})}function eKe({apiKey:t=""}){const[e,n]=w.useState(null),[r,i]=w.useState(!0),[a,o]=w.useState(null),[l,c]=w.useState(new Set),[u,d]=w.useState("");if(w.useEffect(()=>{async function b(){try{const v=await fetch("/openapi.json");if(!v.ok)throw new Error("Failed to fetch OpenAPI schema");const M=await v.json();n(M)}catch(v){o(v instanceof Error?v.message:"Unknown error")}finally{i(!1)}}b()},[]),r)return s.jsx("div",{className:"flex justify-center py-12",children:s.jsx(mt,{className:"w-8 h-8 text-bambu-green animate-spin"})});if(a||!e)return s.jsx(Mt,{children:s.jsx(Et,{className:"py-8",children:s.jsxs("div",{className:"text-center text-red-400",children:[s.jsx(ea,{className:"w-12 h-12 mx-auto mb-3 opacity-50"}),s.jsx("p",{children:"Failed to load API schema"}),s.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:a})]})})});const f={};for(const[b,v]of Object.entries(e.paths))for(const[M,S]of Object.entries(v)){if(M==="parameters")continue;const A=S.tags||["Other"];for(const E of A)f[E]||(f[E]=[]),f[E].push({path:b,method:M,spec:S})}const m=Object.entries(f).map(([b,v])=>{if(!u)return{tag:b,endpoints:v};const M=v.filter(({path:S,method:A,spec:E})=>{const k=u.toLowerCase();return S.toLowerCase().includes(k)||A.toLowerCase().includes(k)||(E.summary?.toLowerCase()||"").includes(k)||(E.description?.toLowerCase()||"").includes(k)});return{tag:b,endpoints:M}}).filter(({endpoints:b})=>b.length>0).sort((b,v)=>b.tag.localeCompare(v.tag)),g=b=>{c(v=>{const M=new Set(v);return M.has(b)?M.delete(b):M.add(b),M})},x=()=>{c(new Set(m.map(b=>b.tag)))},y=()=>{c(new Set)};return s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{className:"flex items-center justify-between gap-4",children:[s.jsx("div",{className:"flex-1",children:s.jsx("input",{type:"text",value:u,onChange:b=>d(b.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"})}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Se,{variant:"secondary",size:"sm",onClick:x,children:"Expand All"}),s.jsx(Se,{variant:"secondary",size:"sm",onClick:y,children:"Collapse All"}),s.jsxs("a",{href:"/docs",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1 text-sm text-bambu-green hover:underline",children:[s.jsx(Lr,{className:"w-4 h-4"}),"Swagger UI"]})]})]}),s.jsxs("p",{className:"text-sm text-bambu-gray",children:[m.reduce((b,v)=>b+v.endpoints.length,0)," endpoints in ",m.length," categories"]}),s.jsx("div",{className:"space-y-3",children:m.map(({tag:b,endpoints:v})=>s.jsxs(Mt,{children:[s.jsx("button",{onClick:()=>g(b),className:"w-full flex items-center justify-between p-4 hover:bg-bambu-dark-tertiary/30 transition-colors text-left",children:s.jsxs("div",{className:"flex items-center gap-2",children:[l.has(b)?s.jsx(Ji,{className:"w-5 h-5 text-bambu-gray"}):s.jsx(Gs,{className:"w-5 h-5 text-bambu-gray"}),s.jsx("h3",{className:"text-base font-semibold text-white capitalize",children:b.replace(/-/g," ")}),s.jsx("span",{className:"text-xs bg-bambu-dark-tertiary px-2 py-0.5 rounded-full text-bambu-gray",children:v.length})]})}),l.has(b)&&s.jsx(Et,{className:"pt-0 space-y-2",children:v.map(({path:M,method:S,spec:A})=>s.jsx(Jqe,{path:M,method:S,spec:A,schema:e,apiKey:t},`${S}-${M}`))})]},b))})]})}const tKe=["general","network","plugs","notifications","filament","apikeys","virtual-printer","users"];function nKe(){const t=tn(),e=ol(),[n,r]=wW(),{t:i,i18n:a}=Tg(),{showToast:o,showPersistentToast:l,dismissToast:c}=$n(),{authEnabled:u,user:d,refreshAuth:f}=Yd(),{mode:m,darkStyle:g,darkBackground:x,darkAccent:y,lightStyle:b,lightBackground:v,lightAccent:M,setDarkStyle:S,setDarkBackground:A,setDarkAccent:E,setLightStyle:k,setLightBackground:C,setLightAccent:R}=Xd(),[T,P]=w.useState(null),[F,L]=w.useState(!1),[X,D]=w.useState(null),[K,Y]=w.useState(!1),[q,Z]=w.useState(null),[re,oe]=w.useState(null),[B,G]=w.useState(!1),[J,te]=w.useState(dq()),ae=n.get("tab"),de=ae&&tKe.includes(ae)?ae:"general",[fe,Ae]=w.useState(de),ge=xe=>{Ae(xe),xe==="general"?n.delete("tab"):n.set("tab",xe),r(n,{replace:!0})},[Me,je]=w.useState(!1),[ne,Ke]=w.useState(""),[$,z]=w.useState({can_queue:!0,can_control_printer:!1,can_read_status:!0}),[W,U]=w.useState(null),[V,Q]=w.useState(null),[Ee,Ce]=w.useState(""),[Ne,H]=w.useState(!1),[O,ie]=w.useState(!1),[ye,_e]=w.useState(null),[le,ke]=w.useState(!1),[Oe,Ze]=w.useState(!1),[ht,We]=w.useState(!1),[he,rt]=w.useState(!1),[qe,Je]=w.useState(!1),[ot,se]=w.useState(null),[$e,be]=w.useState(!1),Fe=xe=>{te(xe),sfe(xe)},De=()=>{localStorage.removeItem("sidebarOrder"),window.location.reload()},{data:ve,isLoading:He}=ct({queryKey:["settings"],queryFn:pe.getSettings}),{data:dt,isLoading:kt}=ct({queryKey:["smart-plugs"],queryFn:pe.getSmartPlugs}),{data:jt,isLoading:Zt}=ct({queryKey:["smart-plugs-energy",dt?.map(xe=>xe.id)],queryFn:async()=>{if(!dt||dt.length===0)return null;const xe=await Promise.all(dt.filter(Gt=>Gt.enabled).map(async Gt=>{try{const Wt=await pe.getSmartPlugStatus(Gt.id);return{plug:Gt,status:Wt}}catch{return{plug:Gt,status:null}}}));let st=0,Ht=0,It=0,on=0,un=0;for(const{status:Gt}of xe)Gt?.reachable&&Gt.energy&&(un++,Gt.energy.power!=null&&(st+=Gt.energy.power),Gt.energy.today!=null&&(Ht+=Gt.energy.today),Gt.energy.yesterday!=null&&(It+=Gt.energy.yesterday),Gt.energy.total!=null&&(on+=Gt.energy.total));return{totalPower:st,totalToday:Ht,totalYesterday:It,totalLifetime:on,reachableCount:un,totalPlugs:dt.filter(Gt=>Gt.enabled).length}},enabled:fe==="plugs"&&!!dt&&dt.length>0,refetchInterval:fe==="plugs"?1e4:!1}),{data:Rt,isLoading:nn}=ct({queryKey:["notification-providers"],queryFn:pe.getNotificationProviders}),{data:pt,isLoading:$t}=ct({queryKey:["api-keys"],queryFn:pe.getAPIKeys}),qt=ft({mutationFn:xe=>pe.createAPIKey(xe),onSuccess:xe=>{U(xe.key||null),je(!1),Ke(""),t.invalidateQueries({queryKey:["api-keys"]}),o("API key created")},onError:xe=>{o(`Failed to create API key: ${xe.message}`,"error")}}),wt=ft({mutationFn:xe=>pe.deleteAPIKey(xe),onSuccess:()=>{t.invalidateQueries({queryKey:["api-keys"]}),o("API key deleted")},onError:xe=>{o(`Failed to delete API key: ${xe.message}`,"error")}}),{data:_r}=ct({queryKey:["printers"],queryFn:pe.getPrinters}),{data:$r,isLoading:Tr}=ct({queryKey:["notification-templates"],queryFn:pe.getNotificationTemplates}),{data:hr}=ct({queryKey:["virtual-printer-settings"],queryFn:R1.getSettings,refetchInterval:1e4}),yt=hr?.status?.running??!1,{data:en}=ct({queryKey:["ffmpeg-status"],queryFn:pe.checkFfmpeg}),{data:wn}=ct({queryKey:["version"],queryFn:pe.getVersion}),{data:ue,refetch:Be,isRefetching:Ye}=ct({queryKey:["updateCheck"],queryFn:pe.checkForUpdates,staleTime:300*1e3}),{data:Xe,refetch:Qe}=ct({queryKey:["updateStatus"],queryFn:pe.getUpdateStatus,refetchInterval:xe=>{const st=xe.state.data;return st?.status==="downloading"||st?.status==="installing"?1e3:!1}}),{data:At}=ct({queryKey:["mqtt-status"],queryFn:pe.getMQTTStatus,refetchInterval:fe==="network"?5e3:!1}),ce=ft({mutationFn:pe.applyUpdate,onSuccess:xe=>{xe.is_docker?o(xe.message,"error"):Qe()}}),[we,Ie]=w.useState(null),Le=ft({mutationFn:pe.testAllNotificationProviders,onSuccess:xe=>{Ie(xe),t.invalidateQueries({queryKey:["notification-providers"]}),xe.failed===0?o(`All ${xe.tested} providers tested successfully!`,"success"):o(`${xe.success}/${xe.tested} providers succeeded`,xe.failed>0?"error":"success")},onError:xe=>{o(`Failed to test providers: ${xe.message}`,"error")}}),Re=ft({mutationFn:async xe=>{if(!dt)return{success:0,failed:0};const st=dt.filter(It=>It.enabled),Ht=await Promise.all(st.map(async It=>{try{return await pe.controlSmartPlug(It.id,xe),{success:!0}}catch{return{success:!1}}}));return{success:Ht.filter(It=>It.success).length,failed:Ht.filter(It=>!It.success).length}},onSuccess:(xe,st)=>{t.invalidateQueries({queryKey:["smart-plugs"]}),t.invalidateQueries({queryKey:["smart-plugs-energy"]}),xe.failed===0?o(`All ${xe.success} plugs turned ${st}`,"success"):o(`${xe.success} plugs turned ${st}, ${xe.failed} failed`,"error")},onError:xe=>{o(`Failed: ${xe.message}`,"error")}}),ut=w.useRef(null),_t=w.useRef(!1),Tt=w.useRef(!0);w.useEffect(()=>{if(ve&&!T){const xe={...ve,external_url:ve.external_url||window.location.origin};P(xe),setTimeout(()=>{Tt.current=!1},100)}},[ve,T]);const St=ft({mutationFn:pe.updateSettings,onSuccess:xe=>{t.setQueryData(["settings"],xe),P(xe),t.invalidateQueries({queryKey:["archiveStats"]}),o("Settings saved","success")},onError:xe=>{o(`Failed to save: ${xe.message}`,"error")},onSettled:()=>{_t.current=!1}});w.useEffect(()=>{if(!(Tt.current||!T||!ve||!(ve.auto_archive!==T.auto_archive||ve.save_thumbnails!==T.save_thumbnails||ve.capture_finish_photo!==T.capture_finish_photo||ve.default_filament_cost!==T.default_filament_cost||ve.currency!==T.currency||ve.energy_cost_per_kwh!==T.energy_cost_per_kwh||ve.energy_tracking_mode!==T.energy_tracking_mode||ve.check_updates!==T.check_updates||ve.notification_language!==T.notification_language||ve.telemetry_enabled!==T.telemetry_enabled||ve.ams_humidity_good!==T.ams_humidity_good||ve.ams_humidity_fair!==T.ams_humidity_fair||ve.ams_temp_good!==T.ams_temp_good||ve.ams_temp_fair!==T.ams_temp_fair||ve.ams_history_retention_days!==T.ams_history_retention_days||ve.per_printer_mapping_expanded!==T.per_printer_mapping_expanded||ve.date_format!==T.date_format||ve.time_format!==T.time_format||ve.default_printer_id!==T.default_printer_id||ve.ftp_retry_enabled!==T.ftp_retry_enabled||ve.ftp_retry_count!==T.ftp_retry_count||ve.ftp_retry_delay!==T.ftp_retry_delay||ve.ftp_timeout!==T.ftp_timeout||ve.mqtt_enabled!==T.mqtt_enabled||ve.mqtt_broker!==T.mqtt_broker||ve.mqtt_port!==T.mqtt_port||ve.mqtt_username!==T.mqtt_username||ve.mqtt_password!==T.mqtt_password||ve.mqtt_topic_prefix!==T.mqtt_topic_prefix||ve.mqtt_use_tls!==T.mqtt_use_tls||ve.external_url!==T.external_url||ve.ha_enabled!==T.ha_enabled||ve.ha_url!==T.ha_url||ve.ha_token!==T.ha_token||(ve.library_archive_mode??"ask")!==(T.library_archive_mode??"ask")||Number(ve.library_disk_warning_gb??5)!==Number(T.library_disk_warning_gb??5)||(ve.camera_view_mode??"window")!==(T.camera_view_mode??"window")))&&!_t.current)return ut.current&&clearTimeout(ut.current),ut.current=setTimeout(()=>{if(_t.current)return;_t.current=!0;const st={auto_archive:T.auto_archive,save_thumbnails:T.save_thumbnails,capture_finish_photo:T.capture_finish_photo,default_filament_cost:T.default_filament_cost,currency:T.currency,energy_cost_per_kwh:T.energy_cost_per_kwh,energy_tracking_mode:T.energy_tracking_mode,check_updates:T.check_updates,notification_language:T.notification_language,telemetry_enabled:T.telemetry_enabled,ams_humidity_good:T.ams_humidity_good,ams_humidity_fair:T.ams_humidity_fair,ams_temp_good:T.ams_temp_good,ams_temp_fair:T.ams_temp_fair,ams_history_retention_days:T.ams_history_retention_days,per_printer_mapping_expanded:T.per_printer_mapping_expanded,date_format:T.date_format,time_format:T.time_format,default_printer_id:T.default_printer_id,ftp_retry_enabled:T.ftp_retry_enabled,ftp_retry_count:T.ftp_retry_count,ftp_retry_delay:T.ftp_retry_delay,ftp_timeout:T.ftp_timeout,mqtt_enabled:T.mqtt_enabled,mqtt_broker:T.mqtt_broker,mqtt_port:T.mqtt_port,mqtt_username:T.mqtt_username,mqtt_password:T.mqtt_password,mqtt_topic_prefix:T.mqtt_topic_prefix,mqtt_use_tls:T.mqtt_use_tls,external_url:T.external_url,ha_enabled:T.ha_enabled,ha_url:T.ha_url,ha_token:T.ha_token,library_archive_mode:T.library_archive_mode,library_disk_warning_gb:T.library_disk_warning_gb,camera_view_mode:T.camera_view_mode};St.mutate(st)},500),()=>{ut.current&&clearTimeout(ut.current)}},[T,ve,St]);const vt=w.useCallback((xe,st)=>{P(Ht=>Ht?{...Ht,[xe]:st}:null)},[]);return He||!T?s.jsx("div",{className:"p-4 md:p-8 flex justify-center",children:s.jsx(mt,{className:"w-8 h-8 text-bambu-green animate-spin"})}):s.jsxs("div",{className:"p-4 md:p-8",children:[s.jsxs("div",{className:"mb-8",children:[s.jsx("h1",{className:"text-2xl font-bold text-white",children:"Settings"}),s.jsx("p",{className:"text-bambu-gray",children:"Configure Bambuddy"})]}),s.jsxs("div",{className:"flex gap-1 mb-6 border-b border-bambu-dark-tertiary overflow-x-auto",children:[s.jsx("button",{onClick:()=>ge("general"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px ${fe==="general"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:"General"}),s.jsxs("button",{onClick:()=>ge("plugs"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${fe==="plugs"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[s.jsx(Us,{className:"w-4 h-4"}),"Smart Plugs",dt&&dt.length>0&&s.jsx("span",{className:"text-xs bg-bambu-dark-tertiary px-1.5 py-0.5 rounded-full",children:dt.length})]}),s.jsxs("button",{onClick:()=>ge("notifications"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${fe==="notifications"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[s.jsx(tf,{className:"w-4 h-4"}),"Notifications",Rt&&Rt.length>0&&s.jsx("span",{className:"text-xs bg-bambu-dark-tertiary px-1.5 py-0.5 rounded-full",children:Rt.length})]}),s.jsxs("button",{onClick:()=>ge("filament"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${fe==="filament"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[s.jsx(qce,{className:"w-4 h-4"}),"Filament"]}),s.jsxs("button",{onClick:()=>ge("network"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${fe==="network"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[s.jsx(Dp,{className:"w-4 h-4"}),"Network",s.jsx("span",{className:`w-2 h-2 rounded-full ${At?.enabled?"bg-green-400":"bg-gray-500"}`})]}),s.jsxs("button",{onClick:()=>ge("apikeys"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${fe==="apikeys"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[s.jsx(Gh,{className:"w-4 h-4"}),"API Keys",pt&&pt.length>0&&s.jsx("span",{className:"text-xs bg-bambu-dark-tertiary px-1.5 py-0.5 rounded-full",children:pt.length})]}),s.jsxs("button",{onClick:()=>ge("virtual-printer"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${fe==="virtual-printer"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[s.jsx(Ir,{className:"w-4 h-4"}),"Virtual Printer",s.jsx("span",{className:`w-2 h-2 rounded-full ${yt?"bg-green-400":"bg-gray-500"}`})]}),s.jsxs("button",{onClick:()=>ge("users"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${fe==="users"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[s.jsx(Wh,{className:"w-4 h-4"}),"Users",u&&s.jsx("span",{className:`w-2 h-2 rounded-full ${u?"bg-green-400":"bg-gray-500"}`})]})]}),fe==="general"&&s.jsxs("div",{className:"flex flex-col lg:flex-row gap-6 lg:gap-8",children:[s.jsxs("div",{className:"space-y-6 flex-1 lg:max-w-xl",children:[s.jsxs(Mt,{children:[s.jsx(mr,{children:s.jsx("h2",{className:"text-lg font-semibold text-white",children:i("settings.general")})}),s.jsxs(Et,{className:"space-y-4",children:[s.jsxs("div",{children:[s.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[s.jsx(Md,{className:"w-4 h-4 inline mr-1"}),i("settings.language")]}),s.jsx("select",{value:a.language,onChange:xe=>a.changeLanguage(xe.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:GU.map(xe=>s.jsxs("option",{value:xe.code,children:[xe.nativeName," (",xe.name,")"]},xe.code))}),s.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:i("settings.languageDescription")})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:i("settings.defaultView")}),s.jsx("select",{value:J,onChange:xe=>Fe(xe.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:s0.map(xe=>s.jsx("option",{value:xe.to,children:i(xe.labelKey)},xe.id))}),s.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:i("settings.defaultViewDescription")})]}),s.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Date Format"}),s.jsxs("select",{value:T.date_format||"system",onChange:xe=>vt("date_format",xe.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:[s.jsx("option",{value:"system",children:"System Default"}),s.jsx("option",{value:"us",children:"US (MM/DD/YYYY)"}),s.jsx("option",{value:"eu",children:"EU (DD/MM/YYYY)"}),s.jsx("option",{value:"iso",children:"ISO (YYYY-MM-DD)"})]})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Time Format"}),s.jsxs("select",{value:T.time_format||"system",onChange:xe=>vt("time_format",xe.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:[s.jsx("option",{value:"system",children:"System Default"}),s.jsx("option",{value:"12h",children:"12-hour (3:30 PM)"}),s.jsx("option",{value:"24h",children:"24-hour (15:30)"})]})]})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Default Printer"}),s.jsxs("select",{value:T.default_printer_id??"",onChange:xe=>vt("default_printer_id",xe.target.value?Number(xe.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:[s.jsx("option",{value:"",children:"No default (ask each time)"}),_r?.map(xe=>s.jsx("option",{value:xe.id,children:xe.name},xe.id))]}),s.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Pre-select this printer for uploads, reprints, and other operations."})]}),s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{children:[s.jsx("p",{className:"text-white",children:"Sidebar order"}),s.jsx("p",{className:"text-sm text-bambu-gray",children:"Drag items in the sidebar to reorder. Reset to default order here."})]}),s.jsxs(Se,{variant:"secondary",size:"sm",onClick:De,children:[s.jsx(Vf,{className:"w-4 h-4"}),"Reset"]})]})]})]}),s.jsxs(Mt,{children:[s.jsx(mr,{children:s.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[s.jsx(nD,{className:"w-5 h-5"}),"Appearance"]})}),s.jsxs(Et,{className:"space-y-6",children:[s.jsxs("div",{className:`space-y-3 p-4 rounded-lg border ${m==="dark"?"border-bambu-green bg-bambu-green/5":"border-bambu-dark-tertiary"}`,children:[s.jsxs("h3",{className:"text-sm font-medium text-white flex items-center gap-2",children:["Dark Mode",m==="dark"&&s.jsx("span",{className:"text-xs text-bambu-green",children:"(active)"})]}),s.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[s.jsxs("div",{children:[s.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Background"}),s.jsxs("select",{value:x,onChange:xe=>{A(xe.target.value),o("Settings saved","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:[s.jsx("option",{value:"neutral",children:"Neutral"}),s.jsx("option",{value:"warm",children:"Warm"}),s.jsx("option",{value:"cool",children:"Cool"}),s.jsx("option",{value:"oled",children:"OLED Black"}),s.jsx("option",{value:"slate",children:"Slate Blue"}),s.jsx("option",{value:"forest",children:"Forest Green"})]})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Accent"}),s.jsxs("select",{value:y,onChange:xe=>{E(xe.target.value),o("Settings saved","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:[s.jsx("option",{value:"green",children:"Green"}),s.jsx("option",{value:"teal",children:"Teal"}),s.jsx("option",{value:"blue",children:"Blue"}),s.jsx("option",{value:"orange",children:"Orange"}),s.jsx("option",{value:"purple",children:"Purple"}),s.jsx("option",{value:"red",children:"Red"})]})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Style"}),s.jsxs("select",{value:g,onChange:xe=>{S(xe.target.value),o("Settings saved","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:[s.jsx("option",{value:"classic",children:"Classic"}),s.jsx("option",{value:"glow",children:"Glow"}),s.jsx("option",{value:"vibrant",children:"Vibrant"})]})]})]})]}),s.jsxs("div",{className:`space-y-3 p-4 rounded-lg border ${m==="light"?"border-bambu-green bg-bambu-green/5":"border-bambu-dark-tertiary"}`,children:[s.jsxs("h3",{className:"text-sm font-medium text-white flex items-center gap-2",children:["Light Mode",m==="light"&&s.jsx("span",{className:"text-xs text-bambu-green",children:"(active)"})]}),s.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[s.jsxs("div",{children:[s.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Background"}),s.jsxs("select",{value:v,onChange:xe=>{C(xe.target.value),o("Settings saved","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:[s.jsx("option",{value:"neutral",children:"Neutral"}),s.jsx("option",{value:"warm",children:"Warm"}),s.jsx("option",{value:"cool",children:"Cool"})]})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Accent"}),s.jsxs("select",{value:M,onChange:xe=>{R(xe.target.value),o("Settings saved","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:[s.jsx("option",{value:"green",children:"Green"}),s.jsx("option",{value:"teal",children:"Teal"}),s.jsx("option",{value:"blue",children:"Blue"}),s.jsx("option",{value:"orange",children:"Orange"}),s.jsx("option",{value:"purple",children:"Purple"}),s.jsx("option",{value:"red",children:"Red"})]})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Style"}),s.jsxs("select",{value:b,onChange:xe=>{k(xe.target.value),o("Settings saved","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:[s.jsx("option",{value:"classic",children:"Classic"}),s.jsx("option",{value:"glow",children:"Glow"}),s.jsx("option",{value:"vibrant",children:"Vibrant"})]})]})]})]}),s.jsx("p",{className:"text-xs text-bambu-gray",children:"Toggle between dark and light mode using the sun/moon icon in the sidebar."})]})]}),s.jsxs(Mt,{children:[s.jsx(mr,{children:s.jsx("h2",{className:"text-lg font-semibold text-white",children:"Archive Settings"})}),s.jsxs(Et,{className:"space-y-4",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{children:[s.jsx("p",{className:"text-white",children:"Auto-archive prints"}),s.jsx("p",{className:"text-sm text-bambu-gray",children:"Automatically save 3MF files when prints complete"})]}),s.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[s.jsx("input",{type:"checkbox",checked:T.auto_archive,onChange:xe=>vt("auto_archive",xe.target.checked),className:"sr-only peer"}),s.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"})]})]}),s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{children:[s.jsx("p",{className:"text-white",children:"Save thumbnails"}),s.jsx("p",{className:"text-sm text-bambu-gray",children:"Extract and save preview images from 3MF files"})]}),s.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[s.jsx("input",{type:"checkbox",checked:T.save_thumbnails,onChange:xe=>vt("save_thumbnails",xe.target.checked),className:"sr-only peer"}),s.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"})]})]}),s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{children:[s.jsx("p",{className:"text-white",children:"Capture finish photo"}),s.jsx("p",{className:"text-sm text-bambu-gray",children:"Take a photo from printer camera when print completes"})]}),s.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[s.jsx("input",{type:"checkbox",checked:T.capture_finish_photo,onChange:xe=>vt("capture_finish_photo",xe.target.checked),className:"sr-only peer"}),s.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"})]})]}),T.capture_finish_photo&&en&&!en.installed&&s.jsxs("div",{className:"flex items-start gap-2 p-3 bg-yellow-500/10 border border-yellow-500/30 rounded-lg",children:[s.jsx(Cn,{className:"w-5 h-5 text-yellow-500 flex-shrink-0 mt-0.5"}),s.jsxs("div",{className:"text-sm",children:[s.jsx("p",{className:"text-yellow-500 font-medium",children:"ffmpeg not installed"}),s.jsxs("p",{className:"text-bambu-gray mt-1",children:["Camera capture requires ffmpeg. Install it via"," ",s.jsx("code",{className:"bg-bambu-dark-tertiary px-1 rounded",children:"brew install ffmpeg"})," (macOS) or"," ",s.jsx("code",{className:"bg-bambu-dark-tertiary px-1 rounded",children:"apt install ffmpeg"})," (Linux)."]})]})]})]})]})]}),s.jsxs("div",{className:"space-y-6 flex-1 lg:max-w-md",children:[s.jsxs(Mt,{children:[s.jsx(mr,{children:s.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[s.jsx(sD,{className:"w-5 h-5 text-bambu-green"}),"Camera"]})}),s.jsx(Et,{className:"space-y-4",children:s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Camera View Mode"}),s.jsxs("select",{value:T.camera_view_mode??"window",onChange:xe=>vt("camera_view_mode",xe.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:[s.jsx("option",{value:"window",children:"New Window"}),s.jsx("option",{value:"embedded",children:"Embedded Overlay"})]}),s.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:T.camera_view_mode==="embedded"?"Camera opens in a resizable overlay on the main screen":"Camera opens in a separate browser window"})]})})]}),s.jsxs(Mt,{children:[s.jsx(mr,{children:s.jsx("h2",{className:"text-lg font-semibold text-white",children:"Cost Tracking"})}),s.jsxs(Et,{className:"space-y-4",children:[s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Default filament cost (per kg)"}),s.jsx("input",{type:"number",step:"0.01",min:"0",value:T.default_filament_cost,onChange:xe=>vt("default_filament_cost",parseFloat(xe.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"})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Currency"}),s.jsxs("select",{value:T.currency,onChange:xe=>vt("currency",xe.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:[s.jsx("option",{value:"USD",children:"USD ($)"}),s.jsx("option",{value:"EUR",children:"EUR (€)"}),s.jsx("option",{value:"GBP",children:"GBP (£)"}),s.jsx("option",{value:"CHF",children:"CHF (Fr.)"}),s.jsx("option",{value:"JPY",children:"JPY (¥)"}),s.jsx("option",{value:"CNY",children:"CNY (¥)"}),s.jsx("option",{value:"CAD",children:"CAD ($)"}),s.jsx("option",{value:"AUD",children:"AUD ($)"})]})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Electricity cost per kWh"}),s.jsx("input",{type:"number",step:"0.01",min:"0",value:T.energy_cost_per_kwh,onChange:xe=>vt("energy_cost_per_kwh",parseFloat(xe.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"})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Energy display mode"}),s.jsxs("select",{value:T.energy_tracking_mode||"total",onChange:xe=>vt("energy_tracking_mode",xe.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:[s.jsx("option",{value:"print",children:"Prints Only"}),s.jsx("option",{value:"total",children:"Total Consumption"})]}),s.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:T.energy_tracking_mode==="print"?"Dashboard shows sum of energy used during prints":"Dashboard shows lifetime energy from smart plugs"})]})]})]}),s.jsxs(Mt,{children:[s.jsx(mr,{children:s.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[s.jsx(za,{className:"w-5 h-5 text-bambu-green"}),"File Manager"]})}),s.jsxs(Et,{className:"space-y-4",children:[s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Create Archive Entry When Printing"}),s.jsxs("select",{value:T.library_archive_mode??"ask",onChange:xe=>vt("library_archive_mode",xe.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:[s.jsx("option",{value:"always",children:"Always create archive entry"}),s.jsx("option",{value:"never",children:"Never create archive entry"}),s.jsx("option",{value:"ask",children:"Ask each time"})]}),s.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"When printing from File Manager, optionally create an archive entry"})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Low Disk Space Warning"}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("input",{type:"number",min:"0.5",max:"100",step:"0.5",value:T.library_disk_warning_gb??5,onChange:xe=>vt("library_disk_warning_gb",parseFloat(xe.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"}),s.jsx("span",{className:"text-bambu-gray",children:"GB"})]}),s.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Show warning when free disk space falls below this threshold"})]})]})]})]}),s.jsxs("div",{className:"space-y-6 flex-1 lg:max-w-sm",children:[s.jsx(Xqe,{}),s.jsxs(Mt,{children:[s.jsx(mr,{children:s.jsx("h2",{className:"text-lg font-semibold text-white",children:"Updates"})}),s.jsxs(Et,{className:"space-y-4",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{children:[s.jsx("p",{className:"text-white",children:"Check for updates"}),s.jsx("p",{className:"text-sm text-bambu-gray",children:"Automatically check for new versions on startup"})]}),s.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[s.jsx("input",{type:"checkbox",checked:T.check_updates,onChange:xe=>vt("check_updates",xe.target.checked),className:"sr-only peer"}),s.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"})]})]}),s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("p",{className:"text-white",children:i("settings.telemetry")}),s.jsxs("button",{onClick:()=>We(!0),className:"inline-flex items-center gap-1 px-2 py-0.5 text-xs bg-bambu-dark rounded-full text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary transition-colors",children:[s.jsx(tl,{className:"w-3 h-3"}),i("settings.telemetryLearnMore")]})]}),s.jsx("p",{className:"text-sm text-bambu-gray",children:i("settings.telemetryDescription")})]}),s.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[s.jsx("input",{type:"checkbox",checked:T.telemetry_enabled,onChange:xe=>vt("telemetry_enabled",xe.target.checked),className:"sr-only peer"}),s.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"})]})]}),s.jsxs("div",{className:"border-t border-bambu-dark-tertiary pt-4",children:[s.jsxs("div",{className:"flex items-center justify-between mb-2",children:[s.jsxs("div",{children:[s.jsx("p",{className:"text-white",children:"Current version"}),s.jsxs("p",{className:"text-sm text-bambu-gray",children:["v",wn?.version||"..."]})]}),s.jsxs(Se,{variant:"secondary",size:"sm",onClick:()=>Be(),disabled:Ye,children:[Ye?s.jsx(mt,{className:"w-4 h-4 animate-spin"}):s.jsx(yr,{className:"w-4 h-4"}),"Check now"]})]}),ue?.update_available?s.jsxs("div",{className:"mt-4 p-3 bg-bambu-green/10 border border-bambu-green/30 rounded-lg",children:[s.jsxs("div",{className:"flex items-start justify-between",children:[s.jsxs("div",{children:[s.jsxs("p",{className:"text-bambu-green font-medium",children:["Update available: v",ue.latest_version]}),ue.release_name&&ue.release_name!==ue.latest_version&&s.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:ue.release_name})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[ue.release_notes&&s.jsx("button",{onClick:()=>rt(!0),className:"text-bambu-gray hover:text-white transition-colors text-sm underline",children:"Release Notes"}),ue.release_url&&s.jsx("a",{href:ue.release_url,target:"_blank",rel:"noopener noreferrer",className:"text-bambu-gray hover:text-white transition-colors",title:"View release on GitHub",children:s.jsx(Lr,{className:"w-4 h-4"})})]})]}),Xe?.status==="downloading"||Xe?.status==="installing"?s.jsxs("div",{className:"mt-3",children:[s.jsxs("div",{className:"flex items-center gap-2 text-sm text-bambu-gray",children:[s.jsx(mt,{className:"w-4 h-4 animate-spin"}),s.jsx("span",{children:Xe.message})]}),s.jsx("div",{className:"mt-2 w-full bg-bambu-dark-tertiary rounded-full h-2",children:s.jsx("div",{className:"bg-bambu-green h-2 rounded-full transition-all duration-300",style:{width:`${Xe.progress}%`}})})]}):Xe?.status==="complete"?s.jsx("div",{className:"mt-3 p-2 bg-bambu-green/20 rounded text-sm text-bambu-green",children:Xe.message}):Xe?.status==="error"?s.jsx("div",{className:"mt-3 p-2 bg-red-500/20 rounded text-sm text-red-400",children:Xe.error||Xe.message}):ue?.is_docker?s.jsxs("div",{className:"mt-3 p-3 bg-bambu-dark-tertiary rounded-lg",children:[s.jsx("p",{className:"text-sm text-bambu-gray mb-2",children:"Update via Docker Compose:"}),s.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"})]}):s.jsxs(Se,{className:"mt-3",onClick:()=>ce.mutate(),disabled:ce.isPending,children:[ce.isPending?s.jsx(mt,{className:"w-4 h-4 animate-spin"}):s.jsx(Jr,{className:"w-4 h-4"}),"Install Update"]})]}):ue?.error?s.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: ",ue.error]}):ue&&!ue.update_available?s.jsx("p",{className:"mt-2 text-sm text-bambu-gray",children:"You're running the latest version"}):null]})]})]}),s.jsxs(Mt,{children:[s.jsx(mr,{children:s.jsx("h2",{className:"text-lg font-semibold text-white",children:"Data Management"})}),s.jsxs(Et,{className:"space-y-4",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{children:[s.jsx("p",{className:"text-white",children:"Backup Data"}),s.jsx("p",{className:"text-sm text-bambu-gray",children:"Export settings, providers, printers, and more"})]}),s.jsxs(Se,{variant:"secondary",size:"sm",onClick:()=>ke(!0),children:[s.jsx(Jr,{className:"w-4 h-4"}),"Export"]})]}),s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{children:[s.jsx("p",{className:"text-white",children:"Restore Backup"}),s.jsx("p",{className:"text-sm text-bambu-gray",children:"Import settings from a backup file with duplicate handling options"})]}),s.jsxs(Se,{variant:"secondary",size:"sm",onClick:()=>Ze(!0),children:[s.jsx(bi,{className:"w-4 h-4"}),"Restore"]})]}),s.jsx("div",{className:"border-t border-bambu-dark-tertiary pt-4",children:s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{children:[s.jsx("p",{className:"text-white",children:"Clear Notification Logs"}),s.jsx("p",{className:"text-sm text-bambu-gray",children:"Delete notification logs older than 30 days"})]}),s.jsxs(Se,{variant:"secondary",size:"sm",onClick:()=>H(!0),children:[s.jsx(an,{className:"w-4 h-4"}),"Clear"]})]})}),s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{children:[s.jsx("p",{className:"text-white",children:"Reset UI Preferences"}),s.jsx("p",{className:"text-sm text-bambu-gray",children:"Reset sidebar order, theme, view modes, and layout preferences. Printers, archives, and settings are not affected."})]}),s.jsxs(Se,{variant:"secondary",size:"sm",onClick:()=>ie(!0),children:[s.jsx(an,{className:"w-4 h-4"}),"Reset"]})]})]})]})]})]}),fe==="network"&&T&&s.jsxs("div",{className:"flex flex-col lg:flex-row gap-6",children:[s.jsxs("div",{className:"flex-1 lg:max-w-xl space-y-4",children:[s.jsxs(Mt,{children:[s.jsx(mr,{children:s.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[s.jsx(Md,{className:"w-5 h-5 text-blue-400"}),"External URL"]})}),s.jsxs(Et,{className:"space-y-4",children:[s.jsx("p",{className:"text-sm text-bambu-gray",children:"The external URL where Bambuddy is accessible. Used for notification images and external integrations."}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Bambuddy URL"}),s.jsx("input",{type:"text",value:T.external_url??"",onChange:xe=>vt("external_url",xe.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"}),s.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Include protocol and port (e.g., http://192.168.1.100:8000)"})]})]})]}),s.jsxs(Mt,{children:[s.jsx(mr,{children:s.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[s.jsx(yr,{className:"w-5 h-5 text-blue-400"}),"FTP Retry"]})}),s.jsxs(Et,{className:"space-y-4",children:[s.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."}),s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{children:[s.jsx("p",{className:"text-white",children:"Enable retry"}),s.jsx("p",{className:"text-sm text-bambu-gray",children:"Automatically retry failed FTP operations"})]}),s.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[s.jsx("input",{type:"checkbox",checked:T.ftp_retry_enabled??!0,onChange:xe=>vt("ftp_retry_enabled",xe.target.checked),className:"sr-only peer"}),s.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"})]})]}),T.ftp_retry_enabled&&s.jsxs("div",{className:"space-y-4 pt-2 border-t border-bambu-dark-tertiary",children:[s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Retry attempts"}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("input",{type:"number",min:"1",max:"10",value:T.ftp_retry_count??3,onChange:xe=>vt("ftp_retry_count",Math.min(10,Math.max(1,parseInt(xe.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"}),s.jsx("span",{className:"text-bambu-gray",children:"times"})]}),s.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Number of retry attempts before giving up (1-10)"})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Retry delay"}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("input",{type:"number",min:"1",max:"30",value:T.ftp_retry_delay??2,onChange:xe=>vt("ftp_retry_delay",Math.min(30,Math.max(1,parseInt(xe.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"}),s.jsx("span",{className:"text-bambu-gray",children:"seconds"})]}),s.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Wait time between retries (1-30)"})]})]}),s.jsxs("div",{className:"pt-2 border-t border-bambu-dark-tertiary",children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Connection timeout"}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("input",{type:"number",min:"10",max:"120",value:T.ftp_timeout??30,onChange:xe=>vt("ftp_timeout",Math.min(120,Math.max(10,parseInt(xe.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"}),s.jsx("span",{className:"text-bambu-gray",children:"seconds"})]}),s.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)"})]})]})]}),s.jsxs(Mt,{children:[s.jsx(mr,{children:s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[s.jsx(R2,{className:"w-5 h-5 text-bambu-green"}),"Home Assistant"]}),T.ha_enabled&&ot&&s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:`w-2.5 h-2.5 rounded-full ${ot.success?"bg-green-400":"bg-red-400"}`}),s.jsx("span",{className:`text-sm ${ot.success?"text-green-400":"text-red-400"}`,children:ot.success?"Connected":"Disconnected"})]})]})}),s.jsxs(Et,{className:"space-y-4",children:[s.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, and input_boolean entities."}),s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{children:[s.jsx("p",{className:"text-white",children:"Enable Home Assistant"}),s.jsx("p",{className:"text-xs text-bambu-gray",children:"Control smart plugs via Home Assistant"})]}),s.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[s.jsx("input",{type:"checkbox",checked:T.ha_enabled??!1,onChange:xe=>vt("ha_enabled",xe.target.checked),className:"sr-only peer"}),s.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"})]})]}),T.ha_enabled&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Home Assistant URL"}),s.jsx("input",{type:"text",value:T.ha_url??"",onChange:xe=>vt("ha_url",xe.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"})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Long-Lived Access Token"}),s.jsx("input",{type:"password",value:T.ha_token??"",onChange:xe=>vt("ha_token",xe.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"}),s.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Create a token in HA: Profile → Long-Lived Access Tokens → Create Token"})]}),T.ha_url&&T.ha_token&&s.jsx("div",{className:"pt-2 border-t border-bambu-dark-tertiary",children:s.jsxs(Se,{variant:"secondary",size:"sm",disabled:$e,onClick:async()=>{be(!0),se(null);try{const xe=await pe.testHAConnection(T.ha_url,T.ha_token);se(xe)}catch(xe){se({success:!1,message:null,error:xe instanceof Error?xe.message:"Unknown error"})}finally{be(!1)}},children:[$e?s.jsx(mt,{className:"w-4 h-4 animate-spin"}):s.jsx(Dp,{className:"w-4 h-4"}),"Test Connection"]})})]})]})]})]}),s.jsx("div",{className:"flex-1 lg:max-w-xl space-y-4",children:s.jsxs(Mt,{children:[s.jsx(mr,{children:s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[s.jsx(Dp,{className:"w-5 h-5 text-blue-400"}),"MQTT Publishing"]}),At?.enabled&&s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:`w-2.5 h-2.5 rounded-full ${At.connected?"bg-green-400":"bg-red-400"}`}),s.jsx("span",{className:`text-sm ${At.connected?"text-green-400":"text-red-400"}`,children:At.connected?"Connected":"Disconnected"})]})]})}),s.jsxs(Et,{className:"space-y-4",children:[s.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."}),s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{children:[s.jsx("p",{className:"text-white",children:"Enable MQTT"}),s.jsx("p",{className:"text-sm text-bambu-gray",children:"Publish events to external MQTT broker"})]}),s.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[s.jsx("input",{type:"checkbox",checked:T.mqtt_enabled??!1,onChange:xe=>vt("mqtt_enabled",xe.target.checked),className:"sr-only peer"}),s.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"})]})]}),T.mqtt_enabled&&s.jsxs("div",{className:"space-y-4 pt-2 border-t border-bambu-dark-tertiary",children:[s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Broker hostname"}),s.jsx("input",{type:"text",value:T.mqtt_broker??"",onChange:xe=>vt("mqtt_broker",xe.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"})]}),s.jsxs("div",{className:"flex items-end gap-4",children:[s.jsxs("div",{className:"flex-1",children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Port"}),s.jsx("input",{type:"number",min:"1",max:"65535",value:T.mqtt_port??1883,onChange:xe=>vt("mqtt_port",Math.min(65535,Math.max(1,parseInt(xe.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"})]}),s.jsxs("div",{className:"flex items-center gap-3 pb-2",children:[s.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[s.jsx("input",{type:"checkbox",checked:T.mqtt_use_tls??!1,onChange:xe=>{const st=xe.target.checked;vt("mqtt_use_tls",st);const Ht=T.mqtt_port??1883;st&&Ht===1883?vt("mqtt_port",8883):!st&&Ht===8883&&vt("mqtt_port",1883)},className:"sr-only peer"}),s.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"})]}),s.jsx("span",{className:"text-white text-sm",children:"Use TLS"})]})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Username (optional)"}),s.jsx("input",{type:"text",value:T.mqtt_username??"",onChange:xe=>vt("mqtt_username",xe.target.value),placeholder:"Leave empty for anonymous",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"})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Password (optional)"}),s.jsx("input",{type:"password",value:T.mqtt_password??"",onChange:xe=>vt("mqtt_password",xe.target.value),placeholder:"Leave empty for anonymous",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"})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Topic prefix"}),s.jsx("input",{type:"text",value:T.mqtt_topic_prefix??"bambuddy",onChange:xe=>vt("mqtt_topic_prefix",xe.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"}),s.jsxs("p",{className:"text-xs text-bambu-gray mt-1",children:["Topics will be: ",T.mqtt_topic_prefix||"bambuddy","/printers//status, etc."]})]}),At&&s.jsx("div",{className:"pt-3 mt-3 border-t border-bambu-dark-tertiary",children:s.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[s.jsx("span",{className:`w-2 h-2 rounded-full ${At.connected?"bg-green-400":"bg-red-400"}`}),s.jsx("span",{className:"text-bambu-gray",children:At.connected?s.jsxs(s.Fragment,{children:["Connected to ",s.jsxs("span",{className:"text-white",children:[At.broker,":",At.port]})]}):"Not connected"})]})})]})]})]})})]}),ot&&s.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50",children:s.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg p-6 max-w-md w-full mx-4",children:[s.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[ot.success?s.jsx(Dn,{className:"w-8 h-8 text-green-400"}):s.jsx(qi,{className:"w-8 h-8 text-red-400"}),s.jsx("h3",{className:"text-lg font-medium text-white",children:ot.success?"Connection Successful":"Connection Failed"})]}),s.jsx("p",{className:"text-bambu-gray mb-6",children:ot.success?ot.message||"Successfully connected to Home Assistant.":ot.error||"Failed to connect to Home Assistant."}),s.jsx("div",{className:"flex justify-end",children:s.jsx(Se,{variant:"primary",onClick:()=>se(null),children:"OK"})})]})}),fe==="plugs"&&s.jsxs("div",{className:"max-w-4xl",children:[s.jsxs("div",{className:"flex items-start justify-between mb-6",children:[s.jsxs("div",{children:[s.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[s.jsx(Us,{className:"w-5 h-5 text-bambu-green"}),"Smart Plugs"]}),s.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."})]}),s.jsxs("div",{className:"flex items-center gap-2 pt-1 shrink-0",children:[dt&&dt.filter(xe=>xe.enabled).length>1&&s.jsxs(s.Fragment,{children:[s.jsxs(Se,{variant:"secondary",size:"sm",className:"whitespace-nowrap",onClick:()=>_e("on"),disabled:Re.isPending,title:"Turn all plugs on",children:[Re.isPending?s.jsx(mt,{className:"w-4 h-4 animate-spin"}):s.jsx(uu,{className:"w-4 h-4 text-bambu-green"}),"All On"]}),s.jsxs(Se,{variant:"secondary",size:"sm",className:"whitespace-nowrap",onClick:()=>_e("off"),disabled:Re.isPending,title:"Turn all plugs off",children:[Re.isPending?s.jsx(mt,{className:"w-4 h-4 animate-spin"}):s.jsx(I2,{className:"w-4 h-4 text-red-400"}),"All Off"]})]}),s.jsxs(Se,{className:"whitespace-nowrap",onClick:()=>{D(null),L(!0)},children:[s.jsx(Kn,{className:"w-4 h-4"}),"Add Smart Plug"]})]})]}),dt&&dt.length>0&&s.jsxs(Mt,{className:"mb-6",children:[s.jsx(mr,{children:s.jsxs("h3",{className:"text-base font-semibold text-white flex items-center gap-2",children:[s.jsx(Mf,{className:"w-4 h-4 text-yellow-400"}),"Energy Summary",Zt&&s.jsx(mt,{className:"w-4 h-4 animate-spin text-bambu-gray ml-2"})]})}),s.jsx(Et,{children:jt?s.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[s.jsxs("div",{className:"bg-bambu-dark rounded-lg p-3",children:[s.jsxs("div",{className:"flex items-center gap-2 text-bambu-gray text-xs mb-1",children:[s.jsx(Mf,{className:"w-3 h-3"}),"Current Power"]}),s.jsxs("div",{className:"text-xl font-bold text-white",children:[jt.totalPower.toFixed(1),s.jsx("span",{className:"text-sm font-normal text-bambu-gray ml-1",children:"W"})]}),s.jsxs("div",{className:"text-xs text-bambu-gray mt-1",children:[jt.reachableCount,"/",jt.totalPlugs," plugs online"]})]}),s.jsxs("div",{className:"bg-bambu-dark rounded-lg p-3",children:[s.jsxs("div",{className:"flex items-center gap-2 text-bambu-gray text-xs mb-1",children:[s.jsx(Qr,{className:"w-3 h-3"}),"Today"]}),s.jsxs("div",{className:"text-xl font-bold text-white",children:[jt.totalToday.toFixed(2),s.jsx("span",{className:"text-sm font-normal text-bambu-gray ml-1",children:"kWh"})]}),T&&T.energy_cost_per_kwh>0&&s.jsxs("div",{className:"text-xs text-bambu-gray mt-1",children:["~",(jt.totalToday*T.energy_cost_per_kwh).toFixed(2)," ",T.currency]})]}),s.jsxs("div",{className:"bg-bambu-dark rounded-lg p-3",children:[s.jsxs("div",{className:"flex items-center gap-2 text-bambu-gray text-xs mb-1",children:[s.jsx(aq,{className:"w-3 h-3"}),"Yesterday"]}),s.jsxs("div",{className:"text-xl font-bold text-white",children:[jt.totalYesterday.toFixed(2),s.jsx("span",{className:"text-sm font-normal text-bambu-gray ml-1",children:"kWh"})]}),T&&T.energy_cost_per_kwh>0&&s.jsxs("div",{className:"text-xs text-bambu-gray mt-1",children:["~",(jt.totalYesterday*T.energy_cost_per_kwh).toFixed(2)," ",T.currency]})]}),s.jsxs("div",{className:"bg-bambu-dark rounded-lg p-3",children:[s.jsxs("div",{className:"flex items-center gap-2 text-bambu-gray text-xs mb-1",children:[s.jsx(Uj,{className:"w-3 h-3"}),"Total"]}),s.jsxs("div",{className:"text-xl font-bold text-white",children:[jt.totalLifetime.toFixed(1),s.jsx("span",{className:"text-sm font-normal text-bambu-gray ml-1",children:"kWh"})]}),T&&T.energy_cost_per_kwh>0&&s.jsxs("div",{className:"text-xs text-bambu-gray mt-1",children:["~",(jt.totalLifetime*T.energy_cost_per_kwh).toFixed(2)," ",T.currency]})]})]}):Zt?null:s.jsx("p",{className:"text-sm text-bambu-gray",children:"Enable plugs to see energy summary"})})]}),kt?s.jsx("div",{className:"flex justify-center py-12",children:s.jsx(mt,{className:"w-8 h-8 text-bambu-green animate-spin"})}):dt&&dt.length>0?s.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:dt.map(xe=>s.jsx(Rqe,{plug:xe,onEdit:st=>{D(st),L(!0)}},xe.id))}):s.jsx(Mt,{children:s.jsx(Et,{className:"py-12",children:s.jsxs("div",{className:"text-center text-bambu-gray",children:[s.jsx(Us,{className:"w-16 h-16 mx-auto mb-4 opacity-30"}),s.jsx("p",{className:"text-lg font-medium text-white mb-2",children:"No smart plugs configured"}),s.jsx("p",{className:"text-sm mb-4",children:"Add a Tasmota-based smart plug to track energy usage and automate power control."}),s.jsxs(Se,{onClick:()=>{D(null),L(!0)},children:[s.jsx(Kn,{className:"w-4 h-4"}),"Add Your First Smart Plug"]})]})})})]}),fe==="notifications"&&s.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-8",children:[s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center justify-between mb-4",children:[s.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[s.jsx(tf,{className:"w-5 h-5 text-bambu-green"}),"Providers"]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs(Se,{size:"sm",variant:"secondary",onClick:()=>G(!0),children:[s.jsx(hw,{className:"w-4 h-4"}),"Log"]}),Rt&&Rt.length>0&&s.jsxs(Se,{size:"sm",variant:"secondary",onClick:()=>{Ie(null),Le.mutate()},disabled:Le.isPending,children:[Le.isPending?s.jsx(mt,{className:"w-4 h-4 animate-spin"}):s.jsx(iD,{className:"w-4 h-4"}),"Test All"]}),s.jsxs(Se,{size:"sm",onClick:()=>{Z(null),Y(!0)},children:[s.jsx(Kn,{className:"w-4 h-4"}),"Add"]})]})]}),s.jsx(Mt,{className:"mb-4",children:s.jsx(Et,{className:"py-3",children:s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{children:[s.jsx("p",{className:"text-white text-sm font-medium",children:i("settings.notificationLanguage")}),s.jsx("p",{className:"text-xs text-bambu-gray",children:i("settings.notificationLanguageDescription")})]}),s.jsx("select",{value:T.notification_language||"en",onChange:xe=>vt("notification_language",xe.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:GU.map(xe=>s.jsx("option",{value:xe.code,children:xe.nativeName},xe.code))})]})})}),we&&s.jsx(Mt,{className:"mb-4",children:s.jsxs(Et,{className:"py-3",children:[s.jsxs("div",{className:"flex items-center justify-between mb-2",children:[s.jsx("span",{className:"text-sm font-medium text-white",children:"Test Results"}),s.jsx("button",{onClick:()=>Ie(null),className:"text-bambu-gray hover:text-white text-xs",children:"Dismiss"})]}),s.jsxs("div",{className:"flex items-center gap-4 text-sm mb-2",children:[s.jsxs("span",{className:"flex items-center gap-1 text-bambu-green",children:[s.jsx(Dn,{className:"w-4 h-4"}),we.success," passed"]}),we.failed>0&&s.jsxs("span",{className:"flex items-center gap-1 text-red-400",children:[s.jsx(qi,{className:"w-4 h-4"}),we.failed," failed"]})]}),we.results.filter(xe=>!xe.success).length>0&&s.jsx("div",{className:"space-y-1 mt-2 pt-2 border-t border-bambu-dark-tertiary",children:we.results.filter(xe=>!xe.success).map(xe=>s.jsxs("div",{className:"text-xs text-red-400",children:[s.jsxs("span",{className:"font-medium",children:[xe.provider_name,":"]})," ",xe.message]},xe.provider_id))})]})}),nn?s.jsx("div",{className:"flex justify-center py-12",children:s.jsx(mt,{className:"w-6 h-6 text-bambu-green animate-spin"})}):Rt&&Rt.length>0?s.jsx("div",{className:"space-y-3",children:Rt.map(xe=>s.jsx(Lqe,{provider:xe,onEdit:st=>{Z(st),Y(!0)}},xe.id))}):s.jsx(Mt,{children:s.jsx(Et,{className:"py-8",children:s.jsxs("div",{className:"text-center text-bambu-gray",children:[s.jsx(tf,{className:"w-12 h-12 mx-auto mb-3 opacity-30"}),s.jsx("p",{className:"text-sm font-medium text-white mb-2",children:"No providers configured"}),s.jsx("p",{className:"text-xs mb-3",children:"Add a provider to receive alerts."}),s.jsxs(Se,{size:"sm",onClick:()=>{Z(null),Y(!0)},children:[s.jsx(Kn,{className:"w-4 h-4"}),"Add Provider"]})]})})})]}),s.jsxs("div",{children:[s.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2 mb-4",children:[s.jsx(za,{className:"w-5 h-5 text-bambu-green"}),"Message Templates"]}),s.jsx("p",{className:"text-sm text-bambu-gray mb-4",children:"Customize notification messages for each event."}),Tr?s.jsx("div",{className:"flex justify-center py-8",children:s.jsx(mt,{className:"w-6 h-6 text-bambu-green animate-spin"})}):$r&&$r.length>0?s.jsx("div",{className:"space-y-2",children:$r.map(xe=>s.jsx(Mt,{className:"cursor-pointer hover:border-bambu-green/50 transition-colors",onClick:()=>oe(xe),children:s.jsx(Et,{className:"py-2.5 px-3",children:s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("p",{className:"text-white font-medium text-sm truncate",children:xe.name}),s.jsx("p",{className:"text-bambu-gray text-xs truncate mt-0.5",children:xe.title_template})]}),s.jsx("button",{className:"p-1.5 hover:bg-bambu-dark-tertiary rounded transition-colors shrink-0 ml-2",onClick:st=>{st.stopPropagation(),oe(xe)},children:s.jsx(L2,{className:"w-4 h-4 text-bambu-gray"})})]})})},xe.id))}):s.jsx(Mt,{children:s.jsx(Et,{className:"py-8",children:s.jsxs("div",{className:"text-center text-bambu-gray",children:[s.jsx(za,{className:"w-12 h-12 mx-auto mb-3 opacity-30"}),s.jsx("p",{className:"text-sm",children:"No templates available. Restart the backend to seed default templates."})]})})})]})]}),fe==="apikeys"&&s.jsxs("div",{className:"grid grid-cols-1 xl:grid-cols-2 gap-8",children:[s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-start justify-between gap-4 mb-6",children:[s.jsxs("div",{className:"flex-1",children:[s.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[s.jsx(Gh,{className:"w-5 h-5 text-bambu-green"}),"API Keys"]}),s.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:"Create API keys for external integrations and webhooks."})]}),s.jsxs(Se,{size:"sm",onClick:()=>je(!0),className:"flex-shrink-0",children:[s.jsx(Kn,{className:"w-4 h-4"}),"Create Key"]})]}),W&&s.jsx(Mt,{className:"mb-6 border-bambu-green",children:s.jsx(Et,{className:"py-4",children:s.jsxs("div",{className:"flex items-start gap-3",children:[s.jsx(Dn,{className:"w-5 h-5 text-bambu-green flex-shrink-0 mt-0.5"}),s.jsxs("div",{className:"flex-1",children:[s.jsx("p",{className:"text-white font-medium mb-1",children:"API Key Created Successfully"}),s.jsx("p",{className:"text-sm text-bambu-gray mb-2",children:"Copy this key now - it won't be shown again!"}),s.jsxs("div",{className:"flex items-center gap-2 bg-bambu-dark rounded-lg p-2",children:[s.jsx("code",{className:"flex-1 text-sm text-bambu-green font-mono break-all",children:W}),s.jsx(Se,{variant:"secondary",size:"sm",onClick:async()=>{try{if(navigator.clipboard&&navigator.clipboard.writeText)await navigator.clipboard.writeText(W);else{const xe=document.createElement("textarea");xe.value=W,xe.style.position="fixed",xe.style.left="-999999px",document.body.appendChild(xe),xe.select(),document.execCommand("copy"),document.body.removeChild(xe)}o("Key copied to clipboard")}catch{o("Failed to copy key","error")}},children:s.jsx(Jo,{className:"w-4 h-4"})})]}),s.jsxs("div",{className:"flex gap-2 mt-3",children:[s.jsx(Se,{variant:"secondary",size:"sm",onClick:()=>{Ce(W),o("Key added to API Browser")},children:"Use in API Browser"}),s.jsx(Se,{variant:"secondary",size:"sm",onClick:()=>U(null),children:"Dismiss"})]})]})]})})}),Me&&s.jsxs(Mt,{className:"mb-6",children:[s.jsx(mr,{children:s.jsx("h3",{className:"text-base font-semibold text-white",children:"Create New API Key"})}),s.jsxs(Et,{className:"space-y-4",children:[s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Key Name"}),s.jsx("input",{type:"text",value:ne,onChange:xe=>Ke(xe.target.value),placeholder:"e.g., Home Assistant, OctoPrint",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"})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-2",children:"Permissions"}),s.jsxs("div",{className:"space-y-2",children:[s.jsxs("label",{className:"flex items-center gap-3 cursor-pointer",children:[s.jsx("input",{type:"checkbox",checked:$.can_read_status,onChange:xe=>z(st=>({...st,can_read_status:xe.target.checked})),className:"w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green"}),s.jsxs("div",{children:[s.jsx("span",{className:"text-white",children:"Read Status"}),s.jsx("p",{className:"text-xs text-bambu-gray",children:"View printer status and queue"})]})]}),s.jsxs("label",{className:"flex items-center gap-3 cursor-pointer",children:[s.jsx("input",{type:"checkbox",checked:$.can_queue,onChange:xe=>z(st=>({...st,can_queue:xe.target.checked})),className:"w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green"}),s.jsxs("div",{children:[s.jsx("span",{className:"text-white",children:"Manage Queue"}),s.jsx("p",{className:"text-xs text-bambu-gray",children:"Add and remove items from print queue"})]})]}),s.jsxs("label",{className:"flex items-center gap-3 cursor-pointer",children:[s.jsx("input",{type:"checkbox",checked:$.can_control_printer,onChange:xe=>z(st=>({...st,can_control_printer:xe.target.checked})),className:"w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green"}),s.jsxs("div",{children:[s.jsx("span",{className:"text-white",children:"Control Printer"}),s.jsx("p",{className:"text-xs text-bambu-gray",children:"Pause, resume, and stop prints"})]})]})]})]}),s.jsxs("div",{className:"flex items-center gap-2 pt-2",children:[s.jsxs(Se,{onClick:()=>qt.mutate({name:ne||"Unnamed Key",...$}),disabled:qt.isPending,children:[qt.isPending?s.jsx(mt,{className:"w-4 h-4 animate-spin"}):s.jsx(Kn,{className:"w-4 h-4"}),"Create Key"]}),s.jsx(Se,{variant:"secondary",onClick:()=>je(!1),children:"Cancel"})]})]})]}),$t?s.jsx("div",{className:"flex justify-center py-12",children:s.jsx(mt,{className:"w-8 h-8 text-bambu-green animate-spin"})}):pt&&pt.length>0?s.jsx("div",{className:"space-y-3",children:pt.map(xe=>s.jsx(Mt,{children:s.jsx(Et,{className:"py-3",children:s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx(Gh,{className:`w-5 h-5 ${xe.enabled?"text-bambu-green":"text-bambu-gray"}`}),s.jsxs("div",{children:[s.jsx("p",{className:"text-white font-medium",children:xe.name}),s.jsxs("p",{className:"text-xs text-bambu-gray",children:[xe.key_prefix,"••••••••",xe.last_used&&` · Last used: ${Jp(xe.last_used)}`]})]})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs("div",{className:"flex gap-1 text-xs",children:[xe.can_read_status&&s.jsx("span",{className:"px-1.5 py-0.5 bg-blue-500/20 text-blue-400 rounded",children:"Read"}),xe.can_queue&&s.jsx("span",{className:"px-1.5 py-0.5 bg-green-500/20 text-green-400 rounded",children:"Queue"}),xe.can_control_printer&&s.jsx("span",{className:"px-1.5 py-0.5 bg-orange-500/20 text-orange-400 rounded",children:"Control"})]}),s.jsx(Se,{variant:"secondary",size:"sm",onClick:()=>Q(xe.id),children:s.jsx(an,{className:"w-4 h-4 text-red-400"})})]})]})})},xe.id))}):s.jsx(Mt,{children:s.jsx(Et,{className:"py-12",children:s.jsxs("div",{className:"text-center text-bambu-gray",children:[s.jsx(Gh,{className:"w-16 h-16 mx-auto mb-4 opacity-30"}),s.jsx("p",{className:"text-lg font-medium text-white mb-2",children:"No API keys"}),s.jsx("p",{className:"text-sm mb-4",children:"Create an API key to integrate with external services."}),s.jsxs(Se,{onClick:()=>je(!0),children:[s.jsx(Kn,{className:"w-4 h-4"}),"Create Your First Key"]})]})})}),s.jsxs(Mt,{className:"mt-6",children:[s.jsx(mr,{children:s.jsx("h3",{className:"text-base font-semibold text-white",children:"Webhook Endpoints"})}),s.jsxs(Et,{className:"space-y-3 text-sm",children:[s.jsxs("p",{className:"text-bambu-gray",children:["Use your API key in the ",s.jsx("code",{className:"text-bambu-green",children:"X-API-Key"})," header."]}),s.jsxs("div",{className:"space-y-2 font-mono text-xs",children:[s.jsxs("div",{className:"p-2 bg-bambu-dark rounded",children:[s.jsx("span",{className:"text-blue-400",children:"GET"})," ",s.jsx("span",{className:"text-white",children:"/api/v1/webhook/status"}),s.jsx("span",{className:"text-bambu-gray",children:" - Get all printer status"})]}),s.jsxs("div",{className:"p-2 bg-bambu-dark rounded",children:[s.jsx("span",{className:"text-blue-400",children:"GET"})," ",s.jsx("span",{className:"text-white",children:"/api/v1/webhook/status/:id"}),s.jsx("span",{className:"text-bambu-gray",children:" - Get specific printer status"})]}),s.jsxs("div",{className:"p-2 bg-bambu-dark rounded",children:[s.jsx("span",{className:"text-green-400",children:"POST"})," ",s.jsx("span",{className:"text-white",children:"/api/v1/webhook/queue"}),s.jsx("span",{className:"text-bambu-gray",children:" - Add to print queue"})]}),s.jsxs("div",{className:"p-2 bg-bambu-dark rounded",children:[s.jsx("span",{className:"text-orange-400",children:"POST"})," ",s.jsx("span",{className:"text-white",children:"/api/v1/webhook/printer/:id/pause"}),s.jsx("span",{className:"text-bambu-gray",children:" - Pause print"})]}),s.jsxs("div",{className:"p-2 bg-bambu-dark rounded",children:[s.jsx("span",{className:"text-orange-400",children:"POST"})," ",s.jsx("span",{className:"text-white",children:"/api/v1/webhook/printer/:id/resume"}),s.jsx("span",{className:"text-bambu-gray",children:" - Resume print"})]}),s.jsxs("div",{className:"p-2 bg-bambu-dark rounded",children:[s.jsx("span",{className:"text-red-400",children:"POST"})," ",s.jsx("span",{className:"text-white",children:"/api/v1/webhook/printer/:id/stop"}),s.jsx("span",{className:"text-bambu-gray",children:" - Stop print"})]})]})]})]})]}),s.jsxs("div",{children:[s.jsxs("div",{className:"mb-6",children:[s.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[s.jsx(Md,{className:"w-5 h-5 text-bambu-green"}),"API Browser"]}),s.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:"Explore and test all available API endpoints."})]}),s.jsx(Mt,{className:"mb-4",children:s.jsxs(Et,{className:"py-3",children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-2",children:"API Key for Testing"}),s.jsx("input",{type:"text",value:Ee,onChange:xe=>Ce(xe.target.value),placeholder:"Paste your API key here to test authenticated endpoints...",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"}),s.jsxs("p",{className:"text-xs text-bambu-gray mt-2",children:["This key will be sent as ",s.jsx("code",{className:"text-bambu-green",children:"X-API-Key"})," header with requests."]})]})}),s.jsx(eKe,{apiKey:Ee})]})]}),fe==="virtual-printer"&&s.jsx(Yqe,{}),fe==="filament"&&T&&s.jsxs("div",{className:"flex flex-col lg:flex-row gap-6 lg:gap-8",children:[s.jsx("div",{className:"flex-1 lg:max-w-xl",children:s.jsxs(Mt,{children:[s.jsx(mr,{children:s.jsx("h2",{className:"text-lg font-semibold text-white",children:"AMS Display Thresholds"})}),s.jsxs(Et,{className:"space-y-4",children:[s.jsx("p",{className:"text-sm text-bambu-gray",children:"Configure color thresholds for AMS humidity and temperature indicators."}),s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"flex items-center gap-2 text-white",children:[s.jsx(tD,{className:"w-4 h-4 text-blue-400"}),s.jsx("span",{className:"font-medium",children:"Humidity"})]}),s.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Good (green) ≤"}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("input",{type:"number",min:"0",max:"100",value:T.ams_humidity_good??40,onChange:xe=>vt("ams_humidity_good",parseInt(xe.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"}),s.jsx("span",{className:"text-bambu-gray",children:"%"})]})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Fair (orange) ≤"}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("input",{type:"number",min:"0",max:"100",value:T.ams_humidity_fair??60,onChange:xe=>vt("ams_humidity_fair",parseInt(xe.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"}),s.jsx("span",{className:"text-bambu-gray",children:"%"})]})]})]}),s.jsx("p",{className:"text-xs text-bambu-gray",children:"Above fair threshold shows as red (bad)"})]}),s.jsxs("div",{className:"space-y-3 pt-2 border-t border-bambu-dark-tertiary",children:[s.jsxs("div",{className:"flex items-center gap-2 text-white",children:[s.jsx(U2,{className:"w-4 h-4 text-orange-400"}),s.jsx("span",{className:"font-medium",children:"Temperature"})]}),s.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Good (blue) ≤"}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("input",{type:"number",step:"0.5",min:"0",max:"60",value:T.ams_temp_good??28,onChange:xe=>vt("ams_temp_good",parseFloat(xe.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"}),s.jsx("span",{className:"text-bambu-gray",children:"°C"})]})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Fair (orange) ≤"}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("input",{type:"number",step:"0.5",min:"0",max:"60",value:T.ams_temp_fair??35,onChange:xe=>vt("ams_temp_fair",parseFloat(xe.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"}),s.jsx("span",{className:"text-bambu-gray",children:"°C"})]})]})]}),s.jsx("p",{className:"text-xs text-bambu-gray",children:"Above fair threshold shows as red (hot)"})]}),s.jsxs("div",{className:"space-y-3 pt-4 border-t border-bambu-dark-tertiary",children:[s.jsxs("div",{className:"flex items-center gap-2 text-white",children:[s.jsx(Yp,{className:"w-4 h-4 text-purple-400"}),s.jsx("span",{className:"font-medium",children:"History Retention"})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Keep sensor history for"}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("input",{type:"number",min:"1",max:"365",value:T.ams_history_retention_days??30,onChange:xe=>vt("ams_history_retention_days",parseInt(xe.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"}),s.jsx("span",{className:"text-bambu-gray",children:"days"})]})]}),s.jsx("p",{className:"text-xs text-bambu-gray",children:"Older humidity and temperature data will be automatically deleted"})]}),s.jsxs("div",{className:"space-y-3 pt-4 border-t border-bambu-dark-tertiary",children:[s.jsxs("div",{className:"flex items-center gap-2 text-white",children:[s.jsx(Ir,{className:"w-4 h-4 text-bambu-green"}),s.jsx("span",{className:"font-medium",children:"Print Modal"})]}),s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-white",children:"Expand custom mapping by default"}),s.jsx("p",{className:"text-xs text-bambu-gray mt-0.5",children:"When printing to multiple printers, show per-printer AMS mapping expanded"})]}),s.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[s.jsx("input",{type:"checkbox",checked:T.per_printer_mapping_expanded??!1,onChange:xe=>vt("per_printer_mapping_expanded",xe.target.checked),className:"sr-only peer"}),s.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"})]})]})]})]})]})}),s.jsx("div",{className:"flex-1 lg:max-w-xl",children:s.jsx(qqe,{})})]}),V!==null&&s.jsx(Ln,{title:"Delete API Key",message:"Are you sure you want to delete this API key? Any integrations using this key will stop working.",confirmText:"Delete Key",variant:"danger",onConfirm:()=>{wt.mutate(V),Q(null)},onCancel:()=>Q(null)}),F&&s.jsx(Dqe,{plug:X,onClose:()=>{L(!1),D(null)}}),K&&s.jsx(Iqe,{provider:q,onClose:()=>{Y(!1),Z(null)}}),re&&s.jsx(Fqe,{template:re,onClose:()=>oe(null)}),B&&s.jsx(Bqe,{onClose:()=>G(!1)}),Ne&&s.jsx(Ln,{title:"Clear Notification Logs",message:"This will permanently delete all notification logs older than 30 days. This action cannot be undone.",confirmText:"Clear Logs",variant:"warning",onConfirm:async()=>{H(!1);try{const xe=await pe.clearNotificationLogs(30);o(xe.message,"success")}catch{o("Failed to clear logs","error")}},onCancel:()=>H(!1)}),O&&s.jsx(Ln,{title:"Reset UI Preferences",message:"This will reset all UI preferences to defaults: sidebar order, theme, dashboard layout, view modes, and sorting preferences. Your printers, archives, and server settings will NOT be affected. The page will reload after clearing.",confirmText:"Reset Preferences",variant:"default",onConfirm:()=>{ie(!1),localStorage.clear(),o("UI preferences reset. Refreshing...","success"),setTimeout(()=>window.location.reload(),1e3)},onCancel:()=>ie(!1)}),ye&&s.jsx(Ln,{title:`Turn All Plugs ${ye==="on"?"On":"Off"}`,message:`This will turn ${ye==="on"?"ON":"OFF"} all ${dt?.filter(xe=>xe.enabled).length||0} enabled smart plugs. ${ye==="off"?"Any running printers may be affected!":""}`,confirmText:`Turn All ${ye==="on"?"On":"Off"}`,variant:ye==="off"?"danger":"warning",onConfirm:()=>{const xe=ye;_e(null),Re.mutate(xe)},onCancel:()=>_e(null)}),le&&s.jsx(Hqe,{onClose:()=>ke(!1),onExport:async xe=>{ke(!1);const st="backup-progress",Ht=xe.archives;Ht&&l(st,i("backup.preparing",{defaultValue:"Preparing backup..."}),"loading");try{const{blob:It,filename:on}=await pe.exportBackup(xe);Ht&&c(st);const un=URL.createObjectURL(It),Gt=document.createElement("a");Gt.href=un,Gt.download=on,Gt.click(),URL.revokeObjectURL(un),o(i("backup.downloaded",{defaultValue:"Backup downloaded"}),"success")}catch{Ht&&c(st),o(i("backup.failed",{defaultValue:"Failed to create backup"}),"error")}}}),Oe&&s.jsx(Vqe,{onClose:()=>Ze(!1),onRestore:async(xe,st)=>await pe.importBackup(xe,st),onSuccess:()=>{P(null),Tt.current=!0,t.resetQueries({queryKey:["settings"]}),t.invalidateQueries({queryKey:["notification-providers"]}),t.invalidateQueries({queryKey:["notification-templates"]}),t.invalidateQueries({queryKey:["smart-plugs"]}),t.invalidateQueries({queryKey:["external-links"]}),t.invalidateQueries({queryKey:["printers"]}),t.invalidateQueries({queryKey:["filaments"]}),t.invalidateQueries({queryKey:["maintenance-types"]}),t.invalidateQueries({queryKey:["api-keys"]})}}),ht&&s.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",onClick:()=>We(!1),children:s.jsxs(Mt,{className:"w-full max-w-lg",onClick:xe=>xe.stopPropagation(),children:[s.jsxs(mr,{className:"flex flex-row items-center justify-between",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(P1,{className:"w-5 h-5 text-bambu-green"}),s.jsx("h2",{className:"text-lg font-semibold text-white",children:i("settings.telemetryInfoTitle")})]}),s.jsx("button",{onClick:()=>We(!1),className:"p-1 rounded hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white",children:s.jsx(Ut,{className:"w-5 h-5"})})]}),s.jsxs(Et,{className:"space-y-4",children:[s.jsx("p",{className:"text-bambu-gray text-sm",children:i("settings.telemetryInfoIntro")}),s.jsxs("div",{className:"space-y-3",children:[s.jsx("h3",{className:"text-white font-medium",children:i("settings.telemetryInfoCollected")}),s.jsxs("ul",{className:"space-y-2 text-sm",children:[s.jsxs("li",{className:"flex items-start gap-2 text-bambu-gray",children:[s.jsx(Dn,{className:"w-4 h-4 text-bambu-green mt-0.5 shrink-0"}),s.jsx("span",{children:i("settings.telemetryInfoItem1")})]}),s.jsxs("li",{className:"flex items-start gap-2 text-bambu-gray",children:[s.jsx(Dn,{className:"w-4 h-4 text-bambu-green mt-0.5 shrink-0"}),s.jsx("span",{children:i("settings.telemetryInfoItem2")})]}),s.jsxs("li",{className:"flex items-start gap-2 text-bambu-gray",children:[s.jsx(Dn,{className:"w-4 h-4 text-bambu-green mt-0.5 shrink-0"}),s.jsx("span",{children:i("settings.telemetryInfoItem3")})]}),s.jsxs("li",{className:"flex items-start gap-2 text-bambu-gray",children:[s.jsx(Dn,{className:"w-4 h-4 text-bambu-green mt-0.5 shrink-0"}),s.jsx("span",{children:i("settings.telemetryInfoItem4")})]})]})]}),s.jsxs("div",{className:"space-y-3",children:[s.jsx("h3",{className:"text-white font-medium",children:i("settings.telemetryInfoNotCollected")}),s.jsxs("ul",{className:"space-y-2 text-sm",children:[s.jsxs("li",{className:"flex items-start gap-2 text-bambu-gray",children:[s.jsx(qi,{className:"w-4 h-4 text-red-400 mt-0.5 shrink-0"}),s.jsx("span",{children:i("settings.telemetryInfoNotItem1")})]}),s.jsxs("li",{className:"flex items-start gap-2 text-bambu-gray",children:[s.jsx(qi,{className:"w-4 h-4 text-red-400 mt-0.5 shrink-0"}),s.jsx("span",{children:i("settings.telemetryInfoNotItem2")})]}),s.jsxs("li",{className:"flex items-start gap-2 text-bambu-gray",children:[s.jsx(qi,{className:"w-4 h-4 text-red-400 mt-0.5 shrink-0"}),s.jsx("span",{children:i("settings.telemetryInfoNotItem3")})]}),s.jsxs("li",{className:"flex items-start gap-2 text-bambu-gray",children:[s.jsx(qi,{className:"w-4 h-4 text-red-400 mt-0.5 shrink-0"}),s.jsx("span",{children:i("settings.telemetryInfoNotItem4")})]})]})]}),s.jsx("p",{className:"text-bambu-gray text-xs border-t border-bambu-dark-tertiary pt-4",children:i("settings.telemetryInfoFooter")}),s.jsx(Se,{onClick:()=>We(!1),className:"w-full",children:i("common.close")})]})]})}),he&&ue?.release_notes&&s.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",onClick:()=>rt(!1),children:s.jsxs(Mt,{className:"w-full max-w-2xl max-h-[80vh] flex flex-col",onClick:xe=>xe.stopPropagation(),children:[s.jsxs(mr,{className:"flex flex-row items-center justify-between shrink-0",children:[s.jsxs("div",{children:[s.jsxs("h2",{className:"text-lg font-semibold text-white",children:["Release Notes - v",ue.latest_version]}),ue.release_name&&ue.release_name!==ue.latest_version&&s.jsx("p",{className:"text-sm text-bambu-gray",children:ue.release_name})]}),s.jsx("button",{onClick:()=>rt(!1),className:"p-1 rounded hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white",children:s.jsx(Ut,{className:"w-5 h-5"})})]}),s.jsx(Et,{className:"overflow-y-auto flex-1",children:s.jsx("pre",{className:"text-sm text-bambu-gray whitespace-pre-wrap font-sans",children:ue.release_notes})}),s.jsxs("div",{className:"p-4 border-t border-bambu-dark-tertiary shrink-0 flex gap-2",children:[ue.release_url&&s.jsx("a",{href:ue.release_url,target:"_blank",rel:"noopener noreferrer",className:"flex-1",children:s.jsxs(Se,{variant:"secondary",className:"w-full",children:[s.jsx(Lr,{className:"w-4 h-4"}),"View on GitHub"]})}),s.jsx(Se,{onClick:()=>rt(!1),className:"flex-1",children:"Close"})]})]})}),fe==="users"&&s.jsxs("div",{className:"grid grid-cols-1 xl:grid-cols-2 gap-8",children:[s.jsxs("div",{children:[s.jsxs("div",{className:"mb-6",children:[s.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[s.jsx(Wh,{className:"w-5 h-5 text-bambu-green"}),"User Authentication"]}),s.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:"Enable authentication to secure your Bambuddy instance and manage user access."})]}),s.jsx(Mt,{children:s.jsx(Et,{className:"py-6",children:u?s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("div",{className:"w-12 h-12 rounded-full flex items-center justify-center bg-green-500/20",children:s.jsx(kA,{className:"w-6 h-6 text-green-400"})}),s.jsxs("div",{className:"flex-1",children:[s.jsx("h3",{className:"text-white font-medium",children:"Authentication Enabled"}),s.jsx("p",{className:"text-sm text-bambu-gray",children:"Your Bambuddy instance is secured with authentication."})]})]}),d&&s.jsx("div",{className:"pt-4 border-t border-bambu-dark-tertiary",children:s.jsxs("div",{className:"flex items-center justify-between mb-4",children:[s.jsxs("div",{children:[s.jsx("p",{className:"text-sm text-bambu-gray",children:"Current User"}),s.jsx("p",{className:"text-white font-medium",children:d.username}),s.jsxs("p",{className:"text-xs text-bambu-gray mt-1",children:["Role: ",s.jsx("span",{className:"capitalize",children:d.role})]})]}),s.jsx("div",{className:`px-3 py-1 rounded-full text-xs font-medium ${d.role==="admin"?"bg-purple-500/20 text-purple-300":"bg-blue-500/20 text-blue-300"}`,children:d.role==="admin"?"Admin":"User"})]})}),s.jsxs("div",{className:"pt-4 border-t border-bambu-dark-tertiary space-y-3",children:[s.jsxs(Se,{onClick:()=>e("/users"),className:"w-full",variant:"secondary",children:[s.jsx(Wh,{className:"w-4 h-4"}),"Manage Users"]}),d?.role==="admin"&&s.jsxs(Se,{onClick:()=>Je(!0),className:"w-full",variant:"secondary",children:[s.jsx(dz,{className:"w-4 h-4"}),"Disable Authentication"]})]})]}):s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("div",{className:`w-12 h-12 rounded-full flex items-center justify-center ${u?"bg-green-500/20":"bg-gray-500/20"}`,children:u?s.jsx(kA,{className:"w-6 h-6 text-green-400"}):s.jsx(dz,{className:"w-6 h-6 text-gray-400"})}),s.jsxs("div",{className:"flex-1",children:[s.jsx("h3",{className:"text-white font-medium",children:"Authentication Disabled"}),s.jsx("p",{className:"text-sm text-bambu-gray",children:"Your Bambuddy instance is currently accessible without authentication."})]})]}),s.jsxs("div",{className:"pt-4 border-t border-bambu-dark-tertiary",children:[s.jsx("p",{className:"text-sm text-bambu-gray mb-4",children:"Enable authentication to:"}),s.jsxs("ul",{className:"space-y-2 text-sm text-bambu-gray mb-4",children:[s.jsxs("li",{className:"flex items-start gap-2",children:[s.jsx(Dn,{className:"w-4 h-4 text-bambu-green mt-0.5 flex-shrink-0"}),s.jsx("span",{children:"Require login to access the system"})]}),s.jsxs("li",{className:"flex items-start gap-2",children:[s.jsx(Dn,{className:"w-4 h-4 text-bambu-green mt-0.5 flex-shrink-0"}),s.jsx("span",{children:"Manage multiple users with different roles"})]}),s.jsxs("li",{className:"flex items-start gap-2",children:[s.jsx(Dn,{className:"w-4 h-4 text-bambu-green mt-0.5 flex-shrink-0"}),s.jsx("span",{children:"Control access to printer settings and user management"})]})]}),s.jsxs(Se,{type:"button",onClick:xe=>{xe.preventDefault(),e("/setup")},className:"w-full",children:[s.jsx(kA,{className:"w-4 h-4"}),"Activate Authentication"]})]})]})})})]}),u&&s.jsxs("div",{children:[s.jsxs("div",{className:"mb-6",children:[s.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[s.jsx(P1,{className:"w-5 h-5 text-bambu-green"}),"Role Permissions"]}),s.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:"Overview of what each role can do."})]}),s.jsxs("div",{className:"space-y-4",children:[s.jsxs(Mt,{children:[s.jsx(mr,{children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("div",{className:"w-8 h-8 rounded-full bg-purple-500/20 flex items-center justify-center",children:s.jsx(P1,{className:"w-4 h-4 text-purple-300"})}),s.jsx("h3",{className:"text-white font-medium",children:"Admin"})]})}),s.jsx(Et,{children:s.jsxs("ul",{className:"space-y-2 text-sm text-bambu-gray",children:[s.jsxs("li",{className:"flex items-start gap-2",children:[s.jsx(Dn,{className:"w-4 h-4 text-bambu-green mt-0.5 flex-shrink-0"}),s.jsx("span",{children:"Manage printer settings"})]}),s.jsxs("li",{className:"flex items-start gap-2",children:[s.jsx(Dn,{className:"w-4 h-4 text-bambu-green mt-0.5 flex-shrink-0"}),s.jsx("span",{children:"Create, edit, and delete users"})]}),s.jsxs("li",{className:"flex items-start gap-2",children:[s.jsx(Dn,{className:"w-4 h-4 text-bambu-green mt-0.5 flex-shrink-0"}),s.jsx("span",{children:"Access all system features"})]})]})})]}),s.jsxs(Mt,{children:[s.jsx(mr,{children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("div",{className:"w-8 h-8 rounded-full bg-blue-500/20 flex items-center justify-center",children:s.jsx(Wh,{className:"w-4 h-4 text-blue-300"})}),s.jsx("h3",{className:"text-white font-medium",children:"User"})]})}),s.jsx(Et,{children:s.jsxs("ul",{className:"space-y-2 text-sm text-bambu-gray",children:[s.jsxs("li",{className:"flex items-start gap-2",children:[s.jsx(Dn,{className:"w-4 h-4 text-bambu-green mt-0.5 flex-shrink-0"}),s.jsx("span",{children:"Send print jobs"})]}),s.jsxs("li",{className:"flex items-start gap-2",children:[s.jsx(Dn,{className:"w-4 h-4 text-bambu-green mt-0.5 flex-shrink-0"}),s.jsx("span",{children:"Manage files and archives"})]}),s.jsxs("li",{className:"flex items-start gap-2",children:[s.jsx(Dn,{className:"w-4 h-4 text-bambu-green mt-0.5 flex-shrink-0"}),s.jsx("span",{children:"Manage filament"})]})]})})]})]})]})]}),qe&&s.jsx(Ln,{title:"Disable Authentication",message:"Are you sure you want to disable authentication? This will make your Bambuddy instance accessible without login. All users will remain in the database but authentication will be disabled.",confirmText:"Disable Authentication",variant:"danger",onConfirm:async()=>{try{await pe.disableAuth(),o("Authentication disabled successfully","success"),await f(),Je(!1),window.location.href="/"}catch(xe){const st=xe instanceof Error?xe.message:"Failed to disable authentication";o(st,"error")}},onCancel:()=>Je(!1)})]})}const hre=t=>{const e=parseFloat(t);return(Math.trunc(e*1e3)/1e3).toFixed(3)},rKe=t=>t.startsWith("HH")?"HF":"S",iKe=t=>{const e=t.match(/^([A-Z]{2}\d{2})/);return e?e[1]:"HH00"},LR=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:a,note:o}){const l=rKe(t.nozzle_id),c=t.nozzle_diameter,u=()=>{r&&a?a():e()};return s.jsxs("div",{className:"flex items-center gap-2",children:[r&&s.jsx("button",{onClick:a,className:"text-bambu-gray hover:text-white transition-colors p-1",children:i?s.jsx(eu,{className:"w-4 h-4 text-bambu-green"}):s.jsx(Ol,{className:"w-4 h-4"})}),s.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:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"text-bambu-green font-mono text-sm font-bold whitespace-nowrap",children:hre(t.k_value)}),s.jsx("span",{className:"text-white text-sm truncate flex-1",title:t.name,children:t.name||"Unnamed"}),o&&s.jsx("span",{title:"Has note",children:s.jsx(tq,{className:"w-3 h-3 text-yellow-500"})}),s.jsxs("span",{className:"text-xs text-bambu-gray whitespace-nowrap",children:[l," ",c]})]}),o&&s.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&&s.jsx("button",{onClick:d=>{d.stopPropagation(),n()},className:"text-bambu-gray hover:text-white transition-colors p-1",title:"Copy profile",children:s.jsx(Jo,{className:"w-4 h-4"})})]})}function xj({profile:t,printerId:e,nozzleDiameter:n,existingProfiles:r=[],isDualNozzle:i=!1,initialNote:a="",initialNoteKey:o=null,onClose:l,onSave:c,onSaveNote:u}){const{showToast:d}=$n(),[f,m]=w.useState(t?.name||""),[g,x]=w.useState(t?.k_value?hre(t.k_value):"0.020"),[y,b]=w.useState(t?.filament_id||""),[v,M]=w.useState(t?.nozzle_id?iKe(t.nozzle_id):"HH00"),[S,A]=w.useState(t?.nozzle_diameter||n),[E,k]=w.useState(t?[t.extruder_id]:i?[0,1]:[0]),[C,R]=w.useState(!1),[T,P]=w.useState({current:0,total:0}),[F,L]=w.useState(a),X=jr.useMemo(()=>{const oe=new Map;for(const B of r)if(B.filament_id&&!oe.has(B.filament_id)){const G=LR(B.name||"");oe.set(B.filament_id,{id:B.filament_id,name:G||B.filament_id})}return Array.from(oe.values()).sort((B,G)=>B.name.localeCompare(G.name))},[r]),D=ft({mutationFn:oe=>(console.log("[KProfile] Calling API..."),pe.setKProfile(e,oe)),onSuccess:oe=>{if(console.log("[KProfile] Save success:",oe),d("K-profile saved"),u&&F!==a){let B;F===""&&o?B=o:t&&t.slot_id>0?B=t.setting_id||`slot_${t.slot_id}_${t.filament_id}_${t.extruder_id}`:B=`name_${f}_${y}`,u(B,F)}R(!0),setTimeout(()=>{R(!1),c()},2500)},onError:oe=>{console.error("[KProfile] Save error:",oe),d(oe.message,"error"),R(!1)}}),K=ft({mutationFn:oe=>(console.log("[KProfile] Deleting profile..."),pe.deleteKProfile(e,oe)),onSuccess:oe=>{console.log("[KProfile] Delete success:",oe),d("K-profile deleted"),R(!0),setTimeout(()=>{R(!1),l()},4e3)},onError:oe=>{console.error("[KProfile] Delete error:",oe),d(oe.message,"error"),R(!1)}}),[Y,q]=w.useState(!1),Z=()=>{t&&K.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})},re=async oe=>{if(oe.preventDefault(),i&&!t&&E.length===0){d("Please select at least one extruder","error");return}const B=parseFloat(g).toFixed(6),G=`${v}-${S}`;if(t||E.length===1){const te={name:f,k_value:B,filament_id:y,nozzle_id:G,nozzle_diameter:S,extruder_id:t?t.extruder_id:E[0],setting_id:t?.setting_id,slot_id:t?.slot_id??0};console.log("[KProfile] Saving profile:",te),D.mutate(te);return}R(!0),P({current:1,total:E.length});const J=E.map(te=>({name:f,k_value:B,filament_id:y,nozzle_id:G,nozzle_diameter:S,extruder_id:te,setting_id:void 0,slot_id:0}));console.log(`[KProfile] Saving ${J.length} profiles in batch:`,J);try{if(await pe.setKProfilesBatch(e,J),d(`K-profile saved to ${E.length} extruders`),u&&F){const te=`name_${f}_${y}`;u(te,F)}}catch(te){console.error("[KProfile] Failed to save batch:",te),d("Failed to save K-profiles","error"),R(!1),P({current:0,total:0});return}P({current:E.length,total:E.length}),setTimeout(()=>{R(!1),P({current:0,total:0}),c()},3e3)};return s.jsxs("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",children:[s.jsxs(Mt,{className:"w-full max-w-md relative",children:[C&&s.jsxs("div",{className:"absolute inset-0 bg-bambu-dark-secondary/90 flex flex-col items-center justify-center z-10 rounded-lg",children:[s.jsx(mt,{className:"w-8 h-8 text-bambu-green animate-spin mb-3"}),s.jsx("p",{className:"text-white font-medium",children:T.total>1?`Saving to extruder ${T.current}/${T.total}...`:"Syncing with printer..."}),s.jsx("p",{className:"text-bambu-gray text-sm mt-1",children:"Please wait"})]}),s.jsxs(Et,{className:"p-0",children:[s.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[s.jsx("h2",{className:"text-xl font-semibold text-white",children:t?"Edit K-Profile":"Add K-Profile"}),s.jsx("button",{onClick:l,className:"text-bambu-gray hover:text-white transition-colors",disabled:C,children:s.jsx(Ut,{className:"w-5 h-5"})})]}),s.jsxs("form",{onSubmit:re,className:"p-4 space-y-4",children:[s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Profile Name"}),s.jsx("input",{type:"text",value:f,onChange:oe=>m(oe.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:"My PLA Profile",required:!t})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"K-Value"}),s.jsx("input",{type:"text",inputMode:"decimal",value:g,onChange:oe=>{const B=oe.target.value;(B===""||/^\d*\.?\d*$/.test(B))&&x(B)},onBlur:oe=>{const B=parseFloat(oe.target.value);isNaN(B)||x((Math.trunc(B*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:"0.020",required:!0}),s.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Typical range: 0.01 - 0.06 for PLA, 0.02 - 0.10 for PETG"})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Filament"}),s.jsxs("select",{value:y,onChange:oe=>{const B=oe.target.value;if(b(B),!t&&B&&!f){const G=X.find(J=>J.id===B);G&&m(`${v==="HH00"?"HF":"S"} ${G.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:[s.jsx("option",{value:"",children:"Select filament..."}),t?.filament_id&&s.jsx("option",{value:t.filament_id,children:X.find(oe=>oe.id===t.filament_id)?.name||t.filament_id},t.filament_id),!t&&X.map(oe=>s.jsx("option",{value:oe.id,children:oe.name},oe.id))]}),!t&&X.length===0&&s.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"No filaments found. Create a K-profile in Bambu Studio first."})]}),s.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Flow Type"}),s.jsxs("select",{value:v,onChange:oe=>{const B=oe.target.value;if(M(B),!t&&y&&!f){const G=X.find(J=>J.id===y);G&&m(`${B==="HS00"?"HF":"S"} ${G.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:[s.jsx("option",{value:"HH00",children:"High Flow"}),s.jsx("option",{value:"HS00",children:"Standard"})]})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Nozzle Size"}),s.jsxs("select",{value:S,onChange:oe=>A(oe.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:[s.jsx("option",{value:"0.2",children:"0.2mm"}),s.jsx("option",{value:"0.4",children:"0.4mm"}),s.jsx("option",{value:"0.6",children:"0.6mm"}),s.jsx("option",{value:"0.8",children:"0.8mm"})]})]})]}),i&&s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:t?"Extruder":"Extruders"}),t?s.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?"Left":"Right"}):s.jsxs("div",{className:"flex gap-4",children:[s.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[s.jsx("input",{type:"checkbox",checked:E.includes(1),onChange:oe=>{oe.target.checked?k([...E,1]):k(E.filter(B=>B!==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"}),s.jsx("span",{className:"text-white",children:"Left"})]}),s.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[s.jsx("input",{type:"checkbox",checked:E.includes(0),onChange:oe=>{oe.target.checked?k([...E,0]):k(E.filter(B=>B!==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"}),s.jsx("span",{className:"text-white",children:"Right"})]})]})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Notes (stored locally)"}),s.jsx("textarea",{value:F,onChange:oe=>L(oe.target.value),placeholder:"Add notes about this profile...",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"}),s.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Notes are saved in Bambuddy, not on the printer"})]}),s.jsxs("div",{className:"flex gap-2 pt-4",children:[t&&s.jsx(Se,{type:"button",variant:"secondary",onClick:()=>q(!0),disabled:K.isPending||C,className:"text-red-500 hover:bg-red-500/10",children:K.isPending?s.jsx(mt,{className:"w-4 h-4 animate-spin"}):s.jsx(an,{className:"w-4 h-4"})}),s.jsx(Se,{type:"button",variant:"secondary",onClick:l,disabled:C,className:"flex-1",children:"Cancel"}),s.jsxs(Se,{type:"submit",disabled:D.isPending||C,className:"flex-1",children:[D.isPending?s.jsx(mt,{className:"w-4 h-4 animate-spin"}):s.jsx(j2,{className:"w-4 h-4"}),"Save"]})]})]})]})]}),Y&&s.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-[60]",children:s.jsx(Mt,{className:"w-full max-w-sm",children:s.jsxs(Et,{className:"p-6",children:[s.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[s.jsx("div",{className:"w-10 h-10 rounded-full bg-red-500/20 flex items-center justify-center",children:s.jsx(an,{className:"w-5 h-5 text-red-500"})}),s.jsxs("div",{children:[s.jsx("h3",{className:"text-lg font-semibold text-white",children:"Delete Profile"}),s.jsx("p",{className:"text-sm text-bambu-gray",children:"This cannot be undone"})]})]}),s.jsxs("p",{className:"text-bambu-gray mb-6",children:["Are you sure you want to delete ",s.jsxs("span",{className:"text-white font-medium",children:['"',t?.name,'"']})," from the printer?"]}),s.jsxs("div",{className:"flex gap-3",children:[s.jsx(Se,{variant:"secondary",onClick:()=>q(!1),className:"flex-1",children:"Cancel"}),s.jsxs(Se,{onClick:()=>{q(!1),Z()},disabled:K.isPending,className:"flex-1 bg-red-500 hover:bg-red-600 text-white",children:[K.isPending?s.jsx(mt,{className:"w-4 h-4 animate-spin"}):s.jsx(an,{className:"w-4 h-4"}),"Delete"]})]})]})})})]})}const C1={NOZZLE_DIAMETER:"bambusy_kprofiles_nozzle",SORT_OPTION:"bambusy_kprofiles_sort"};function aKe(){const{showToast:t}=$n(),[e,n]=w.useState(null),[r,i]=w.useState(()=>localStorage.getItem(C1.NOZZLE_DIAMETER)||"0.4"),[a,o]=w.useState(null),[l,c]=w.useState(!1),[u,d]=w.useState(null),[f,m]=w.useState(""),[g,x]=w.useState("all"),[y,b]=w.useState("all"),[v,M]=w.useState(()=>localStorage.getItem(C1.SORT_OPTION)||"name"),[S,A]=w.useState(!1),[E,k]=w.useState(new Set),[C,R]=w.useState(!1),[T,P]=w.useState(!1),F=w.useCallback(U=>`${U.slot_id}_${U.extruder_id}`,[]);w.useEffect(()=>{localStorage.setItem(C1.NOZZLE_DIAMETER,r)},[r]),w.useEffect(()=>{localStorage.setItem(C1.SORT_OPTION,v)},[v]);const{data:L,isLoading:X}=ct({queryKey:["printers"],queryFn:pe.getPrinters}),{data:D,isLoading:K,isFetching:Y,error:q,refetch:Z}=ct({queryKey:["kprofiles",e,r],queryFn:async()=>{console.log("[KProfiles] Fetching profiles for printer",e,"nozzle",r);const U=await pe.getKProfiles(e,r);return console.log("[KProfiles] Received profiles:",U?.profiles?.length||0,"profiles"),U},enabled:!!e,retry:!1,staleTime:0,gcTime:0,refetchOnMount:"always"}),{data:re}=ct({queryKey:["kprofiles",e,"0.4"],queryFn:()=>pe.getKProfiles(e,"0.4"),enabled:!!e,staleTime:6e4}),{data:oe,refetch:B}=ct({queryKey:["kprofile-notes",e],queryFn:()=>pe.getKProfileNotes(e),enabled:!!e,staleTime:3e4}),G=q?.message?.includes("not connected");w.useEffect(()=>{if(!e&&L&&L.length>0){const U=L.find(V=>V.is_active);U&&n(U.id)}},[e,L]),w.useEffect(()=>{if(e){const U=setTimeout(()=>{Z()},150);return()=>clearTimeout(U)}},[e,r]);const J=L?.filter(U=>U.is_active)||[],te=jr.useMemo(()=>D?.profiles?D.profiles.filter(V=>{const Q=f.toLowerCase(),Ee=!Q||V.name.toLowerCase().includes(Q)||V.filament_id.toLowerCase().includes(Q),Ce=g==="all"||g==="left"&&V.extruder_id===1||g==="right"&&V.extruder_id===0,Ne=y==="all"||y==="hf"&&V.nozzle_id.startsWith("HH")||y==="s"&&V.nozzle_id.startsWith("HS");return Ee&&Ce&&Ne}).sort((V,Q)=>{switch(v){case"k_value":return parseFloat(V.k_value)-parseFloat(Q.k_value);case"filament":return LR(V.name).localeCompare(LR(Q.name));case"name":default:return V.name.localeCompare(Q.name)}}):[],[D?.profiles,f,g,y,v]),ae=L?.find(U=>U.id===e),de=ae?.nozzle_count===2;w.useEffect(()=>{const U=V=>{V.target instanceof HTMLInputElement||V.target instanceof HTMLTextAreaElement||V.target instanceof HTMLSelectElement||a||l||u||(V.key==="r"||V.key==="R"?(V.preventDefault(),Z()):V.key==="n"||V.key==="N"?(V.preventDefault(),c(!0)):V.key==="Escape"&&S&&(V.preventDefault(),A(!1),k(new Set)))};return window.addEventListener("keydown",U),()=>window.removeEventListener("keydown",U)},[a,l,u,S,Z]);const fe=w.useCallback(()=>{if(!D?.profiles||D.profiles.length===0){t("No profiles to export","error");return}const U={version:1,exported_at:new Date().toISOString(),printer:ae?.name||"Unknown",nozzle_diameter:r,profiles:D.profiles.map(Ce=>({name:Ce.name,k_value:Ce.k_value,filament_id:Ce.filament_id,nozzle_id:Ce.nozzle_id,nozzle_diameter:Ce.nozzle_diameter,extruder_id:Ce.extruder_id}))},V=new Blob([JSON.stringify(U,null,2)],{type:"application/json"}),Q=URL.createObjectURL(V),Ee=document.createElement("a");Ee.href=Q,Ee.download=`kprofiles_${ae?.name||"printer"}_${r}mm_${new Date().toISOString().split("T")[0]}.json`,document.body.appendChild(Ee),Ee.click(),document.body.removeChild(Ee),URL.revokeObjectURL(Q),t(`Exported ${D.profiles.length} profiles`)},[D?.profiles,ae,r,t]),Ae=w.useCallback(()=>{const U=document.createElement("input");U.type="file",U.accept=".json",U.onchange=async V=>{const Q=V.target.files?.[0];if(Q)try{const Ee=await Q.text(),Ce=JSON.parse(Ee);if(!Ce.profiles||!Array.isArray(Ce.profiles)){t("Invalid file format","error");return}let Ne=0;for(const H of Ce.profiles)if(!(!H.name||!H.k_value||!H.filament_id))try{await pe.setKProfile(e,{name:H.name,k_value:parseFloat(H.k_value).toFixed(6),filament_id:H.filament_id,nozzle_id:H.nozzle_id||`HH00-${r}`,nozzle_diameter:H.nozzle_diameter||r,extruder_id:H.extruder_id??0,slot_id:0}),Ne++,await new Promise(O=>setTimeout(O,500))}catch(O){console.error("Failed to import profile:",H.name,O)}t(`Imported ${Ne} of ${Ce.profiles.length} profiles`),Z()}catch(Ee){console.error("Import error:",Ee),t("Failed to parse import file","error")}},U.click()},[e,r,t,Z]),ge=w.useCallback(U=>{k(V=>{const Q=new Set(V);return Q.has(U)?Q.delete(U):Q.add(U),Q})},[]),Me=w.useCallback(()=>{k(new Set(te.map(U=>F(U))))},[te,F]),je=w.useCallback(()=>{E.size!==0&&R(!0)},[E.size]),ne=w.useCallback(async()=>{const U=te.filter(Q=>E.has(F(Q)));P(!0);let V=0;for(const Q of U)try{await pe.deleteKProfile(e,{slot_id:Q.slot_id,extruder_id:Q.extruder_id,nozzle_id:Q.nozzle_id,nozzle_diameter:Q.nozzle_diameter,filament_id:Q.filament_id,setting_id:Q.setting_id}),V++,await new Promise(Ee=>setTimeout(Ee,300))}catch(Ee){console.error("Failed to delete profile:",Q.name,Ee)}t(`Deleted ${V} profiles`),P(!1),R(!1),A(!1),k(new Set),Z()},[e,E,te,t,Z,F]),Ke=w.useCallback(U=>{const V=[];return U.setting_id&&V.push(U.setting_id),V.push(`slot_${U.slot_id}_${U.filament_id}_${U.extruder_id}`),V.push(`name_${U.name}_${U.filament_id}`),V},[]),$=w.useCallback(async(U,V)=>{if(e)try{await pe.setKProfileNote(e,U,V),B()}catch(Q){console.error("Failed to save note:",Q),t("Failed to save note","error")}},[e,B,t]),z=w.useCallback(U=>{if(!oe?.notes)return{note:"",key:null};const V=Ke(U);for(const Q of V)if(oe.notes[Q])return{note:oe.notes[Q],key:Q};return{note:"",key:null}},[oe,Ke]),W=w.useCallback(U=>z(U).note,[z]);return X?s.jsx("div",{className:"flex justify-center py-12",children:s.jsx(mt,{className:"w-8 h-8 text-bambu-green animate-spin"})}):!L||L.length===0?s.jsx(Mt,{children:s.jsxs(Et,{className:"py-12 text-center",children:[s.jsx(ea,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),s.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:"No Printers Configured"}),s.jsx("p",{className:"text-bambu-gray",children:"Add a printer in Settings to manage K-profiles"})]})}):J.length===0?s.jsx(Mt,{children:s.jsxs(Et,{className:"py-12 text-center",children:[s.jsx(Ir,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),s.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:"No Active Printers"}),s.jsx("p",{className:"text-bambu-gray",children:"Enable a printer connection to view its K-profiles"})]})}):s.jsxs(s.Fragment,{children:[Y&&!K&&s.jsxs("div",{className:"fixed inset-0 bg-black/50 flex flex-col items-center justify-center z-40",children:[s.jsx(mt,{className:"w-10 h-10 text-bambu-green animate-spin mb-3"}),s.jsx("p",{className:"text-white font-medium",children:"Loading K-Profiles..."})]}),s.jsxs("div",{className:"flex flex-wrap gap-4 mb-6",children:[s.jsxs("div",{className:"flex-1 min-w-48",children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Printer"}),s.jsx("select",{value:e||"",onChange:U=>n(parseInt(U.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:J.map(U=>s.jsx("option",{value:U.id,children:U.name},U.id))})]}),s.jsxs("div",{className:"w-32",children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Nozzle"}),s.jsxs("select",{value:r,onChange:U=>i(U.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[s.jsx("option",{value:"0.2",children:"0.2mm"}),s.jsx("option",{value:"0.4",children:"0.4mm"}),s.jsx("option",{value:"0.6",children:"0.6mm"}),s.jsx("option",{value:"0.8",children:"0.8mm"})]})]}),s.jsxs("div",{className:"flex items-end gap-2",children:[s.jsxs(Se,{variant:"secondary",onClick:()=>Z(),disabled:Y,children:[s.jsx(yr,{className:`w-4 h-4 ${Y?"animate-spin":""}`}),"Refresh"]}),s.jsxs(Se,{onClick:()=>c(!0),children:[s.jsx(Kn,{className:"w-4 h-4"}),"Add Profile"]})]})]}),s.jsxs("div",{className:"flex flex-wrap gap-4 mb-4",children:[s.jsxs("div",{className:"flex-1 min-w-48 relative",children:[s.jsx(xa,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray"}),s.jsx("input",{type:"text",value:f,onChange:U=>m(U.target.value),placeholder:"Search by name or filament...",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"})]}),de&&s.jsx("div",{className:"w-36",children:s.jsxs("select",{value:g,onChange:U=>x(U.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:[s.jsx("option",{value:"all",children:"All Extruders"}),s.jsx("option",{value:"left",children:"Left Only"}),s.jsx("option",{value:"right",children:"Right Only"})]})}),s.jsx("div",{className:"w-32",children:s.jsxs("select",{value:y,onChange:U=>b(U.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:[s.jsx("option",{value:"all",children:"All Flow"}),s.jsx("option",{value:"hf",children:"HF Only"}),s.jsx("option",{value:"s",children:"S Only"})]})}),s.jsx("div",{className:"w-32",children:s.jsxs("select",{value:v,onChange:U=>M(U.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[s.jsx("option",{value:"name",children:"Sort: Name"}),s.jsx("option",{value:"k_value",children:"Sort: K-Value"}),s.jsx("option",{value:"filament",children:"Sort: Filament"})]})})]}),s.jsxs("div",{className:"flex flex-wrap gap-2 mb-6",children:[s.jsxs(Se,{variant:"secondary",onClick:fe,disabled:!D?.profiles?.length,title:"Export profiles to JSON",children:[s.jsx(Jr,{className:"w-4 h-4"}),"Export"]}),s.jsxs(Se,{variant:"secondary",onClick:Ae,title:"Import profiles from JSON",children:[s.jsx(bi,{className:"w-4 h-4"}),"Import"]}),s.jsx("div",{className:"flex-1"}),S?s.jsxs(s.Fragment,{children:[s.jsxs(Se,{variant:"secondary",onClick:Me,title:"Select all visible profiles",children:[s.jsx(eu,{className:"w-4 h-4"}),"Select All"]}),s.jsxs(Se,{variant:"secondary",onClick:je,disabled:E.size===0,className:"text-red-500 hover:bg-red-500/10",title:`Delete ${E.size} selected profiles`,children:[s.jsx(an,{className:"w-4 h-4"}),"Delete (",E.size,")"]}),s.jsxs(Se,{variant:"secondary",onClick:()=>{A(!1),k(new Set)},children:[s.jsx(Ut,{className:"w-4 h-4"}),"Cancel"]})]}):s.jsxs(Se,{variant:"secondary",onClick:()=>A(!0),disabled:!te.length,title:"Enter selection mode for bulk delete",children:[s.jsx(eu,{className:"w-4 h-4"}),"Select"]})]}),K?s.jsx("div",{className:"flex justify-center py-12",children:s.jsx(mt,{className:"w-8 h-8 text-bambu-green animate-spin"})}):G?s.jsx(Mt,{children:s.jsxs(Et,{className:"py-12 text-center",children:[s.jsx(Pg,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),s.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:"Printer Offline"}),s.jsx("p",{className:"text-bambu-gray mb-4",children:"The selected printer is not connected. Power it on to view K-profiles."}),s.jsxs(Se,{variant:"secondary",onClick:()=>Z(),children:[s.jsx(yr,{className:"w-4 h-4"}),"Retry"]})]})}):te.length>0?de?s.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[s.jsxs("div",{children:[s.jsx("h3",{className:"text-sm font-medium text-bambu-gray mb-2 px-1",children:"Left Extruder"}),s.jsx("div",{className:"space-y-1",children:te.filter(U=>U.extruder_id===1).map(U=>s.jsx(gj,{profile:U,onEdit:()=>o(U),onCopy:()=>d(U),selectionMode:S,isSelected:E.has(F(U)),onToggleSelect:()=>ge(F(U)),note:W(U)},F(U)))})]}),s.jsxs("div",{children:[s.jsx("h3",{className:"text-sm font-medium text-bambu-gray mb-2 px-1",children:"Right Extruder"}),s.jsx("div",{className:"space-y-1",children:te.filter(U=>U.extruder_id===0).map(U=>s.jsx(gj,{profile:U,onEdit:()=>o(U),onCopy:()=>d(U),selectionMode:S,isSelected:E.has(F(U)),onToggleSelect:()=>ge(F(U)),note:W(U)},F(U)))})]})]}):s.jsx("div",{className:"space-y-1",children:te.map(U=>s.jsx(gj,{profile:U,onEdit:()=>o(U),onCopy:()=>d(U),selectionMode:S,isSelected:E.has(F(U)),onToggleSelect:()=>ge(F(U)),note:W(U)},F(U)))}):f||g!=="all"||y!=="all"?s.jsx(Mt,{children:s.jsxs(Et,{className:"py-12 text-center",children:[s.jsx(xa,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),s.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:"No Matching Profiles"}),s.jsx("p",{className:"text-bambu-gray",children:"No profiles match your search criteria"})]})}):s.jsx(Mt,{children:s.jsxs(Et,{className:"py-12 text-center",children:[s.jsx(j2,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),s.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:"No K-Profiles"}),s.jsxs("p",{className:"text-bambu-gray mb-4",children:["No pressure advance profiles found for ",r,"mm nozzle"]}),s.jsxs(Se,{onClick:()=>c(!0),children:[s.jsx(Kn,{className:"w-4 h-4"}),"Create First Profile"]})]})}),a&&e&&(()=>{const{note:U,key:V}=z(a);return s.jsx(xj,{profile:a,printerId:e,nozzleDiameter:r,existingProfiles:re?.profiles||D?.profiles,isDualNozzle:de,initialNote:U,initialNoteKey:V,onSaveNote:$,onClose:()=>{console.log("[KProfiles] Edit modal onClose - refetching profiles..."),o(null),Z()},onSave:()=>{o(null),Z()}})})(),l&&e&&s.jsx(xj,{printerId:e,nozzleDiameter:r,existingProfiles:re?.profiles||D?.profiles,isDualNozzle:de,onSaveNote:$,onClose:()=>{c(!1),Z()},onSave:()=>{c(!1),Z()}}),u&&e&&s.jsx(xj,{printerId:e,nozzleDiameter:r,existingProfiles:re?.profiles||D?.profiles,isDualNozzle:de,onSaveNote:$,profile:{...u,slot_id:0,name:`${u.name} (Copy)`},onClose:()=>{d(null),Z()},onSave:()=>{d(null),Z()}}),C&&s.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",children:s.jsx(Mt,{className:"w-full max-w-sm",children:s.jsxs(Et,{className:"p-6",children:[s.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[s.jsx("div",{className:"w-10 h-10 rounded-full bg-red-500/20 flex items-center justify-center",children:s.jsx(an,{className:"w-5 h-5 text-red-500"})}),s.jsxs("div",{children:[s.jsx("h3",{className:"text-lg font-semibold text-white",children:"Delete Profiles"}),s.jsx("p",{className:"text-sm text-bambu-gray",children:"This cannot be undone"})]})]}),s.jsxs("p",{className:"text-bambu-gray mb-6",children:["Are you sure you want to delete ",s.jsx("span",{className:"text-white font-medium",children:E.size})," selected profiles from the printer?"]}),s.jsxs("div",{className:"flex gap-3",children:[s.jsx(Se,{variant:"secondary",onClick:()=>R(!1),disabled:T,className:"flex-1",children:"Cancel"}),s.jsxs(Se,{onClick:ne,disabled:T,className:"flex-1 bg-red-500 hover:bg-red-600 text-white",children:[T?s.jsx(mt,{className:"w-4 h-4 animate-spin"}):s.jsx(an,{className:"w-4 h-4"}),"Delete"]})]})]})})})]})}function RL(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,a=n.match(/(\d+\.?\d*)\s*(?:mm\s*)?nozzle|nozzle\s*(\d+\.?\d*)/i),o=a?(a[1]||a[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 W0(t){return/^(P[FPM]US|PF\d|PP\d)/.test(t)}function sKe(t){const e=mi(t);if(!e)return"";const r=new Date().getTime()-e.getTime(),i=Math.floor(r/6e4),a=Math.floor(r/36e5),o=Math.floor(r/864e5);return i<1?"Just now":i<60?`${i}m ago`:a<24?`${a}h ago`:o<7?`${o}d ago`:e.toLocaleDateString()}function oKe({onSuccess:t}){const{showToast:e}=$n(),[n,r]=w.useState("email"),[i,a]=w.useState(""),[o,l]=w.useState(""),[c,u]=w.useState(""),[d,f]=w.useState(""),[m,g]=w.useState("global"),x=ft({mutationFn:()=>pe.cloudLogin(i,o,m),onSuccess:S=>{S.success?(e("Logged in successfully"),t()):S.needs_verification?(e("Verification code sent to your email"),r("code")):e(S.message,"error")},onError:S=>e(S.message,"error")}),y=ft({mutationFn:()=>pe.cloudVerify(i,c),onSuccess:S=>{S.success?(e("Logged in successfully"),t()):e(S.message,"error")},onError:S=>e(S.message,"error")}),b=ft({mutationFn:()=>pe.cloudSetToken(d),onSuccess:()=>{e("Token set successfully"),t()},onError:S=>e(S.message,"error")}),v=S=>{S.preventDefault(),n==="email"?x.mutate():n==="code"?y.mutate():n==="token"&&b.mutate()},M=x.isPending||y.isPending||b.isPending;return s.jsx(Mt,{className:"max-w-md mx-auto",children:s.jsxs(Et,{children:[s.jsxs("div",{className:"text-center mb-6",children:[s.jsx("div",{className:"inline-flex items-center justify-center w-12 h-12 rounded-xl bg-bambu-green/20 mb-3",children:s.jsx(A2,{className:"w-6 h-6 text-bambu-green"})}),s.jsx("h2",{className:"text-xl font-semibold text-white",children:"Connect to Bambu Cloud"}),s.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:"Sync your slicer presets across devices"})]}),s.jsxs("form",{onSubmit:v,className:"space-y-4",children:[n==="email"&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Email"}),s.jsx("input",{type:"email",value:i,onChange:S=>a(S.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})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Password"}),s.jsx("input",{type:"password",value:o,onChange:S=>l(S.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})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Region"}),s.jsxs("select",{value:m,onChange:S=>g(S.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:[s.jsx("option",{value:"global",children:"Global"}),s.jsx("option",{value:"china",children:"China"})]})]})]}),n==="code"&&s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Verification Code"}),s.jsxs("p",{className:"text-xs text-bambu-gray mb-2",children:["Check your email (",i,") for a 6-digit code"]}),s.jsx("input",{type:"text",value:c,onChange:S=>u(S.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})]}),n==="token"&&s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Access Token"}),s.jsx("p",{className:"text-xs text-bambu-gray mb-2",children:"Paste your Bambu Lab access token (from Bambu Studio)"}),s.jsx("textarea",{value:d,onChange:S=>f(S.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})]}),s.jsxs("div",{className:"flex gap-2",children:[n==="code"&&s.jsx(Se,{type:"button",variant:"secondary",onClick:()=>r("email"),className:"flex-1",children:"Back"}),s.jsxs(Se,{type:"submit",disabled:M,className:"flex-1",children:[M?s.jsx(mt,{className:"w-4 h-4 animate-spin"}):s.jsx(hz,{className:"w-4 h-4"}),n==="email"?"Login":n==="code"?"Verify":"Set Token"]})]}),n==="email"&&s.jsx("div",{className:"pt-4 border-t border-bambu-dark-tertiary",children:s.jsxs("button",{type:"button",onClick:()=>r("token"),className:"text-sm text-bambu-gray hover:text-white flex items-center gap-2 transition-colors",children:[s.jsx(Gh,{className:"w-4 h-4"}),"Use access token instead"]})}),n==="token"&&s.jsx("div",{className:"pt-4 border-t border-bambu-dark-tertiary",children:s.jsxs("button",{type:"button",onClick:()=>r("email"),className:"text-sm text-bambu-gray hover:text-white flex items-center gap-2 transition-colors",children:[s.jsx(hz,{className:"w-4 h-4"}),"Login with email instead"]})})]})]})})}function xp({label:t,value:e,options:n,onChange:r}){const[i,a]=w.useState(!1),o=n.find(l=>l.value===e);return s.jsxs("div",{className:"relative",children:[s.jsxs("button",{onClick:()=>a(!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:[s.jsxs("span",{className:"text-bambu-gray",children:[t,":"]}),s.jsx("span",{children:o?.label||"All"}),s.jsx(Ji,{className:`w-4 h-4 text-bambu-gray transition-transform ${i?"rotate-180":""}`})]}),i&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"fixed inset-0 z-10",onClick:()=>a(!1)}),s.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=>s.jsxs("button",{onClick:()=>{r(l.value),a(!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:[s.jsx("span",{children:l.label}),l.count!==void 0&&s.jsx("span",{className:"text-bambu-gray text-xs",children:l.count})]},l.value))})]})]})}function lKe(){const[t,e]=w.useState(!1);w.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?s.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:s.jsx(Kp,{className:"w-5 h-5"})}):null}function bj({setting:t,onClick:e,onDuplicate:n,compareMode:r,isCompareSelected:i,compareIndex:a,compareDisabled:o}){const l=RL(t.name),c=W0(t.setting_id);return s.jsxs("div",{className:"flex items-center gap-2 group",children:[s.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:s.jsxs("div",{className:"flex items-center gap-2",children:[i&&a!==void 0&&s.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:a+1}),!i&&c&&s.jsx("span",{className:"flex-shrink-0 w-1.5 h-1.5 rounded-full bg-bambu-green",title:"My preset (editable)"}),s.jsx("span",{className:"text-white text-sm truncate flex-1",title:t.name,children:t.name}),l.filamentType&&t.type==="filament"&&s.jsx("span",{className:"text-xs text-bambu-gray whitespace-nowrap",children:l.filamentType}),l.layerHeight&&t.type==="process"&&s.jsx("span",{className:"text-xs text-bambu-gray whitespace-nowrap",children:l.layerHeight}),l.printer&&s.jsx("span",{className:"text-xs text-bambu-gray whitespace-nowrap",children:l.printer})]})}),s.jsx("button",{onClick:u=>{u.stopPropagation(),n()},className:"opacity-0 group-hover:opacity-100 text-bambu-gray hover:text-white transition-all p-1",title:"Duplicate",children:s.jsx(Jo,{className:"w-4 h-4"})})]})}function IR(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:s.jsxs("div",{className:"flex items-center gap-4 p-4",children:[v?s.jsx("div",{...u,...d,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:s.jsx(Qp,{className:"w-6 h-6 md:w-4 md:h-4 text-bambu-gray"})}):e!==void 0?s.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]}):s.jsx("div",{className:"w-8"}),s.jsx("div",{className:"w-14 h-14 flex-shrink-0 bg-bambu-dark rounded-lg overflow-hidden",children:t.archive_thumbnail?s.jsx("img",{src:pe.getArchiveThumbnail(t.archive_id),alt:"",className:"w-full h-full object-cover"}):t.library_file_thumbnail?s.jsx("img",{src:pe.getLibraryFileThumbnailUrl(t.library_file_id),alt:"",className:"w-full h-full object-cover"}):s.jsx("div",{className:"w-full h-full flex items-center justify-center text-bambu-gray",children:s.jsx(nl,{className:"w-6 h-6"})})}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[s.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?s.jsx(ls,{to:`/archives?highlight=${t.archive_id}`,className:"text-bambu-gray hover:text-bambu-green transition-colors flex-shrink-0",title:"View archive",children:s.jsx(Lr,{className:"w-3.5 h-3.5"})}):t.library_file_id?s.jsx(ls,{to:`/library?highlight=${t.library_file_id}`,className:"text-bambu-gray hover:text-bambu-green transition-colors flex-shrink-0",title:"View in File Manager",children:s.jsx(Lr,{className:"w-3.5 h-3.5"})}):null]}),s.jsxs("div",{className:"flex items-center gap-3 text-sm text-bambu-gray",children:[s.jsxs("span",{className:`flex items-center gap-1.5 ${t.printer_id===null?"text-orange-400":""}`,children:[s.jsx(Ir,{className:"w-3.5 h-3.5"}),t.printer_id===null?"Unassigned":t.printer_name||`Printer #${t.printer_id}`]}),t.print_time_seconds&&s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx(md,{className:"w-3.5 h-3.5"}),dre(t.print_time_seconds)]}),v&&!t.manual_start&&s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx(Gn,{className:"w-3.5 h-3.5"}),gqe(t.scheduled_time,c)]})]}),s.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[t.manual_start&&s.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:[s.jsx(qW,{className:"w-3 h-3"}),"Staged"]}),t.require_previous_success&&s.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:"Requires previous success"}),t.auto_off_after&&s.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:[s.jsx(uu,{className:"w-3 h-3"}),"Auto power off"]})]}),b&&s.jsxs("div",{className:"mt-3",children:[s.jsx("div",{className:"h-2 bg-bambu-dark rounded-full overflow-hidden",children:s.jsx("div",{className:"h-full bg-gradient-to-r from-blue-500 to-blue-400 animate-pulse w-full opacity-50"})}),s.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Printing in progress..."})]}),t.error_message&&s.jsxs("p",{className:"text-xs text-red-400 mt-2 flex items-center gap-1",children:[s.jsx(ea,{className:"w-3 h-3"}),t.error_message]})]}),s.jsx(xqe,{status:t.status}),s.jsxs("div",{className:"flex items-center gap-1",children:[b&&s.jsx(Se,{variant:"ghost",size:"sm",onClick:a,title:"Stop Print",className:"text-red-400 hover:text-red-300 hover:bg-red-500/10",children:s.jsx(kce,{className:"w-4 h-4"})}),v&&s.jsxs(s.Fragment,{children:[t.manual_start&&s.jsx(Se,{variant:"ghost",size:"sm",onClick:l,title:"Start Print",className:"text-bambu-green hover:text-bambu-green-light hover:bg-bambu-green/10",children:s.jsx(rl,{className:"w-4 h-4"})}),s.jsx(Se,{variant:"ghost",size:"sm",onClick:n,title:"Edit",children:s.jsx(Ga,{className:"w-4 h-4"})}),s.jsx(Se,{variant:"ghost",size:"sm",onClick:r,title:"Cancel",className:"text-red-400 hover:text-red-300 hover:bg-red-500/10",children:s.jsx(Ut,{className:"w-4 h-4"})})]}),M&&s.jsxs(s.Fragment,{children:[s.jsx(Se,{variant:"ghost",size:"sm",onClick:o,title:"Re-queue",className:"text-bambu-green hover:text-bambu-green/80 hover:bg-bambu-green/10",children:s.jsx(yr,{className:"w-4 h-4"})}),s.jsx(Se,{variant:"ghost",size:"sm",onClick:i,title:"Remove",children:s.jsx(an,{className:"w-4 h-4"})})]})]})]})})}function bqe(){const t=tn(),{showToast:e}=$n(),[n,r]=w.useState(null),[i,a]=w.useState(""),[o,l]=w.useState(!1),[c,u]=w.useState(null),[d,f]=w.useState(null),[m,g]=w.useState(null),[x,y]=w.useState(()=>localStorage.getItem("queue.historySortBy")||"date"),[b,v]=w.useState(()=>{const J=localStorage.getItem("queue.historySortAsc");return J!==null?J==="true":!1}),[M,S]=w.useState(()=>localStorage.getItem("queue.pendingSortBy")||"position"),[A,E]=w.useState(()=>{const J=localStorage.getItem("queue.pendingSortAsc");return J!==null?J==="true":!0});w.useEffect(()=>{localStorage.setItem("queue.historySortBy",x)},[x]),w.useEffect(()=>{localStorage.setItem("queue.historySortAsc",String(b))},[b]),w.useEffect(()=>{localStorage.setItem("queue.pendingSortBy",M)},[M]),w.useEffect(()=>{localStorage.setItem("queue.pendingSortAsc",String(A))},[A]);const k=zne(y2(lN,{activationConstraint:{distance:8}}),y2(oN,{coordinateGetter:cre})),{data:C}=ct({queryKey:["settings"],queryFn:pe.getSettings}),R=C?.time_format||"system",{data:T,isLoading:P}=ct({queryKey:["queue",n,i],queryFn:()=>pe.getQueue(n||void 0,i||void 0),refetchInterval:5e3}),{data:F}=ct({queryKey:["printers"],queryFn:()=>pe.getPrinters()}),L=ft({mutationFn:J=>pe.cancelQueueItem(J),onSuccess:()=>{t.invalidateQueries({queryKey:["queue"]}),e("Queue item cancelled")},onError:()=>e("Failed to cancel item","error")}),X=ft({mutationFn:J=>pe.removeFromQueue(J),onSuccess:()=>{t.invalidateQueries({queryKey:["queue"]}),e("Queue item removed")},onError:()=>e("Failed to remove item","error")}),D=ft({mutationFn:J=>pe.stopQueueItem(J),onSuccess:()=>{t.invalidateQueries({queryKey:["queue"]}),e("Print stopped")},onError:()=>e("Failed to stop print","error")}),K=ft({mutationFn:J=>pe.startQueueItem(J),onSuccess:()=>{t.invalidateQueries({queryKey:["queue"]}),e("Print released to queue")},onError:()=>e("Failed to start print","error")}),Y=ft({mutationFn:J=>pe.reorderQueue(J),onSuccess:()=>{t.invalidateQueries({queryKey:["queue"]})},onError:()=>e("Failed to reorder queue","error")}),q=ft({mutationFn:async()=>{const J=T?.filter(te=>["completed","failed","skipped","cancelled"].includes(te.status))||[];for(const te of J)await pe.removeFromQueue(te.id);return J.length},onSuccess:J=>{t.invalidateQueries({queryKey:["queue"]}),e(`Cleared ${J} history item${J!==1?"s":""}`)},onError:()=>e("Failed to clear history","error")}),Z=w.useMemo(()=>{const J=T?.filter(ae=>ae.status==="pending")||[],te=ae=>{if(!ae.scheduled_time)return 0;const de=new Date(ae.scheduled_time).getTime(),fe=Date.now()+4320*60*60*1e3;return de>fe?0:de};return[...J].sort((ae,de)=>{let fe;if(M==="name"){const Ae=ae.archive_name||ae.library_file_name||"",ge=de.archive_name||de.library_file_name||"";fe=Ae.localeCompare(ge)}else M==="printer"?fe=(ae.printer_name||"").localeCompare(de.printer_name||""):M==="time"?fe=te(ae)-te(de):fe=ae.position-de.position;return A?fe:-fe})},[T,M,A]),re=T?.filter(J=>J.status==="printing")||[],oe=w.useMemo(()=>[...T?.filter(te=>["completed","failed","skipped","cancelled"].includes(te.status))||[]].sort((te,ae)=>{let de;if(x==="name"){const fe=te.archive_name||te.library_file_name||"",Ae=ae.archive_name||ae.library_file_name||"";de=fe.localeCompare(Ae)}else x==="printer"?de=(te.printer_name||"").localeCompare(ae.printer_name||""):de=new Date(ae.completed_at||ae.created_at).getTime()-new Date(te.completed_at||te.created_at).getTime();return b?-de:de}),[T,x,b]),B=w.useMemo(()=>Z.reduce((J,te)=>J+(te.print_time_seconds||0),0),[Z]),G=J=>{const{active:te,over:ae}=J;if(!ae||te.id===ae.id)return;const de=Z.findIndex(Ae=>Ae.id===te.id),fe=Z.findIndex(Ae=>Ae.id===ae.id);if(de!==-1&&fe!==-1){const ge=dN(Z,de,fe).map((Me,je)=>({id:Me.id,position:je+1}));Y.mutate(ge)}};return s.jsxs("div",{className:"p-4 md:p-8",children:[s.jsx("div",{className:"flex items-center justify-between mb-8",children:s.jsxs("div",{children:[s.jsxs("h1",{className:"text-2xl font-bold text-white flex items-center gap-3",children:[s.jsx(KW,{className:"w-7 h-7 text-bambu-green"}),"Print Queue"]}),s.jsx("p",{className:"text-bambu-gray mt-1",children:"Schedule and manage your print jobs"})]})}),s.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-4 gap-4 mb-8",children:[s.jsx(Mt,{className:"bg-gradient-to-br from-blue-500/10 to-transparent border-blue-500/20",children:s.jsx(Et,{className:"p-4",children:s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("div",{className:"w-10 h-10 rounded-lg bg-blue-500/20 flex items-center justify-center",children:s.jsx(rl,{className:"w-5 h-5 text-blue-400"})}),s.jsxs("div",{children:[s.jsx("p",{className:"text-2xl font-bold text-white",children:re.length}),s.jsx("p",{className:"text-sm text-bambu-gray",children:"Printing"})]})]})})}),s.jsx(Mt,{className:"bg-gradient-to-br from-yellow-500/10 to-transparent border-yellow-500/20",children:s.jsx(Et,{className:"p-4",children:s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("div",{className:"w-10 h-10 rounded-lg bg-yellow-500/20 flex items-center justify-center",children:s.jsx(Gn,{className:"w-5 h-5 text-yellow-400"})}),s.jsxs("div",{children:[s.jsx("p",{className:"text-2xl font-bold text-white",children:Z.length}),s.jsx("p",{className:"text-sm text-bambu-gray",children:"Queued"})]})]})})}),s.jsx(Mt,{className:"bg-gradient-to-br from-bambu-green/10 to-transparent border-bambu-green/20",children:s.jsx(Et,{className:"p-4",children:s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("div",{className:"w-10 h-10 rounded-lg bg-bambu-green/20 flex items-center justify-center",children:s.jsx(md,{className:"w-5 h-5 text-bambu-green"})}),s.jsxs("div",{children:[s.jsx("p",{className:"text-2xl font-bold text-white",children:dre(B)}),s.jsx("p",{className:"text-sm text-bambu-gray",children:"Total Queue Time"})]})]})})}),s.jsx(Mt,{className:"bg-gradient-to-br from-gray-500/10 to-transparent border-gray-500/20",children:s.jsx(Et,{className:"p-4",children:s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("div",{className:"w-10 h-10 rounded-lg bg-gray-500/20 flex items-center justify-center",children:s.jsx(Dn,{className:"w-5 h-5 text-gray-400"})}),s.jsxs("div",{children:[s.jsx("p",{className:"text-2xl font-bold text-white",children:oe.length}),s.jsx("p",{className:"text-sm text-bambu-gray",children:"History"})]})]})})})]}),s.jsxs("div",{className:"flex items-center gap-4 mb-6",children:[s.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:n===-1?"unassigned":n||"",onChange:J=>{const te=J.target.value;r(te==="unassigned"?-1:te===""?null:Number(te))},children:[s.jsx("option",{value:"",children:"All Printers"}),s.jsx("option",{value:"unassigned",children:"Unassigned"}),F?.map(J=>s.jsx("option",{value:J.id,children:J.name},J.id))]}),s.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:i,onChange:J=>a(J.target.value),children:[s.jsx("option",{value:"",children:"All Status"}),s.jsx("option",{value:"pending",children:"Pending"}),s.jsx("option",{value:"printing",children:"Printing"}),s.jsx("option",{value:"completed",children:"Completed"}),s.jsx("option",{value:"failed",children:"Failed"}),s.jsx("option",{value:"skipped",children:"Skipped"}),s.jsx("option",{value:"cancelled",children:"Cancelled"})]}),s.jsx("div",{className:"flex-1"}),oe.length>0&&s.jsxs(Se,{variant:"secondary",size:"sm",onClick:()=>l(!0),children:[s.jsx(an,{className:"w-4 h-4"}),"Clear History"]})]}),P?s.jsx("div",{className:"text-center py-12 text-bambu-gray",children:"Loading..."}):T?.length===0?s.jsxs(Mt,{className:"p-12 text-center border-dashed",children:[s.jsx(Qr,{className:"w-16 h-16 text-bambu-gray mx-auto mb-4 opacity-50"}),s.jsx("h3",{className:"text-xl font-medium text-white mb-2",children:"No prints scheduled"}),s.jsx("p",{className:"text-bambu-gray max-w-md mx-auto",children:'Schedule a print from the Archives page using the "Schedule" option in the context menu, or drag and drop files to get started.'})]}):s.jsxs("div",{className:"space-y-8",children:[re.length>0&&s.jsxs("div",{children:[s.jsxs("h2",{className:"text-lg font-semibold text-white mb-4 flex items-center gap-2",children:[s.jsx("div",{className:"w-2 h-2 rounded-full bg-blue-400 animate-pulse"}),"Currently Printing"]}),s.jsx("div",{className:"space-y-3",children:re.map(J=>s.jsx(pj,{item:J,onEdit:()=>{},onCancel:()=>{},onRemove:()=>{},onStop:()=>g({type:"stop",item:J}),onRequeue:()=>{},onStart:()=>{},timeFormat:R},J.id))})]}),Z.length>0&&s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center justify-between mb-4",children:[s.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[s.jsx(Gn,{className:"w-5 h-5 text-yellow-400"}),"Queued",s.jsxs("span",{className:"text-sm font-normal text-bambu-gray",children:["(",Z.length," item",Z.length!==1?"s":"",")"]}),s.jsx("span",{className:"text-xs text-bambu-gray ml-2",title:"Position only affects ASAP items. Scheduled items run at their set time.",children:"Drag to reorder (ASAP only)"})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.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:M,onChange:J=>S(J.target.value),children:[s.jsx("option",{value:"position",children:"Sort by Position"}),s.jsx("option",{value:"name",children:"Sort by Name"}),s.jsx("option",{value:"printer",children:"Sort by Printer"}),s.jsx("option",{value:"time",children:"Sort by Schedule"})]}),s.jsx(Se,{variant:"ghost",size:"sm",onClick:()=>E(!A),title:A?"Ascending":"Descending",className:"px-2",children:A?s.jsx(Kp,{className:"w-4 h-4"}):s.jsx(i0,{className:"w-4 h-4"})})]})]}),s.jsx(rre,{sensors:k,collisionDetection:Vne,onDragEnd:G,children:s.jsx(sre,{items:Z.map(J=>J.id),strategy:aqe,children:s.jsx("div",{className:"space-y-3",children:Z.map((J,te)=>s.jsx(pj,{item:J,position:te+1,onEdit:()=>u(J),onCancel:()=>g({type:"cancel",item:J}),onRemove:()=>{},onStop:()=>{},onRequeue:()=>{},onStart:()=>K.mutate(J.id),timeFormat:R},J.id))})})})]}),oe.length>0&&s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center justify-between mb-4",children:[s.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[s.jsx(Dn,{className:"w-5 h-5 text-bambu-gray"}),"History",s.jsxs("span",{className:"text-sm font-normal text-bambu-gray",children:["(",oe.length," item",oe.length!==1?"s":"",")"]})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.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:x,onChange:J=>y(J.target.value),children:[s.jsx("option",{value:"date",children:"Sort by Date"}),s.jsx("option",{value:"name",children:"Sort by Name"}),s.jsx("option",{value:"printer",children:"Sort by Printer"})]}),s.jsx(Se,{variant:"ghost",size:"sm",onClick:()=>v(!b),title:b?"Ascending (oldest first)":"Descending (newest first)",className:"px-2",children:b?s.jsx(Kp,{className:"w-4 h-4"}):s.jsx(i0,{className:"w-4 h-4"})})]})]}),s.jsx("div",{className:"space-y-3",children:oe.slice(0,20).map((J,te)=>s.jsx(pj,{item:J,position:te+1,onEdit:()=>{},onCancel:()=>{},onRemove:()=>g({type:"remove",item:J}),onStop:()=>{},onRequeue:()=>f(J),onStart:()=>{},timeFormat:R},J.id))})]})]}),c&&s.jsx(Wd,{mode:"edit-queue-item",archiveId:c.archive_id??void 0,libraryFileId:c.library_file_id??void 0,archiveName:c.archive_name||c.library_file_name||`File #${c.archive_id||c.library_file_id}`,queueItem:c,onClose:()=>u(null)}),d&&s.jsx(Wd,{mode:"add-to-queue",archiveId:d.archive_id??void 0,libraryFileId:d.library_file_id??void 0,archiveName:d.archive_name||d.library_file_name||`File #${d.archive_id||d.library_file_id}`,onClose:()=>f(null)}),m&&s.jsx(Ln,{title:m.type==="cancel"?"Cancel Scheduled Print":m.type==="stop"?"Stop Print":"Remove from History",message:m.type==="cancel"?`Are you sure you want to cancel "${m.item.archive_name||m.item.library_file_name||"this print"}"?`:m.type==="stop"?`Are you sure you want to stop the current print "${m.item.archive_name||m.item.library_file_name||"this print"}"? This will cancel the print job on the printer.`:`Are you sure you want to remove "${m.item.archive_name||m.item.library_file_name||"this item"}" from the queue history?`,confirmText:m.type==="cancel"?"Cancel Print":m.type==="stop"?"Stop Print":"Remove",variant:"danger",onConfirm:()=>{m.type==="cancel"?L.mutate(m.item.id):m.type==="stop"?D.mutate(m.item.id):X.mutate(m.item.id),g(null)},onCancel:()=>g(null)}),o&&s.jsx(Ln,{title:"Clear History",message:`Are you sure you want to remove all ${oe.length} item${oe.length!==1?"s":""} from the history?`,confirmText:"Clear History",variant:"danger",onConfirm:()=>{q.mutate(),l(!1)},onCancel:()=>l(!1)})]})}function yqe({printDates:t,months:e=3}){const n=w.useRef(null),[r,i]=w.useState(0);w.useEffect(()=>{const M=n.current;if(!M)return;const S=new ResizeObserver(A=>{const E=A[0]?.contentRect.width||0;i(E)});return S.observe(M),()=>S.disconnect()},[]);const{weeks:a,monthLabels:o,printCounts:l}=w.useMemo(()=>{const M={};t.forEach(F=>{const L=F.split("T")[0];M[L]=(M[L]||0)+1});const S=new Date,A=new Date(S);A.setMonth(A.getMonth()-e),A.setDate(A.getDate()-A.getDay());const E=[],k=[];let C=[],R=-1;const T=new Date(A);let P=0;for(;T<=S;)T.getDay()===0&&C.length>0&&(E.push(C),C=[],P++),T.getMonth()!==R&&(k.push({month:T.toLocaleDateString("en-US",{month:"short"}),weekIndex:P}),R=T.getMonth()),C.push(new Date(T)),T.setDate(T.getDate()+1);return C.length>0&&E.push(C),{weeks:E,monthLabels:k,printCounts:M}},[t,e]),c=Math.max(1,...Object.values(l)),u=M=>{if(M===0)return"bg-bambu-dark";const S=M/c;return S<=.25?"bg-bambu-green/30":S<=.5?"bg-bambu-green/50":S<=.75?"bg-bambu-green/75":"bg-bambu-green"},d=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],f=a.length,m=32,g=2,x=r-m-16,y=f>0?Math.floor((x-(f-1)*g)/f):12,b=Math.max(8,Math.min(20,y)),v=b<=10?10:12;return s.jsx("div",{ref:n,className:"w-full flex justify-center",children:r>0&&s.jsxs("div",{children:[s.jsx("div",{className:"flex mb-1",style:{marginLeft:m+4},children:o.map(({month:M,weekIndex:S},A)=>s.jsx("div",{className:"text-bambu-gray",style:{fontSize:v,marginLeft:A===0?0:`${(S-(o[A-1]?.weekIndex||0))*(b+g)-24}px`},children:M},A))}),s.jsxs("div",{className:"flex",style:{gap:g},children:[s.jsx("div",{className:"flex flex-col",style:{gap:g,marginRight:4,width:m},children:d.map((M,S)=>s.jsx("div",{className:"text-bambu-gray flex items-center",style:{width:m,height:b,fontSize:v,visibility:S%2===1?"visible":"hidden"},children:M},M))}),a.map((M,S)=>s.jsx("div",{className:"flex flex-col",style:{gap:g},children:[0,1,2,3,4,5,6].map(A=>{const E=M.find(T=>T.getDay()===A);if(!E)return s.jsx("div",{style:{width:b,height:b}},A);const k=E.toISOString().split("T")[0],C=l[k]||0,R=k===new Date().toISOString().split("T")[0];return s.jsx("div",{className:`rounded-sm ${u(C)} ${R?"ring-1 ring-white":""}`,style:{width:b,height:b},title:`${E.toLocaleDateString()}: ${C} print${C!==1?"s":""}`},A)})},S))]}),s.jsxs("div",{className:"flex items-center gap-2 mt-3 text-bambu-gray",style:{fontSize:v},children:[s.jsx("span",{children:"Less"}),s.jsxs("div",{className:"flex",style:{gap:g},children:[s.jsx("div",{className:"rounded-sm bg-bambu-dark",style:{width:b,height:b}}),s.jsx("div",{className:"rounded-sm bg-bambu-green/30",style:{width:b,height:b}}),s.jsx("div",{className:"rounded-sm bg-bambu-green/50",style:{width:b,height:b}}),s.jsx("div",{className:"rounded-sm bg-bambu-green/75",style:{width:b,height:b}}),s.jsx("div",{className:"rounded-sm bg-bambu-green",style:{width:b,height:b}})]}),s.jsx("span",{children:"More"})]})]})})}const A1=["#00ae42","#3b82f6","#f59e0b","#ef4444","#8b5cf6","#ec4899","#14b8a6","#f97316"];function vqe(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 _qe({archives:t,currency:e="$"}){const[n,r]=w.useState("30d"),i=w.useMemo(()=>{const m=vqe(n);return t.filter(g=>(mi(g.completed_at||g.created_at)||new Date(0))>=m)},[t,n]),a=w.useMemo(()=>{const m=new Map;return i.forEach(g=>{const x=mi(g.completed_at||g.created_at)||new Date,y=`${x.getFullYear()}-${String(x.getMonth()+1).padStart(2,"0")}-${String(x.getDate()).padStart(2,"0")}`,b=m.get(y)||{date:y,filament:0,cost:0,prints:0};b.filament+=g.filament_used_grams||0,b.cost+=g.cost||0,b.prints+=1,m.set(y,b)}),Array.from(m.values()).sort((g,x)=>g.date.localeCompare(x.date)).map(g=>({...g,dateLabel:new Date(g.date).toLocaleDateString("en-US",{month:"short",day:"numeric"})}))},[i]),o=w.useMemo(()=>{if(n==="7d"||n==="30d")return a;const m=new Map;return i.forEach(g=>{const x=mi(g.completed_at||g.created_at)||new Date,y=new Date(x);y.setDate(x.getDate()-x.getDay());const b=`${y.getFullYear()}-${String(y.getMonth()+1).padStart(2,"0")}-${String(y.getDate()).padStart(2,"0")}`,v=m.get(b)||{week:b,filament:0,cost:0,prints:0};v.filament+=g.filament_used_grams||0,v.cost+=g.cost||0,v.prints+=1,m.set(b,v)}),Array.from(m.values()).sort((g,x)=>g.week.localeCompare(x.week)).map(g=>({date:g.week,dateLabel:`Week of ${new Date(g.week).toLocaleDateString("en-US",{month:"short",day:"numeric"})}`,...g}))},[i,a,n]),l=w.useMemo(()=>{const m=new Map;return i.forEach(g=>{const y=(g.filament_type||"Unknown").split(", ");y.forEach(b=>{const v=(g.filament_used_grams||0)/y.length;m.set(b,(m.get(b)||0)+v)})}),Array.from(m.entries()).map(([g,x])=>({name:g,value:Math.round(x)})).sort((g,x)=>x.value-g.value)},[i]),c=w.useMemo(()=>{const m=new Date,g=[];for(let x=5;x>=0;x--){const y=new Date(m.getFullYear(),m.getMonth()-x,1),b=new Date(m.getFullYear(),m.getMonth()-x+1,0),v=y.toLocaleDateString("en-US",{month:"short",year:"2-digit"}),M=t.filter(S=>{const A=mi(S.completed_at||S.created_at)||new Date(0);return A>=y&&A<=b});g.push({month:v,filament:Math.round(M.reduce((S,A)=>S+(A.filament_used_grams||0),0)),cost:M.reduce((S,A)=>S+(A.cost||0),0),prints:M.length})}return g},[t]),u=n==="7d"||n==="30d"?a:o,d=i.reduce((m,g)=>m+(g.filament_used_grams||0),0),f=i.reduce((m,g)=>m+(g.cost||0),0);return s.jsxs("div",{className:"space-y-6",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("h3",{className:"text-lg font-semibold text-white",children:"Filament Usage Trends"}),s.jsx("div",{className:"flex gap-1 bg-bambu-dark rounded-lg p-1",children:["7d","30d","90d","365d","all"].map(m=>s.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))})]}),s.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[s.jsxs("div",{className:"bg-bambu-dark rounded-lg p-4",children:[s.jsx("p",{className:"text-sm text-bambu-gray",children:"Period Filament"}),s.jsxs("p",{className:"text-2xl font-bold text-white",children:[(d/1e3).toFixed(2),"kg"]}),s.jsxs("p",{className:"text-xs text-bambu-gray",children:[d.toFixed(0),"g total"]})]}),s.jsxs("div",{className:"bg-bambu-dark rounded-lg p-4",children:[s.jsx("p",{className:"text-sm text-bambu-gray",children:"Period Cost"}),s.jsxs("p",{className:"text-2xl font-bold text-white",children:[e,f.toFixed(2)]}),s.jsxs("p",{className:"text-xs text-bambu-gray",children:[i.length," prints"]})]}),s.jsxs("div",{className:"bg-bambu-dark rounded-lg p-4",children:[s.jsx("p",{className:"text-sm text-bambu-gray",children:"Avg per Print"}),s.jsxs("p",{className:"text-2xl font-bold text-white",children:[i.length>0?(d/i.length).toFixed(0):0,"g"]}),s.jsxs("p",{className:"text-xs text-bambu-gray",children:[e,i.length>0?(f/i.length).toFixed(2):"0.00"," avg"]})]})]}),u.length>0?s.jsxs("div",{className:"bg-bambu-dark rounded-lg p-4",children:[s.jsx("h4",{className:"text-sm font-medium text-bambu-gray mb-4",children:"Usage Over Time"}),s.jsx(F1,{width:"100%",height:250,children:s.jsxs(bke,{data:u,children:[s.jsx("defs",{children:s.jsxs("linearGradient",{id:"colorFilament",x1:"0",y1:"0",x2:"0",y2:"1",children:[s.jsx("stop",{offset:"5%",stopColor:"#00ae42",stopOpacity:.3}),s.jsx("stop",{offset:"95%",stopColor:"#00ae42",stopOpacity:0})]})}),s.jsx(lS,{strokeDasharray:"3 3",stroke:"#3d3d3d"}),s.jsx(uS,{dataKey:"dateLabel",stroke:"#9ca3af",tick:{fontSize:12},interval:"preserveStartEnd"}),s.jsx(dS,{stroke:"#9ca3af",tick:{fontSize:12},tickFormatter:m=>`${m}g`}),s.jsx(z1,{contentStyle:{backgroundColor:"#2d2d2d",border:"1px solid #3d3d3d",borderRadius:"8px"},labelStyle:{color:"#fff"},formatter:m=>[`${m.toFixed(0)}g`,"Filament"]}),s.jsx(cZ,{type:"monotone",dataKey:"filament",stroke:"#00ae42",strokeWidth:2,fillOpacity:1,fill:"url(#colorFilament)"})]})})]}):s.jsx("div",{className:"bg-bambu-dark rounded-lg p-8 text-center text-bambu-gray",children:"No data for selected time range"}),s.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[s.jsxs("div",{className:"bg-bambu-dark rounded-lg p-4",children:[s.jsx("h4",{className:"text-sm font-medium text-bambu-gray mb-4",children:"By Filament Type"}),l.length>0?s.jsxs("div",{className:"flex items-center gap-4",children:[s.jsx(F1,{width:160,height:160,children:s.jsxs(gke,{children:[s.jsx(RQ,{data:l,cx:"50%",cy:"50%",innerRadius:40,outerRadius:70,paddingAngle:2,dataKey:"value",children:l.map((m,g)=>s.jsx(wy,{fill:A1[g%A1.length]},`cell-${g}`))}),s.jsx(z1,{contentStyle:{backgroundColor:"#2d2d2d",border:"1px solid #3d3d3d",borderRadius:"8px"},formatter:m=>[`${m}g`,"Usage"]})]})}),s.jsx("div",{className:"flex-1 space-y-2 overflow-hidden",children:l.map((m,g)=>{const x=l.reduce((b,v)=>b+v.value,0),y=x>0?(m.value/x*100).toFixed(0):0;return s.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[s.jsx("div",{className:"w-3 h-3 rounded-sm flex-shrink-0",style:{backgroundColor:A1[g%A1.length]}}),s.jsx("span",{className:"text-white truncate flex-1",children:m.name}),s.jsxs("span",{className:"text-bambu-gray flex-shrink-0",children:[y,"%"]})]},m.name)})})]}):s.jsx("div",{className:"h-[160px] flex items-center justify-center text-bambu-gray",children:"No filament data"})]}),s.jsxs("div",{className:"bg-bambu-dark rounded-lg p-4",children:[s.jsx("h4",{className:"text-sm font-medium text-bambu-gray mb-4",children:"Monthly Comparison"}),s.jsx(F1,{width:"100%",height:200,children:s.jsxs(ike,{data:c,children:[s.jsx(lS,{strokeDasharray:"3 3",stroke:"#3d3d3d"}),s.jsx(uS,{dataKey:"month",stroke:"#9ca3af",tick:{fontSize:12}}),s.jsx(dS,{stroke:"#9ca3af",tick:{fontSize:12},tickFormatter:m=>`${m}g`}),s.jsx(z1,{contentStyle:{backgroundColor:"#2d2d2d",border:"1px solid #3d3d3d",borderRadius:"8px"},formatter:(m,g)=>[g==="filament"?`${m}g`:g==="cost"?`${e}${m.toFixed(2)}`:m,g==="filament"?"Filament":g==="cost"?"Cost":"Prints"]}),s.jsx(OD,{}),s.jsx(UQ,{dataKey:"filament",name:"Filament (g)",fill:"#00ae42",radius:[4,4,0,0]})]})})]})]})]})}function wqe({id:t,title:e,component:n,isHidden:r,size:i,onToggleVisibility:a,onToggleSize:o}){const{attributes:l,listeners:c,setNodeRef:u,transform:d,transition:f,isDragging:m}=lre({id:t}),g={transform:Eg.Transform.toString(d),transition:f,opacity:m?.5:1};return r?null:s.jsxs("div",{ref:u,style:{...g,gridColumn:`span ${i}`},className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary overflow-hidden ${m?"ring-2 ring-bambu-green shadow-lg":""}`,children:[s.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-bambu-dark-tertiary bg-bambu-dark/30",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.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:s.jsx(Qp,{className:"w-6 h-6 md:w-4 md:h-4 text-bambu-gray"})}),s.jsx("h3",{className:"text-sm font-medium text-white",children:e})]}),s.jsxs("div",{className:"flex items-center gap-1",children:[s.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?s.jsx(YW,{className:"w-4 h-4 text-bambu-gray hover:text-white"}):s.jsx(XW,{className:"w-4 h-4 text-bambu-gray hover:text-white"})}),s.jsx("button",{onClick:a,className:"p-1 hover:bg-bambu-dark-tertiary rounded transition-colors",title:"Hide widget",children:s.jsx(T2,{className:"w-4 h-4 text-bambu-gray hover:text-white"})})]})]}),s.jsx("div",{className:"p-4",children:typeof n=="function"?n(i):n})]})}function Sqe({widgets:t,storageKey:e,columns:n=4,hideControls:r=!1,onResetLayout:i,renderControls:a}){const o=()=>{const A={};return t.forEach(E=>{A[E.id]=E.defaultSize||4}),A},[l,c]=w.useState(()=>{const A=localStorage.getItem(e);if(A)try{const E=JSON.parse(A);return E.sizes||(E.sizes=o()),E}catch{}return{order:t.map(E=>E.id),hidden:t.filter(E=>E.defaultVisible===!1).map(E=>E.id),sizes:o()}}),[u,d]=w.useState(!1);w.useEffect(()=>{const A=()=>d(E=>!E);return window.addEventListener("toggle-hidden-panel",A),()=>window.removeEventListener("toggle-hidden-panel",A)},[]),w.useEffect(()=>{localStorage.setItem(e,JSON.stringify(l))},[l,e]),w.useEffect(()=>{const E=t.map(k=>k.id).filter(k=>!l.order.includes(k));E.length>0&&c(k=>({...k,order:[...k.order,...E]}))},[t,l.order]);const f=zne(y2(lN,{activationConstraint:{distance:8}}),y2(oN,{coordinateGetter:cre})),m=A=>{const{active:E,over:k}=A;k&&E.id!==k.id&&c(C=>{const R=C.order.indexOf(E.id),T=C.order.indexOf(k.id);return{...C,order:dN(C.order,R,T)}})},g=A=>{c(E=>({...E,hidden:E.hidden.includes(A)?E.hidden.filter(k=>k!==A):[...E.hidden,A]}))},x=A=>{c(E=>{const k=E.sizes[A]||4,C=k===1?2:k===2?4:1;return{...E,sizes:{...E.sizes,[A]:C}}})},y=()=>{const A={order:t.map(E=>E.id),hidden:t.filter(E=>E.defaultVisible===!1).map(E=>E.id),sizes:o()};c(A),i?.()},b=l.order.map(A=>t.find(E=>E.id===A)).filter(Boolean),v=b.filter(A=>!l.hidden.includes(A.id)),M=b.filter(A=>l.hidden.includes(A.id)),S=a?.({hiddenCount:M.length,showHiddenPanel:u,setShowHiddenPanel:d,resetLayout:y});return s.jsxs("div",{className:"space-y-4",children:[S,!r&&!a&&s.jsxs("div",{className:"flex items-center justify-end gap-2",children:[s.jsxs(Se,{variant:"secondary",size:"sm",onClick:y,children:[s.jsx(Vf,{className:"w-4 h-4"}),"Reset Layout"]}),M.length>0&&s.jsxs(Se,{variant:"secondary",size:"sm",onClick:()=>d(!u),children:[s.jsx(_f,{className:"w-4 h-4"}),M.length," Hidden"]})]}),u&&M.length>0&&s.jsxs("div",{className:"p-4 bg-bambu-dark rounded-xl border border-bambu-dark-tertiary",children:[s.jsx("p",{className:"text-sm text-bambu-gray mb-3",children:"Hidden widgets (click to show):"}),s.jsx("div",{className:"flex flex-wrap gap-2",children:M.map(A=>s.jsxs("button",{onClick:()=>g(A.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:[s.jsx(_f,{className:"w-3 h-3"}),A.title]},A.id))})]}),s.jsx(rre,{sensors:f,collisionDetection:Vne,onDragEnd:m,children:s.jsx(sre,{items:v.map(A=>A.id),strategy:PL,children:s.jsx("div",{className:"grid gap-6",style:{gridTemplateColumns:`repeat(${n}, minmax(0, 1fr))`},children:v.map(A=>s.jsx(wqe,{id:A.id,title:A.title,component:A.component,isHidden:l.hidden.includes(A.id),size:l.sizes[A.id]||2,onToggleVisibility:()=>g(A.id),onToggleSize:()=>x(A.id)},A.id))})})}),v.length===0&&s.jsxs("div",{className:"text-center py-12 text-bambu-gray",children:[s.jsx("p",{children:"All widgets are hidden."}),s.jsx(Se,{className:"mt-4",onClick:y,children:"Reset Layout"})]})]})}function Mqe({stats:t,currency:e}){return s.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-3 gap-4",children:[s.jsxs("div",{className:"flex items-start gap-3",children:[s.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark text-bambu-green",children:s.jsx(Dl,{className:"w-5 h-5"})}),s.jsxs("div",{children:[s.jsx("p",{className:"text-xs text-bambu-gray",children:"Total Prints"}),s.jsx("p",{className:"text-xl font-bold text-white",children:t?.total_prints||0})]})]}),s.jsxs("div",{className:"flex items-start gap-3",children:[s.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark text-blue-400",children:s.jsx(Gn,{className:"w-5 h-5"})}),s.jsxs("div",{children:[s.jsx("p",{className:"text-xs text-bambu-gray",children:"Print Time"}),s.jsxs("p",{className:"text-xl font-bold text-white",children:[t?.total_print_time_hours.toFixed(1)||0,"h"]})]})]}),s.jsxs("div",{className:"flex items-start gap-3",children:[s.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark text-orange-400",children:s.jsx(Dl,{className:"w-5 h-5"})}),s.jsxs("div",{children:[s.jsx("p",{className:"text-xs text-bambu-gray",children:"Filament Used"}),s.jsxs("p",{className:"text-xl font-bold text-white",children:[((t?.total_filament_grams||0)/1e3).toFixed(2),"kg"]})]})]}),s.jsxs("div",{className:"flex items-start gap-3",children:[s.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark text-green-400",children:s.jsx(Uj,{className:"w-5 h-5"})}),s.jsxs("div",{children:[s.jsx("p",{className:"text-xs text-bambu-gray",children:"Filament Cost"}),s.jsxs("p",{className:"text-xl font-bold text-white",children:[e," ",t?.total_cost.toFixed(2)||"0.00"]})]})]}),s.jsxs("div",{className:"flex items-start gap-3",children:[s.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark text-yellow-400",children:s.jsx(Mf,{className:"w-5 h-5"})}),s.jsxs("div",{children:[s.jsx("p",{className:"text-xs text-bambu-gray",children:"Energy Used"}),s.jsxs("p",{className:"text-xl font-bold text-white",children:[t?.total_energy_kwh.toFixed(2)||"0.00"," kWh"]})]})]}),s.jsxs("div",{className:"flex items-start gap-3",children:[s.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark text-yellow-500",children:s.jsx(Uj,{className:"w-5 h-5"})}),s.jsxs("div",{children:[s.jsx("p",{className:"text-xs text-bambu-gray",children:"Energy Cost"}),s.jsxs("p",{className:"text-xl font-bold text-white",children:[e," ",t?.total_energy_cost.toFixed(2)||"0.00"]})]})]})]})}function Nqe({stats:t,printerMap:e,size:n=1}){const r=t?.total_prints?Math.round(t.successful_prints/t.total_prints*100):0,i=n===1?112:n===2?128:144,a=i/2-8,o=a*2*Math.PI;return s.jsxs("div",{className:"flex items-center gap-6",children:[s.jsxs("div",{className:"relative flex-shrink-0",style:{width:i,height:i},children:[s.jsxs("svg",{className:"w-full h-full -rotate-90",children:[s.jsx("circle",{cx:i/2,cy:i/2,r:a,fill:"none",stroke:"#3d3d3d",strokeWidth:"10"}),s.jsx("circle",{cx:i/2,cy:i/2,r:a,fill:"none",stroke:"#00ae42",strokeWidth:"10",strokeLinecap:"round",strokeDasharray:`${r/100*o} ${o}`})]}),s.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:s.jsxs("span",{className:`font-bold text-white ${n>=2?"text-2xl":"text-xl"}`,children:[r,"%"]})})]}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Dn,{className:"w-4 h-4 text-bambu-green flex-shrink-0"}),s.jsx("span",{className:"text-sm text-bambu-gray",children:"Successful:"}),s.jsx("span",{className:"text-sm text-white font-medium",children:t?.successful_prints||0})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(qi,{className:"w-4 h-4 text-red-400 flex-shrink-0"}),s.jsx("span",{className:"text-sm text-bambu-gray",children:"Failed:"}),s.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&&s.jsxs("div",{className:"mt-4 pt-4 border-t border-bambu-dark-tertiary",children:[s.jsx("p",{className:"text-xs text-bambu-gray font-medium mb-2",children:"Prints by Printer"}),s.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(([l,c])=>s.jsxs("div",{className:"flex items-center gap-3 text-sm",children:[s.jsx("span",{className:"text-bambu-gray truncate max-w-[120px]",children:e.get(l)||`Printer ${l}`}),s.jsx("span",{className:"text-white font-medium",children:c})]},l))})]})]})]})}function Eqe({stats:t,printerMap:e,size:n=1}){const r=t?.average_time_accuracy;if(r==null)return s.jsx("div",{className:"flex items-center justify-center h-full",children:s.jsx("p",{className:"text-bambu-gray text-center py-4",children:"No time accuracy data yet"})});const a=(Math.min(150,Math.max(50,r))-50)/100*100,l=(x=>x>=95&&x<=105?"#00ae42":x>105?"#3b82f6":"#f97316")(r),c=r-100,u=n===1?112:n===2?128:144,d=u/2-8,f=d*2*Math.PI,m=n===1?3:n===2?6:999,g=t?.time_accuracy_by_printer?Object.entries(t.time_accuracy_by_printer).slice(0,m):[];return s.jsxs("div",{className:"flex items-center gap-6",children:[s.jsxs("div",{className:"relative flex-shrink-0",style:{width:u,height:u},children:[s.jsxs("svg",{className:"w-full h-full -rotate-90",children:[s.jsx("circle",{cx:u/2,cy:u/2,r:d,fill:"none",stroke:"#3d3d3d",strokeWidth:"10"}),s.jsx("circle",{cx:u/2,cy:u/2,r:d,fill:"none",stroke:l,strokeWidth:"10",strokeLinecap:"round",strokeDasharray:`${a/100*f} ${f}`})]}),s.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center",children:[s.jsxs("span",{className:`font-bold text-white ${n>=2?"text-2xl":"text-xl"}`,children:[r.toFixed(0),"%"]}),s.jsxs("span",{className:`text-xs ${c>=0?"text-blue-400":"text-orange-400"}`,children:[c>=0?"+":"",c.toFixed(0),"%"]})]})]}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsxs("div",{className:"flex items-center gap-2 text-xs text-bambu-gray",children:[s.jsx(nq,{className:"w-3 h-3 flex-shrink-0"}),s.jsx("span",{children:"100% = perfect estimate"})]}),g.length>0&&s.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:g.map(([x,y])=>s.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[s.jsx("span",{className:"text-bambu-gray truncate max-w-[100px]",children:e.get(x)||`Printer ${x}`}),s.jsxs("span",{className:`font-medium ${y>=95&&y<=105?"text-bambu-green":y>105?"text-blue-400":"text-orange-400"}`,children:[y.toFixed(0),"%"]})]},x))})]})]})}function Aqe({stats:t,size:e=1}){if(!t?.prints_by_filament_type||Object.keys(t.prints_by_filament_type).length===0)return s.jsx("p",{className:"text-bambu-gray text-center py-4",children:"No filament data available"});const n=Object.entries(t.prints_by_filament_type).sort(([,o],[,l])=>l-o),r=e===1?5:e===2?8:999,i=n.slice(0,r),a=n.length>r;return e===4&&i.length>4?s.jsx("div",{className:"grid grid-cols-2 lg:grid-cols-3 gap-4",children:i.map(([o,l])=>{const c=Math.round(l/(t.total_prints||1)*100);return s.jsxs("div",{children:[s.jsxs("div",{className:"flex justify-between text-sm mb-1",children:[s.jsx("span",{className:"text-white truncate max-w-[120px]",children:o}),s.jsx("span",{className:"text-bambu-gray",children:l})]}),s.jsx("div",{className:"h-2 bg-bambu-dark rounded-full",children:s.jsx("div",{className:"h-full bg-bambu-green rounded-full transition-all",style:{width:`${c}%`}})})]},o)})}):s.jsxs("div",{className:"space-y-3",children:[i.map(([o,l])=>{const c=Math.round(l/(t.total_prints||1)*100);return s.jsxs("div",{children:[s.jsxs("div",{className:"flex justify-between text-sm mb-1",children:[s.jsx("span",{className:"text-white",children:o}),s.jsxs("span",{className:"text-bambu-gray",children:[l," prints"]})]}),s.jsx("div",{className:"h-2 bg-bambu-dark rounded-full",children:s.jsx("div",{className:"h-full bg-bambu-green rounded-full transition-all",style:{width:`${c}%`}})})]},o)}),a&&s.jsxs("p",{className:"text-xs text-bambu-gray text-center pt-1",children:["+",n.length-r," more types"]})]})}function Tqe({printDates:t,size:e=2}){const n=e===1?3:e===2?6:12;return s.jsx(yqe,{printDates:t,months:n})}function Cqe({stats:t,printerMap:e}){return!t?.prints_by_printer||Object.keys(t.prints_by_printer).length===0?s.jsx("p",{className:"text-bambu-gray text-center py-4",children:"No printer data available"}):s.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:Object.entries(t.prints_by_printer).map(([n,r])=>s.jsxs("div",{className:"flex items-center gap-3 p-3 bg-bambu-dark rounded-lg",children:[s.jsx("div",{className:"p-2 bg-bambu-dark-tertiary rounded-lg",children:s.jsx(Ir,{className:"w-4 h-4 text-bambu-green"})}),s.jsxs("div",{children:[s.jsx("p",{className:"text-white font-medium text-sm",children:e.get(n)||`Printer ${n}`}),s.jsxs("p",{className:"text-xs text-bambu-gray",children:[r," prints"]})]})]},n))})}function kqe({archives:t,currency:e}){return!t||t.length===0?s.jsx("p",{className:"text-bambu-gray text-center py-4",children:"No print data available"}):s.jsx(_qe,{archives:t,currency:e})}function jqe({size:t=1}){const{data:e,isLoading:n}=ct({queryKey:["failureAnalysis"],queryFn:()=>pe.getFailureAnalysis({days:30})});if(n)return s.jsx("div",{className:"flex justify-center py-4",children:s.jsx(mt,{className:"w-6 h-6 text-bambu-green animate-spin"})});if(!e||e.total_prints===0)return s.jsx("p",{className:"text-bambu-gray text-center py-4",children:"No print data in the last 30 days"});const r=t===1?5:t===2?8:999,i=Object.entries(e.failures_by_reason).sort(([,l],[,c])=>c-l),a=i.slice(0,r),o=i.length>r;return s.jsxs("div",{className:`${t>=2?"flex gap-8":"space-y-4"}`,children:[s.jsxs("div",{className:t>=2?"flex-shrink-0":"",children:[s.jsx("div",{className:"flex items-center gap-4",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Cn,{className:`w-5 h-5 ${e.failure_rate>20?"text-red-400":e.failure_rate>10?"text-yellow-400":"text-bambu-green"}`}),s.jsxs("span",{className:`font-bold text-white ${t>=2?"text-3xl":"text-2xl"}`,children:[e.failure_rate.toFixed(1),"%"]})]})}),s.jsxs("div",{className:"text-sm text-bambu-gray mt-1",children:[e.failed_prints," / ",e.total_prints," prints failed"]}),e.trend&&e.trend.length>=2&&s.jsx("div",{className:`${t>=2?"mt-4":"mt-2 pt-2 border-t border-bambu-dark-tertiary"}`,children:s.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[s.jsx(iq,{className:`w-4 h-4 ${e.trend[e.trend.length-1].failure_rate0&&s.jsxs("div",{className:`flex-1 ${t>=2?"border-l border-bambu-dark-tertiary pl-8":"pt-2"}`,children:[s.jsx("p",{className:"text-xs text-bambu-gray font-medium mb-2",children:t>=2?"Failure Reasons":"Top Failure Reasons"}),s.jsx("div",{className:`${t===4?"grid grid-cols-2 gap-x-6 gap-y-1":"space-y-1"}`,children:a.map(([l,c])=>s.jsxs("div",{className:"flex items-center justify-between text-sm",children:[s.jsx("span",{className:`text-white truncate ${t===4?"max-w-[200px]":"max-w-[160px]"}`,children:l||"Unknown"}),s.jsx("span",{className:"text-bambu-gray ml-2",children:c})]},l))}),o&&s.jsxs("p",{className:"text-xs text-bambu-gray mt-2",children:["+",i.length-r," more reasons"]})]})]})}function Pqe(){const{showToast:t}=$n(),[e,n]=w.useState(!1),[r,i]=w.useState(!1),[a,o]=w.useState(0),[l,c]=w.useState(0);w.useEffect(()=>{const S=()=>{try{const E=localStorage.getItem("bambusy-dashboard-layout");if(E){const k=JSON.parse(E);c(k.hidden?.length||0)}}catch{c(0)}};S(),window.addEventListener("storage",S);const A=setInterval(S,500);return()=>{window.removeEventListener("storage",S),clearInterval(A)}},[a]);const{data:u,isLoading:d}=ct({queryKey:["archiveStats"],queryFn:pe.getArchiveStats}),{data:f}=ct({queryKey:["printers"],queryFn:pe.getPrinters}),{data:m}=ct({queryKey:["archives"],queryFn:()=>pe.getArchives(void 0,void 0,1e3,0)}),{data:g}=ct({queryKey:["settings"],queryFn:pe.getSettings}),x=async S=>{i(!1),n(!0);try{const{blob:A,filename:E}=await pe.exportStats({format:S,days:90}),k=URL.createObjectURL(A),C=document.createElement("a");C.href=k,C.download=E,C.click(),URL.revokeObjectURL(k),t("Export downloaded")}catch{t("Export failed","error")}finally{n(!1)}},y=g?.currency||"$",b=new Map(f?.map(S=>[String(S.id),S.name])||[]),v=m?.map(S=>S.created_at)||[];if(d)return s.jsx("div",{className:"p-4 md:p-8",children:s.jsx("div",{className:"text-center py-12 text-bambu-gray",children:"Loading statistics..."})});const M=[{id:"quick-stats",title:"Quick Stats",component:s.jsx(Mqe,{stats:u,currency:y}),defaultSize:2},{id:"success-rate",title:"Success Rate",component:S=>s.jsx(Nqe,{stats:u,printerMap:b,size:S}),defaultSize:1},{id:"time-accuracy",title:"Time Accuracy",component:S=>s.jsx(Eqe,{stats:u,printerMap:b,size:S}),defaultSize:1},{id:"filament-types",title:"Filament Types",component:S=>s.jsx(Aqe,{stats:u,size:S}),defaultSize:1},{id:"failure-analysis",title:"Failure Analysis (30 days)",component:S=>s.jsx(jqe,{size:S}),defaultSize:1},{id:"print-activity",title:"Print Activity",component:S=>s.jsx(Tqe,{printDates:v,size:S}),defaultSize:2},{id:"prints-by-printer",title:"Prints by Printer",component:s.jsx(Cqe,{stats:u,printerMap:b}),defaultSize:2},{id:"filament-trends",title:"Filament Usage Trends",component:s.jsx(kqe,{archives:m||[],currency:y}),defaultSize:4}];return s.jsxs("div",{className:"p-4 md:p-8",children:[s.jsxs("div",{className:"flex items-center justify-between mb-6",children:[s.jsxs("div",{children:[s.jsx("h1",{className:"text-2xl font-bold text-white",children:"Dashboard"}),s.jsx("p",{className:"text-bambu-gray",children:"Drag widgets to rearrange. Click the eye icon to hide."})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[l>0&&s.jsxs(Se,{variant:"secondary",onClick:()=>{window.dispatchEvent(new CustomEvent("toggle-hidden-panel"))},children:[s.jsx(_f,{className:"w-4 h-4"}),l," Hidden"]}),s.jsxs(Se,{variant:"secondary",onClick:()=>{localStorage.removeItem("bambusy-dashboard-layout"),o(S=>S+1),t("Layout reset")},children:[s.jsx(Vf,{className:"w-4 h-4"}),"Reset Layout"]}),s.jsxs("div",{className:"relative",children:[s.jsxs(Se,{variant:"secondary",onClick:()=>i(!r),disabled:e,children:[e?s.jsx(mt,{className:"w-4 h-4 animate-spin"}):s.jsx(dw,{className:"w-4 h-4"}),"Export Stats"]}),r&&s.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:[s.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:()=>x("csv"),children:[s.jsx(za,{className:"w-4 h-4"}),"Export as CSV"]}),s.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:()=>x("xlsx"),children:[s.jsx(dw,{className:"w-4 h-4"}),"Export as Excel"]})]})]})]})]}),s.jsx(Sqe,{widgets:M,storageKey:"bambusy-dashboard-layout",hideControls:!0},a)]})}function Rqe({plug:t,onEdit:e}){const n=tn(),{showToast:r}=$n(),[i,a]=w.useState(!1),[o,l]=w.useState(!1),[c,u]=w.useState(!1),[d,f]=w.useState(!1),{data:m,isLoading:g}=ct({queryKey:["smart-plug-status",t.id],queryFn:()=>pe.getSmartPlugStatus(t.id),refetchInterval:3e4}),{data:x}=ct({queryKey:["printers"],queryFn:pe.getPrinters}),y=x?.find(R=>R.id===t.printer_id),b=ft({mutationFn:R=>pe.controlSmartPlug(t.id,R),onMutate:async R=>{await n.cancelQueries({queryKey:["smart-plug-status",t.id]});const T=n.getQueryData(["smart-plug-status",t.id]),P=R==="on"?"ON":R==="off"||m?.state==="ON"?"OFF":"ON";return n.setQueryData(["smart-plug-status",t.id],F=>({...F,state:P})),{previousStatus:T}},onError:(R,T,P)=>{P?.previousStatus&&n.setQueryData(["smart-plug-status",t.id],P.previousStatus),r(`Failed to turn ${T} "${t.name}"`,"error")},onSettled:()=>{setTimeout(()=>{n.invalidateQueries({queryKey:["smart-plug-status",t.id]}),n.invalidateQueries({queryKey:["smart-plugs"]})},1e3)}}),v=ft({mutationFn:R=>pe.updateSmartPlug(t.id,R),onSuccess:()=>{n.invalidateQueries({queryKey:["smart-plugs"]}),t.printer_id&&n.invalidateQueries({queryKey:["smartPlugByPrinter",t.printer_id]})}}),M=ft({mutationFn:()=>pe.deleteSmartPlug(t.id),onSuccess:()=>{n.invalidateQueries({queryKey:["smart-plugs"]})}}),S=m?.state==="ON",A=m?.reachable??!1,E=b.isPending,C=(()=>{if(t.plug_type!=="tasmota"||!t.ip_address)return null;const R=t.ip_address;return t.username&&t.password?`http://${encodeURIComponent(t.username)}:${encodeURIComponent(t.password)}@${R}/`:`http://${R}/`})();return s.jsxs(s.Fragment,{children:[s.jsx(Mt,{className:"relative",children:s.jsxs(Et,{className:"p-4",children:[s.jsxs("div",{className:"flex items-start justify-between mb-3",children:[s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("div",{className:`p-2 rounded-lg ${A?S?"bg-bambu-green/20":"bg-bambu-dark":"bg-red-500/20"}`,children:t.plug_type==="homeassistant"?s.jsx(R2,{className:`w-5 h-5 ${A?S?"text-bambu-green":"text-bambu-gray":"text-red-400"}`}):s.jsx(Us,{className:`w-5 h-5 ${A?S?"text-bambu-green":"text-bambu-gray":"text-red-400"}`})}),s.jsxs("div",{children:[s.jsx("h3",{className:"font-medium text-white",children:t.name}),s.jsx("p",{className:"text-sm text-bambu-gray",children:t.plug_type==="homeassistant"?t.ha_entity_id:t.ip_address})]})]}),s.jsxs("div",{className:"flex flex-col items-end gap-1",children:[g?s.jsx(mt,{className:"w-4 h-4 text-bambu-gray animate-spin"}):A?s.jsxs("div",{className:"flex items-center gap-1 text-sm",children:[s.jsx(Dp,{className:"w-4 h-4 text-bambu-green"}),s.jsx("span",{className:S?"text-bambu-green":"text-bambu-gray",children:m?.state||"Unknown"})]}):s.jsxs("div",{className:"flex items-center gap-1 text-sm text-red-400",children:[s.jsx(Pg,{className:"w-4 h-4"}),s.jsx("span",{children:"Offline"})]}),C&&s.jsxs("a",{href:C,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:[s.jsx(Lr,{className:"w-3 h-3"}),"Admin"]})]})]}),y&&s.jsxs("div",{className:"mb-3 px-2 py-1.5 bg-bambu-dark rounded-lg",children:[s.jsx("span",{className:"text-xs text-bambu-gray",children:"Linked to: "}),s.jsx("span",{className:"text-sm text-white",children:y.name})]}),(t.power_alert_enabled||t.schedule_enabled)&&s.jsxs("div",{className:"flex flex-wrap gap-1.5 mb-3",children:[t.power_alert_enabled&&s.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:[s.jsx(tf,{className:"w-3 h-3"}),"Alerts"]}),t.schedule_enabled&&s.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:[s.jsx(Qr,{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}`]})]}),s.jsxs("div",{className:"flex gap-2 mb-3",children:[s.jsxs(Se,{size:"sm",variant:S?"primary":"secondary",disabled:!A||E,onClick:()=>l(!0),className:"flex-1",children:[E?s.jsx(mt,{className:"w-4 h-4 animate-spin"}):s.jsx(uu,{className:"w-4 h-4"}),"On"]}),s.jsxs(Se,{size:"sm",variant:S?"secondary":"primary",disabled:!A||E,onClick:()=>u(!0),className:"flex-1",children:[E?s.jsx(mt,{className:"w-4 h-4 animate-spin"}):s.jsx(I2,{className:"w-4 h-4"}),"Off"]})]}),s.jsxs("button",{onClick:()=>f(!d),className:"w-full flex items-center justify-between py-2 text-sm text-bambu-gray hover:text-white transition-colors",children:[s.jsxs("span",{className:"flex items-center gap-2",children:[s.jsx(Dd,{className:"w-4 h-4"}),"Automation Settings"]}),s.jsx("span",{children:d?"-":"+"})]}),d&&s.jsxs("div",{className:"pt-3 border-t border-bambu-dark-tertiary space-y-4",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(D2,{className:"w-4 h-4 text-bambu-green"}),s.jsxs("div",{children:[s.jsx("p",{className:"text-sm text-white",children:"Show in Switchbar"}),s.jsx("p",{className:"text-xs text-bambu-gray",children:"Quick access from sidebar"})]})]}),s.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[s.jsx("input",{type:"checkbox",checked:t.show_in_switchbar,onChange:R=>v.mutate({show_in_switchbar:R.target.checked}),className:"sr-only peer"}),s.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"})]})]}),s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{children:[s.jsx("p",{className:"text-sm text-white",children:"Enabled"}),s.jsx("p",{className:"text-xs text-bambu-gray",children:"Enable automation for this plug"})]}),s.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[s.jsx("input",{type:"checkbox",checked:t.enabled,onChange:R=>v.mutate({enabled:R.target.checked}),className:"sr-only peer"}),s.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"})]})]}),s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{children:[s.jsx("p",{className:"text-sm text-white",children:"Auto On"}),s.jsx("p",{className:"text-xs text-bambu-gray",children:"Turn on when print starts"})]}),s.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[s.jsx("input",{type:"checkbox",checked:t.auto_on,onChange:R=>v.mutate({auto_on:R.target.checked}),className:"sr-only peer"}),s.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"})]})]}),s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{children:[s.jsx("p",{className:"text-sm text-white",children:"Auto Off"}),s.jsx("p",{className:"text-xs text-bambu-gray",children:"Turn off when print completes (one-shot)"})]}),s.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[s.jsx("input",{type:"checkbox",checked:t.auto_off,onChange:R=>v.mutate({auto_off:R.target.checked}),className:"sr-only peer"}),s.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&&s.jsxs("div",{className:"space-y-3 pl-4 border-l-2 border-bambu-dark-tertiary",children:[s.jsxs("div",{children:[s.jsx("p",{className:"text-sm text-white mb-2",children:"Turn Off Delay Mode"}),s.jsxs("div",{className:"flex gap-2",children:[s.jsxs("button",{onClick:()=>v.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:[s.jsx(Gn,{className:"w-4 h-4"}),"Time"]}),s.jsxs("button",{onClick:()=>v.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:[s.jsx(U2,{className:"w-4 h-4"}),"Temp"]})]})]}),t.off_delay_mode==="time"?s.jsxs("div",{children:[s.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Delay (minutes)"}),s.jsx("input",{type:"number",min:"1",max:"60",value:t.off_delay_minutes,onChange:R=>v.mutate({off_delay_minutes:parseInt(R.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"})]}):s.jsxs("div",{children:[s.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Temperature threshold (C)"}),s.jsx("input",{type:"number",min:"30",max:"100",value:t.off_temp_threshold,onChange:R=>v.mutate({off_temp_threshold:parseInt(R.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"}),s.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Turns off when nozzle cools below this temperature"})]})]}),s.jsxs("div",{className:"flex gap-2 pt-2",children:[s.jsxs(Se,{size:"sm",variant:"secondary",onClick:()=>e(t),className:"flex-1",children:[s.jsx(L2,{className:"w-4 h-4"}),"Edit"]}),s.jsx(Se,{size:"sm",variant:"secondary",onClick:()=>a(!0),className:"text-red-400 hover:text-red-300",children:s.jsx(an,{className:"w-4 h-4"})})]})]})]})}),i&&s.jsx(Ln,{title:"Delete Smart Plug",message:`Are you sure you want to delete "${t.name}"? This cannot be undone.`,confirmText:"Delete",variant:"danger",onConfirm:()=>{M.mutate(),a(!1)},onCancel:()=>a(!1)}),o&&s.jsx(Ln,{title:"Turn On Smart Plug",message:`Are you sure you want to turn on "${t.name}"?`,confirmText:"Turn On",variant:"default",onConfirm:()=>{b.mutate("on"),l(!1)},onCancel:()=>l(!1)}),c&&s.jsx(Ln,{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:()=>{b.mutate("off"),u(!1)},onCancel:()=>u(!1)})]})}function Dqe({plug:t,onClose:e}){const n=tn(),r=!!t,[i,a]=w.useState(t?.plug_type||"tasmota"),[o,l]=w.useState(t?.name||""),[c,u]=w.useState(t?.ip_address||""),[d,f]=w.useState(t?.username||""),[m,g]=w.useState(t?.password||""),[x,y]=w.useState(t?.ha_entity_id||""),[b,v]=w.useState(t?.ha_power_entity||""),[M,S]=w.useState(t?.ha_energy_today_entity||""),[A,E]=w.useState(t?.ha_energy_total_entity||""),[k,C]=w.useState(""),[R,T]=w.useState(""),[P,F]=w.useState(!1),L=w.useRef(null),[X,D]=w.useState(""),[K,Y]=w.useState(!1),q=w.useRef(null),[Z,re]=w.useState(""),[oe,B]=w.useState(!1),G=w.useRef(null),[J,te]=w.useState(""),[ae,de]=w.useState(!1),fe=w.useRef(null),[Ae,ge]=w.useState(t?.printer_id||null),[Me,je]=w.useState(null),[ne,Ke]=w.useState(null),[$,z]=w.useState(t?.power_alert_enabled||!1),[W,U]=w.useState(t?.power_alert_high?.toString()||""),[V,Q]=w.useState(t?.power_alert_low?.toString()||""),[Ee,Ce]=w.useState(t?.schedule_enabled||!1),[Ne,H]=w.useState(t?.schedule_on_time||""),[O,ie]=w.useState(t?.schedule_off_time||""),[ye,_e]=w.useState(t?.show_in_switchbar||!1),[le,ke]=w.useState(!1),[Oe,Ze]=w.useState({scanned:0,total:0}),[ht,We]=w.useState([]),he=w.useRef(null),{data:rt}=ct({queryKey:["printers"],queryFn:pe.getPrinters}),{data:qe}=ct({queryKey:["smart-plugs"],queryFn:pe.getSmartPlugs}),{data:Je}=ct({queryKey:["settings"],queryFn:pe.getSettings}),ot=!!(Je?.ha_enabled&&Je?.ha_url&&Je?.ha_token);w.useEffect(()=>{const pt=setTimeout(()=>{T(k)},300);return()=>clearTimeout(pt)},[k]),w.useEffect(()=>{const pt=$t=>{L.current&&!L.current.contains($t.target)&&F(!1),q.current&&!q.current.contains($t.target)&&Y(!1),G.current&&!G.current.contains($t.target)&&B(!1),fe.current&&!fe.current.contains($t.target)&&de(!1)};return document.addEventListener("mousedown",pt),()=>document.removeEventListener("mousedown",pt)},[]);const{data:se,isLoading:$e,error:be}=ct({queryKey:["ha-entities",R],queryFn:()=>pe.getHAEntities(R||void 0),enabled:i==="homeassistant"&&ot,retry:!1,staleTime:0}),{data:Fe}=ct({queryKey:["ha-sensor-entities"],queryFn:pe.getHASensorEntities,enabled:i==="homeassistant"&&ot,retry:!1,staleTime:0});w.useEffect(()=>{const pt=$t=>{$t.key==="Escape"&&e()};return window.addEventListener("keydown",pt),()=>{window.removeEventListener("keydown",pt),he.current&&clearInterval(he.current)}},[e]);const De=async()=>{ke(!0),We([]),Ze({scanned:0,total:0}),Ke(null);try{await pe.startTasmotaScan();const pt=async()=>{try{const $t=await pe.getTasmotaScanStatus();Ze({scanned:$t.scanned,total:$t.total});const qt=await pe.getDiscoveredTasmotaDevices();We(qt),$t.running||(ke(!1),he.current&&(clearInterval(he.current),he.current=null))}catch($t){console.error("Polling error:",$t)}};await pt(),he.current=setInterval(pt,500)}catch(pt){ke(!1);const $t=pt instanceof Error?pt.message:typeof pt=="string"?pt:JSON.stringify(pt);Ke($t||"Failed to start scan")}},ve=async()=>{try{await pe.stopTasmotaScan()}catch{}ke(!1),he.current&&(clearInterval(he.current),he.current=null)},He=pt=>{u(pt.ip_address),l(pt.name),je(null)},dt=ft({mutationFn:()=>pe.testSmartPlugConnection(c,d||null,m||null),onSuccess:pt=>{je(pt),Ke(null),!o&&pt.device_name&&l(pt.device_name)},onError:pt=>{je(null),Ke(pt.message)}}),kt=ft({mutationFn:pt=>pe.createSmartPlug(pt),onSuccess:()=>{n.invalidateQueries({queryKey:["smart-plugs"]}),e()},onError:pt=>{Ke(pt.message)}}),jt=ft({mutationFn:pt=>pe.updateSmartPlug(t.id,pt),onSuccess:()=>{n.invalidateQueries({queryKey:["smart-plugs"]}),e()},onError:pt=>{Ke(pt.message)}}),Zt=rt?.filter(pt=>!qe?.some(qt=>qt.printer_id===pt.id&&qt.id!==t?.id)),Rt=pt=>{if(pt.preventDefault(),Ke(null),!o.trim()){Ke("Name is required");return}if(i==="tasmota"&&!c.trim()){Ke("IP address is required for Tasmota plugs");return}if(i==="homeassistant"&&!x){Ke("Entity is required for Home Assistant plugs");return}const $t={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"&&b||null,ha_energy_today_entity:i==="homeassistant"&&M||null,ha_energy_total_entity:i==="homeassistant"&&A||null,username:i==="tasmota"&&d.trim()||null,password:i==="tasmota"&&m.trim()||null,printer_id:Ae,power_alert_enabled:$,power_alert_high:W?parseFloat(W):null,power_alert_low:V?parseFloat(V):null,schedule_enabled:Ee,schedule_on_time:Ne||null,schedule_off_time:O||null,show_in_switchbar:ye};r?jt.mutate($t):kt.mutate($t)},nn=kt.isPending||jt.isPending;return s.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",onClick:e,children:s.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:pt=>pt.stopPropagation(),children:[s.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary flex-shrink-0",children:[s.jsx("h2",{className:"text-lg font-semibold text-white",children:r?"Edit Smart Plug":"Add Smart Plug"}),s.jsx("button",{onClick:e,className:"text-bambu-gray hover:text-white transition-colors",children:s.jsx(Ut,{className:"w-5 h-5"})})]}),s.jsxs("form",{onSubmit:Rt,className:"p-6 space-y-4 overflow-y-auto",children:[ne&&s.jsx("div",{className:"p-3 bg-red-500/20 border border-red-500/50 rounded-lg text-sm text-red-400",children:ne}),!r&&s.jsxs("div",{className:"flex gap-2 mb-2",children:[s.jsxs("button",{type:"button",onClick:()=>{a("tasmota"),je(null),Ke(null)},className:`flex-1 flex items-center justify-center gap-2 px-4 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:[s.jsx(Us,{className:"w-4 h-4"}),"Tasmota"]}),s.jsxs("button",{type:"button",onClick:()=>{a("homeassistant"),je(null),Ke(null)},className:`flex-1 flex items-center justify-center gap-2 px-4 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:[s.jsx(R2,{className:"w-4 h-4"}),"Home Assistant"]})]}),!r&&i==="tasmota"&&s.jsxs("div",{className:"space-y-3",children:[le?s.jsxs(Se,{type:"button",variant:"secondary",onClick:ve,className:"w-full",children:[s.jsx(Ut,{className:"w-4 h-4"}),"Stop Scanning"]}):s.jsxs(Se,{type:"button",variant:"primary",onClick:De,className:"w-full",children:[s.jsx(xa,{className:"w-4 h-4"}),"Discover Tasmota Devices"]}),le&&Oe.total>0&&s.jsxs("div",{className:"space-y-1",children:[s.jsxs("div",{className:"flex justify-between text-xs text-bambu-gray",children:[s.jsx("span",{children:"Scanning network..."}),s.jsxs("span",{children:[Oe.scanned," / ",Oe.total]})]}),s.jsx("div",{className:"w-full bg-bambu-dark-tertiary rounded-full h-2",children:s.jsx("div",{className:"bg-bambu-green h-2 rounded-full transition-all duration-300",style:{width:`${Oe.scanned/Oe.total*100}%`}})})]}),ht.length>0&&s.jsxs("div",{className:"space-y-2",children:[s.jsxs("p",{className:"text-xs text-bambu-gray",children:["Found ",ht.length," device(s) - click to select:"]}),s.jsx("div",{className:"max-h-40 overflow-y-auto space-y-1",children:ht.map(pt=>s.jsxs("button",{type:"button",onClick:()=>He(pt),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:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Us,{className:"w-4 h-4 text-bambu-green"}),s.jsxs("div",{children:[s.jsx("p",{className:"text-sm text-white",children:pt.name}),s.jsx("p",{className:"text-xs text-bambu-gray",children:pt.ip_address})]})]}),pt.state&&s.jsxs("span",{className:`flex items-center gap-1 text-xs ${pt.state==="ON"?"text-bambu-green":"text-bambu-gray"}`,children:[s.jsx(uu,{className:"w-3 h-3"}),pt.state]})]},pt.ip_address))})]}),!le&&ht.length===0&&Oe.total>0&&s.jsx("p",{className:"text-xs text-bambu-gray text-center py-2",children:"No Tasmota devices found on your network"})]}),i==="homeassistant"&&s.jsxs("div",{className:"space-y-3",children:[!ot&&s.jsxs("div",{className:"space-y-3",children:[s.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"," ",s.jsx("span",{className:"font-medium",children:"Settings → Network → Home Assistant"})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1 opacity-50",children:"Select Entity *"}),s.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:s.jsx("option",{children:"Choose an entity..."})})]})]}),ot&&s.jsxs(s.Fragment,{children:[$e&&s.jsxs("div",{className:"flex items-center justify-center py-4 text-bambu-gray",children:[s.jsx(mt,{className:"w-5 h-5 animate-spin mr-2"}),"Loading entities..."]}),be&&s.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: ",be.message]}),(()=>{const pt=qe?.filter(wt=>wt.ha_entity_id&&wt.id!==t?.id).map(wt=>wt.ha_entity_id)||[],$t=(se||[]).filter(wt=>!pt.includes(wt.entity_id)),qt=se?.find(wt=>wt.entity_id===x);return s.jsxs("div",{ref:L,className:"relative",children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Select Entity *"}),s.jsxs("div",{className:"relative",children:[s.jsx(xa,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"}),s.jsx("input",{type:"text",value:P?k:qt?`${qt.friendly_name} (${qt.entity_id})`:"",onChange:wt=>{C(wt.target.value),P||F(!0)},onFocus:()=>{F(!0),C("")},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&&!P&&s.jsx("button",{type:"button",onClick:()=>{y(""),C("")},className:"absolute right-2 top-1/2 -translate-y-1/2 p-1 hover:bg-bambu-dark-tertiary rounded",children:s.jsx(Ut,{className:"w-4 h-4 text-bambu-gray hover:text-white"})}),$e&&s.jsx(mt,{className:"absolute right-2 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray animate-spin"})]}),P&&s.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:[$e&&s.jsxs("div",{className:"px-3 py-2 text-sm text-bambu-gray flex items-center gap-2",children:[s.jsx(mt,{className:"w-4 h-4 animate-spin"}),"Loading..."]}),!$e&&$t.length===0&&s.jsx("div",{className:"px-3 py-2 text-sm text-bambu-gray",children:R?`No entities found matching "${R}"`:"No entities available"}),!$e&&$t.map(wt=>s.jsxs("button",{type:"button",onClick:()=>{y(wt.entity_id),F(!1),C(""),o||l(wt.friendly_name)},className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary transition-colors ${wt.entity_id===x?"bg-bambu-green/20 text-bambu-green":"text-white"}`,children:[s.jsx("div",{className:"font-medium",children:wt.friendly_name}),s.jsxs("div",{className:"text-xs text-bambu-gray flex items-center justify-between",children:[s.jsx("span",{children:wt.entity_id}),s.jsx("span",{className:wt.state==="on"?"text-bambu-green":"",children:wt.state})]})]},wt.entity_id))]}),s.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:R?`Searching all entities (${$t.length} found)`:`Showing switch, light, input_boolean (${$t.length} available)`})]})})(),x&&Fe&&Fe.length>0&&s.jsxs("div",{className:"border-t border-bambu-dark-tertiary pt-4 mt-4 space-y-3",children:[s.jsxs("div",{children:[s.jsx("p",{className:"text-white font-medium mb-1",children:"Energy Monitoring (Optional)"}),s.jsx("p",{className:"text-xs text-bambu-gray mb-3",children:"Search and select sensors that provide power/energy data."})]}),(()=>{const pt=Fe.filter(wt=>wt.unit_of_measurement==="W"||wt.unit_of_measurement==="kW"||wt.unit_of_measurement==="mW"),$t=X?pt.filter(wt=>wt.entity_id.toLowerCase().includes(X.toLowerCase())||wt.friendly_name.toLowerCase().includes(X.toLowerCase())):pt,qt=Fe.find(wt=>wt.entity_id===b);return s.jsxs("div",{ref:q,className:"relative",children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Power Sensor (W)"}),s.jsxs("div",{className:"relative",children:[s.jsx(xa,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"}),s.jsx("input",{type:"text",value:K?X:qt?`${qt.friendly_name} (${qt.state} ${qt.unit_of_measurement})`:"",onChange:wt=>{D(wt.target.value),K||Y(!0)},onFocus:()=>{Y(!0),D("")},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"}),b&&!K&&s.jsx("button",{type:"button",onClick:()=>{v(""),D("")},className:"absolute right-2 top-1/2 -translate-y-1/2 p-1 hover:bg-bambu-dark-tertiary rounded",children:s.jsx(Ut,{className:"w-4 h-4 text-bambu-gray hover:text-white"})})]}),K&&s.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:[s.jsx("button",{type:"button",onClick:()=>{v(""),Y(!1),D("")},className:"w-full px-3 py-2 text-left text-sm text-bambu-gray hover:bg-bambu-dark-tertiary",children:"None"}),$t.map(wt=>s.jsxs("button",{type:"button",onClick:()=>{v(wt.entity_id),Y(!1),D("")},className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary ${wt.entity_id===b?"bg-bambu-green/20 text-bambu-green":"text-white"}`,children:[s.jsx("div",{className:"font-medium",children:wt.friendly_name}),s.jsxs("div",{className:"text-xs text-bambu-gray",children:[wt.entity_id," • ",wt.state," ",wt.unit_of_measurement]})]},wt.entity_id)),$t.length===0&&s.jsx("div",{className:"px-3 py-2 text-sm text-bambu-gray",children:"No matching sensors"})]})]})})(),(()=>{const pt=Fe.filter(wt=>wt.unit_of_measurement==="kWh"||wt.unit_of_measurement==="Wh"||wt.unit_of_measurement==="MWh"),$t=Z?pt.filter(wt=>wt.entity_id.toLowerCase().includes(Z.toLowerCase())||wt.friendly_name.toLowerCase().includes(Z.toLowerCase())):pt,qt=Fe.find(wt=>wt.entity_id===M);return s.jsxs("div",{ref:G,className:"relative",children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Energy Today (kWh)"}),s.jsxs("div",{className:"relative",children:[s.jsx(xa,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"}),s.jsx("input",{type:"text",value:oe?Z:qt?`${qt.friendly_name} (${qt.state} ${qt.unit_of_measurement})`:"",onChange:wt=>{re(wt.target.value),oe||B(!0)},onFocus:()=>{B(!0),re("")},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"}),M&&!oe&&s.jsx("button",{type:"button",onClick:()=>{S(""),re("")},className:"absolute right-2 top-1/2 -translate-y-1/2 p-1 hover:bg-bambu-dark-tertiary rounded",children:s.jsx(Ut,{className:"w-4 h-4 text-bambu-gray hover:text-white"})})]}),oe&&s.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:[s.jsx("button",{type:"button",onClick:()=>{S(""),B(!1),re("")},className:"w-full px-3 py-2 text-left text-sm text-bambu-gray hover:bg-bambu-dark-tertiary",children:"None"}),$t.map(wt=>s.jsxs("button",{type:"button",onClick:()=>{S(wt.entity_id),B(!1),re("")},className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary ${wt.entity_id===M?"bg-bambu-green/20 text-bambu-green":"text-white"}`,children:[s.jsx("div",{className:"font-medium",children:wt.friendly_name}),s.jsxs("div",{className:"text-xs text-bambu-gray",children:[wt.entity_id," • ",wt.state," ",wt.unit_of_measurement]})]},wt.entity_id)),$t.length===0&&s.jsx("div",{className:"px-3 py-2 text-sm text-bambu-gray",children:"No matching sensors"})]})]})})(),(()=>{const pt=Fe.filter(wt=>wt.unit_of_measurement==="kWh"||wt.unit_of_measurement==="Wh"||wt.unit_of_measurement==="MWh"),$t=J?pt.filter(wt=>wt.entity_id.toLowerCase().includes(J.toLowerCase())||wt.friendly_name.toLowerCase().includes(J.toLowerCase())):pt,qt=Fe.find(wt=>wt.entity_id===A);return s.jsxs("div",{ref:fe,className:"relative",children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Total Energy (kWh)"}),s.jsxs("div",{className:"relative",children:[s.jsx(xa,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"}),s.jsx("input",{type:"text",value:ae?J:qt?`${qt.friendly_name} (${qt.state} ${qt.unit_of_measurement})`:"",onChange:wt=>{te(wt.target.value),ae||de(!0)},onFocus:()=>{de(!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"}),A&&!ae&&s.jsx("button",{type:"button",onClick:()=>{E(""),te("")},className:"absolute right-2 top-1/2 -translate-y-1/2 p-1 hover:bg-bambu-dark-tertiary rounded",children:s.jsx(Ut,{className:"w-4 h-4 text-bambu-gray hover:text-white"})})]}),ae&&s.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:[s.jsx("button",{type:"button",onClick:()=>{E(""),de(!1),te("")},className:"w-full px-3 py-2 text-left text-sm text-bambu-gray hover:bg-bambu-dark-tertiary",children:"None"}),$t.map(wt=>s.jsxs("button",{type:"button",onClick:()=>{E(wt.entity_id),de(!1),te("")},className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary ${wt.entity_id===A?"bg-bambu-green/20 text-bambu-green":"text-white"}`,children:[s.jsx("div",{className:"font-medium",children:wt.friendly_name}),s.jsxs("div",{className:"text-xs text-bambu-gray",children:[wt.entity_id," • ",wt.state," ",wt.unit_of_measurement]})]},wt.entity_id)),$t.length===0&&s.jsx("div",{className:"px-3 py-2 text-sm text-bambu-gray",children:"No matching sensors"})]})]})})()]})]})]}),i==="tasmota"&&s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"IP Address *"}),s.jsxs("div",{className:"flex gap-2",children:[s.jsx("input",{type:"text",value:c,onChange:pt=>{u(pt.target.value),je(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"}),s.jsxs(Se,{type:"button",variant:"secondary",onClick:()=>dt.mutate(),disabled:!c.trim()||dt.isPending,children:[dt.isPending?s.jsx(mt,{className:"w-4 h-4 animate-spin"}):s.jsx(Dp,{className:"w-4 h-4"}),"Test"]})]})]}),i==="tasmota"&&Me&&s.jsx("div",{className:`p-3 rounded-lg flex items-center gap-2 ${Me.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:Me.success?s.jsxs(s.Fragment,{children:[s.jsx(Dn,{className:"w-5 h-5"}),s.jsxs("div",{children:[s.jsx("p",{className:"font-medium",children:"Connected!"}),s.jsxs("p",{className:"text-sm opacity-80",children:[Me.device_name&&`Device: ${Me.device_name} - `,"State: ",Me.state]})]})]}):s.jsxs(s.Fragment,{children:[s.jsx(Pg,{className:"w-5 h-5"}),s.jsx("span",{children:"Connection failed"})]})}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Name *"}),s.jsx("input",{type:"text",value:o,onChange:pt=>l(pt.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"&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Username"}),s.jsx("input",{type:"text",value:d,onChange:pt=>f(pt.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"})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Password"}),s.jsx("input",{type:"password",value:m,onChange:pt=>g(pt.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"})]})]}),s.jsx("p",{className:"text-xs text-bambu-gray -mt-2",children:"Leave empty if your Tasmota device doesn't require authentication"})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Link to Printer"}),s.jsxs("select",{value:Ae??"",onChange:pt=>ge(pt.target.value?Number(pt.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:[s.jsx("option",{value:"",children:"No printer (manual control only)"}),Zt?.map(pt=>s.jsx("option",{value:pt.id,children:pt.name},pt.id))]}),s.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Linking enables automatic on/off when prints start/complete"})]}),s.jsxs("div",{className:"border-t border-bambu-dark-tertiary pt-4",children:[s.jsxs("div",{className:"flex items-center justify-between mb-3",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(tf,{className:"w-4 h-4 text-bambu-green"}),s.jsx("span",{className:"text-white font-medium",children:"Power Alerts"})]}),s.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[s.jsx("input",{type:"checkbox",checked:$,onChange:pt=>z(pt.target.checked),className:"sr-only peer"}),s.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"})]})]}),$&&s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Alert if above (W)"}),s.jsx("input",{type:"number",value:W,onChange:pt=>U(pt.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"})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Alert if below (W)"}),s.jsx("input",{type:"number",value:V,onChange:pt=>Q(pt.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"})]})]}),s.jsx("p",{className:"text-xs text-bambu-gray",children:"Get notified when power consumption crosses these thresholds. Leave empty to disable that direction."})]})]}),s.jsxs("div",{className:"border-t border-bambu-dark-tertiary pt-4",children:[s.jsxs("div",{className:"flex items-center justify-between mb-3",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Gn,{className:"w-4 h-4 text-bambu-green"}),s.jsx("span",{className:"text-white font-medium",children:"Daily Schedule"})]}),s.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[s.jsx("input",{type:"checkbox",checked:Ee,onChange:pt=>Ce(pt.target.checked),className:"sr-only peer"}),s.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"})]})]}),Ee&&s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Turn On at"}),s.jsx("input",{type:"time",value:Ne,onChange:pt=>H(pt.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"})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Turn Off at"}),s.jsx("input",{type:"time",value:O,onChange:pt=>ie(pt.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"})]})]}),s.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."})]})]}),s.jsx("div",{className:"border-t border-bambu-dark-tertiary pt-4",children:s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(D2,{className:"w-4 h-4 text-bambu-green"}),s.jsxs("div",{children:[s.jsx("span",{className:"text-white font-medium",children:"Show in Switchbar"}),s.jsx("p",{className:"text-xs text-bambu-gray",children:"Quick access from sidebar"})]})]}),s.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[s.jsx("input",{type:"checkbox",checked:ye,onChange:pt=>_e(pt.target.checked),className:"sr-only peer"}),s.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"})]})]})}),s.jsxs("div",{className:"flex gap-3 pt-2",children:[s.jsx(Se,{type:"button",variant:"secondary",onClick:e,className:"flex-1",children:"Cancel"}),s.jsxs(Se,{type:"submit",disabled:nn,className:"flex-1",children:[nn?s.jsx(mt,{className:"w-4 h-4 animate-spin"}):s.jsx(ds,{className:"w-4 h-4"}),r?"Save":"Add"]})]})]})]})})}function Vn({checked:t,onChange:e,disabled:n}){const r=i=>{i.preventDefault(),i.stopPropagation(),n||e(!t)};return s.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:s.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 Oqe={callmebot:"CallMeBot/WhatsApp",ntfy:"ntfy",pushover:"Pushover",telegram:"Telegram",email:"Email",discord:"Discord",webhook:"Webhook"};function Lqe({provider:t,onEdit:e}){const n=tn(),[r,i]=w.useState(!1),[a,o]=w.useState(!1),[l,c]=w.useState(null),{data:u}=ct({queryKey:["printers"],queryFn:pe.getPrinters}),d=u?.find(y=>y.id===t.printer_id),f=ft({mutationFn:y=>pe.updateNotificationProvider(t.id,y),onSuccess:()=>{n.invalidateQueries({queryKey:["notification-providers"]})}}),m=ft({mutationFn:()=>pe.deleteNotificationProvider(t.id),onSuccess:()=>{n.invalidateQueries({queryKey:["notification-providers"]})}}),g=ft({mutationFn:()=>pe.testNotificationProvider(t.id),onSuccess:y=>{c(y),n.invalidateQueries({queryKey:["notification-providers"]})},onError:y=>{c({success:!1,message:y.message})}}),x=y=>y||"";return s.jsxs(s.Fragment,{children:[s.jsx(Mt,{className:"relative",children:s.jsxs(Et,{className:"p-4",children:[s.jsxs("div",{className:"flex items-start justify-between mb-3",children:[s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("div",{className:`p-2 rounded-lg ${t.enabled?"bg-bambu-green/20":"bg-bambu-dark"}`,children:s.jsx(tf,{className:`w-5 h-5 ${t.enabled?"text-bambu-green":"text-bambu-gray"}`})}),s.jsxs("div",{children:[s.jsx("h3",{className:"font-medium text-white",children:t.name}),s.jsx("p",{className:"text-sm text-bambu-gray",children:Oqe[t.provider_type]||t.provider_type})]})]}),s.jsxs("div",{className:"flex items-center gap-3",children:[t.last_success&&s.jsxs("span",{className:"text-xs text-bambu-green hidden sm:inline",children:["Last: ",Jp(t.last_success)]}),t.last_error&&t.last_error_at&&(!t.last_success||(mi(t.last_error_at)?.getTime()||0)>(mi(t.last_success)?.getTime()||0))&&s.jsx("span",{className:"text-xs text-red-400",title:t.last_error,children:"Error"}),s.jsx(Vn,{checked:t.enabled,onChange:y=>f.mutate({enabled:y})})]})]}),d&&s.jsxs("div",{className:"mb-3 px-2 py-1.5 bg-bambu-dark rounded-lg",children:[s.jsx("span",{className:"text-xs text-bambu-gray",children:"Printer: "}),s.jsx("span",{className:"text-sm text-white",children:d.name})]}),!d&&!t.printer_id&&s.jsx("div",{className:"mb-3 px-2 py-1.5 bg-bambu-dark rounded-lg",children:s.jsx("span",{className:"text-xs text-bambu-gray",children:"All printers"})}),s.jsxs("div",{className:"mb-3 flex flex-wrap gap-1",children:[t.on_print_start&&s.jsx("span",{className:"px-2 py-0.5 bg-blue-500/20 text-blue-400 text-xs rounded",children:"Start"}),t.on_print_complete&&s.jsx("span",{className:"px-2 py-0.5 bg-bambu-green/20 text-bambu-green text-xs rounded",children:"Complete"}),t.on_print_failed&&s.jsx("span",{className:"px-2 py-0.5 bg-red-500/20 text-red-400 text-xs rounded",children:"Failed"}),t.on_print_stopped&&s.jsx("span",{className:"px-2 py-0.5 bg-orange-500/20 text-orange-400 text-xs rounded",children:"Stopped"}),t.on_print_progress&&s.jsx("span",{className:"px-2 py-0.5 bg-yellow-500/20 text-yellow-400 text-xs rounded",children:"Progress"}),t.on_printer_offline&&s.jsx("span",{className:"px-2 py-0.5 bg-gray-500/20 text-gray-400 text-xs rounded",children:"Offline"}),t.on_printer_error&&s.jsx("span",{className:"px-2 py-0.5 bg-rose-500/20 text-rose-400 text-xs rounded",children:"Error"}),t.on_filament_low&&s.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&&s.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&&s.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&&s.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&&s.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&&s.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&&s.jsxs("span",{className:"px-2 py-0.5 bg-indigo-500/20 text-indigo-400 text-xs rounded flex items-center gap-1",children:[s.jsx(fw,{className:"w-3 h-3"}),"Quiet"]}),t.daily_digest_enabled&&s.jsxs("span",{className:"px-2 py-0.5 bg-emerald-500/20 text-emerald-400 text-xs rounded flex items-center gap-1",children:[s.jsx(Qr,{className:"w-3 h-3"}),"Digest ",t.daily_digest_time]})]}),s.jsx("div",{className:"mb-3",children:s.jsxs(Se,{size:"sm",variant:"secondary",disabled:g.isPending,onClick:()=>{c(null),g.mutate()},className:"w-full",children:[g.isPending?s.jsx(mt,{className:"w-4 h-4 animate-spin"}):s.jsx(iD,{className:"w-4 h-4"}),"Send Test Notification"]})}),l&&s.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?s.jsx(Dn,{className:"w-4 h-4"}):s.jsx(qi,{className:"w-4 h-4"}),s.jsx("span",{children:l.message})]}),s.jsxs("button",{onClick:()=>o(!a),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:[s.jsxs("span",{className:"flex items-center gap-2",children:[s.jsx(Dd,{className:"w-4 h-4"}),"Event Settings"]}),a?s.jsx(Jc,{className:"w-4 h-4"}):s.jsx(Ji,{className:"w-4 h-4"})]}),a&&s.jsxs("div",{className:"pt-3 border-t border-bambu-dark-tertiary space-y-4",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{children:[s.jsx("p",{className:"text-sm text-white",children:"Enabled"}),s.jsx("p",{className:"text-xs text-bambu-gray",children:"Send notifications from this provider"})]}),s.jsx(Vn,{checked:t.enabled,onChange:y=>f.mutate({enabled:y})})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsx("p",{className:"text-xs text-bambu-gray uppercase tracking-wide",children:"Print Events"}),s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("p",{className:"text-sm text-white",children:"Print Started"}),s.jsx(Vn,{checked:t.on_print_start,onChange:y=>f.mutate({on_print_start:y})})]}),s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("p",{className:"text-sm text-white",children:"Print Completed"}),s.jsx(Vn,{checked:t.on_print_complete,onChange:y=>f.mutate({on_print_complete:y})})]}),s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("p",{className:"text-sm text-white",children:"Print Failed"}),s.jsx(Vn,{checked:t.on_print_failed,onChange:y=>f.mutate({on_print_failed:y})})]}),s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("p",{className:"text-sm text-white",children:"Print Stopped"}),s.jsx(Vn,{checked:t.on_print_stopped,onChange:y=>f.mutate({on_print_stopped:y})})]}),s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{children:[s.jsx("p",{className:"text-sm text-white",children:"Progress Milestones"}),s.jsx("p",{className:"text-xs text-bambu-gray",children:"Notify at 25%, 50%, 75%"})]}),s.jsx(Vn,{checked:t.on_print_progress,onChange:y=>f.mutate({on_print_progress:y})})]})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsx("p",{className:"text-xs text-bambu-gray uppercase tracking-wide",children:"Printer Status"}),s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("p",{className:"text-sm text-white",children:"Printer Offline"}),s.jsx(Vn,{checked:t.on_printer_offline,onChange:y=>f.mutate({on_printer_offline:y})})]}),s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("p",{className:"text-sm text-white",children:"Printer Error"}),s.jsx(Vn,{checked:t.on_printer_error,onChange:y=>f.mutate({on_printer_error:y})})]}),s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("p",{className:"text-sm text-white",children:"Low Filament"}),s.jsx(Vn,{checked:t.on_filament_low,onChange:y=>f.mutate({on_filament_low:y})})]}),s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{children:[s.jsx("p",{className:"text-sm text-white",children:"Maintenance Due"}),s.jsx("p",{className:"text-xs text-bambu-gray",children:"Notify when maintenance is needed"})]}),s.jsx(Vn,{checked:t.on_maintenance_due??!1,onChange:y=>f.mutate({on_maintenance_due:y})})]})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsx("p",{className:"text-xs text-bambu-gray uppercase tracking-wide",children:"AMS Alarms"}),s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{children:[s.jsx("p",{className:"text-sm text-white",children:"AMS Humidity High"}),s.jsx("p",{className:"text-xs text-bambu-gray",children:"Regular AMS humidity exceeds threshold"})]}),s.jsx(Vn,{checked:t.on_ams_humidity_high??!1,onChange:y=>f.mutate({on_ams_humidity_high:y})})]}),s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{children:[s.jsx("p",{className:"text-sm text-white",children:"AMS Temperature High"}),s.jsx("p",{className:"text-xs text-bambu-gray",children:"Regular AMS temperature exceeds threshold"})]}),s.jsx(Vn,{checked:t.on_ams_temperature_high??!1,onChange:y=>f.mutate({on_ams_temperature_high:y})})]})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsx("p",{className:"text-xs text-bambu-gray uppercase tracking-wide",children:"AMS-HT Alarms"}),s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{children:[s.jsx("p",{className:"text-sm text-white",children:"AMS-HT Humidity High"}),s.jsx("p",{className:"text-xs text-bambu-gray",children:"AMS-HT humidity exceeds threshold"})]}),s.jsx(Vn,{checked:t.on_ams_ht_humidity_high??!1,onChange:y=>f.mutate({on_ams_ht_humidity_high:y})})]}),s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{children:[s.jsx("p",{className:"text-sm text-white",children:"AMS-HT Temperature High"}),s.jsx("p",{className:"text-xs text-bambu-gray",children:"AMS-HT temperature exceeds threshold"})]}),s.jsx(Vn,{checked:t.on_ams_ht_temperature_high??!1,onChange:y=>f.mutate({on_ams_ht_temperature_high:y})})]})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(fw,{className:"w-4 h-4 text-purple-400"}),s.jsx("p",{className:"text-sm text-white",children:"Quiet Hours"})]}),s.jsx(Vn,{checked:t.quiet_hours_enabled,onChange:y=>f.mutate({quiet_hours_enabled:y})})]}),t.quiet_hours_enabled&&s.jsxs("div",{className:"pl-4 border-l-2 border-bambu-dark-tertiary space-y-2",children:[s.jsx("p",{className:"text-xs text-bambu-gray",children:"No notifications during these hours"}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Gn,{className:"w-4 h-4 text-bambu-gray"}),s.jsxs("span",{className:"text-sm text-white",children:[x(t.quiet_hours_start)||"22:00"," - ",x(t.quiet_hours_end)||"07:00"]})]}),s.jsx("p",{className:"text-xs text-bambu-gray",children:"Edit provider to change quiet hours"})]})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Qr,{className:"w-4 h-4 text-emerald-400"}),s.jsx("p",{className:"text-sm text-white",children:"Daily Digest"})]}),s.jsx(Vn,{checked:t.daily_digest_enabled,onChange:y=>f.mutate({daily_digest_enabled:y})})]}),t.daily_digest_enabled&&s.jsxs("div",{className:"pl-4 border-l-2 border-bambu-dark-tertiary space-y-2",children:[s.jsx("p",{className:"text-xs text-bambu-gray",children:"Batch notifications into a single daily summary"}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Gn,{className:"w-4 h-4 text-bambu-gray"}),s.jsxs("span",{className:"text-sm text-white",children:["Send at ",x(t.daily_digest_time)||"08:00"]})]}),s.jsx("p",{className:"text-xs text-bambu-gray",children:"Edit provider to change digest time"})]})]}),s.jsxs("div",{className:"flex gap-2 pt-2",children:[s.jsxs(Se,{size:"sm",variant:"secondary",onClick:()=>e(t),className:"flex-1",children:[s.jsx(L2,{className:"w-4 h-4"}),"Edit"]}),s.jsx(Se,{size:"sm",variant:"secondary",onClick:()=>i(!0),className:"text-red-400 hover:text-red-300",children:s.jsx(an,{className:"w-4 h-4"})})]})]})]})}),r&&s.jsx(Ln,{title:"Delete Notification Provider",message:`Are you sure you want to delete "${t.name}"? This cannot be undone.`,confirmText:"Delete",variant:"danger",onConfirm:()=>{m.mutate(),i(!1)},onCancel:()=>i(!1)})]})}const GG=[{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 Iqe({provider:t,onClose:e}){const n=tn(),r=!!t,[i,a]=w.useState(t?.name||""),[o,l]=w.useState(t?.provider_type||"email"),[c,u]=w.useState(t?.printer_id||null),[d,f]=w.useState(t?.quiet_hours_enabled||!1),[m,g]=w.useState(t?.quiet_hours_start||"22:00"),[x,y]=w.useState(t?.quiet_hours_end||"07:00"),[b,v]=w.useState(t?.daily_digest_enabled||!1),[M,S]=w.useState(t?.daily_digest_time||"08:00"),[A,E]=w.useState(t?.on_print_start??!1),[k,C]=w.useState(t?.on_print_complete??!0),[R,T]=w.useState(t?.on_print_failed??!0),[P,F]=w.useState(t?.on_print_stopped??!0),[L,X]=w.useState(t?.on_print_progress??!1),[D,K]=w.useState(t?.on_printer_offline??!1),[Y,q]=w.useState(t?.on_printer_error??!1),[Z,re]=w.useState(t?.on_filament_low??!1),[oe,B]=w.useState(t?.on_maintenance_due??!1),[G,J]=w.useState(t?.config?Object.fromEntries(Object.entries(t.config).map(([U,V])=>[U,String(V)])):{}),[te,ae]=w.useState(null),[de,fe]=w.useState(null),{data:Ae}=ct({queryKey:["printers"],queryFn:pe.getPrinters});w.useEffect(()=>{const U=V=>{V.key==="Escape"&&e()};return window.addEventListener("keydown",U),()=>window.removeEventListener("keydown",U)},[e]);const ge=ft({mutationFn:()=>pe.testNotificationConfig({provider_type:o,config:G}),onSuccess:U=>{ae(U),fe(null)},onError:U=>{ae({success:!1,message:U.message})}}),Me=ft({mutationFn:U=>pe.createNotificationProvider(U),onSuccess:()=>{n.invalidateQueries({queryKey:["notification-providers"]}),e()},onError:U=>{fe(U.message)}}),je=ft({mutationFn:U=>pe.updateNotificationProvider(t.id,U),onSuccess:()=>{n.invalidateQueries({queryKey:["notification-providers"]}),e()},onError:U=>{fe(U.message)}}),ne=U=>{if(U.preventDefault(),fe(null),!i.trim()){fe("Name is required");return}const V=z(o);for(const Ee of V)if(!G[Ee.key]?.trim()){fe(`${Ee.label} is required`);return}const Q={name:i.trim(),provider_type:o,config:G,printer_id:c,quiet_hours_enabled:d,quiet_hours_start:d?m:null,quiet_hours_end:d?x:null,daily_digest_enabled:b,daily_digest_time:b?M:null,on_print_start:A,on_print_complete:k,on_print_failed:R,on_print_stopped:P,on_print_progress:L,on_printer_offline:D,on_printer_error:Y,on_filament_low:Z,on_maintenance_due:oe};r?je.mutate(Q):Me.mutate(Q)},Ke=Me.isPending||je.isPending,$=U=>{switch(U){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:V=>V.payload_format!=="slack"},{key:"field_message",label:"Message Field Name",placeholder:"message",type:"text",required:!1,showIf:V=>V.payload_format!=="slack"}];default:return[]}},z=U=>$(U).filter(V=>V.required),W=$(o);return s.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4 overflow-y-auto",onClick:e,children:s.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:U=>U.stopPropagation(),children:[s.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary",children:[s.jsx("h2",{className:"text-lg font-semibold text-white",children:r?"Edit Notification Provider":"Add Notification Provider"}),s.jsx("button",{onClick:e,className:"text-bambu-gray hover:text-white transition-colors",children:s.jsx(Ut,{className:"w-5 h-5"})})]}),s.jsxs("form",{onSubmit:ne,className:"p-6 space-y-4",children:[de&&s.jsx("div",{className:"p-3 bg-red-500/20 border border-red-500/50 rounded-lg text-sm text-red-400",children:de}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Name *"}),s.jsx("input",{type:"text",value:i,onChange:U=>a(U.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"})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Provider Type *"}),s.jsx("select",{value:o,onChange:U=>{l(U.target.value),J({}),ae(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:GG.map(U=>s.jsx("option",{value:U.value,children:U.label},U.value))}),s.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:GG.find(U=>U.value===o)?.description})]}),s.jsxs("div",{className:"space-y-3",children:[s.jsx("p",{className:"text-sm text-bambu-gray",children:"Configuration"}),W.filter(U=>!("showIf"in U)||U.showIf?.(G)!==!1).map(U=>s.jsxs("div",{children:[s.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[U.label," ",U.required&&"*"]}),U.type==="select"&&"options"in U&&U.options?s.jsx("select",{value:G[U.key]||U.options[0]?.value||"",onChange:V=>{J({...G,[U.key]:V.target.value}),ae(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:U.options.map(V=>s.jsx("option",{value:V.value,children:V.label},V.value))}):s.jsx("input",{type:U.type,value:G[U.key]||"",onChange:V=>{J({...G,[U.key]:V.target.value}),ae(null)},placeholder:U.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"})]},U.key))]}),s.jsx("div",{className:"flex gap-2",children:s.jsxs(Se,{type:"button",variant:"secondary",onClick:()=>{ae(null),ge.mutate()},disabled:ge.isPending||!G[z(o)[0]?.key],className:"flex-1",children:[ge.isPending?s.jsx(mt,{className:"w-4 h-4 animate-spin"}):s.jsx(iD,{className:"w-4 h-4"}),"Test Configuration"]})}),te&&s.jsx("div",{className:`p-3 rounded-lg flex items-center gap-2 ${te.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:te.success?s.jsxs(s.Fragment,{children:[s.jsx(Dn,{className:"w-5 h-5"}),s.jsx("span",{children:te.message})]}):s.jsxs(s.Fragment,{children:[s.jsx(qi,{className:"w-5 h-5"}),s.jsx("span",{children:te.message})]})}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Printer Filter"}),s.jsxs("select",{value:c??"",onChange:U=>u(U.target.value?Number(U.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:[s.jsx("option",{value:"",children:"All printers"}),Ae?.map(U=>s.jsx("option",{value:U.id,children:U.name},U.id))]}),s.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Only send notifications for events from this printer"})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("label",{className:"text-sm text-white",children:"Quiet Hours (Do Not Disturb)"}),s.jsx(Vn,{checked:d,onChange:f})]}),d&&s.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[s.jsxs("div",{children:[s.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Start"}),s.jsx("input",{type:"time",value:m,onChange:U=>g(U.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"})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"End"}),s.jsx("input",{type:"time",value:x,onChange:U=>y(U.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"})]})]})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{children:[s.jsx("label",{className:"text-sm text-white",children:"Daily Digest"}),s.jsx("p",{className:"text-xs text-bambu-gray",children:"Batch notifications into a single daily summary"})]}),s.jsx(Vn,{checked:b,onChange:v})]}),b&&s.jsxs("div",{children:[s.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Send digest at"}),s.jsx("input",{type:"time",value:M,onChange:U=>S(U.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"}),s.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Events will be collected and sent as a single summary at this time"})]})]}),s.jsxs("div",{className:"space-y-3",children:[s.jsx("p",{className:"text-sm text-bambu-gray",children:"Notification Events"}),s.jsxs("div",{className:"space-y-2 p-3 bg-bambu-dark rounded-lg",children:[s.jsx("p",{className:"text-xs text-bambu-gray uppercase tracking-wide mb-2",children:"Print Events"}),s.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("span",{className:"text-sm text-white",children:"Start"}),s.jsx(Vn,{checked:A,onChange:E})]}),s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("span",{className:"text-sm text-white",children:"Complete"}),s.jsx(Vn,{checked:k,onChange:C})]}),s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("span",{className:"text-sm text-white",children:"Failed"}),s.jsx(Vn,{checked:R,onChange:T})]}),s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("span",{className:"text-sm text-white",children:"Stopped"}),s.jsx(Vn,{checked:P,onChange:F})]}),s.jsxs("div",{className:"flex items-center justify-between col-span-2",children:[s.jsxs("div",{children:[s.jsx("span",{className:"text-sm text-white",children:"Progress"}),s.jsx("span",{className:"text-xs text-bambu-gray ml-1",children:"(25%, 50%, 75%)"})]}),s.jsx(Vn,{checked:L,onChange:X})]})]})]}),s.jsxs("div",{className:"space-y-2 p-3 bg-bambu-dark rounded-lg",children:[s.jsx("p",{className:"text-xs text-bambu-gray uppercase tracking-wide mb-2",children:"Printer Status"}),s.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("span",{className:"text-sm text-white",children:"Offline"}),s.jsx(Vn,{checked:D,onChange:K})]}),s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("span",{className:"text-sm text-white",children:"Error"}),s.jsx(Vn,{checked:Y,onChange:q})]}),s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("span",{className:"text-sm text-white",children:"Low Filament"}),s.jsx(Vn,{checked:Z,onChange:re})]}),s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("span",{className:"text-sm text-white",children:"Maintenance"}),s.jsx(Vn,{checked:oe,onChange:B})]})]})]})]}),s.jsxs("div",{className:"flex gap-3 pt-2",children:[s.jsx(Se,{type:"button",variant:"secondary",onClick:e,className:"flex-1",children:"Cancel"}),s.jsxs(Se,{type:"submit",disabled:Ke,className:"flex-1",children:[Ke?s.jsx(mt,{className:"w-4 h-4 animate-spin"}):s.jsx(ds,{className:"w-4 h-4"}),r?"Save":"Add"]})]})]})]})})}function Fqe({template:t,onClose:e}){const n=tn(),r=w.useRef(null),[i,a]=w.useState(t.title_template),[o,l]=w.useState(t.body_template),[c,u]=w.useState(null),[d,f]=w.useState(!0),{data:m}=ct({queryKey:["template-variables"],queryFn:pe.getTemplateVariables}),g=m?.find(E=>E.event_type===t.event_type),{data:x,isLoading:y}=ct({queryKey:["template-preview",t.event_type,i,o],queryFn:()=>pe.previewTemplate({event_type:t.event_type,title_template:i,body_template:o}),enabled:d&&i.length>0&&o.length>0});w.useEffect(()=>{const E=k=>{k.key==="Escape"&&e()};return window.addEventListener("keydown",E),()=>window.removeEventListener("keydown",E)},[e]);const b=ft({mutationFn:E=>pe.updateNotificationTemplate(t.id,E),onSuccess:()=>{n.invalidateQueries({queryKey:["notification-templates"]}),e()},onError:E=>{u(E.message)}}),v=ft({mutationFn:()=>pe.resetNotificationTemplate(t.id),onSuccess:E=>{a(E.title_template),l(E.body_template),n.invalidateQueries({queryKey:["notification-templates"]})},onError:E=>{u(E.message)}}),M=E=>{if(E.preventDefault(),u(null),!i.trim()){u("Title is required");return}if(!o.trim()){u("Body is required");return}b.mutate({title_template:i,body_template:o})},S=E=>{const k=r.current;if(!k)return;const C=k.selectionStart,R=k.selectionEnd,T=o,P=T.substring(0,C),F=T.substring(R),L=P+`{${E}}`+F;l(L),setTimeout(()=>{k.focus();const X=C+E.length+2;k.setSelectionRange(X,X)},0)},A=i!==t.title_template||o!==t.body_template;return s.jsx("div",{className:"fixed inset-0 bg-black/80 flex items-center justify-center z-50 p-4",children:s.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg w-full max-w-2xl max-h-[90vh] flex flex-col",children:[s.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary shrink-0",children:[s.jsxs("h2",{className:"text-lg font-semibold text-white",children:["Edit Template: ",t.name]}),s.jsx("button",{onClick:e,className:"p-1 hover:bg-bambu-dark-tertiary rounded transition-colors",children:s.jsx(Ut,{className:"w-5 h-5 text-bambu-gray"})})]}),s.jsxs("form",{onSubmit:M,className:"flex-1 overflow-y-auto p-4 space-y-4",children:[c&&s.jsx("div",{className:"p-3 bg-red-500/20 border border-red-500/50 rounded text-red-400 text-sm",children:c}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm font-medium text-bambu-gray mb-1",children:"Title"}),s.jsx("input",{type:"text",value:i,onChange:E=>a(E.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..."})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm font-medium text-bambu-gray mb-1",children:"Body"}),s.jsx("textarea",{ref:r,value:o,onChange:E=>l(E.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..."})]}),g&&s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm font-medium text-bambu-gray mb-2",children:"Available Variables"}),s.jsx("div",{className:"flex flex-wrap gap-2",children:g.variables.map(E=>s.jsxs("button",{type:"button",onClick:()=>S(E),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:[s.jsx(Kn,{className:"w-3 h-3"}),E]},E))}),s.jsx("p",{className:"text-xs text-bambu-gray/60 mt-1",children:"Click to insert at cursor position in body"})]}),s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center justify-between mb-2",children:[s.jsxs("label",{className:"text-sm font-medium text-bambu-gray flex items-center gap-2",children:[s.jsx(_f,{className:"w-4 h-4"}),"Live Preview"]}),s.jsx("button",{type:"button",onClick:()=>f(!d),className:"text-xs text-bambu-green hover:text-bambu-green-light",children:d?"Hide":"Show"})]}),d&&s.jsx("div",{className:"bg-bambu-dark border border-bambu-dark-tertiary rounded p-3 space-y-2",children:y?s.jsxs("div",{className:"flex items-center gap-2 text-bambu-gray text-sm",children:[s.jsx(mt,{className:"w-4 h-4 animate-spin"}),"Loading preview..."]}):x?s.jsxs(s.Fragment,{children:[s.jsxs("div",{children:[s.jsx("span",{className:"text-xs text-bambu-gray",children:"Title:"}),s.jsx("div",{className:"text-white font-medium",children:x.title})]}),s.jsxs("div",{children:[s.jsx("span",{className:"text-xs text-bambu-gray",children:"Body:"}),s.jsx("div",{className:"text-white whitespace-pre-wrap text-sm",children:x.body})]})]}):s.jsx("div",{className:"text-bambu-gray text-sm",children:"Enter template content to see preview"})})]})]}),s.jsxs("div",{className:"flex items-center justify-between p-4 border-t border-bambu-dark-tertiary shrink-0",children:[s.jsxs(Se,{type:"button",variant:"ghost",onClick:()=>v.mutate(),disabled:v.isPending,className:"text-orange-400 hover:text-orange-300",children:[v.isPending?s.jsx(mt,{className:"w-4 h-4 animate-spin mr-2"}):s.jsx(Vf,{className:"w-4 h-4 mr-2"}),"Reset to Default"]}),s.jsxs("div",{className:"flex gap-2",children:[s.jsx(Se,{type:"button",variant:"secondary",onClick:e,children:"Cancel"}),s.jsxs(Se,{onClick:M,disabled:b.isPending||!A,children:[b.isPending?s.jsx(mt,{className:"w-4 h-4 animate-spin mr-2"}):s.jsx(ds,{className:"w-4 h-4 mr-2"}),"Save"]})]})]})]})})}const Uqe={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"},zqe={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 Bqe({onClose:t}){const e=tn(),{showToast:n}=$n(),[r,i]=w.useState(7),[a,o]=w.useState(null),[l,c]=w.useState(!1),{data:u}=ct({queryKey:["settings"],queryFn:pe.getSettings}),d=u?.time_format||"system",{data:f,isLoading:m,refetch:g,isRefetching:x}=ct({queryKey:["notification-logs",r,l],queryFn:()=>pe.getNotificationLogs({days:r,limit:100,success:l?!1:void 0})}),{data:y}=ct({queryKey:["notification-log-stats",r],queryFn:()=>pe.getNotificationLogStats(r)}),b=ft({mutationFn:()=>pe.clearNotificationLogs(30),onSuccess:M=>{n(M.message,"success"),e.invalidateQueries({queryKey:["notification-logs"]}),e.invalidateQueries({queryKey:["notification-log-stats"]})},onError:M=>{n(`Failed to clear logs: ${M.message}`,"error")}}),v=M=>{const S=mi(M);if(!S)return"";const E=new Date().getTime()-S.getTime();return E<6e4?"Just now":E<36e5?`${Math.floor(E/6e4)}m ago`:E<864e5?`${Math.floor(E/36e5)}h ago`:S.toLocaleDateString()+" "+lfe(S,d)};return s.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",children:s.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:[s.jsxs("div",{className:"p-4 border-b border-bambu-dark-tertiary flex items-center justify-between",children:[s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx(hw,{className:"w-5 h-5 text-bambu-green"}),s.jsx("h2",{className:"text-lg font-semibold text-white",children:"Notification Log"})]}),s.jsx("button",{onClick:t,className:"text-bambu-gray hover:text-white transition-colors",children:"×"})]}),y&&s.jsx("div",{className:"px-4 py-3 border-b border-bambu-dark-tertiary bg-bambu-dark/50",children:s.jsxs("div",{className:"flex items-center gap-6 text-sm",children:[s.jsxs("span",{className:"text-bambu-gray",children:["Last ",r," days: ",s.jsx("span",{className:"text-white font-medium",children:y.total})," notifications"]}),s.jsxs("span",{className:"flex items-center gap-1 text-bambu-green",children:[s.jsx(Dn,{className:"w-4 h-4"}),y.success_count," sent"]}),y.failure_count>0&&s.jsxs("span",{className:"flex items-center gap-1 text-red-400",children:[s.jsx(qi,{className:"w-4 h-4"}),y.failure_count," failed"]})]})}),s.jsxs("div",{className:"px-4 py-3 border-b border-bambu-dark-tertiary flex items-center gap-4",children:[s.jsxs("select",{value:r,onChange:M=>i(Number(M.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:[s.jsx("option",{value:1,children:"Last 24 hours"}),s.jsx("option",{value:7,children:"Last 7 days"}),s.jsx("option",{value:30,children:"Last 30 days"}),s.jsx("option",{value:90,children:"Last 90 days"})]}),s.jsxs("label",{className:"flex items-center gap-2 text-sm text-bambu-gray cursor-pointer",children:[s.jsx("input",{type:"checkbox",checked:l,onChange:M=>c(M.target.checked),className:"rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),"Show failed only"]}),s.jsx("div",{className:"flex-1"}),s.jsxs(Se,{size:"sm",variant:"secondary",onClick:()=>g(),disabled:x,children:[x?s.jsx(mt,{className:"w-4 h-4 animate-spin"}):s.jsx(yr,{className:"w-4 h-4"}),"Refresh"]}),s.jsxs(Se,{size:"sm",variant:"secondary",onClick:()=>b.mutate(),disabled:b.isPending,className:"text-red-400 hover:text-red-300",children:[b.isPending?s.jsx(mt,{className:"w-4 h-4 animate-spin"}):s.jsx(an,{className:"w-4 h-4"}),"Clear Old"]})]}),s.jsx("div",{className:"flex-1 overflow-y-auto p-4",children:m?s.jsx("div",{className:"flex justify-center py-12",children:s.jsx(mt,{className:"w-6 h-6 text-bambu-green animate-spin"})}):f&&f.length>0?s.jsx("div",{className:"space-y-2",children:f.map(M=>s.jsx($qe,{log:M,isExpanded:a===M.id,onToggle:()=>o(a===M.id?null:M.id),formatDate:v,formatFullDate:S=>eg(S,d)},M.id))}):s.jsxs("div",{className:"text-center py-12 text-bambu-gray",children:[s.jsx(hw,{className:"w-12 h-12 mx-auto mb-3 opacity-30"}),s.jsx("p",{className:"text-sm",children:l?"No failed notifications":"No notifications logged"})]})})]})})}function $qe({log:t,isExpanded:e,onToggle:n,formatDate:r,formatFullDate:i}){return s.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:[s.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?s.jsx(Dn,{className:"w-4 h-4 text-bambu-green shrink-0"}):s.jsx(qi,{className:"w-4 h-4 text-red-400 shrink-0"}),s.jsx("span",{className:`text-xs font-medium ${zqe[t.event_type]||"text-bambu-gray"}`,children:Uqe[t.event_type]||t.event_type}),s.jsx("span",{className:"text-sm text-white truncate flex-1",children:t.provider_name||"Unknown Provider"}),t.printer_name&&s.jsx("span",{className:"text-xs text-bambu-gray",children:t.printer_name}),s.jsx("span",{className:"text-xs text-bambu-gray shrink-0",children:r(t.created_at)}),e?s.jsx(Jc,{className:"w-4 h-4 text-bambu-gray shrink-0"}):s.jsx(Ji,{className:"w-4 h-4 text-bambu-gray shrink-0"})]}),e&&s.jsxs("div",{className:"px-3 py-2 border-t border-bambu-dark-tertiary bg-bambu-dark/20 space-y-2",children:[s.jsxs("div",{children:[s.jsx("p",{className:"text-xs text-bambu-gray mb-1",children:"Title"}),s.jsx("p",{className:"text-sm text-white",children:t.title})]}),s.jsxs("div",{children:[s.jsx("p",{className:"text-xs text-bambu-gray mb-1",children:"Message"}),s.jsx("p",{className:"text-sm text-white whitespace-pre-wrap",children:t.message})]}),!t.success&&t.error_message&&s.jsxs("div",{children:[s.jsx("p",{className:"text-xs text-red-400 mb-1",children:"Error"}),s.jsx("p",{className:"text-sm text-red-300",children:t.error_message})]}),s.jsxs("div",{className:"flex gap-4 text-xs text-bambu-gray pt-1",children:[s.jsxs("span",{children:["Provider: ",t.provider_type]}),s.jsxs("span",{children:["Time: ",i(t.created_at)]})]})]})]})}const T1=[{id:"settings",labelKey:"backup.categories.settings",defaultLabel:"App Settings",icon:s.jsx(F2,{className:"w-4 h-4"}),default:!0,description:"Language, theme, update preferences"},{id:"notifications",labelKey:"backup.categories.notifications",defaultLabel:"Notification Providers",icon:s.jsx(tf,{className:"w-4 h-4"}),default:!0,description:"ntfy, Pushover, Discord, etc."},{id:"templates",labelKey:"backup.categories.templates",defaultLabel:"Notification Templates",icon:s.jsx(za,{className:"w-4 h-4"}),default:!0,description:"Custom message templates"},{id:"smart_plugs",labelKey:"backup.categories.smartPlugs",defaultLabel:"Smart Plugs",icon:s.jsx(Us,{className:"w-4 h-4"}),default:!0,description:"Tasmota plug configurations"},{id:"external_links",labelKey:"backup.categories.externalLinks",defaultLabel:"External Links",icon:s.jsx(Y0,{className:"w-4 h-4"}),default:!0,description:"Sidebar links to external services"},{id:"printers",labelKey:"backup.categories.printers",defaultLabel:"Printers",icon:s.jsx(Ir,{className:"w-4 h-4"}),default:!1,description:"Printer info (access codes excluded)"},{id:"filaments",labelKey:"backup.categories.filaments",defaultLabel:"Filament Inventory",icon:s.jsx(nD,{className:"w-4 h-4"}),default:!1,description:"Filament types and costs"},{id:"maintenance",labelKey:"backup.categories.maintenance",defaultLabel:"Maintenance Types",icon:s.jsx(Od,{className:"w-4 h-4"}),default:!1,description:"Custom maintenance schedules"},{id:"archives",labelKey:"backup.categories.archives",defaultLabel:"Print Archives",icon:s.jsx(Ha,{className:"w-4 h-4"}),default:!1,description:"All print data + files (3MF, thumbnails, photos)"},{id:"projects",labelKey:"backup.categories.projects",defaultLabel:"Projects",icon:s.jsx(ba,{className:"w-4 h-4"}),default:!1,description:"Projects, BOM items, and attachments"},{id:"pending_uploads",labelKey:"backup.categories.pendingUploads",defaultLabel:"Pending Uploads",icon:s.jsx(bi,{className:"w-4 h-4"}),default:!1,description:"Virtual printer uploads awaiting review"},{id:"api_keys",labelKey:"backup.categories.apiKeys",defaultLabel:"API Keys",icon:s.jsx(Gh,{className:"w-4 h-4"}),default:!1,description:"Webhook API keys (new keys generated on import)"}];function Hqe({onClose:t,onExport:e}){const{t:n}=Tg(),[r,i]=w.useState(()=>{const x={};return T1.forEach(y=>{x[y.id]=y.default}),x}),[a,o]=w.useState(!1),[l,c]=w.useState(!1);w.useEffect(()=>{const x=y=>{y.key==="Escape"&&t()};return window.addEventListener("keydown",x),()=>window.removeEventListener("keydown",x)},[t]);const u=x=>{i(y=>({...y,[x]:!y[x]}))},d=()=>{const x={};T1.forEach(y=>{x[y.id]=!0}),i(x)},f=()=>{const x={};T1.forEach(y=>{x[y.id]=!1}),i(x)},m=Object.values(r).filter(Boolean).length,g=async()=>{c(!0);try{await e({...r,access_codes:a&&r.printers})}finally{c(!1)}};return s.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",onClick:l?void 0:t,children:s.jsx(Mt,{className:"w-full max-w-lg",onClick:x=>x.stopPropagation(),children:s.jsxs(Et,{className:"p-0",children:[s.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("div",{className:"p-2 rounded-full bg-bambu-green/20 text-bambu-green",children:s.jsx(Jr,{className:"w-5 h-5"})}),s.jsxs("div",{children:[s.jsx("h3",{className:"text-lg font-semibold text-white",children:n("backup.exportTitle",{defaultValue:"Export Backup"})}),s.jsx("p",{className:"text-sm text-bambu-gray",children:n("backup.selectCategories",{defaultValue:"Select data to include"})})]})]}),s.jsx("button",{onClick:t,className:"p-2 hover:bg-bambu-dark-tertiary rounded-lg transition-colors",children:s.jsx(Ut,{className:"w-5 h-5"})})]}),s.jsxs("div",{className:"flex gap-2 px-4 pt-4",children:[s.jsx("button",{onClick:d,disabled:l,className:"text-sm text-bambu-green hover:text-bambu-green/80 disabled:opacity-50 disabled:cursor-not-allowed",children:n("common.selectAll",{defaultValue:"Select All"})}),s.jsx("span",{className:"text-bambu-gray",children:"|"}),s.jsx("button",{onClick:f,disabled:l,className:"text-sm text-bambu-gray hover:text-white disabled:opacity-50 disabled:cursor-not-allowed",children:n("common.selectNone",{defaultValue:"Select None"})})]}),s.jsx("div",{className:`p-4 space-y-2 max-h-[400px] overflow-y-auto ${l?"opacity-50 pointer-events-none":""}`,children:T1.map(x=>s.jsxs("label",{className:`flex items-center gap-3 p-3 rounded-lg cursor-pointer transition-colors ${r[x.id]?"bg-bambu-green/10 border border-bambu-green/30":"bg-bambu-dark hover:bg-bambu-dark-tertiary border border-transparent"}`,children:[s.jsx("input",{type:"checkbox",checked:r[x.id],onChange:()=>u(x.id),disabled:l,className:"w-4 h-4 rounded border-bambu-gray bg-bambu-dark text-bambu-green focus:ring-bambu-green focus:ring-offset-0"}),s.jsx("div",{className:`${r[x.id]?"text-bambu-green":"text-bambu-gray"}`,children:x.icon}),s.jsxs("div",{className:"flex-1",children:[s.jsx("div",{className:"text-white text-sm font-medium",children:n(x.labelKey,{defaultValue:x.defaultLabel})}),s.jsx("div",{className:"text-xs text-bambu-gray",children:x.description})]})]},x.id))}),r.archives&&s.jsx("div",{className:"mx-4 mb-2 p-3 rounded-lg bg-yellow-500/10 border border-yellow-500/30",children:s.jsxs("div",{className:"flex items-start gap-2 text-sm",children:[s.jsx(Ha,{className:"w-4 h-4 text-yellow-500 mt-0.5 flex-shrink-0"}),s.jsxs("div",{className:"text-yellow-200 dark:text-yellow-200 text-yellow-700",children:[s.jsx("span",{className:"font-medium",children:"ZIP file will be created."}),s.jsx("span",{className:"text-yellow-600 dark:text-yellow-200/70",children:" Includes all 3MF files, thumbnails, timelapses, and photos. This may take a while and result in a large file."})]})]})}),r.printers&&s.jsxs("div",{className:"mx-4 mb-2 p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsx(Gh,{className:"w-4 h-4 text-orange-500 dark:text-orange-400 mt-0.5 flex-shrink-0"}),s.jsxs("div",{children:[s.jsx("p",{className:"text-sm font-medium text-white",children:"Include Access Codes"}),s.jsx("p",{className:"text-xs text-bambu-gray",children:"For transferring to another machine"})]})]}),s.jsx(Vn,{checked:a,onChange:o})]}),a&&s.jsx("div",{className:"mt-2 p-2 rounded bg-orange-500/10 border border-orange-500/30",children:s.jsxs("div",{className:"flex items-start gap-2 text-xs",children:[s.jsx(Cn,{className:"w-3 h-3 text-orange-500 dark:text-orange-400 mt-0.5 flex-shrink-0"}),s.jsx("span",{className:"text-orange-700 dark:text-orange-200",children:"Access codes will be included in plain text. Keep this backup file secure!"})]})})]}),s.jsxs("div",{className:"flex items-center justify-between p-4 border-t border-bambu-dark-tertiary",children:[s.jsx("span",{className:"text-sm text-bambu-gray",children:n("backup.selectedCount",{count:m,defaultValue:`${m} categories selected`})}),s.jsxs("div",{className:"flex gap-3",children:[s.jsx(Se,{variant:"secondary",onClick:t,disabled:l,children:n("common.cancel",{defaultValue:"Cancel"})}),s.jsx(Se,{onClick:g,disabled:m===0||l,className:"bg-bambu-green hover:bg-bambu-green-dark disabled:opacity-50 disabled:cursor-not-allowed min-w-[100px]",children:l?s.jsxs(s.Fragment,{children:[s.jsx(mt,{className:"w-4 h-4 mr-2 animate-spin"}),n("backup.exporting",{defaultValue:"Exporting..."})]}):s.jsxs(s.Fragment,{children:[s.jsx(Jr,{className:"w-4 h-4 mr-2"}),n("backup.export",{defaultValue:"Export"})]})})]})]})]})})})}const WG={settings:"Settings",notification_providers:"Notification Providers",notification_templates:"Notification Templates",smart_plugs:"Smart Plugs",printers:"Printers",filaments:"Filaments",maintenance_types:"Maintenance Types",archives:"Archives",projects:"Projects",pending_uploads:"Pending Uploads",external_links:"External Links",api_keys:"API Keys"};function Vqe({onClose:t,onRestore:e,onSuccess:n}){const[r,i]=w.useState("options"),[a,o]=w.useState(!1),[l,c]=w.useState(null),[u,d]=w.useState(null),[f,m]=w.useState(new Set),g=w.useRef(null);w.useEffect(()=>{const A=E=>{E.key==="Escape"&&r!=="restoring"&&(r==="result"&&u?.success&&n(),t())};return window.addEventListener("keydown",A),()=>window.removeEventListener("keydown",A)},[t,n,r,u]);const x=A=>{const E=A.target.files?.[0];E&&c(E)},y=async()=>{if(l){i("restoring");try{const A=await e(l,a);d(A),i("result")}catch{d({success:!1,message:"Failed to restore backup. Please check the file format."}),i("result")}}},b=()=>{u?.success&&n(),t()},v=A=>{m(E=>{const k=new Set(E);return k.has(A)?k.delete(A):k.add(A),k})},M=u?.restored?Object.values(u.restored).reduce((A,E)=>A+E,0)+(u.files_restored||0):0,S=u?.total_skipped||0;return s.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",onMouseDown:A=>{A.target===A.currentTarget&&r!=="restoring"&&t()},children:s.jsx(Mt,{className:"w-full max-w-lg",children:s.jsxs(Et,{className:"p-0",children:[s.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("div",{className:`p-2 rounded-full ${r==="result"&&u?.success?"bg-bambu-green/20 text-bambu-green":r==="result"&&!u?.success?"bg-red-500/20 text-red-500":"bg-blue-500/20 text-blue-500"}`,children:r==="result"&&u?.success?s.jsx(Dn,{className:"w-5 h-5"}):r==="result"&&!u?.success?s.jsx(Cn,{className:"w-5 h-5"}):s.jsx(bi,{className:"w-5 h-5"})}),s.jsxs("div",{children:[s.jsxs("h3",{className:"text-lg font-semibold text-white",children:[r==="options"&&"Restore Backup",r==="restoring"&&"Restoring...",r==="result"&&(u?.success?"Restore Complete":"Restore Failed")]}),s.jsxs("p",{className:"text-sm text-bambu-gray",children:[r==="options"&&"Import settings from a backup file",r==="restoring"&&"Please wait while your data is being restored",r==="result"&&u?.message]})]})]}),r!=="restoring"&&s.jsx("button",{onClick:b,className:"p-2 hover:bg-bambu-dark-tertiary rounded-lg transition-colors",children:s.jsx(Ut,{className:"w-5 h-5"})})]}),r==="options"&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"p-4 space-y-4",children:[s.jsxs("div",{children:[s.jsx("input",{ref:g,type:"file",accept:".json,.zip",className:"hidden",onChange:x}),s.jsx("button",{type:"button",onClick:()=>g.current?.click(),className:`w-full p-4 border-2 border-dashed rounded-lg transition-colors ${l?"border-bambu-green bg-bambu-green/10":"border-bambu-dark-tertiary hover:border-bambu-gray"}`,children:l?s.jsxs("div",{className:"flex items-center justify-center gap-2 text-bambu-green",children:[s.jsx(Dn,{className:"w-5 h-5"}),s.jsx("span",{className:"font-medium",children:l.name})]}):s.jsxs("div",{className:"flex flex-col items-center gap-2 text-bambu-gray",children:[s.jsx(bi,{className:"w-8 h-8"}),s.jsx("span",{children:"Click to select backup file (.json or .zip)"})]})})]}),s.jsx("div",{className:"p-3 rounded-lg bg-blue-500/10 border border-blue-500/30",children:s.jsxs("div",{className:"flex items-start gap-2 text-sm",children:[s.jsx(Cn,{className:"w-4 h-4 text-blue-500 dark:text-blue-400 mt-0.5 flex-shrink-0"}),s.jsxs("div",{className:"text-blue-700 dark:text-blue-200",children:[s.jsx("p",{className:"font-medium mb-1",children:"How duplicate handling works:"}),s.jsxs("ul",{className:"text-blue-600 dark:text-blue-200/80 space-y-1 text-xs",children:[s.jsxs("li",{children:[s.jsx("strong",{children:"Printers"})," - matched by serial number"]}),s.jsxs("li",{children:[s.jsx("strong",{children:"Smart Plugs"})," - matched by IP address"]}),s.jsxs("li",{children:[s.jsx("strong",{children:"Notification Providers"})," - matched by name"]}),s.jsxs("li",{children:[s.jsx("strong",{children:"Filaments"})," - matched by name + type + brand"]}),s.jsxs("li",{children:[s.jsx("strong",{children:"Archives"})," - matched by content hash (always skipped)"]}),s.jsxs("li",{children:[s.jsx("strong",{children:"Pending Uploads"})," - matched by filename"]}),s.jsxs("li",{children:[s.jsx("strong",{children:"Settings & Templates"})," - always overwritten"]})]})]})]})}),s.jsx("div",{className:"p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary",children:s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{children:[s.jsxs("p",{className:"text-white font-medium flex items-center gap-2",children:[a?s.jsx(yr,{className:"w-4 h-4 text-orange-400"}):s.jsx(mw,{className:"w-4 h-4 text-bambu-gray"}),a?"Replace existing data":"Keep existing data"]}),s.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:a?"Overwrite items that already exist with backup data":"Only restore items that don't already exist"})]}),s.jsx(Vn,{checked:a,onChange:o})]})}),a&&s.jsx("div",{className:"p-3 rounded-lg bg-orange-500/10 border border-orange-500/30",children:s.jsxs("div",{className:"flex items-start gap-2 text-sm",children:[s.jsx(Cn,{className:"w-4 h-4 text-orange-500 dark:text-orange-400 mt-0.5 flex-shrink-0"}),s.jsxs("div",{className:"text-orange-700 dark:text-orange-200",children:[s.jsx("span",{className:"font-medium",children:"Caution:"})," Overwriting will replace your current configurations with data from the backup. Printer access codes are never overwritten for security."]})]})})]}),s.jsxs("div",{className:"flex items-center justify-end gap-3 p-4 border-t border-bambu-dark-tertiary",children:[s.jsx(Se,{type:"button",variant:"secondary",onClick:t,children:"Cancel"}),s.jsxs(Se,{type:"button",onClick:y,disabled:!l,className:"bg-bambu-green hover:bg-bambu-green-dark disabled:opacity-50",children:[s.jsx(bi,{className:"w-4 h-4 mr-2"}),"Restore"]})]})]}),r==="restoring"&&s.jsxs("div",{className:"p-8 flex flex-col items-center gap-4",children:[s.jsx(mt,{className:"w-12 h-12 text-bambu-green animate-spin"}),s.jsx("p",{className:"text-bambu-gray",children:"Processing backup file..."})]}),r==="result"&&u&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"p-4 space-y-4 max-h-[400px] overflow-y-auto",children:[s.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[s.jsxs("div",{className:"p-3 rounded-lg bg-bambu-green/10 border border-bambu-green/30",children:[s.jsx("div",{className:"text-2xl font-bold text-bambu-green",children:M}),s.jsx("div",{className:"text-sm text-bambu-gray",children:"Items Restored"})]}),s.jsxs("div",{className:"p-3 rounded-lg bg-yellow-500/10 border border-yellow-500/30",children:[s.jsx("div",{className:"text-2xl font-bold text-yellow-500",children:S}),s.jsx("div",{className:"text-sm text-bambu-gray",children:"Items Skipped"})]})]}),u.restored&&Object.entries(u.restored).some(([,A])=>A>0)&&s.jsxs("div",{className:"space-y-2",children:[s.jsxs("h4",{className:"text-sm font-medium text-bambu-gray flex items-center gap-2",children:[s.jsx(Dn,{className:"w-4 h-4 text-bambu-green"}),"Restored"]}),s.jsxs("div",{className:"space-y-1",children:[Object.entries(u.restored).filter(([,A])=>A>0).map(([A,E])=>s.jsxs("div",{className:"flex items-center justify-between text-sm p-2 rounded bg-bambu-dark",children:[s.jsx("span",{className:"text-white",children:WG[A]||A}),s.jsx("span",{className:"text-bambu-green font-medium",children:E})]},A)),(u.files_restored||0)>0&&s.jsxs("div",{className:"flex items-center justify-between text-sm p-2 rounded bg-bambu-dark",children:[s.jsx("span",{className:"text-white",children:"Files (3MF, thumbnails, etc.)"}),s.jsx("span",{className:"text-bambu-green font-medium",children:u.files_restored})]})]})]}),u.skipped&&Object.entries(u.skipped).some(([,A])=>A>0)&&s.jsxs("div",{className:"space-y-2",children:[s.jsxs("h4",{className:"text-sm font-medium text-bambu-gray flex items-center gap-2",children:[s.jsx(mw,{className:"w-4 h-4 text-yellow-500"}),"Skipped (already exist)"]}),s.jsx("div",{className:"space-y-1",children:Object.entries(u.skipped).filter(([,A])=>A>0).map(([A,E])=>{const k=u.skipped_details?.[A]||[],C=f.has(A);return s.jsxs("div",{children:[s.jsxs("button",{onClick:()=>k.length>0&&v(A),className:`w-full flex items-center justify-between text-sm p-2 rounded bg-bambu-dark ${k.length>0?"hover:bg-bambu-dark-tertiary cursor-pointer":""}`,children:[s.jsxs("span",{className:"text-white flex items-center gap-2",children:[WG[A]||A,k.length>0&&(C?s.jsx(Jc,{className:"w-3 h-3"}):s.jsx(Ji,{className:"w-3 h-3"}))]}),s.jsx("span",{className:"text-yellow-500 font-medium",children:E})]}),C&&k.length>0&&s.jsxs("div",{className:"mt-1 ml-4 p-2 rounded bg-bambu-dark-tertiary text-xs text-bambu-gray space-y-1",children:[k.slice(0,10).map((R,T)=>s.jsx("div",{children:R},T)),k.length>10&&s.jsxs("div",{className:"text-bambu-gray/60",children:["...and ",k.length-10," more"]})]})]},A)})})]}),u.new_api_keys&&u.new_api_keys.length>0&&s.jsxs("div",{className:"space-y-2",children:[s.jsxs("h4",{className:"text-sm font-medium text-bambu-gray flex items-center gap-2",children:[s.jsx(Cn,{className:"w-4 h-4 text-orange-500"}),"New API Keys Generated"]}),s.jsxs("div",{className:"p-3 rounded bg-orange-500/10 border border-orange-500/30",children:[s.jsx("p",{className:"text-xs text-orange-200 mb-2",children:"These keys are only shown once. Copy them now!"}),s.jsx("div",{className:"space-y-2",children:u.new_api_keys.map((A,E)=>s.jsxs("div",{className:"p-2 rounded bg-bambu-dark",children:[s.jsx("div",{className:"text-sm text-white font-medium mb-1",children:A.name}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("code",{className:"text-xs text-bambu-green bg-bambu-dark-tertiary px-2 py-1 rounded font-mono flex-1 break-all",children:A.key}),s.jsx("button",{onClick:()=>navigator.clipboard.writeText(A.key),className:"text-xs text-bambu-gray hover:text-white px-2 py-1 rounded bg-bambu-dark-tertiary",children:"Copy"})]})]},E))})]})]}),M===0&&S===0&&s.jsx("div",{className:"p-4 text-center text-bambu-gray",children:"No data was found to restore in the backup file."})]}),s.jsx("div",{className:"flex items-center justify-end gap-3 p-4 border-t border-bambu-dark-tertiary",children:s.jsx(Se,{onClick:b,children:"Close"})})]})]})})})}async function Gqe(){const t=await fetch("/api/v1/settings/spoolman");if(!t.ok)throw new Error("Failed to load Spoolman settings");return t.json()}async function Wqe(t){const e=await fetch("/api/v1/settings/spoolman",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!e.ok)throw new Error("Failed to save Spoolman settings");return e.json()}function qqe(){const t=tn(),[e,n]=w.useState(!1),[r,i]=w.useState(""),[a,o]=w.useState("auto"),[l,c]=w.useState(!1),[u,d]=w.useState("all"),[f,m]=w.useState(!1),[g,x]=w.useState(!1),{data:y,isLoading:b}=ct({queryKey:["spoolman-settings"],queryFn:Gqe}),{data:v,isLoading:M,refetch:S}=ct({queryKey:["spoolman-status"],queryFn:pe.getSpoolmanStatus,refetchInterval:3e4}),{data:A}=ct({queryKey:["printers"],queryFn:pe.getPrinters});w.useEffect(()=>{y&&(n(y.spoolman_enabled==="true"),i(y.spoolman_url||""),o(y.spoolman_sync_mode||"auto"),m(!0))},[y]),w.useEffect(()=>{if(!f||!y)return;if(y.spoolman_enabled==="true"!==e||(y.spoolman_url||"")!==r||(y.spoolman_sync_mode||"auto")!==a){const K=setTimeout(()=>{E.mutate()},500);return()=>clearTimeout(K)}},[e,r,a,f]);const E=ft({mutationFn:()=>Wqe({spoolman_enabled:e?"true":"false",spoolman_url:r,spoolman_sync_mode:a}),onSuccess:()=>{t.invalidateQueries({queryKey:["spoolman-settings"]}),t.invalidateQueries({queryKey:["spoolman-status"]}),c(!0),setTimeout(()=>c(!1),2e3)}}),k=ft({mutationFn:pe.connectSpoolman,onSuccess:()=>{S()}}),C=ft({mutationFn:pe.disconnectSpoolman,onSuccess:()=>{S()}}),R=ft({mutationFn:pe.syncAllPrintersAms,onSuccess:D=>{D.success}}),T=ft({mutationFn:D=>pe.syncPrinterAms(D),onSuccess:D=>{D.success}}),P=()=>{u==="all"?R.mutate():T.mutate(u)},F=R.isPending||T.isPending,L=u==="all"?R.data:T.data,X=u==="all"?R.isSuccess:T.isSuccess;return b?s.jsxs(Mt,{children:[s.jsx(mr,{children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Yp,{className:"w-5 h-5 text-bambu-green"}),s.jsx("h2",{className:"text-lg font-semibold text-white",children:"Spoolman Integration"})]})}),s.jsx(Et,{children:s.jsx("div",{className:"flex justify-center py-8",children:s.jsx(mt,{className:"w-6 h-6 text-bambu-green animate-spin"})})})]}):s.jsxs(Mt,{children:[s.jsx(mr,{children:s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Yp,{className:"w-5 h-5 text-bambu-green"}),s.jsx("h2",{className:"text-lg font-semibold text-white",children:"Spoolman Integration"})]}),E.isPending&&s.jsx(mt,{className:"w-4 h-4 text-bambu-green animate-spin"}),l&&s.jsx(xs,{className:"w-4 h-4 text-bambu-green"})]})}),s.jsxs(Et,{className:"space-y-4",children:[s.jsx("p",{className:"text-sm text-bambu-gray",children:"Connect to Spoolman for filament inventory tracking. AMS data will sync automatically."}),s.jsx("div",{className:"p-3 bg-blue-500/10 border border-blue-500/30 rounded-lg",children:s.jsxs("div",{className:"flex gap-2",children:[s.jsx(tl,{className:"w-4 h-4 text-blue-400 flex-shrink-0 mt-0.5"}),s.jsxs("div",{className:"text-xs text-blue-300",children:[s.jsx("p",{className:"font-medium mb-1",children:"How Sync Works"}),s.jsxs("ul",{className:"list-disc list-inside space-y-0.5 text-blue-300/80",children:[s.jsx("li",{children:"Only official Bambu Lab spools with RFID are synced"}),s.jsx("li",{children:"New spools are auto-created in Spoolman on first sync"}),s.jsx("li",{children:"Non-Bambu Lab spools (third-party, refilled) are skipped"})]}),s.jsx("p",{className:"font-medium mt-2 mb-1",children:"Linking Existing Spools"}),s.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".'})]})]})}),s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{children:[s.jsx("p",{className:"text-white",children:"Enable Spoolman"}),s.jsx("p",{className:"text-sm text-bambu-gray",children:"Sync filament data with Spoolman server"})]}),s.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[s.jsx("input",{type:"checkbox",checked:e,onChange:D=>n(D.target.checked),className:"sr-only peer"}),s.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"})]})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Spoolman URL"}),s.jsx("input",{type:"text",placeholder:"http://192.168.1.100:7912",value:r,onChange:D=>i(D.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"}),s.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"URL of your Spoolman server (e.g., http://localhost:7912)"})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Sync Mode"}),s.jsxs("select",{value:a,onChange:D=>o(D.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:[s.jsx("option",{value:"auto",children:"Automatic"}),s.jsx("option",{value:"manual",children:"Manual Only"})]}),s.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:a==="auto"?"AMS data syncs automatically when changes are detected":"Only sync when manually triggered"})]}),e&&s.jsxs("div",{className:"pt-2 border-t border-bambu-dark-tertiary",children:[s.jsxs("div",{className:"flex items-center justify-between mb-3",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"text-sm text-bambu-gray",children:"Status:"}),M?s.jsx(mt,{className:"w-4 h-4 text-bambu-gray animate-spin"}):v?.connected?s.jsxs("span",{className:"flex items-center gap-1 text-sm text-green-500",children:[s.jsx(xs,{className:"w-4 h-4"}),"Connected"]}):s.jsxs("span",{className:"flex items-center gap-1 text-sm text-red-500",children:[s.jsx(Ut,{className:"w-4 h-4"}),"Disconnected"]})]}),s.jsx("div",{className:"flex gap-2",children:v?.connected?s.jsxs(Se,{variant:"secondary",size:"sm",onClick:()=>C.mutate(),disabled:C.isPending,children:[C.isPending?s.jsx(mt,{className:"w-4 h-4 animate-spin"}):s.jsx(Que,{className:"w-4 h-4"}),"Disconnect"]}):s.jsxs(Se,{size:"sm",onClick:()=>k.mutate(),disabled:k.isPending||!r,children:[k.isPending?s.jsx(mt,{className:"w-4 h-4 animate-spin"}):s.jsx(kl,{className:"w-4 h-4"}),"Connect"]})})]}),k.isError&&s.jsx("div",{className:"mb-3 p-2 bg-red-500/20 border border-red-500/50 rounded text-sm text-red-400",children:k.error.message}),v?.connected&&s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{children:[s.jsx("p",{className:"text-sm text-white",children:"Sync AMS Data"}),s.jsx("p",{className:"text-xs text-bambu-gray",children:"Manually sync printer AMS data to Spoolman"})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs("div",{className:"relative flex-1",children:[s.jsxs("select",{value:u,onChange:D=>d(D.target.value==="all"?"all":Number(D.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:[s.jsx("option",{value:"all",children:"All Printers"}),A?.map(D=>s.jsx("option",{value:D.id,children:D.name},D.id))]}),s.jsx(Ji,{className:"absolute right-2 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}),s.jsxs(Se,{variant:"secondary",size:"sm",onClick:P,disabled:F,children:[F?s.jsx(mt,{className:"w-4 h-4 animate-spin"}):s.jsx(yr,{className:"w-4 h-4"}),"Sync"]})]})]}),X&&L&&s.jsxs("div",{className:"mt-3 space-y-2",children:[s.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&&s.jsxs("div",{className:"p-2 bg-amber-500/10 border border-amber-500/30 rounded text-sm",children:[s.jsxs("div",{className:"flex items-center justify-between text-amber-400 mb-1",children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(Cn,{className:"w-3.5 h-3.5"}),s.jsxs("span",{className:"font-medium",children:[L.skipped_count," spool",L.skipped_count!==1?"s":""," skipped"]})]}),L.skipped_count>5&&s.jsx("button",{onClick:()=>x(!g),className:"text-xs text-amber-400 hover:text-amber-300 underline",children:g?"Show less":"Show all"})]}),s.jsxs("ul",{className:"text-xs text-amber-300/80 space-y-0.5",children:[(g?L.skipped:L.skipped.slice(0,5)).map((D,K)=>s.jsxs("li",{className:"flex items-center gap-2",children:[D.color&&s.jsx("span",{className:"w-3 h-3 rounded-full border border-white/20",style:{backgroundColor:`#${D.color}`}}),s.jsx("span",{children:D.location}),s.jsxs("span",{className:"text-amber-300/60",children:["- ",D.reason]})]},K)),!g&&L.skipped_count>5&&s.jsxs("li",{className:"text-amber-300/60 italic",children:["...and ",L.skipped_count-5," more"]})]})]}),L.errors.length>0&&s.jsxs("div",{className:"p-2 bg-red-500/10 border border-red-500/30 rounded text-sm",children:[s.jsx("div",{className:"text-red-400 font-medium mb-1",children:"Errors:"}),s.jsx("ul",{className:"text-xs text-red-300/80 space-y-0.5",children:L.errors.map((D,K)=>s.jsx("li",{children:D},K))})]})]})]})]})]})}function Kqe({link:t,onClose:e}){const n=tn(),{mode:r}=Xd(),i=!!t,a=w.useRef(null),[o,l]=w.useState(t?.name||""),[c,u]=w.useState(t?.url||""),[d,f]=w.useState(t?.icon||"link"),[m,g]=w.useState(!!t?.custom_icon),[x,y]=w.useState(t?.custom_icon?pe.getExternalLinkIconUrl(t.id):null),[b,v]=w.useState(null),[M,S]=w.useState(null);w.useEffect(()=>{const F=L=>{L.key==="Escape"&&e()};return window.addEventListener("keydown",F),()=>window.removeEventListener("keydown",F)},[e]);const A=ft({mutationFn:async F=>{const L=await pe.createExternalLink(F);return b?await pe.uploadExternalLinkIcon(L.id,b):L},onSuccess:()=>{n.invalidateQueries({queryKey:["external-links"]}),e()},onError:F=>{S(F.message)}}),E=ft({mutationFn:async F=>{let L=await pe.updateExternalLink(t.id,F);return b?L=await pe.uploadExternalLinkIcon(t.id,b):!m&&t?.custom_icon&&(L=await pe.deleteExternalLinkIcon(t.id)),L},onSuccess:()=>{n.invalidateQueries({queryKey:["external-links"]}),e()},onError:F=>{S(F.message)}}),k=F=>{const L=F.target.files?.[0];if(L){if(!["image/png","image/jpeg","image/gif","image/svg+xml","image/webp","image/x-icon"].includes(L.type)){S("Please select a valid image file (PNG, JPG, GIF, SVG, WebP, or ICO)");return}if(L.size>1024*1024){S("Image file must be less than 1MB");return}v(L),g(!0);const D=new FileReader;D.onload=K=>{y(K.target?.result)},D.readAsDataURL(L)}},C=()=>{v(null),y(null),g(!1),a.current&&(a.current.value="")},R=F=>{if(F.preventDefault(),S(null),!o.trim()){S("Name is required");return}if(!c.trim()){S("URL is required");return}if(!c.startsWith("http://")&&!c.startsWith("https://")){S("URL must start with http:// or https://");return}const L={name:o.trim(),url:c.trim(),icon:d};i?E.mutate(L):A.mutate(L)},T=A.isPending||E.isPending,P=z2(d);return s.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",onClick:e,children:s.jsxs("div",{className:"bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-md",onClick:F=>F.stopPropagation(),children:[s.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary",children:[s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("div",{className:"p-2 rounded-full bg-bambu-green/20 text-bambu-green",children:m&&x?s.jsx("img",{src:x,alt:"",className:`w-5 h-5 rounded ${r==="dark"?"invert opacity-[0.65]":"opacity-60"}`}):s.jsx(P,{className:"w-5 h-5"})}),s.jsx("h2",{className:"text-lg font-semibold text-white",children:i?"Edit Link":"Add External Link"})]}),s.jsx("button",{onClick:e,className:"text-bambu-gray hover:text-white transition-colors",children:s.jsx(Ut,{className:"w-5 h-5"})})]}),s.jsxs("form",{onSubmit:R,className:"p-6 space-y-4",children:[M&&s.jsx("div",{className:"p-3 bg-red-500/20 border border-red-500/50 rounded-lg text-sm text-red-400",children:M}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Name *"}),s.jsx("input",{type:"text",value:o,onChange:F=>l(F.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"})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"URL *"}),s.jsx("input",{type:"text",value:c,onChange:F=>u(F.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"})]}),s.jsxs("div",{className:"space-y-3",children:[s.jsx("label",{className:"block text-sm text-bambu-gray",children:"Icon"}),s.jsxs("div",{className:"p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary",children:[s.jsxs("div",{className:"flex items-center justify-between mb-2",children:[s.jsx("span",{className:"text-sm text-white",children:"Custom Icon"}),s.jsx("input",{ref:a,type:"file",accept:"image/png,image/jpeg,image/gif,image/svg+xml,image/webp,image/x-icon",className:"hidden",onChange:k}),m&&x?s.jsxs("div",{className:"flex items-center gap-2",children:[s.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"}`}),s.jsx("button",{type:"button",onClick:C,className:"p-1 text-red-400 hover:text-red-300 transition-colors",title:"Remove custom icon",children:s.jsx(an,{className:"w-4 h-4"})})]}):s.jsxs(Se,{type:"button",variant:"secondary",size:"sm",onClick:()=>a.current?.click(),children:[s.jsx(bi,{className:"w-4 h-4"}),"Upload"]})]}),s.jsx("p",{className:"text-xs text-bambu-gray",children:"PNG, JPG, GIF, SVG, WebP, or ICO. Max 1MB."})]}),!m&&s.jsxs("div",{children:[s.jsx("span",{className:"text-sm text-bambu-gray block mb-2",children:"Or choose a preset icon"}),s.jsx(nfe,{value:d,onChange:f})]})]}),s.jsxs("div",{className:"flex gap-3 pt-2",children:[s.jsx(Se,{type:"button",variant:"secondary",onClick:e,className:"flex-1",children:"Cancel"}),s.jsxs(Se,{type:"submit",disabled:T,className:"flex-1",children:[T?s.jsx(mt,{className:"w-4 h-4 animate-spin"}):s.jsx(ds,{className:"w-4 h-4"}),i?"Save":"Add"]})]})]})]})})}function Xqe(){const t=tn(),[e,n]=w.useState(!1),[r,i]=w.useState(null),[a,o]=w.useState(null),[l,c]=w.useState(null),{data:u,isLoading:d}=ct({queryKey:["external-links"],queryFn:pe.getExternalLinks}),f=ft({mutationFn:M=>pe.deleteExternalLink(M),onSuccess:()=>{t.invalidateQueries({queryKey:["external-links"]})}}),m=ft({mutationFn:M=>pe.reorderExternalLinks(M),onSuccess:()=>{t.invalidateQueries({queryKey:["external-links"]})}}),g=(M,S)=>{c(S),M.dataTransfer.effectAllowed="move"},x=M=>{M.preventDefault(),M.dataTransfer.dropEffect="move"},y=(M,S)=>{if(M.preventDefault(),l===null||l===S||!u)return;const A=u.map(R=>R.id),E=A.indexOf(l),k=A.indexOf(S);if(E===-1||k===-1)return;const C=[...A];C.splice(E,1),C.splice(k,0,l),m.mutate(C),c(null)},b=M=>{o(M)},v=()=>{a&&(f.mutate(a.id),o(null))};return s.jsxs(s.Fragment,{children:[s.jsxs(Mt,{children:[s.jsx(mr,{children:s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(kl,{className:"w-5 h-5 text-bambu-green"}),s.jsx("h2",{className:"text-lg font-semibold text-white",children:"Sidebar Links"})]}),s.jsxs(Se,{size:"sm",onClick:()=>n(!0),children:[s.jsx(Kn,{className:"w-4 h-4"}),"Add Link"]})]})}),s.jsxs(Et,{children:[s.jsx("p",{className:"text-sm text-bambu-gray mb-4",children:"Add external links to the sidebar navigation. Drag to reorder."}),d?s.jsx("div",{className:"flex justify-center py-8",children:s.jsx(mt,{className:"w-6 h-6 text-bambu-green animate-spin"})}):u&&u.length>0?s.jsx("div",{className:"space-y-2",children:u.map(M=>{const S=z2(M.icon);return s.jsxs("div",{draggable:!0,onDragStart:A=>g(A,M.id),onDragOver:x,onDrop:A=>y(A,M.id),className:`flex items-center gap-3 p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary transition-colors ${l===M.id?"opacity-50":""}`,children:[s.jsx(Qp,{className:"w-6 h-6 md:w-4 md:h-4 text-bambu-gray cursor-grab flex-shrink-0"}),s.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark-tertiary text-bambu-gray",children:s.jsx(S,{className:"w-4 h-4"})}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"text-white font-medium truncate",children:M.name}),s.jsx(Lr,{className:"w-3 h-3 text-bambu-gray flex-shrink-0"})]}),s.jsx("span",{className:"text-sm text-bambu-gray truncate block",children:M.url})]}),s.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[s.jsx("button",{onClick:()=>i(M),className:"p-2 rounded-lg hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white transition-colors",title:"Edit",children:s.jsx(Ga,{className:"w-4 h-4"})}),s.jsx("button",{onClick:()=>b(M),disabled:f.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:s.jsx(an,{className:"w-4 h-4"})})]})]},M.id)})}):s.jsxs("div",{className:"text-center py-8 text-bambu-gray",children:[s.jsx(kl,{className:"w-8 h-8 mx-auto mb-2 opacity-50"}),s.jsx("p",{children:"No external links configured"}),s.jsx("p",{className:"text-sm",children:'Click "Add Link" to add one'})]})]})]}),(e||r)&&s.jsx(Kqe,{link:r,onClose:()=>{n(!1),i(null)}}),a&&s.jsx(Ln,{title:"Delete Link",message:`Are you sure you want to delete "${a.name}"? This action cannot be undone.`,confirmText:"Delete",cancelText:"Cancel",variant:"danger",onConfirm:v,onCancel:()=>o(null)})]})}function Yqe(){const t=tn(),{showToast:e}=$n(),[n,r]=w.useState(!1),[i,a]=w.useState(""),[o,l]=w.useState("immediate"),[c,u]=w.useState("3DPrinter-X1-Carbon"),[d,f]=w.useState(!1),[m,g]=w.useState(null),{data:x,isLoading:y}=ct({queryKey:["virtual-printer-settings"],queryFn:R1.getSettings,refetchInterval:1e4}),{data:b}=ct({queryKey:["virtual-printer-models"],queryFn:R1.getModels});w.useEffect(()=>{if(x){r(x.enabled);let R=x.mode==="queue"?"review":x.mode;R!=="immediate"&&R!=="review"&&R!=="print_queue"&&(R="immediate"),l(R),u(x.model)}},[x]);const v=ft({mutationFn:R=>R1.updateSettings(R),onSuccess:()=>{t.invalidateQueries({queryKey:["virtual-printer-settings"]}),e("Virtual printer settings updated"),g(null)},onError:R=>{if(e(R.message||"Failed to update settings","error"),x){r(x.enabled);const T=x.mode==="queue"?"review":x.mode;l(T==="print_queue"||T==="review"?T:"immediate"),u(x.model)}g(null)}}),M=()=>{const R=!n;if(R&&!i&&!x?.access_code_set){e("Please set an access code first","error");return}r(R),g("toggle"),v.mutate({enabled:R,access_code:i||void 0,mode:o})},S=()=>{if(!i){e("Access code cannot be empty","error");return}if(i.length!==8){e("Access code must be exactly 8 characters","error");return}g("accessCode"),v.mutate({access_code:i}),a("")},A=R=>{l(R),g("mode"),v.mutate({mode:R})},E=R=>{u(R),g("model"),v.mutate({model:R})};if(y)return s.jsx(Mt,{children:s.jsx(Et,{className:"py-8 flex justify-center",children:s.jsx(mt,{className:"w-6 h-6 animate-spin text-bambu-green"})})});const k=x?.status,C=k?.running||!1;return s.jsxs("div",{className:"flex flex-col lg:flex-row gap-6 lg:gap-8",children:[s.jsx("div",{className:"space-y-6 lg:w-[480px] lg:flex-shrink-0",children:s.jsxs(Mt,{children:[s.jsx(mr,{children:s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Ir,{className:"w-5 h-5 text-bambu-green"}),s.jsx("h2",{className:"text-lg font-semibold text-white",children:"Virtual Printer"})]}),k&&s.jsxs("div",{className:`flex items-center gap-2 text-sm ${C?"text-green-400":"text-bambu-gray"}`,children:[s.jsx("span",{className:`w-2 h-2 rounded-full ${C?"bg-green-400 animate-pulse":"bg-gray-500"}`}),C?"Running":"Stopped"]})]})}),s.jsxs(Et,{className:"space-y-4",children:[s.jsx("p",{className:"text-sm text-bambu-gray",children:"Enable a virtual printer that appears in Bambu Studio and OrcaSlicer. Files sent to this printer will be archived directly without printing."}),s.jsxs("div",{className:"flex items-center justify-between py-3 border-t border-bambu-dark-tertiary",children:[s.jsxs("div",{children:[s.jsx("div",{className:"text-white font-medium",children:"Enable Virtual Printer"}),s.jsx("div",{className:"text-sm text-bambu-gray",children:C?'Visible as "Bambuddy" in slicer discovery':"Not visible to slicers"})]}),s.jsx("button",{onClick:M,disabled:m==="toggle",className:`relative w-12 h-6 rounded-full transition-colors ${n?"bg-bambu-green":"bg-bambu-dark-tertiary"} ${m==="toggle"?"opacity-50":""}`,children:s.jsx("span",{className:`absolute top-1 left-1 w-4 h-4 bg-white rounded-full transition-transform ${n?"translate-x-6":""}`})})]}),s.jsxs("div",{className:"py-3 border-t border-bambu-dark-tertiary",children:[s.jsx("div",{className:"text-white font-medium mb-2",children:"Printer Model"}),s.jsx("div",{className:"text-sm text-bambu-gray mb-3",children:"Select which printer model to emulate."}),s.jsxs("div",{className:"relative",children:[s.jsx("select",{value:c,onChange:R=>E(R.target.value),disabled:m==="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:b?.models&&Object.entries(b.models).sort(([,R],[,T])=>R.localeCompare(T)).map(([R,T])=>s.jsx("option",{value:R,children:T},R))}),s.jsx(Ji,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}),n&&C&&s.jsxs("p",{className:"text-xs text-bambu-gray mt-2",children:[s.jsx(tl,{className:"w-3 h-3 inline mr-1"}),"Changing the model will restart the virtual printer"]})]}),s.jsxs("div",{className:"py-3 border-t border-bambu-dark-tertiary",children:[s.jsx("div",{className:"text-white font-medium mb-2",children:"Access Code"}),s.jsx("div",{className:"text-sm text-bambu-gray mb-3",children:x?.access_code_set?s.jsxs("span",{className:"flex items-center gap-1 text-green-400",children:[s.jsx(xs,{className:"w-4 h-4"}),"Access code is set"]}):s.jsxs("span",{className:"flex items-center gap-1 text-yellow-400",children:[s.jsx(Cn,{className:"w-4 h-4"}),"No access code set - required to enable"]})}),s.jsxs("div",{className:"flex gap-2",children:[s.jsxs("div",{className:"relative flex-1",children:[s.jsx("input",{type:d?"text":"password",value:i,onChange:R=>a(R.target.value),placeholder:x?.access_code_set?"Enter new code to change":"Enter 8-char code",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"}),s.jsx("button",{onClick:()=>f(!d),className:"absolute right-2 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white",children:d?s.jsx(T2,{className:"w-4 h-4"}):s.jsx(_f,{className:"w-4 h-4"})})]}),s.jsx(Se,{onClick:S,disabled:!i||m==="accessCode",variant:"primary",children:m==="accessCode"?s.jsx(mt,{className:"w-4 h-4 animate-spin"}):"Save"})]}),s.jsxs("p",{className:"text-xs text-bambu-gray mt-2",children:["Must be exactly 8 characters. Used by slicers to authenticate.",i&&s.jsxs("span",{className:i.length===8?"text-green-400":"text-yellow-400",children:[" ","(",i.length,"/8)"]})]})]}),s.jsxs("div",{className:"py-3 border-t border-bambu-dark-tertiary",children:[s.jsx("div",{className:"text-white font-medium mb-2",children:"Mode"}),s.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[s.jsxs("button",{onClick:()=>A("immediate"),disabled:m==="mode",className:`p-3 rounded-lg border text-left transition-colors ${o==="immediate"?"border-bambu-green bg-bambu-green/10":"border-bambu-dark-tertiary hover:border-bambu-gray"}`,children:[s.jsx("div",{className:"text-white font-medium",children:"Archive"}),s.jsx("div",{className:"text-xs text-bambu-gray",children:"Archive files immediately"})]}),s.jsxs("button",{onClick:()=>A("review"),disabled:m==="mode",className:`p-3 rounded-lg border text-left transition-colors ${o==="review"?"border-bambu-green bg-bambu-green/10":"border-bambu-dark-tertiary hover:border-bambu-gray"}`,children:[s.jsx("div",{className:"text-white font-medium",children:"Review"}),s.jsx("div",{className:"text-xs text-bambu-gray",children:"Review and tag before archiving"})]}),s.jsxs("button",{onClick:()=>A("print_queue"),disabled:m==="mode",className:`p-3 rounded-lg border text-left transition-colors ${o==="print_queue"?"border-bambu-green bg-bambu-green/10":"border-bambu-dark-tertiary hover:border-bambu-gray"}`,children:[s.jsx("div",{className:"text-white font-medium",children:"Queue"}),s.jsx("div",{className:"text-xs text-bambu-gray",children:"Archive and add to print queue"})]})]})]})]})]})}),s.jsxs("div",{className:"space-y-6 lg:w-[480px] lg:flex-shrink-0",children:[s.jsx(Mt,{className:"border-l-4 border-l-yellow-500",children:s.jsx(Et,{className:"py-4",children:s.jsxs("div",{className:"flex items-start gap-3",children:[s.jsx(Cn,{className:"w-5 h-5 text-yellow-500 flex-shrink-0 mt-0.5"}),s.jsxs("div",{className:"text-sm",children:[s.jsx("p",{className:"text-white font-medium mb-2",children:"Setup Required"}),s.jsx("p",{className:"text-bambu-gray mb-3",children:"The virtual printer feature requires additional system configuration before it will work. This includes port forwarding, firewall rules, and platform-specific settings."}),s.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:[s.jsx(Lr,{className:"w-4 h-4"}),"Read the setup guide before enabling"]})]})]})})}),s.jsx(Mt,{children:s.jsx(Et,{className:"py-4",children:s.jsxs("div",{className:"flex items-start gap-3",children:[s.jsx(tl,{className:"w-5 h-5 text-blue-400 flex-shrink-0 mt-0.5"}),s.jsxs("div",{className:"text-sm text-bambu-gray",children:[s.jsx("p",{className:"mb-2",children:s.jsx("strong",{className:"text-white",children:"How it works:"})}),s.jsxs("ol",{className:"list-decimal list-inside space-y-1",children:[s.jsx("li",{children:"Complete the setup guide for your platform"}),s.jsx("li",{children:"Enable the virtual printer and set an access code"}),s.jsx("li",{children:'In Bambu Studio or OrcaSlicer, go to "Add Printer"'}),s.jsx("li",{children:'The "Bambuddy" printer should appear in the discovery list'}),s.jsx("li",{children:"Connect using the access code you set"}),s.jsx("li",{children:'When you "print" to Bambuddy, the 3MF file is archived instead'})]})]})]})})}),k&&C&&s.jsxs(Mt,{children:[s.jsx(mr,{children:s.jsx("h3",{className:"text-md font-semibold text-white",children:"Status Details"})}),s.jsx(Et,{children:s.jsxs("div",{className:"grid grid-cols-2 gap-4 text-sm",children:[s.jsxs("div",{children:[s.jsx("div",{className:"text-bambu-gray",children:"Printer Name"}),s.jsx("div",{className:"text-white",children:k.name})]}),s.jsxs("div",{children:[s.jsx("div",{className:"text-bambu-gray",children:"Model"}),s.jsx("div",{className:"text-white",children:k.model_name||k.model})]}),s.jsxs("div",{children:[s.jsx("div",{className:"text-bambu-gray",children:"Serial Number"}),s.jsx("div",{className:"text-white font-mono",children:k.serial})]}),s.jsxs("div",{children:[s.jsx("div",{className:"text-bambu-gray",children:"Mode"}),s.jsx("div",{className:"text-white capitalize",children:k.mode})]}),s.jsxs("div",{children:[s.jsx("div",{className:"text-bambu-gray",children:"Pending Files"}),s.jsx("div",{className:"text-white",children:k.pending_files})]})]})})]})]})]})}const Qqe={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 Zqe(t,e){const n=e.replace("#/","").split("/");let r=t;for(const i of n)r=r[i];return r}function Tb(t,e,n=0){if(n>5)return"...";if(e.$ref)return Tb(t,Zqe(t,e.$ref),n+1);if(e.allOf){const r={};for(const i of e.allOf){const a=Tb(t,i,n+1);typeof a=="object"&&a!==null&&Object.assign(r,a)}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?[Tb(t,e.items,n+1)]:[];case"object":if(e.properties){const r={};for(const[i,a]of Object.entries(e.properties))r[i]=Tb(t,a,n+1);return r}return{};default:return null}}function Jqe({path:t,method:e,spec:n,schema:r,apiKey:i}){const[a,o]=w.useState(!1),[l,c]=w.useState({}),[u,d]=w.useState(""),[f,m]=w.useState(null),[g,x]=w.useState(!1),[y,b]=w.useState(!1);w.useEffect(()=>{if(a&&n.parameters){const R={};for(const T of n.parameters)T.schema?.default!==void 0&&(R[T.name]=String(T.schema.default));c(T=>({...R,...T}))}},[a,n.parameters]),w.useEffect(()=>{if(a&&n.requestBody?.content?.["application/json"]?.schema&&!u){const R=n.requestBody.content["application/json"].schema,T=Tb(r,R);d(JSON.stringify(T,null,2))}},[a,n.requestBody,r,u]);const M=(()=>{const R=[];for(const T of n.parameters||[])if(T.in==="path"||T.required){const P=l[T.name];(P===void 0||P==="")&&R.push(T.name)}return R})(),S=async()=>{if(M.length>0){m({status:0,statusText:"Validation Error",headers:{},body:`Missing required parameters: ${M.join(", ")}`,duration:0});return}x(!0),m(null);try{let R=t;const T=new URLSearchParams;for(const oe of n.parameters||[]){const B=l[oe.name];B!==void 0&&B!==""&&(oe.in==="path"?R=R.replace(`{${oe.name}}`,encodeURIComponent(B)):oe.in==="query"&&T.append(oe.name,B))}const P=T.toString(),F=`${R}${P?`?${P}`:""}`,L={"Content-Type":"application/json"};i&&(L["X-API-Key"]=i);const X={method:e.toUpperCase(),headers:L};["post","put","patch"].includes(e)&&u&&(X.body=u);const D=performance.now(),K=await fetch(F,X),Y=Math.round(performance.now()-D),q={};K.headers.forEach((oe,B)=>{q[B]=oe});let Z;K.headers.get("content-type")?.includes("application/json")?Z=await K.json():Z=await K.text(),m({status:K.status,statusText:K.statusText,headers:q,body:Z,duration:Y})}catch(R){m({status:0,statusText:"Network Error",headers:{},body:R instanceof Error?R.message:"Unknown error",duration:0})}finally{x(!1)}},A=async()=>{if(f){const R=typeof f.body=="string"?f.body:JSON.stringify(f.body,null,2);try{await navigator.clipboard.writeText(R),b(!0),setTimeout(()=>b(!1),2e3)}catch{const T=document.createElement("textarea");T.value=R,T.style.position="fixed",T.style.left="-999999px",document.body.appendChild(T),T.select(),document.execCommand("copy"),document.body.removeChild(T),b(!0),setTimeout(()=>b(!1),2e3)}}},E=(n.parameters||[]).filter(R=>R.in==="path"),k=(n.parameters||[]).filter(R=>R.in==="query"),C=["post","put","patch"].includes(e)&&n.requestBody;return s.jsxs("div",{className:"border border-bambu-dark-tertiary rounded-lg overflow-hidden",children:[s.jsxs("button",{onClick:()=>o(!a),className:"w-full flex items-center gap-3 p-3 hover:bg-bambu-dark-tertiary/50 transition-colors text-left",children:[a?s.jsx(Ji,{className:"w-4 h-4 text-bambu-gray flex-shrink-0"}):s.jsx(Gs,{className:"w-4 h-4 text-bambu-gray flex-shrink-0"}),s.jsx("span",{className:`px-2 py-0.5 text-xs font-mono font-semibold uppercase rounded border ${Qqe[e]||"bg-gray-500/20 text-gray-400"}`,children:e}),s.jsx("code",{className:"text-sm text-white font-mono flex-1 truncate",children:t}),n.summary&&s.jsx("span",{className:"text-sm text-bambu-gray truncate max-w-[40%]",children:n.summary})]}),a&&s.jsxs("div",{className:"border-t border-bambu-dark-tertiary p-4 space-y-4 bg-bambu-dark/50",children:[n.description&&s.jsx("p",{className:"text-sm text-bambu-gray",children:n.description}),E.length>0&&s.jsxs("div",{className:"space-y-2",children:[s.jsx("h4",{className:"text-sm font-medium text-white",children:"Path Parameters"}),s.jsx("div",{className:"space-y-2",children:E.map(R=>s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs("label",{className:"text-sm text-bambu-gray w-32 flex-shrink-0",children:[R.name,R.required&&s.jsx("span",{className:"text-red-400 ml-1",children:"*"})]}),s.jsx("input",{type:"text",value:l[R.name]||"",onChange:T=>c(P=>({...P,[R.name]:T.target.value})),placeholder:R.description||R.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"})]},R.name))})]}),k.length>0&&s.jsxs("div",{className:"space-y-2",children:[s.jsx("h4",{className:"text-sm font-medium text-white",children:"Query Parameters"}),s.jsx("div",{className:"space-y-2",children:k.map(R=>s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs("label",{className:"text-sm text-bambu-gray w-32 flex-shrink-0",children:[R.name,R.required&&s.jsx("span",{className:"text-red-400 ml-1",children:"*"})]}),R.schema?.enum?s.jsxs("select",{value:l[R.name]||"",onChange:T=>c(P=>({...P,[R.name]:T.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:[s.jsx("option",{value:"",children:"-- Select --"}),R.schema.enum.map(T=>s.jsx("option",{value:T,children:T},T))]}):s.jsx("input",{type:"text",value:l[R.name]||"",onChange:T=>c(P=>({...P,[R.name]:T.target.value})),placeholder:R.description||R.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"})]},R.name))})]}),C&&s.jsxs("div",{className:"space-y-2",children:[s.jsx("h4",{className:"text-sm font-medium text-white",children:"Request Body"}),s.jsx("textarea",{value:u,onChange:R=>d(R.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..."})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs(Se,{onClick:S,disabled:g,children:[g?s.jsx(mt,{className:"w-4 h-4 animate-spin"}):s.jsx(rl,{className:"w-4 h-4"}),"Execute"]}),M.length>0&&s.jsxs("span",{className:"text-xs text-yellow-400 flex items-center gap-1",children:[s.jsx(ea,{className:"w-3 h-3"}),"Fill in: ",M.join(", ")]})]}),f&&s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("h4",{className:"text-sm font-medium text-white flex items-center gap-2",children:["Response",s.jsxs("span",{className:`px-2 py-0.5 text-xs rounded ${f.status>=200&&f.status<300?"bg-green-500/20 text-green-400":f.status>=400?"bg-red-500/20 text-red-400":"bg-yellow-500/20 text-yellow-400"}`,children:[f.status," ",f.statusText]}),s.jsxs("span",{className:"text-xs text-bambu-gray",children:[f.duration,"ms"]})]}),s.jsx(Se,{variant:"secondary",size:"sm",onClick:A,children:y?s.jsx(Dn,{className:"w-3 h-3 text-green-400"}):s.jsx(Jo,{className:"w-3 h-3"})})]}),s.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 f.body=="string"?f.body:JSON.stringify(f.body,null,2)})]})]})]})}function eKe({apiKey:t=""}){const[e,n]=w.useState(null),[r,i]=w.useState(!0),[a,o]=w.useState(null),[l,c]=w.useState(new Set),[u,d]=w.useState("");if(w.useEffect(()=>{async function b(){try{const v=await fetch("/openapi.json");if(!v.ok)throw new Error("Failed to fetch OpenAPI schema");const M=await v.json();n(M)}catch(v){o(v instanceof Error?v.message:"Unknown error")}finally{i(!1)}}b()},[]),r)return s.jsx("div",{className:"flex justify-center py-12",children:s.jsx(mt,{className:"w-8 h-8 text-bambu-green animate-spin"})});if(a||!e)return s.jsx(Mt,{children:s.jsx(Et,{className:"py-8",children:s.jsxs("div",{className:"text-center text-red-400",children:[s.jsx(ea,{className:"w-12 h-12 mx-auto mb-3 opacity-50"}),s.jsx("p",{children:"Failed to load API schema"}),s.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:a})]})})});const f={};for(const[b,v]of Object.entries(e.paths))for(const[M,S]of Object.entries(v)){if(M==="parameters")continue;const A=S.tags||["Other"];for(const E of A)f[E]||(f[E]=[]),f[E].push({path:b,method:M,spec:S})}const m=Object.entries(f).map(([b,v])=>{if(!u)return{tag:b,endpoints:v};const M=v.filter(({path:S,method:A,spec:E})=>{const k=u.toLowerCase();return S.toLowerCase().includes(k)||A.toLowerCase().includes(k)||(E.summary?.toLowerCase()||"").includes(k)||(E.description?.toLowerCase()||"").includes(k)});return{tag:b,endpoints:M}}).filter(({endpoints:b})=>b.length>0).sort((b,v)=>b.tag.localeCompare(v.tag)),g=b=>{c(v=>{const M=new Set(v);return M.has(b)?M.delete(b):M.add(b),M})},x=()=>{c(new Set(m.map(b=>b.tag)))},y=()=>{c(new Set)};return s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{className:"flex items-center justify-between gap-4",children:[s.jsx("div",{className:"flex-1",children:s.jsx("input",{type:"text",value:u,onChange:b=>d(b.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"})}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Se,{variant:"secondary",size:"sm",onClick:x,children:"Expand All"}),s.jsx(Se,{variant:"secondary",size:"sm",onClick:y,children:"Collapse All"}),s.jsxs("a",{href:"/docs",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1 text-sm text-bambu-green hover:underline",children:[s.jsx(Lr,{className:"w-4 h-4"}),"Swagger UI"]})]})]}),s.jsxs("p",{className:"text-sm text-bambu-gray",children:[m.reduce((b,v)=>b+v.endpoints.length,0)," endpoints in ",m.length," categories"]}),s.jsx("div",{className:"space-y-3",children:m.map(({tag:b,endpoints:v})=>s.jsxs(Mt,{children:[s.jsx("button",{onClick:()=>g(b),className:"w-full flex items-center justify-between p-4 hover:bg-bambu-dark-tertiary/30 transition-colors text-left",children:s.jsxs("div",{className:"flex items-center gap-2",children:[l.has(b)?s.jsx(Ji,{className:"w-5 h-5 text-bambu-gray"}):s.jsx(Gs,{className:"w-5 h-5 text-bambu-gray"}),s.jsx("h3",{className:"text-base font-semibold text-white capitalize",children:b.replace(/-/g," ")}),s.jsx("span",{className:"text-xs bg-bambu-dark-tertiary px-2 py-0.5 rounded-full text-bambu-gray",children:v.length})]})}),l.has(b)&&s.jsx(Et,{className:"pt-0 space-y-2",children:v.map(({path:M,method:S,spec:A})=>s.jsx(Jqe,{path:M,method:S,spec:A,schema:e,apiKey:t},`${S}-${M}`))})]},b))})]})}const tKe=["general","network","plugs","notifications","filament","apikeys","virtual-printer","users"];function nKe(){const t=tn(),e=ol(),[n,r]=wW(),{t:i,i18n:a}=Tg(),{showToast:o,showPersistentToast:l,dismissToast:c}=$n(),{authEnabled:u,user:d,refreshAuth:f}=Yd(),{mode:m,darkStyle:g,darkBackground:x,darkAccent:y,lightStyle:b,lightBackground:v,lightAccent:M,setDarkStyle:S,setDarkBackground:A,setDarkAccent:E,setLightStyle:k,setLightBackground:C,setLightAccent:R}=Xd(),[T,P]=w.useState(null),[F,L]=w.useState(!1),[X,D]=w.useState(null),[K,Y]=w.useState(!1),[q,Z]=w.useState(null),[re,oe]=w.useState(null),[B,G]=w.useState(!1),[J,te]=w.useState(dq()),ae=n.get("tab"),de=ae&&tKe.includes(ae)?ae:"general",[fe,Ae]=w.useState(de),ge=xe=>{Ae(xe),xe==="general"?n.delete("tab"):n.set("tab",xe),r(n,{replace:!0})},[Me,je]=w.useState(!1),[ne,Ke]=w.useState(""),[$,z]=w.useState({can_queue:!0,can_control_printer:!1,can_read_status:!0}),[W,U]=w.useState(null),[V,Q]=w.useState(null),[Ee,Ce]=w.useState(""),[Ne,H]=w.useState(!1),[O,ie]=w.useState(!1),[ye,_e]=w.useState(null),[le,ke]=w.useState(!1),[Oe,Ze]=w.useState(!1),[ht,We]=w.useState(!1),[he,rt]=w.useState(!1),[qe,Je]=w.useState(!1),[ot,se]=w.useState(null),[$e,be]=w.useState(!1),Fe=xe=>{te(xe),sfe(xe)},De=()=>{localStorage.removeItem("sidebarOrder"),window.location.reload()},{data:ve,isLoading:He}=ct({queryKey:["settings"],queryFn:pe.getSettings}),{data:dt,isLoading:kt}=ct({queryKey:["smart-plugs"],queryFn:pe.getSmartPlugs}),{data:jt,isLoading:Zt}=ct({queryKey:["smart-plugs-energy",dt?.map(xe=>xe.id)],queryFn:async()=>{if(!dt||dt.length===0)return null;const xe=await Promise.all(dt.filter(Gt=>Gt.enabled).map(async Gt=>{try{const Wt=await pe.getSmartPlugStatus(Gt.id);return{plug:Gt,status:Wt}}catch{return{plug:Gt,status:null}}}));let st=0,Ht=0,It=0,on=0,un=0;for(const{status:Gt}of xe)Gt?.reachable&&Gt.energy&&(un++,Gt.energy.power!=null&&(st+=Gt.energy.power),Gt.energy.today!=null&&(Ht+=Gt.energy.today),Gt.energy.yesterday!=null&&(It+=Gt.energy.yesterday),Gt.energy.total!=null&&(on+=Gt.energy.total));return{totalPower:st,totalToday:Ht,totalYesterday:It,totalLifetime:on,reachableCount:un,totalPlugs:dt.filter(Gt=>Gt.enabled).length}},enabled:fe==="plugs"&&!!dt&&dt.length>0,refetchInterval:fe==="plugs"?1e4:!1}),{data:Rt,isLoading:nn}=ct({queryKey:["notification-providers"],queryFn:pe.getNotificationProviders}),{data:pt,isLoading:$t}=ct({queryKey:["api-keys"],queryFn:pe.getAPIKeys}),qt=ft({mutationFn:xe=>pe.createAPIKey(xe),onSuccess:xe=>{U(xe.key||null),je(!1),Ke(""),t.invalidateQueries({queryKey:["api-keys"]}),o("API key created")},onError:xe=>{o(`Failed to create API key: ${xe.message}`,"error")}}),wt=ft({mutationFn:xe=>pe.deleteAPIKey(xe),onSuccess:()=>{t.invalidateQueries({queryKey:["api-keys"]}),o("API key deleted")},onError:xe=>{o(`Failed to delete API key: ${xe.message}`,"error")}}),{data:_r}=ct({queryKey:["printers"],queryFn:pe.getPrinters}),{data:$r,isLoading:Tr}=ct({queryKey:["notification-templates"],queryFn:pe.getNotificationTemplates}),{data:hr}=ct({queryKey:["virtual-printer-settings"],queryFn:R1.getSettings,refetchInterval:1e4}),yt=hr?.status?.running??!1,{data:en}=ct({queryKey:["ffmpeg-status"],queryFn:pe.checkFfmpeg}),{data:wn}=ct({queryKey:["version"],queryFn:pe.getVersion}),{data:ue,refetch:Be,isRefetching:Ye}=ct({queryKey:["updateCheck"],queryFn:pe.checkForUpdates,staleTime:300*1e3}),{data:Xe,refetch:Qe}=ct({queryKey:["updateStatus"],queryFn:pe.getUpdateStatus,refetchInterval:xe=>{const st=xe.state.data;return st?.status==="downloading"||st?.status==="installing"?1e3:!1}}),{data:At}=ct({queryKey:["mqtt-status"],queryFn:pe.getMQTTStatus,refetchInterval:fe==="network"?5e3:!1}),ce=ft({mutationFn:pe.applyUpdate,onSuccess:xe=>{xe.is_docker?o(xe.message,"error"):Qe()}}),[we,Ie]=w.useState(null),Le=ft({mutationFn:pe.testAllNotificationProviders,onSuccess:xe=>{Ie(xe),t.invalidateQueries({queryKey:["notification-providers"]}),xe.failed===0?o(`All ${xe.tested} providers tested successfully!`,"success"):o(`${xe.success}/${xe.tested} providers succeeded`,xe.failed>0?"error":"success")},onError:xe=>{o(`Failed to test providers: ${xe.message}`,"error")}}),Re=ft({mutationFn:async xe=>{if(!dt)return{success:0,failed:0};const st=dt.filter(It=>It.enabled),Ht=await Promise.all(st.map(async It=>{try{return await pe.controlSmartPlug(It.id,xe),{success:!0}}catch{return{success:!1}}}));return{success:Ht.filter(It=>It.success).length,failed:Ht.filter(It=>!It.success).length}},onSuccess:(xe,st)=>{t.invalidateQueries({queryKey:["smart-plugs"]}),t.invalidateQueries({queryKey:["smart-plugs-energy"]}),xe.failed===0?o(`All ${xe.success} plugs turned ${st}`,"success"):o(`${xe.success} plugs turned ${st}, ${xe.failed} failed`,"error")},onError:xe=>{o(`Failed: ${xe.message}`,"error")}}),ut=w.useRef(null),_t=w.useRef(!1),Tt=w.useRef(!0);w.useEffect(()=>{if(ve&&!T){const xe={...ve,external_url:ve.external_url||window.location.origin};P(xe),setTimeout(()=>{Tt.current=!1},100)}},[ve,T]);const St=ft({mutationFn:pe.updateSettings,onSuccess:xe=>{t.setQueryData(["settings"],xe),P(xe),t.invalidateQueries({queryKey:["archiveStats"]}),o("Settings saved","success")},onError:xe=>{o(`Failed to save: ${xe.message}`,"error")},onSettled:()=>{_t.current=!1}});w.useEffect(()=>{if(!(Tt.current||!T||!ve||!(ve.auto_archive!==T.auto_archive||ve.save_thumbnails!==T.save_thumbnails||ve.capture_finish_photo!==T.capture_finish_photo||ve.default_filament_cost!==T.default_filament_cost||ve.currency!==T.currency||ve.energy_cost_per_kwh!==T.energy_cost_per_kwh||ve.energy_tracking_mode!==T.energy_tracking_mode||ve.check_updates!==T.check_updates||ve.notification_language!==T.notification_language||ve.telemetry_enabled!==T.telemetry_enabled||ve.ams_humidity_good!==T.ams_humidity_good||ve.ams_humidity_fair!==T.ams_humidity_fair||ve.ams_temp_good!==T.ams_temp_good||ve.ams_temp_fair!==T.ams_temp_fair||ve.ams_history_retention_days!==T.ams_history_retention_days||ve.per_printer_mapping_expanded!==T.per_printer_mapping_expanded||ve.date_format!==T.date_format||ve.time_format!==T.time_format||ve.default_printer_id!==T.default_printer_id||ve.ftp_retry_enabled!==T.ftp_retry_enabled||ve.ftp_retry_count!==T.ftp_retry_count||ve.ftp_retry_delay!==T.ftp_retry_delay||ve.ftp_timeout!==T.ftp_timeout||ve.mqtt_enabled!==T.mqtt_enabled||ve.mqtt_broker!==T.mqtt_broker||ve.mqtt_port!==T.mqtt_port||ve.mqtt_username!==T.mqtt_username||ve.mqtt_password!==T.mqtt_password||ve.mqtt_topic_prefix!==T.mqtt_topic_prefix||ve.mqtt_use_tls!==T.mqtt_use_tls||ve.external_url!==T.external_url||ve.ha_enabled!==T.ha_enabled||ve.ha_url!==T.ha_url||ve.ha_token!==T.ha_token||(ve.library_archive_mode??"ask")!==(T.library_archive_mode??"ask")||Number(ve.library_disk_warning_gb??5)!==Number(T.library_disk_warning_gb??5)||(ve.camera_view_mode??"window")!==(T.camera_view_mode??"window")))&&!_t.current)return ut.current&&clearTimeout(ut.current),ut.current=setTimeout(()=>{if(_t.current)return;_t.current=!0;const st={auto_archive:T.auto_archive,save_thumbnails:T.save_thumbnails,capture_finish_photo:T.capture_finish_photo,default_filament_cost:T.default_filament_cost,currency:T.currency,energy_cost_per_kwh:T.energy_cost_per_kwh,energy_tracking_mode:T.energy_tracking_mode,check_updates:T.check_updates,notification_language:T.notification_language,telemetry_enabled:T.telemetry_enabled,ams_humidity_good:T.ams_humidity_good,ams_humidity_fair:T.ams_humidity_fair,ams_temp_good:T.ams_temp_good,ams_temp_fair:T.ams_temp_fair,ams_history_retention_days:T.ams_history_retention_days,per_printer_mapping_expanded:T.per_printer_mapping_expanded,date_format:T.date_format,time_format:T.time_format,default_printer_id:T.default_printer_id,ftp_retry_enabled:T.ftp_retry_enabled,ftp_retry_count:T.ftp_retry_count,ftp_retry_delay:T.ftp_retry_delay,ftp_timeout:T.ftp_timeout,mqtt_enabled:T.mqtt_enabled,mqtt_broker:T.mqtt_broker,mqtt_port:T.mqtt_port,mqtt_username:T.mqtt_username,mqtt_password:T.mqtt_password,mqtt_topic_prefix:T.mqtt_topic_prefix,mqtt_use_tls:T.mqtt_use_tls,external_url:T.external_url,ha_enabled:T.ha_enabled,ha_url:T.ha_url,ha_token:T.ha_token,library_archive_mode:T.library_archive_mode,library_disk_warning_gb:T.library_disk_warning_gb,camera_view_mode:T.camera_view_mode};St.mutate(st)},500),()=>{ut.current&&clearTimeout(ut.current)}},[T,ve,St]);const vt=w.useCallback((xe,st)=>{P(Ht=>Ht?{...Ht,[xe]:st}:null)},[]);return He||!T?s.jsx("div",{className:"p-4 md:p-8 flex justify-center",children:s.jsx(mt,{className:"w-8 h-8 text-bambu-green animate-spin"})}):s.jsxs("div",{className:"p-4 md:p-8",children:[s.jsxs("div",{className:"mb-8",children:[s.jsx("h1",{className:"text-2xl font-bold text-white",children:"Settings"}),s.jsx("p",{className:"text-bambu-gray",children:"Configure Bambuddy"})]}),s.jsxs("div",{className:"flex gap-1 mb-6 border-b border-bambu-dark-tertiary overflow-x-auto",children:[s.jsx("button",{onClick:()=>ge("general"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px ${fe==="general"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:"General"}),s.jsxs("button",{onClick:()=>ge("plugs"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${fe==="plugs"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[s.jsx(Us,{className:"w-4 h-4"}),"Smart Plugs",dt&&dt.length>0&&s.jsx("span",{className:"text-xs bg-bambu-dark-tertiary px-1.5 py-0.5 rounded-full",children:dt.length})]}),s.jsxs("button",{onClick:()=>ge("notifications"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${fe==="notifications"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[s.jsx(tf,{className:"w-4 h-4"}),"Notifications",Rt&&Rt.length>0&&s.jsx("span",{className:"text-xs bg-bambu-dark-tertiary px-1.5 py-0.5 rounded-full",children:Rt.length})]}),s.jsxs("button",{onClick:()=>ge("filament"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${fe==="filament"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[s.jsx(qce,{className:"w-4 h-4"}),"Filament"]}),s.jsxs("button",{onClick:()=>ge("network"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${fe==="network"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[s.jsx(Dp,{className:"w-4 h-4"}),"Network",s.jsx("span",{className:`w-2 h-2 rounded-full ${At?.enabled?"bg-green-400":"bg-gray-500"}`})]}),s.jsxs("button",{onClick:()=>ge("apikeys"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${fe==="apikeys"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[s.jsx(Gh,{className:"w-4 h-4"}),"API Keys",pt&&pt.length>0&&s.jsx("span",{className:"text-xs bg-bambu-dark-tertiary px-1.5 py-0.5 rounded-full",children:pt.length})]}),s.jsxs("button",{onClick:()=>ge("virtual-printer"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${fe==="virtual-printer"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[s.jsx(Ir,{className:"w-4 h-4"}),"Virtual Printer",s.jsx("span",{className:`w-2 h-2 rounded-full ${yt?"bg-green-400":"bg-gray-500"}`})]}),s.jsxs("button",{onClick:()=>ge("users"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${fe==="users"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[s.jsx(Wh,{className:"w-4 h-4"}),"Users",u&&s.jsx("span",{className:`w-2 h-2 rounded-full ${u?"bg-green-400":"bg-gray-500"}`})]})]}),fe==="general"&&s.jsxs("div",{className:"flex flex-col lg:flex-row gap-6 lg:gap-8",children:[s.jsxs("div",{className:"space-y-6 flex-1 lg:max-w-xl",children:[s.jsxs(Mt,{children:[s.jsx(mr,{children:s.jsx("h2",{className:"text-lg font-semibold text-white",children:i("settings.general")})}),s.jsxs(Et,{className:"space-y-4",children:[s.jsxs("div",{children:[s.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[s.jsx(Md,{className:"w-4 h-4 inline mr-1"}),i("settings.language")]}),s.jsx("select",{value:a.language,onChange:xe=>a.changeLanguage(xe.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:GU.map(xe=>s.jsxs("option",{value:xe.code,children:[xe.nativeName," (",xe.name,")"]},xe.code))}),s.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:i("settings.languageDescription")})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:i("settings.defaultView")}),s.jsx("select",{value:J,onChange:xe=>Fe(xe.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:s0.map(xe=>s.jsx("option",{value:xe.to,children:i(xe.labelKey)},xe.id))}),s.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:i("settings.defaultViewDescription")})]}),s.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Date Format"}),s.jsxs("select",{value:T.date_format||"system",onChange:xe=>vt("date_format",xe.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:[s.jsx("option",{value:"system",children:"System Default"}),s.jsx("option",{value:"us",children:"US (MM/DD/YYYY)"}),s.jsx("option",{value:"eu",children:"EU (DD/MM/YYYY)"}),s.jsx("option",{value:"iso",children:"ISO (YYYY-MM-DD)"})]})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Time Format"}),s.jsxs("select",{value:T.time_format||"system",onChange:xe=>vt("time_format",xe.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:[s.jsx("option",{value:"system",children:"System Default"}),s.jsx("option",{value:"12h",children:"12-hour (3:30 PM)"}),s.jsx("option",{value:"24h",children:"24-hour (15:30)"})]})]})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Default Printer"}),s.jsxs("select",{value:T.default_printer_id??"",onChange:xe=>vt("default_printer_id",xe.target.value?Number(xe.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:[s.jsx("option",{value:"",children:"No default (ask each time)"}),_r?.map(xe=>s.jsx("option",{value:xe.id,children:xe.name},xe.id))]}),s.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Pre-select this printer for uploads, reprints, and other operations."})]}),s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{children:[s.jsx("p",{className:"text-white",children:"Sidebar order"}),s.jsx("p",{className:"text-sm text-bambu-gray",children:"Drag items in the sidebar to reorder. Reset to default order here."})]}),s.jsxs(Se,{variant:"secondary",size:"sm",onClick:De,children:[s.jsx(Vf,{className:"w-4 h-4"}),"Reset"]})]})]})]}),s.jsxs(Mt,{children:[s.jsx(mr,{children:s.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[s.jsx(nD,{className:"w-5 h-5"}),"Appearance"]})}),s.jsxs(Et,{className:"space-y-6",children:[s.jsxs("div",{className:`space-y-3 p-4 rounded-lg border ${m==="dark"?"border-bambu-green bg-bambu-green/5":"border-bambu-dark-tertiary"}`,children:[s.jsxs("h3",{className:"text-sm font-medium text-white flex items-center gap-2",children:["Dark Mode",m==="dark"&&s.jsx("span",{className:"text-xs text-bambu-green",children:"(active)"})]}),s.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[s.jsxs("div",{children:[s.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Background"}),s.jsxs("select",{value:x,onChange:xe=>{A(xe.target.value),o("Settings saved","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:[s.jsx("option",{value:"neutral",children:"Neutral"}),s.jsx("option",{value:"warm",children:"Warm"}),s.jsx("option",{value:"cool",children:"Cool"}),s.jsx("option",{value:"oled",children:"OLED Black"}),s.jsx("option",{value:"slate",children:"Slate Blue"}),s.jsx("option",{value:"forest",children:"Forest Green"})]})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Accent"}),s.jsxs("select",{value:y,onChange:xe=>{E(xe.target.value),o("Settings saved","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:[s.jsx("option",{value:"green",children:"Green"}),s.jsx("option",{value:"teal",children:"Teal"}),s.jsx("option",{value:"blue",children:"Blue"}),s.jsx("option",{value:"orange",children:"Orange"}),s.jsx("option",{value:"purple",children:"Purple"}),s.jsx("option",{value:"red",children:"Red"})]})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Style"}),s.jsxs("select",{value:g,onChange:xe=>{S(xe.target.value),o("Settings saved","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:[s.jsx("option",{value:"classic",children:"Classic"}),s.jsx("option",{value:"glow",children:"Glow"}),s.jsx("option",{value:"vibrant",children:"Vibrant"})]})]})]})]}),s.jsxs("div",{className:`space-y-3 p-4 rounded-lg border ${m==="light"?"border-bambu-green bg-bambu-green/5":"border-bambu-dark-tertiary"}`,children:[s.jsxs("h3",{className:"text-sm font-medium text-white flex items-center gap-2",children:["Light Mode",m==="light"&&s.jsx("span",{className:"text-xs text-bambu-green",children:"(active)"})]}),s.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[s.jsxs("div",{children:[s.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Background"}),s.jsxs("select",{value:v,onChange:xe=>{C(xe.target.value),o("Settings saved","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:[s.jsx("option",{value:"neutral",children:"Neutral"}),s.jsx("option",{value:"warm",children:"Warm"}),s.jsx("option",{value:"cool",children:"Cool"})]})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Accent"}),s.jsxs("select",{value:M,onChange:xe=>{R(xe.target.value),o("Settings saved","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:[s.jsx("option",{value:"green",children:"Green"}),s.jsx("option",{value:"teal",children:"Teal"}),s.jsx("option",{value:"blue",children:"Blue"}),s.jsx("option",{value:"orange",children:"Orange"}),s.jsx("option",{value:"purple",children:"Purple"}),s.jsx("option",{value:"red",children:"Red"})]})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Style"}),s.jsxs("select",{value:b,onChange:xe=>{k(xe.target.value),o("Settings saved","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:[s.jsx("option",{value:"classic",children:"Classic"}),s.jsx("option",{value:"glow",children:"Glow"}),s.jsx("option",{value:"vibrant",children:"Vibrant"})]})]})]})]}),s.jsx("p",{className:"text-xs text-bambu-gray",children:"Toggle between dark and light mode using the sun/moon icon in the sidebar."})]})]}),s.jsxs(Mt,{children:[s.jsx(mr,{children:s.jsx("h2",{className:"text-lg font-semibold text-white",children:"Archive Settings"})}),s.jsxs(Et,{className:"space-y-4",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{children:[s.jsx("p",{className:"text-white",children:"Auto-archive prints"}),s.jsx("p",{className:"text-sm text-bambu-gray",children:"Automatically save 3MF files when prints complete"})]}),s.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[s.jsx("input",{type:"checkbox",checked:T.auto_archive,onChange:xe=>vt("auto_archive",xe.target.checked),className:"sr-only peer"}),s.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"})]})]}),s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{children:[s.jsx("p",{className:"text-white",children:"Save thumbnails"}),s.jsx("p",{className:"text-sm text-bambu-gray",children:"Extract and save preview images from 3MF files"})]}),s.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[s.jsx("input",{type:"checkbox",checked:T.save_thumbnails,onChange:xe=>vt("save_thumbnails",xe.target.checked),className:"sr-only peer"}),s.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"})]})]}),s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{children:[s.jsx("p",{className:"text-white",children:"Capture finish photo"}),s.jsx("p",{className:"text-sm text-bambu-gray",children:"Take a photo from printer camera when print completes"})]}),s.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[s.jsx("input",{type:"checkbox",checked:T.capture_finish_photo,onChange:xe=>vt("capture_finish_photo",xe.target.checked),className:"sr-only peer"}),s.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"})]})]}),T.capture_finish_photo&&en&&!en.installed&&s.jsxs("div",{className:"flex items-start gap-2 p-3 bg-yellow-500/10 border border-yellow-500/30 rounded-lg",children:[s.jsx(Cn,{className:"w-5 h-5 text-yellow-500 flex-shrink-0 mt-0.5"}),s.jsxs("div",{className:"text-sm",children:[s.jsx("p",{className:"text-yellow-500 font-medium",children:"ffmpeg not installed"}),s.jsxs("p",{className:"text-bambu-gray mt-1",children:["Camera capture requires ffmpeg. Install it via"," ",s.jsx("code",{className:"bg-bambu-dark-tertiary px-1 rounded",children:"brew install ffmpeg"})," (macOS) or"," ",s.jsx("code",{className:"bg-bambu-dark-tertiary px-1 rounded",children:"apt install ffmpeg"})," (Linux)."]})]})]})]})]})]}),s.jsxs("div",{className:"space-y-6 flex-1 lg:max-w-md",children:[s.jsxs(Mt,{children:[s.jsx(mr,{children:s.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[s.jsx(sD,{className:"w-5 h-5 text-bambu-green"}),"Camera"]})}),s.jsx(Et,{className:"space-y-4",children:s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Camera View Mode"}),s.jsxs("select",{value:T.camera_view_mode??"window",onChange:xe=>vt("camera_view_mode",xe.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:[s.jsx("option",{value:"window",children:"New Window"}),s.jsx("option",{value:"embedded",children:"Embedded Overlay"})]}),s.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:T.camera_view_mode==="embedded"?"Camera opens in a resizable overlay on the main screen":"Camera opens in a separate browser window"})]})})]}),s.jsxs(Mt,{children:[s.jsx(mr,{children:s.jsx("h2",{className:"text-lg font-semibold text-white",children:"Cost Tracking"})}),s.jsxs(Et,{className:"space-y-4",children:[s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Default filament cost (per kg)"}),s.jsx("input",{type:"number",step:"0.01",min:"0",value:T.default_filament_cost,onChange:xe=>vt("default_filament_cost",parseFloat(xe.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"})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Currency"}),s.jsxs("select",{value:T.currency,onChange:xe=>vt("currency",xe.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:[s.jsx("option",{value:"USD",children:"USD ($)"}),s.jsx("option",{value:"EUR",children:"EUR (€)"}),s.jsx("option",{value:"GBP",children:"GBP (£)"}),s.jsx("option",{value:"CHF",children:"CHF (Fr.)"}),s.jsx("option",{value:"JPY",children:"JPY (¥)"}),s.jsx("option",{value:"CNY",children:"CNY (¥)"}),s.jsx("option",{value:"CAD",children:"CAD ($)"}),s.jsx("option",{value:"AUD",children:"AUD ($)"})]})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Electricity cost per kWh"}),s.jsx("input",{type:"number",step:"0.01",min:"0",value:T.energy_cost_per_kwh,onChange:xe=>vt("energy_cost_per_kwh",parseFloat(xe.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"})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Energy display mode"}),s.jsxs("select",{value:T.energy_tracking_mode||"total",onChange:xe=>vt("energy_tracking_mode",xe.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:[s.jsx("option",{value:"print",children:"Prints Only"}),s.jsx("option",{value:"total",children:"Total Consumption"})]}),s.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:T.energy_tracking_mode==="print"?"Dashboard shows sum of energy used during prints":"Dashboard shows lifetime energy from smart plugs"})]})]})]}),s.jsxs(Mt,{children:[s.jsx(mr,{children:s.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[s.jsx(za,{className:"w-5 h-5 text-bambu-green"}),"File Manager"]})}),s.jsxs(Et,{className:"space-y-4",children:[s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Create Archive Entry When Printing"}),s.jsxs("select",{value:T.library_archive_mode??"ask",onChange:xe=>vt("library_archive_mode",xe.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:[s.jsx("option",{value:"always",children:"Always create archive entry"}),s.jsx("option",{value:"never",children:"Never create archive entry"}),s.jsx("option",{value:"ask",children:"Ask each time"})]}),s.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"When printing from File Manager, optionally create an archive entry"})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Low Disk Space Warning"}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("input",{type:"number",min:"0.5",max:"100",step:"0.5",value:T.library_disk_warning_gb??5,onChange:xe=>vt("library_disk_warning_gb",parseFloat(xe.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"}),s.jsx("span",{className:"text-bambu-gray",children:"GB"})]}),s.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Show warning when free disk space falls below this threshold"})]})]})]})]}),s.jsxs("div",{className:"space-y-6 flex-1 lg:max-w-sm",children:[s.jsx(Xqe,{}),s.jsxs(Mt,{children:[s.jsx(mr,{children:s.jsx("h2",{className:"text-lg font-semibold text-white",children:"Updates"})}),s.jsxs(Et,{className:"space-y-4",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{children:[s.jsx("p",{className:"text-white",children:"Check for updates"}),s.jsx("p",{className:"text-sm text-bambu-gray",children:"Automatically check for new versions on startup"})]}),s.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[s.jsx("input",{type:"checkbox",checked:T.check_updates,onChange:xe=>vt("check_updates",xe.target.checked),className:"sr-only peer"}),s.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"})]})]}),s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("p",{className:"text-white",children:i("settings.telemetry")}),s.jsxs("button",{onClick:()=>We(!0),className:"inline-flex items-center gap-1 px-2 py-0.5 text-xs bg-bambu-dark rounded-full text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary transition-colors",children:[s.jsx(tl,{className:"w-3 h-3"}),i("settings.telemetryLearnMore")]})]}),s.jsx("p",{className:"text-sm text-bambu-gray",children:i("settings.telemetryDescription")})]}),s.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[s.jsx("input",{type:"checkbox",checked:T.telemetry_enabled,onChange:xe=>vt("telemetry_enabled",xe.target.checked),className:"sr-only peer"}),s.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"})]})]}),s.jsxs("div",{className:"border-t border-bambu-dark-tertiary pt-4",children:[s.jsxs("div",{className:"flex items-center justify-between mb-2",children:[s.jsxs("div",{children:[s.jsx("p",{className:"text-white",children:"Current version"}),s.jsxs("p",{className:"text-sm text-bambu-gray",children:["v",wn?.version||"..."]})]}),s.jsxs(Se,{variant:"secondary",size:"sm",onClick:()=>Be(),disabled:Ye,children:[Ye?s.jsx(mt,{className:"w-4 h-4 animate-spin"}):s.jsx(yr,{className:"w-4 h-4"}),"Check now"]})]}),ue?.update_available?s.jsxs("div",{className:"mt-4 p-3 bg-bambu-green/10 border border-bambu-green/30 rounded-lg",children:[s.jsxs("div",{className:"flex items-start justify-between",children:[s.jsxs("div",{children:[s.jsxs("p",{className:"text-bambu-green font-medium",children:["Update available: v",ue.latest_version]}),ue.release_name&&ue.release_name!==ue.latest_version&&s.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:ue.release_name})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[ue.release_notes&&s.jsx("button",{onClick:()=>rt(!0),className:"text-bambu-gray hover:text-white transition-colors text-sm underline",children:"Release Notes"}),ue.release_url&&s.jsx("a",{href:ue.release_url,target:"_blank",rel:"noopener noreferrer",className:"text-bambu-gray hover:text-white transition-colors",title:"View release on GitHub",children:s.jsx(Lr,{className:"w-4 h-4"})})]})]}),Xe?.status==="downloading"||Xe?.status==="installing"?s.jsxs("div",{className:"mt-3",children:[s.jsxs("div",{className:"flex items-center gap-2 text-sm text-bambu-gray",children:[s.jsx(mt,{className:"w-4 h-4 animate-spin"}),s.jsx("span",{children:Xe.message})]}),s.jsx("div",{className:"mt-2 w-full bg-bambu-dark-tertiary rounded-full h-2",children:s.jsx("div",{className:"bg-bambu-green h-2 rounded-full transition-all duration-300",style:{width:`${Xe.progress}%`}})})]}):Xe?.status==="complete"?s.jsx("div",{className:"mt-3 p-2 bg-bambu-green/20 rounded text-sm text-bambu-green",children:Xe.message}):Xe?.status==="error"?s.jsx("div",{className:"mt-3 p-2 bg-red-500/20 rounded text-sm text-red-400",children:Xe.error||Xe.message}):ue?.is_docker?s.jsxs("div",{className:"mt-3 p-3 bg-bambu-dark-tertiary rounded-lg",children:[s.jsx("p",{className:"text-sm text-bambu-gray mb-2",children:"Update via Docker Compose:"}),s.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"})]}):s.jsxs(Se,{className:"mt-3",onClick:()=>ce.mutate(),disabled:ce.isPending,children:[ce.isPending?s.jsx(mt,{className:"w-4 h-4 animate-spin"}):s.jsx(Jr,{className:"w-4 h-4"}),"Install Update"]})]}):ue?.error?s.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: ",ue.error]}):ue&&!ue.update_available?s.jsx("p",{className:"mt-2 text-sm text-bambu-gray",children:"You're running the latest version"}):null]})]})]}),s.jsxs(Mt,{children:[s.jsx(mr,{children:s.jsx("h2",{className:"text-lg font-semibold text-white",children:"Data Management"})}),s.jsxs(Et,{className:"space-y-4",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{children:[s.jsx("p",{className:"text-white",children:"Backup Data"}),s.jsx("p",{className:"text-sm text-bambu-gray",children:"Export settings, providers, printers, and more"})]}),s.jsxs(Se,{variant:"secondary",size:"sm",onClick:()=>ke(!0),children:[s.jsx(Jr,{className:"w-4 h-4"}),"Export"]})]}),s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{children:[s.jsx("p",{className:"text-white",children:"Restore Backup"}),s.jsx("p",{className:"text-sm text-bambu-gray",children:"Import settings from a backup file with duplicate handling options"})]}),s.jsxs(Se,{variant:"secondary",size:"sm",onClick:()=>Ze(!0),children:[s.jsx(bi,{className:"w-4 h-4"}),"Restore"]})]}),s.jsx("div",{className:"border-t border-bambu-dark-tertiary pt-4",children:s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{children:[s.jsx("p",{className:"text-white",children:"Clear Notification Logs"}),s.jsx("p",{className:"text-sm text-bambu-gray",children:"Delete notification logs older than 30 days"})]}),s.jsxs(Se,{variant:"secondary",size:"sm",onClick:()=>H(!0),children:[s.jsx(an,{className:"w-4 h-4"}),"Clear"]})]})}),s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{children:[s.jsx("p",{className:"text-white",children:"Reset UI Preferences"}),s.jsx("p",{className:"text-sm text-bambu-gray",children:"Reset sidebar order, theme, view modes, and layout preferences. Printers, archives, and settings are not affected."})]}),s.jsxs(Se,{variant:"secondary",size:"sm",onClick:()=>ie(!0),children:[s.jsx(an,{className:"w-4 h-4"}),"Reset"]})]})]})]})]})]}),fe==="network"&&T&&s.jsxs("div",{className:"flex flex-col lg:flex-row gap-6",children:[s.jsxs("div",{className:"flex-1 lg:max-w-xl space-y-4",children:[s.jsxs(Mt,{children:[s.jsx(mr,{children:s.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[s.jsx(Md,{className:"w-5 h-5 text-blue-400"}),"External URL"]})}),s.jsxs(Et,{className:"space-y-4",children:[s.jsx("p",{className:"text-sm text-bambu-gray",children:"The external URL where Bambuddy is accessible. Used for notification images and external integrations."}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Bambuddy URL"}),s.jsx("input",{type:"text",value:T.external_url??"",onChange:xe=>vt("external_url",xe.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"}),s.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Include protocol and port (e.g., http://192.168.1.100:8000)"})]})]})]}),s.jsxs(Mt,{children:[s.jsx(mr,{children:s.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[s.jsx(yr,{className:"w-5 h-5 text-blue-400"}),"FTP Retry"]})}),s.jsxs(Et,{className:"space-y-4",children:[s.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."}),s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{children:[s.jsx("p",{className:"text-white",children:"Enable retry"}),s.jsx("p",{className:"text-sm text-bambu-gray",children:"Automatically retry failed FTP operations"})]}),s.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[s.jsx("input",{type:"checkbox",checked:T.ftp_retry_enabled??!0,onChange:xe=>vt("ftp_retry_enabled",xe.target.checked),className:"sr-only peer"}),s.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"})]})]}),T.ftp_retry_enabled&&s.jsxs("div",{className:"space-y-4 pt-2 border-t border-bambu-dark-tertiary",children:[s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Retry attempts"}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("input",{type:"number",min:"1",max:"10",value:T.ftp_retry_count??3,onChange:xe=>vt("ftp_retry_count",Math.min(10,Math.max(1,parseInt(xe.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"}),s.jsx("span",{className:"text-bambu-gray",children:"times"})]}),s.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Number of retry attempts before giving up (1-10)"})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Retry delay"}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("input",{type:"number",min:"1",max:"30",value:T.ftp_retry_delay??2,onChange:xe=>vt("ftp_retry_delay",Math.min(30,Math.max(1,parseInt(xe.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"}),s.jsx("span",{className:"text-bambu-gray",children:"seconds"})]}),s.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Wait time between retries (1-30)"})]})]}),s.jsxs("div",{className:"pt-2 border-t border-bambu-dark-tertiary",children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Connection timeout"}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("input",{type:"number",min:"10",max:"120",value:T.ftp_timeout??30,onChange:xe=>vt("ftp_timeout",Math.min(120,Math.max(10,parseInt(xe.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"}),s.jsx("span",{className:"text-bambu-gray",children:"seconds"})]}),s.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)"})]})]})]})]}),s.jsxs("div",{className:"flex-1 lg:max-w-xl space-y-4",children:[s.jsxs(Mt,{children:[s.jsx(mr,{children:s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[s.jsx(R2,{className:"w-5 h-5 text-bambu-green"}),"Home Assistant"]}),T.ha_enabled&&ot&&s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:`w-2.5 h-2.5 rounded-full ${ot.success?"bg-green-400":"bg-red-400"}`}),s.jsx("span",{className:`text-sm ${ot.success?"text-green-400":"text-red-400"}`,children:ot.success?"Connected":"Disconnected"})]})]})}),s.jsxs(Et,{className:"space-y-4",children:[s.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, and input_boolean entities."}),s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{children:[s.jsx("p",{className:"text-white",children:"Enable Home Assistant"}),s.jsx("p",{className:"text-xs text-bambu-gray",children:"Control smart plugs via Home Assistant"})]}),s.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[s.jsx("input",{type:"checkbox",checked:T.ha_enabled??!1,onChange:xe=>vt("ha_enabled",xe.target.checked),className:"sr-only peer"}),s.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"})]})]}),T.ha_enabled&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Home Assistant URL"}),s.jsx("input",{type:"text",value:T.ha_url??"",onChange:xe=>vt("ha_url",xe.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"})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Long-Lived Access Token"}),s.jsx("input",{type:"password",value:T.ha_token??"",onChange:xe=>vt("ha_token",xe.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"}),s.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Create a token in HA: Profile → Long-Lived Access Tokens → Create Token"})]}),T.ha_url&&T.ha_token&&s.jsx("div",{className:"pt-2 border-t border-bambu-dark-tertiary",children:s.jsxs(Se,{variant:"secondary",size:"sm",disabled:$e,onClick:async()=>{be(!0),se(null);try{const xe=await pe.testHAConnection(T.ha_url,T.ha_token);se(xe)}catch(xe){se({success:!1,message:null,error:xe instanceof Error?xe.message:"Unknown error"})}finally{be(!1)}},children:[$e?s.jsx(mt,{className:"w-4 h-4 animate-spin"}):s.jsx(Dp,{className:"w-4 h-4"}),"Test Connection"]})})]})]})]}),s.jsxs(Mt,{children:[s.jsx(mr,{children:s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[s.jsx(Dp,{className:"w-5 h-5 text-blue-400"}),"MQTT Publishing"]}),At?.enabled&&s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:`w-2.5 h-2.5 rounded-full ${At.connected?"bg-green-400":"bg-red-400"}`}),s.jsx("span",{className:`text-sm ${At.connected?"text-green-400":"text-red-400"}`,children:At.connected?"Connected":"Disconnected"})]})]})}),s.jsxs(Et,{className:"space-y-4",children:[s.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."}),s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{children:[s.jsx("p",{className:"text-white",children:"Enable MQTT"}),s.jsx("p",{className:"text-sm text-bambu-gray",children:"Publish events to external MQTT broker"})]}),s.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[s.jsx("input",{type:"checkbox",checked:T.mqtt_enabled??!1,onChange:xe=>vt("mqtt_enabled",xe.target.checked),className:"sr-only peer"}),s.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"})]})]}),T.mqtt_enabled&&s.jsxs("div",{className:"space-y-4 pt-2 border-t border-bambu-dark-tertiary",children:[s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Broker hostname"}),s.jsx("input",{type:"text",value:T.mqtt_broker??"",onChange:xe=>vt("mqtt_broker",xe.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"})]}),s.jsxs("div",{className:"flex items-end gap-4",children:[s.jsxs("div",{className:"flex-1",children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Port"}),s.jsx("input",{type:"number",min:"1",max:"65535",value:T.mqtt_port??1883,onChange:xe=>vt("mqtt_port",Math.min(65535,Math.max(1,parseInt(xe.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"})]}),s.jsxs("div",{className:"flex items-center gap-3 pb-2",children:[s.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[s.jsx("input",{type:"checkbox",checked:T.mqtt_use_tls??!1,onChange:xe=>{const st=xe.target.checked;vt("mqtt_use_tls",st);const Ht=T.mqtt_port??1883;st&&Ht===1883?vt("mqtt_port",8883):!st&&Ht===8883&&vt("mqtt_port",1883)},className:"sr-only peer"}),s.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"})]}),s.jsx("span",{className:"text-white text-sm",children:"Use TLS"})]})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Username (optional)"}),s.jsx("input",{type:"text",value:T.mqtt_username??"",onChange:xe=>vt("mqtt_username",xe.target.value),placeholder:"Leave empty for anonymous",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"})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Password (optional)"}),s.jsx("input",{type:"password",value:T.mqtt_password??"",onChange:xe=>vt("mqtt_password",xe.target.value),placeholder:"Leave empty for anonymous",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"})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Topic prefix"}),s.jsx("input",{type:"text",value:T.mqtt_topic_prefix??"bambuddy",onChange:xe=>vt("mqtt_topic_prefix",xe.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"}),s.jsxs("p",{className:"text-xs text-bambu-gray mt-1",children:["Topics will be: ",T.mqtt_topic_prefix||"bambuddy","/printers//status, etc."]})]}),At&&s.jsx("div",{className:"pt-3 mt-3 border-t border-bambu-dark-tertiary",children:s.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[s.jsx("span",{className:`w-2 h-2 rounded-full ${At.connected?"bg-green-400":"bg-red-400"}`}),s.jsx("span",{className:"text-bambu-gray",children:At.connected?s.jsxs(s.Fragment,{children:["Connected to ",s.jsxs("span",{className:"text-white",children:[At.broker,":",At.port]})]}):"Not connected"})]})})]})]})]})]})]}),ot&&s.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50",children:s.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg p-6 max-w-md w-full mx-4",children:[s.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[ot.success?s.jsx(Dn,{className:"w-8 h-8 text-green-400"}):s.jsx(qi,{className:"w-8 h-8 text-red-400"}),s.jsx("h3",{className:"text-lg font-medium text-white",children:ot.success?"Connection Successful":"Connection Failed"})]}),s.jsx("p",{className:"text-bambu-gray mb-6",children:ot.success?ot.message||"Successfully connected to Home Assistant.":ot.error||"Failed to connect to Home Assistant."}),s.jsx("div",{className:"flex justify-end",children:s.jsx(Se,{variant:"primary",onClick:()=>se(null),children:"OK"})})]})}),fe==="plugs"&&s.jsxs("div",{className:"max-w-4xl",children:[s.jsxs("div",{className:"flex items-start justify-between mb-6",children:[s.jsxs("div",{children:[s.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[s.jsx(Us,{className:"w-5 h-5 text-bambu-green"}),"Smart Plugs"]}),s.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."})]}),s.jsxs("div",{className:"flex items-center gap-2 pt-1 shrink-0",children:[dt&&dt.filter(xe=>xe.enabled).length>1&&s.jsxs(s.Fragment,{children:[s.jsxs(Se,{variant:"secondary",size:"sm",className:"whitespace-nowrap",onClick:()=>_e("on"),disabled:Re.isPending,title:"Turn all plugs on",children:[Re.isPending?s.jsx(mt,{className:"w-4 h-4 animate-spin"}):s.jsx(uu,{className:"w-4 h-4 text-bambu-green"}),"All On"]}),s.jsxs(Se,{variant:"secondary",size:"sm",className:"whitespace-nowrap",onClick:()=>_e("off"),disabled:Re.isPending,title:"Turn all plugs off",children:[Re.isPending?s.jsx(mt,{className:"w-4 h-4 animate-spin"}):s.jsx(I2,{className:"w-4 h-4 text-red-400"}),"All Off"]})]}),s.jsxs(Se,{className:"whitespace-nowrap",onClick:()=>{D(null),L(!0)},children:[s.jsx(Kn,{className:"w-4 h-4"}),"Add Smart Plug"]})]})]}),dt&&dt.length>0&&s.jsxs(Mt,{className:"mb-6",children:[s.jsx(mr,{children:s.jsxs("h3",{className:"text-base font-semibold text-white flex items-center gap-2",children:[s.jsx(Mf,{className:"w-4 h-4 text-yellow-400"}),"Energy Summary",Zt&&s.jsx(mt,{className:"w-4 h-4 animate-spin text-bambu-gray ml-2"})]})}),s.jsx(Et,{children:jt?s.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[s.jsxs("div",{className:"bg-bambu-dark rounded-lg p-3",children:[s.jsxs("div",{className:"flex items-center gap-2 text-bambu-gray text-xs mb-1",children:[s.jsx(Mf,{className:"w-3 h-3"}),"Current Power"]}),s.jsxs("div",{className:"text-xl font-bold text-white",children:[jt.totalPower.toFixed(1),s.jsx("span",{className:"text-sm font-normal text-bambu-gray ml-1",children:"W"})]}),s.jsxs("div",{className:"text-xs text-bambu-gray mt-1",children:[jt.reachableCount,"/",jt.totalPlugs," plugs online"]})]}),s.jsxs("div",{className:"bg-bambu-dark rounded-lg p-3",children:[s.jsxs("div",{className:"flex items-center gap-2 text-bambu-gray text-xs mb-1",children:[s.jsx(Qr,{className:"w-3 h-3"}),"Today"]}),s.jsxs("div",{className:"text-xl font-bold text-white",children:[jt.totalToday.toFixed(2),s.jsx("span",{className:"text-sm font-normal text-bambu-gray ml-1",children:"kWh"})]}),T&&T.energy_cost_per_kwh>0&&s.jsxs("div",{className:"text-xs text-bambu-gray mt-1",children:["~",(jt.totalToday*T.energy_cost_per_kwh).toFixed(2)," ",T.currency]})]}),s.jsxs("div",{className:"bg-bambu-dark rounded-lg p-3",children:[s.jsxs("div",{className:"flex items-center gap-2 text-bambu-gray text-xs mb-1",children:[s.jsx(aq,{className:"w-3 h-3"}),"Yesterday"]}),s.jsxs("div",{className:"text-xl font-bold text-white",children:[jt.totalYesterday.toFixed(2),s.jsx("span",{className:"text-sm font-normal text-bambu-gray ml-1",children:"kWh"})]}),T&&T.energy_cost_per_kwh>0&&s.jsxs("div",{className:"text-xs text-bambu-gray mt-1",children:["~",(jt.totalYesterday*T.energy_cost_per_kwh).toFixed(2)," ",T.currency]})]}),s.jsxs("div",{className:"bg-bambu-dark rounded-lg p-3",children:[s.jsxs("div",{className:"flex items-center gap-2 text-bambu-gray text-xs mb-1",children:[s.jsx(Uj,{className:"w-3 h-3"}),"Total"]}),s.jsxs("div",{className:"text-xl font-bold text-white",children:[jt.totalLifetime.toFixed(1),s.jsx("span",{className:"text-sm font-normal text-bambu-gray ml-1",children:"kWh"})]}),T&&T.energy_cost_per_kwh>0&&s.jsxs("div",{className:"text-xs text-bambu-gray mt-1",children:["~",(jt.totalLifetime*T.energy_cost_per_kwh).toFixed(2)," ",T.currency]})]})]}):Zt?null:s.jsx("p",{className:"text-sm text-bambu-gray",children:"Enable plugs to see energy summary"})})]}),kt?s.jsx("div",{className:"flex justify-center py-12",children:s.jsx(mt,{className:"w-8 h-8 text-bambu-green animate-spin"})}):dt&&dt.length>0?s.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:dt.map(xe=>s.jsx(Rqe,{plug:xe,onEdit:st=>{D(st),L(!0)}},xe.id))}):s.jsx(Mt,{children:s.jsx(Et,{className:"py-12",children:s.jsxs("div",{className:"text-center text-bambu-gray",children:[s.jsx(Us,{className:"w-16 h-16 mx-auto mb-4 opacity-30"}),s.jsx("p",{className:"text-lg font-medium text-white mb-2",children:"No smart plugs configured"}),s.jsx("p",{className:"text-sm mb-4",children:"Add a Tasmota-based smart plug to track energy usage and automate power control."}),s.jsxs(Se,{onClick:()=>{D(null),L(!0)},children:[s.jsx(Kn,{className:"w-4 h-4"}),"Add Your First Smart Plug"]})]})})})]}),fe==="notifications"&&s.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-8",children:[s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center justify-between mb-4",children:[s.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[s.jsx(tf,{className:"w-5 h-5 text-bambu-green"}),"Providers"]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs(Se,{size:"sm",variant:"secondary",onClick:()=>G(!0),children:[s.jsx(hw,{className:"w-4 h-4"}),"Log"]}),Rt&&Rt.length>0&&s.jsxs(Se,{size:"sm",variant:"secondary",onClick:()=>{Ie(null),Le.mutate()},disabled:Le.isPending,children:[Le.isPending?s.jsx(mt,{className:"w-4 h-4 animate-spin"}):s.jsx(iD,{className:"w-4 h-4"}),"Test All"]}),s.jsxs(Se,{size:"sm",onClick:()=>{Z(null),Y(!0)},children:[s.jsx(Kn,{className:"w-4 h-4"}),"Add"]})]})]}),s.jsx(Mt,{className:"mb-4",children:s.jsx(Et,{className:"py-3",children:s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{children:[s.jsx("p",{className:"text-white text-sm font-medium",children:i("settings.notificationLanguage")}),s.jsx("p",{className:"text-xs text-bambu-gray",children:i("settings.notificationLanguageDescription")})]}),s.jsx("select",{value:T.notification_language||"en",onChange:xe=>vt("notification_language",xe.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:GU.map(xe=>s.jsx("option",{value:xe.code,children:xe.nativeName},xe.code))})]})})}),we&&s.jsx(Mt,{className:"mb-4",children:s.jsxs(Et,{className:"py-3",children:[s.jsxs("div",{className:"flex items-center justify-between mb-2",children:[s.jsx("span",{className:"text-sm font-medium text-white",children:"Test Results"}),s.jsx("button",{onClick:()=>Ie(null),className:"text-bambu-gray hover:text-white text-xs",children:"Dismiss"})]}),s.jsxs("div",{className:"flex items-center gap-4 text-sm mb-2",children:[s.jsxs("span",{className:"flex items-center gap-1 text-bambu-green",children:[s.jsx(Dn,{className:"w-4 h-4"}),we.success," passed"]}),we.failed>0&&s.jsxs("span",{className:"flex items-center gap-1 text-red-400",children:[s.jsx(qi,{className:"w-4 h-4"}),we.failed," failed"]})]}),we.results.filter(xe=>!xe.success).length>0&&s.jsx("div",{className:"space-y-1 mt-2 pt-2 border-t border-bambu-dark-tertiary",children:we.results.filter(xe=>!xe.success).map(xe=>s.jsxs("div",{className:"text-xs text-red-400",children:[s.jsxs("span",{className:"font-medium",children:[xe.provider_name,":"]})," ",xe.message]},xe.provider_id))})]})}),nn?s.jsx("div",{className:"flex justify-center py-12",children:s.jsx(mt,{className:"w-6 h-6 text-bambu-green animate-spin"})}):Rt&&Rt.length>0?s.jsx("div",{className:"space-y-3",children:Rt.map(xe=>s.jsx(Lqe,{provider:xe,onEdit:st=>{Z(st),Y(!0)}},xe.id))}):s.jsx(Mt,{children:s.jsx(Et,{className:"py-8",children:s.jsxs("div",{className:"text-center text-bambu-gray",children:[s.jsx(tf,{className:"w-12 h-12 mx-auto mb-3 opacity-30"}),s.jsx("p",{className:"text-sm font-medium text-white mb-2",children:"No providers configured"}),s.jsx("p",{className:"text-xs mb-3",children:"Add a provider to receive alerts."}),s.jsxs(Se,{size:"sm",onClick:()=>{Z(null),Y(!0)},children:[s.jsx(Kn,{className:"w-4 h-4"}),"Add Provider"]})]})})})]}),s.jsxs("div",{children:[s.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2 mb-4",children:[s.jsx(za,{className:"w-5 h-5 text-bambu-green"}),"Message Templates"]}),s.jsx("p",{className:"text-sm text-bambu-gray mb-4",children:"Customize notification messages for each event."}),Tr?s.jsx("div",{className:"flex justify-center py-8",children:s.jsx(mt,{className:"w-6 h-6 text-bambu-green animate-spin"})}):$r&&$r.length>0?s.jsx("div",{className:"space-y-2",children:$r.map(xe=>s.jsx(Mt,{className:"cursor-pointer hover:border-bambu-green/50 transition-colors",onClick:()=>oe(xe),children:s.jsx(Et,{className:"py-2.5 px-3",children:s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("p",{className:"text-white font-medium text-sm truncate",children:xe.name}),s.jsx("p",{className:"text-bambu-gray text-xs truncate mt-0.5",children:xe.title_template})]}),s.jsx("button",{className:"p-1.5 hover:bg-bambu-dark-tertiary rounded transition-colors shrink-0 ml-2",onClick:st=>{st.stopPropagation(),oe(xe)},children:s.jsx(L2,{className:"w-4 h-4 text-bambu-gray"})})]})})},xe.id))}):s.jsx(Mt,{children:s.jsx(Et,{className:"py-8",children:s.jsxs("div",{className:"text-center text-bambu-gray",children:[s.jsx(za,{className:"w-12 h-12 mx-auto mb-3 opacity-30"}),s.jsx("p",{className:"text-sm",children:"No templates available. Restart the backend to seed default templates."})]})})})]})]}),fe==="apikeys"&&s.jsxs("div",{className:"grid grid-cols-1 xl:grid-cols-2 gap-8",children:[s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-start justify-between gap-4 mb-6",children:[s.jsxs("div",{className:"flex-1",children:[s.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[s.jsx(Gh,{className:"w-5 h-5 text-bambu-green"}),"API Keys"]}),s.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:"Create API keys for external integrations and webhooks."})]}),s.jsxs(Se,{size:"sm",onClick:()=>je(!0),className:"flex-shrink-0",children:[s.jsx(Kn,{className:"w-4 h-4"}),"Create Key"]})]}),W&&s.jsx(Mt,{className:"mb-6 border-bambu-green",children:s.jsx(Et,{className:"py-4",children:s.jsxs("div",{className:"flex items-start gap-3",children:[s.jsx(Dn,{className:"w-5 h-5 text-bambu-green flex-shrink-0 mt-0.5"}),s.jsxs("div",{className:"flex-1",children:[s.jsx("p",{className:"text-white font-medium mb-1",children:"API Key Created Successfully"}),s.jsx("p",{className:"text-sm text-bambu-gray mb-2",children:"Copy this key now - it won't be shown again!"}),s.jsxs("div",{className:"flex items-center gap-2 bg-bambu-dark rounded-lg p-2",children:[s.jsx("code",{className:"flex-1 text-sm text-bambu-green font-mono break-all",children:W}),s.jsx(Se,{variant:"secondary",size:"sm",onClick:async()=>{try{if(navigator.clipboard&&navigator.clipboard.writeText)await navigator.clipboard.writeText(W);else{const xe=document.createElement("textarea");xe.value=W,xe.style.position="fixed",xe.style.left="-999999px",document.body.appendChild(xe),xe.select(),document.execCommand("copy"),document.body.removeChild(xe)}o("Key copied to clipboard")}catch{o("Failed to copy key","error")}},children:s.jsx(Jo,{className:"w-4 h-4"})})]}),s.jsxs("div",{className:"flex gap-2 mt-3",children:[s.jsx(Se,{variant:"secondary",size:"sm",onClick:()=>{Ce(W),o("Key added to API Browser")},children:"Use in API Browser"}),s.jsx(Se,{variant:"secondary",size:"sm",onClick:()=>U(null),children:"Dismiss"})]})]})]})})}),Me&&s.jsxs(Mt,{className:"mb-6",children:[s.jsx(mr,{children:s.jsx("h3",{className:"text-base font-semibold text-white",children:"Create New API Key"})}),s.jsxs(Et,{className:"space-y-4",children:[s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Key Name"}),s.jsx("input",{type:"text",value:ne,onChange:xe=>Ke(xe.target.value),placeholder:"e.g., Home Assistant, OctoPrint",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"})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-2",children:"Permissions"}),s.jsxs("div",{className:"space-y-2",children:[s.jsxs("label",{className:"flex items-center gap-3 cursor-pointer",children:[s.jsx("input",{type:"checkbox",checked:$.can_read_status,onChange:xe=>z(st=>({...st,can_read_status:xe.target.checked})),className:"w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green"}),s.jsxs("div",{children:[s.jsx("span",{className:"text-white",children:"Read Status"}),s.jsx("p",{className:"text-xs text-bambu-gray",children:"View printer status and queue"})]})]}),s.jsxs("label",{className:"flex items-center gap-3 cursor-pointer",children:[s.jsx("input",{type:"checkbox",checked:$.can_queue,onChange:xe=>z(st=>({...st,can_queue:xe.target.checked})),className:"w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green"}),s.jsxs("div",{children:[s.jsx("span",{className:"text-white",children:"Manage Queue"}),s.jsx("p",{className:"text-xs text-bambu-gray",children:"Add and remove items from print queue"})]})]}),s.jsxs("label",{className:"flex items-center gap-3 cursor-pointer",children:[s.jsx("input",{type:"checkbox",checked:$.can_control_printer,onChange:xe=>z(st=>({...st,can_control_printer:xe.target.checked})),className:"w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green"}),s.jsxs("div",{children:[s.jsx("span",{className:"text-white",children:"Control Printer"}),s.jsx("p",{className:"text-xs text-bambu-gray",children:"Pause, resume, and stop prints"})]})]})]})]}),s.jsxs("div",{className:"flex items-center gap-2 pt-2",children:[s.jsxs(Se,{onClick:()=>qt.mutate({name:ne||"Unnamed Key",...$}),disabled:qt.isPending,children:[qt.isPending?s.jsx(mt,{className:"w-4 h-4 animate-spin"}):s.jsx(Kn,{className:"w-4 h-4"}),"Create Key"]}),s.jsx(Se,{variant:"secondary",onClick:()=>je(!1),children:"Cancel"})]})]})]}),$t?s.jsx("div",{className:"flex justify-center py-12",children:s.jsx(mt,{className:"w-8 h-8 text-bambu-green animate-spin"})}):pt&&pt.length>0?s.jsx("div",{className:"space-y-3",children:pt.map(xe=>s.jsx(Mt,{children:s.jsx(Et,{className:"py-3",children:s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx(Gh,{className:`w-5 h-5 ${xe.enabled?"text-bambu-green":"text-bambu-gray"}`}),s.jsxs("div",{children:[s.jsx("p",{className:"text-white font-medium",children:xe.name}),s.jsxs("p",{className:"text-xs text-bambu-gray",children:[xe.key_prefix,"••••••••",xe.last_used&&` · Last used: ${Jp(xe.last_used)}`]})]})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs("div",{className:"flex gap-1 text-xs",children:[xe.can_read_status&&s.jsx("span",{className:"px-1.5 py-0.5 bg-blue-500/20 text-blue-400 rounded",children:"Read"}),xe.can_queue&&s.jsx("span",{className:"px-1.5 py-0.5 bg-green-500/20 text-green-400 rounded",children:"Queue"}),xe.can_control_printer&&s.jsx("span",{className:"px-1.5 py-0.5 bg-orange-500/20 text-orange-400 rounded",children:"Control"})]}),s.jsx(Se,{variant:"secondary",size:"sm",onClick:()=>Q(xe.id),children:s.jsx(an,{className:"w-4 h-4 text-red-400"})})]})]})})},xe.id))}):s.jsx(Mt,{children:s.jsx(Et,{className:"py-12",children:s.jsxs("div",{className:"text-center text-bambu-gray",children:[s.jsx(Gh,{className:"w-16 h-16 mx-auto mb-4 opacity-30"}),s.jsx("p",{className:"text-lg font-medium text-white mb-2",children:"No API keys"}),s.jsx("p",{className:"text-sm mb-4",children:"Create an API key to integrate with external services."}),s.jsxs(Se,{onClick:()=>je(!0),children:[s.jsx(Kn,{className:"w-4 h-4"}),"Create Your First Key"]})]})})}),s.jsxs(Mt,{className:"mt-6",children:[s.jsx(mr,{children:s.jsx("h3",{className:"text-base font-semibold text-white",children:"Webhook Endpoints"})}),s.jsxs(Et,{className:"space-y-3 text-sm",children:[s.jsxs("p",{className:"text-bambu-gray",children:["Use your API key in the ",s.jsx("code",{className:"text-bambu-green",children:"X-API-Key"})," header."]}),s.jsxs("div",{className:"space-y-2 font-mono text-xs",children:[s.jsxs("div",{className:"p-2 bg-bambu-dark rounded",children:[s.jsx("span",{className:"text-blue-400",children:"GET"})," ",s.jsx("span",{className:"text-white",children:"/api/v1/webhook/status"}),s.jsx("span",{className:"text-bambu-gray",children:" - Get all printer status"})]}),s.jsxs("div",{className:"p-2 bg-bambu-dark rounded",children:[s.jsx("span",{className:"text-blue-400",children:"GET"})," ",s.jsx("span",{className:"text-white",children:"/api/v1/webhook/status/:id"}),s.jsx("span",{className:"text-bambu-gray",children:" - Get specific printer status"})]}),s.jsxs("div",{className:"p-2 bg-bambu-dark rounded",children:[s.jsx("span",{className:"text-green-400",children:"POST"})," ",s.jsx("span",{className:"text-white",children:"/api/v1/webhook/queue"}),s.jsx("span",{className:"text-bambu-gray",children:" - Add to print queue"})]}),s.jsxs("div",{className:"p-2 bg-bambu-dark rounded",children:[s.jsx("span",{className:"text-orange-400",children:"POST"})," ",s.jsx("span",{className:"text-white",children:"/api/v1/webhook/printer/:id/pause"}),s.jsx("span",{className:"text-bambu-gray",children:" - Pause print"})]}),s.jsxs("div",{className:"p-2 bg-bambu-dark rounded",children:[s.jsx("span",{className:"text-orange-400",children:"POST"})," ",s.jsx("span",{className:"text-white",children:"/api/v1/webhook/printer/:id/resume"}),s.jsx("span",{className:"text-bambu-gray",children:" - Resume print"})]}),s.jsxs("div",{className:"p-2 bg-bambu-dark rounded",children:[s.jsx("span",{className:"text-red-400",children:"POST"})," ",s.jsx("span",{className:"text-white",children:"/api/v1/webhook/printer/:id/stop"}),s.jsx("span",{className:"text-bambu-gray",children:" - Stop print"})]})]})]})]})]}),s.jsxs("div",{children:[s.jsxs("div",{className:"mb-6",children:[s.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[s.jsx(Md,{className:"w-5 h-5 text-bambu-green"}),"API Browser"]}),s.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:"Explore and test all available API endpoints."})]}),s.jsx(Mt,{className:"mb-4",children:s.jsxs(Et,{className:"py-3",children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-2",children:"API Key for Testing"}),s.jsx("input",{type:"text",value:Ee,onChange:xe=>Ce(xe.target.value),placeholder:"Paste your API key here to test authenticated endpoints...",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"}),s.jsxs("p",{className:"text-xs text-bambu-gray mt-2",children:["This key will be sent as ",s.jsx("code",{className:"text-bambu-green",children:"X-API-Key"})," header with requests."]})]})}),s.jsx(eKe,{apiKey:Ee})]})]}),fe==="virtual-printer"&&s.jsx(Yqe,{}),fe==="filament"&&T&&s.jsxs("div",{className:"flex flex-col lg:flex-row gap-6 lg:gap-8",children:[s.jsx("div",{className:"flex-1 lg:max-w-xl",children:s.jsxs(Mt,{children:[s.jsx(mr,{children:s.jsx("h2",{className:"text-lg font-semibold text-white",children:"AMS Display Thresholds"})}),s.jsxs(Et,{className:"space-y-4",children:[s.jsx("p",{className:"text-sm text-bambu-gray",children:"Configure color thresholds for AMS humidity and temperature indicators."}),s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"flex items-center gap-2 text-white",children:[s.jsx(tD,{className:"w-4 h-4 text-blue-400"}),s.jsx("span",{className:"font-medium",children:"Humidity"})]}),s.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Good (green) ≤"}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("input",{type:"number",min:"0",max:"100",value:T.ams_humidity_good??40,onChange:xe=>vt("ams_humidity_good",parseInt(xe.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"}),s.jsx("span",{className:"text-bambu-gray",children:"%"})]})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Fair (orange) ≤"}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("input",{type:"number",min:"0",max:"100",value:T.ams_humidity_fair??60,onChange:xe=>vt("ams_humidity_fair",parseInt(xe.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"}),s.jsx("span",{className:"text-bambu-gray",children:"%"})]})]})]}),s.jsx("p",{className:"text-xs text-bambu-gray",children:"Above fair threshold shows as red (bad)"})]}),s.jsxs("div",{className:"space-y-3 pt-2 border-t border-bambu-dark-tertiary",children:[s.jsxs("div",{className:"flex items-center gap-2 text-white",children:[s.jsx(U2,{className:"w-4 h-4 text-orange-400"}),s.jsx("span",{className:"font-medium",children:"Temperature"})]}),s.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Good (blue) ≤"}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("input",{type:"number",step:"0.5",min:"0",max:"60",value:T.ams_temp_good??28,onChange:xe=>vt("ams_temp_good",parseFloat(xe.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"}),s.jsx("span",{className:"text-bambu-gray",children:"°C"})]})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Fair (orange) ≤"}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("input",{type:"number",step:"0.5",min:"0",max:"60",value:T.ams_temp_fair??35,onChange:xe=>vt("ams_temp_fair",parseFloat(xe.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"}),s.jsx("span",{className:"text-bambu-gray",children:"°C"})]})]})]}),s.jsx("p",{className:"text-xs text-bambu-gray",children:"Above fair threshold shows as red (hot)"})]}),s.jsxs("div",{className:"space-y-3 pt-4 border-t border-bambu-dark-tertiary",children:[s.jsxs("div",{className:"flex items-center gap-2 text-white",children:[s.jsx(Yp,{className:"w-4 h-4 text-purple-400"}),s.jsx("span",{className:"font-medium",children:"History Retention"})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Keep sensor history for"}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("input",{type:"number",min:"1",max:"365",value:T.ams_history_retention_days??30,onChange:xe=>vt("ams_history_retention_days",parseInt(xe.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"}),s.jsx("span",{className:"text-bambu-gray",children:"days"})]})]}),s.jsx("p",{className:"text-xs text-bambu-gray",children:"Older humidity and temperature data will be automatically deleted"})]}),s.jsxs("div",{className:"space-y-3 pt-4 border-t border-bambu-dark-tertiary",children:[s.jsxs("div",{className:"flex items-center gap-2 text-white",children:[s.jsx(Ir,{className:"w-4 h-4 text-bambu-green"}),s.jsx("span",{className:"font-medium",children:"Print Modal"})]}),s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-white",children:"Expand custom mapping by default"}),s.jsx("p",{className:"text-xs text-bambu-gray mt-0.5",children:"When printing to multiple printers, show per-printer AMS mapping expanded"})]}),s.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[s.jsx("input",{type:"checkbox",checked:T.per_printer_mapping_expanded??!1,onChange:xe=>vt("per_printer_mapping_expanded",xe.target.checked),className:"sr-only peer"}),s.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"})]})]})]})]})]})}),s.jsx("div",{className:"flex-1 lg:max-w-xl",children:s.jsx(qqe,{})})]}),V!==null&&s.jsx(Ln,{title:"Delete API Key",message:"Are you sure you want to delete this API key? Any integrations using this key will stop working.",confirmText:"Delete Key",variant:"danger",onConfirm:()=>{wt.mutate(V),Q(null)},onCancel:()=>Q(null)}),F&&s.jsx(Dqe,{plug:X,onClose:()=>{L(!1),D(null)}}),K&&s.jsx(Iqe,{provider:q,onClose:()=>{Y(!1),Z(null)}}),re&&s.jsx(Fqe,{template:re,onClose:()=>oe(null)}),B&&s.jsx(Bqe,{onClose:()=>G(!1)}),Ne&&s.jsx(Ln,{title:"Clear Notification Logs",message:"This will permanently delete all notification logs older than 30 days. This action cannot be undone.",confirmText:"Clear Logs",variant:"warning",onConfirm:async()=>{H(!1);try{const xe=await pe.clearNotificationLogs(30);o(xe.message,"success")}catch{o("Failed to clear logs","error")}},onCancel:()=>H(!1)}),O&&s.jsx(Ln,{title:"Reset UI Preferences",message:"This will reset all UI preferences to defaults: sidebar order, theme, dashboard layout, view modes, and sorting preferences. Your printers, archives, and server settings will NOT be affected. The page will reload after clearing.",confirmText:"Reset Preferences",variant:"default",onConfirm:()=>{ie(!1),localStorage.clear(),o("UI preferences reset. Refreshing...","success"),setTimeout(()=>window.location.reload(),1e3)},onCancel:()=>ie(!1)}),ye&&s.jsx(Ln,{title:`Turn All Plugs ${ye==="on"?"On":"Off"}`,message:`This will turn ${ye==="on"?"ON":"OFF"} all ${dt?.filter(xe=>xe.enabled).length||0} enabled smart plugs. ${ye==="off"?"Any running printers may be affected!":""}`,confirmText:`Turn All ${ye==="on"?"On":"Off"}`,variant:ye==="off"?"danger":"warning",onConfirm:()=>{const xe=ye;_e(null),Re.mutate(xe)},onCancel:()=>_e(null)}),le&&s.jsx(Hqe,{onClose:()=>ke(!1),onExport:async xe=>{ke(!1);const st="backup-progress",Ht=xe.archives;Ht&&l(st,i("backup.preparing",{defaultValue:"Preparing backup..."}),"loading");try{const{blob:It,filename:on}=await pe.exportBackup(xe);Ht&&c(st);const un=URL.createObjectURL(It),Gt=document.createElement("a");Gt.href=un,Gt.download=on,Gt.click(),URL.revokeObjectURL(un),o(i("backup.downloaded",{defaultValue:"Backup downloaded"}),"success")}catch{Ht&&c(st),o(i("backup.failed",{defaultValue:"Failed to create backup"}),"error")}}}),Oe&&s.jsx(Vqe,{onClose:()=>Ze(!1),onRestore:async(xe,st)=>await pe.importBackup(xe,st),onSuccess:()=>{P(null),Tt.current=!0,t.resetQueries({queryKey:["settings"]}),t.invalidateQueries({queryKey:["notification-providers"]}),t.invalidateQueries({queryKey:["notification-templates"]}),t.invalidateQueries({queryKey:["smart-plugs"]}),t.invalidateQueries({queryKey:["external-links"]}),t.invalidateQueries({queryKey:["printers"]}),t.invalidateQueries({queryKey:["filaments"]}),t.invalidateQueries({queryKey:["maintenance-types"]}),t.invalidateQueries({queryKey:["api-keys"]})}}),ht&&s.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",onClick:()=>We(!1),children:s.jsxs(Mt,{className:"w-full max-w-lg",onClick:xe=>xe.stopPropagation(),children:[s.jsxs(mr,{className:"flex flex-row items-center justify-between",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(P1,{className:"w-5 h-5 text-bambu-green"}),s.jsx("h2",{className:"text-lg font-semibold text-white",children:i("settings.telemetryInfoTitle")})]}),s.jsx("button",{onClick:()=>We(!1),className:"p-1 rounded hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white",children:s.jsx(Ut,{className:"w-5 h-5"})})]}),s.jsxs(Et,{className:"space-y-4",children:[s.jsx("p",{className:"text-bambu-gray text-sm",children:i("settings.telemetryInfoIntro")}),s.jsxs("div",{className:"space-y-3",children:[s.jsx("h3",{className:"text-white font-medium",children:i("settings.telemetryInfoCollected")}),s.jsxs("ul",{className:"space-y-2 text-sm",children:[s.jsxs("li",{className:"flex items-start gap-2 text-bambu-gray",children:[s.jsx(Dn,{className:"w-4 h-4 text-bambu-green mt-0.5 shrink-0"}),s.jsx("span",{children:i("settings.telemetryInfoItem1")})]}),s.jsxs("li",{className:"flex items-start gap-2 text-bambu-gray",children:[s.jsx(Dn,{className:"w-4 h-4 text-bambu-green mt-0.5 shrink-0"}),s.jsx("span",{children:i("settings.telemetryInfoItem2")})]}),s.jsxs("li",{className:"flex items-start gap-2 text-bambu-gray",children:[s.jsx(Dn,{className:"w-4 h-4 text-bambu-green mt-0.5 shrink-0"}),s.jsx("span",{children:i("settings.telemetryInfoItem3")})]}),s.jsxs("li",{className:"flex items-start gap-2 text-bambu-gray",children:[s.jsx(Dn,{className:"w-4 h-4 text-bambu-green mt-0.5 shrink-0"}),s.jsx("span",{children:i("settings.telemetryInfoItem4")})]})]})]}),s.jsxs("div",{className:"space-y-3",children:[s.jsx("h3",{className:"text-white font-medium",children:i("settings.telemetryInfoNotCollected")}),s.jsxs("ul",{className:"space-y-2 text-sm",children:[s.jsxs("li",{className:"flex items-start gap-2 text-bambu-gray",children:[s.jsx(qi,{className:"w-4 h-4 text-red-400 mt-0.5 shrink-0"}),s.jsx("span",{children:i("settings.telemetryInfoNotItem1")})]}),s.jsxs("li",{className:"flex items-start gap-2 text-bambu-gray",children:[s.jsx(qi,{className:"w-4 h-4 text-red-400 mt-0.5 shrink-0"}),s.jsx("span",{children:i("settings.telemetryInfoNotItem2")})]}),s.jsxs("li",{className:"flex items-start gap-2 text-bambu-gray",children:[s.jsx(qi,{className:"w-4 h-4 text-red-400 mt-0.5 shrink-0"}),s.jsx("span",{children:i("settings.telemetryInfoNotItem3")})]}),s.jsxs("li",{className:"flex items-start gap-2 text-bambu-gray",children:[s.jsx(qi,{className:"w-4 h-4 text-red-400 mt-0.5 shrink-0"}),s.jsx("span",{children:i("settings.telemetryInfoNotItem4")})]})]})]}),s.jsx("p",{className:"text-bambu-gray text-xs border-t border-bambu-dark-tertiary pt-4",children:i("settings.telemetryInfoFooter")}),s.jsx(Se,{onClick:()=>We(!1),className:"w-full",children:i("common.close")})]})]})}),he&&ue?.release_notes&&s.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",onClick:()=>rt(!1),children:s.jsxs(Mt,{className:"w-full max-w-2xl max-h-[80vh] flex flex-col",onClick:xe=>xe.stopPropagation(),children:[s.jsxs(mr,{className:"flex flex-row items-center justify-between shrink-0",children:[s.jsxs("div",{children:[s.jsxs("h2",{className:"text-lg font-semibold text-white",children:["Release Notes - v",ue.latest_version]}),ue.release_name&&ue.release_name!==ue.latest_version&&s.jsx("p",{className:"text-sm text-bambu-gray",children:ue.release_name})]}),s.jsx("button",{onClick:()=>rt(!1),className:"p-1 rounded hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white",children:s.jsx(Ut,{className:"w-5 h-5"})})]}),s.jsx(Et,{className:"overflow-y-auto flex-1",children:s.jsx("pre",{className:"text-sm text-bambu-gray whitespace-pre-wrap font-sans",children:ue.release_notes})}),s.jsxs("div",{className:"p-4 border-t border-bambu-dark-tertiary shrink-0 flex gap-2",children:[ue.release_url&&s.jsx("a",{href:ue.release_url,target:"_blank",rel:"noopener noreferrer",className:"flex-1",children:s.jsxs(Se,{variant:"secondary",className:"w-full",children:[s.jsx(Lr,{className:"w-4 h-4"}),"View on GitHub"]})}),s.jsx(Se,{onClick:()=>rt(!1),className:"flex-1",children:"Close"})]})]})}),fe==="users"&&s.jsxs("div",{className:"grid grid-cols-1 xl:grid-cols-2 gap-8",children:[s.jsxs("div",{children:[s.jsxs("div",{className:"mb-6",children:[s.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[s.jsx(Wh,{className:"w-5 h-5 text-bambu-green"}),"User Authentication"]}),s.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:"Enable authentication to secure your Bambuddy instance and manage user access."})]}),s.jsx(Mt,{children:s.jsx(Et,{className:"py-6",children:u?s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("div",{className:"w-12 h-12 rounded-full flex items-center justify-center bg-green-500/20",children:s.jsx(kA,{className:"w-6 h-6 text-green-400"})}),s.jsxs("div",{className:"flex-1",children:[s.jsx("h3",{className:"text-white font-medium",children:"Authentication Enabled"}),s.jsx("p",{className:"text-sm text-bambu-gray",children:"Your Bambuddy instance is secured with authentication."})]})]}),d&&s.jsx("div",{className:"pt-4 border-t border-bambu-dark-tertiary",children:s.jsxs("div",{className:"flex items-center justify-between mb-4",children:[s.jsxs("div",{children:[s.jsx("p",{className:"text-sm text-bambu-gray",children:"Current User"}),s.jsx("p",{className:"text-white font-medium",children:d.username}),s.jsxs("p",{className:"text-xs text-bambu-gray mt-1",children:["Role: ",s.jsx("span",{className:"capitalize",children:d.role})]})]}),s.jsx("div",{className:`px-3 py-1 rounded-full text-xs font-medium ${d.role==="admin"?"bg-purple-500/20 text-purple-300":"bg-blue-500/20 text-blue-300"}`,children:d.role==="admin"?"Admin":"User"})]})}),s.jsxs("div",{className:"pt-4 border-t border-bambu-dark-tertiary space-y-3",children:[s.jsxs(Se,{onClick:()=>e("/users"),className:"w-full",variant:"secondary",children:[s.jsx(Wh,{className:"w-4 h-4"}),"Manage Users"]}),d?.role==="admin"&&s.jsxs(Se,{onClick:()=>Je(!0),className:"w-full",variant:"secondary",children:[s.jsx(dz,{className:"w-4 h-4"}),"Disable Authentication"]})]})]}):s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("div",{className:`w-12 h-12 rounded-full flex items-center justify-center ${u?"bg-green-500/20":"bg-gray-500/20"}`,children:u?s.jsx(kA,{className:"w-6 h-6 text-green-400"}):s.jsx(dz,{className:"w-6 h-6 text-gray-400"})}),s.jsxs("div",{className:"flex-1",children:[s.jsx("h3",{className:"text-white font-medium",children:"Authentication Disabled"}),s.jsx("p",{className:"text-sm text-bambu-gray",children:"Your Bambuddy instance is currently accessible without authentication."})]})]}),s.jsxs("div",{className:"pt-4 border-t border-bambu-dark-tertiary",children:[s.jsx("p",{className:"text-sm text-bambu-gray mb-4",children:"Enable authentication to:"}),s.jsxs("ul",{className:"space-y-2 text-sm text-bambu-gray mb-4",children:[s.jsxs("li",{className:"flex items-start gap-2",children:[s.jsx(Dn,{className:"w-4 h-4 text-bambu-green mt-0.5 flex-shrink-0"}),s.jsx("span",{children:"Require login to access the system"})]}),s.jsxs("li",{className:"flex items-start gap-2",children:[s.jsx(Dn,{className:"w-4 h-4 text-bambu-green mt-0.5 flex-shrink-0"}),s.jsx("span",{children:"Manage multiple users with different roles"})]}),s.jsxs("li",{className:"flex items-start gap-2",children:[s.jsx(Dn,{className:"w-4 h-4 text-bambu-green mt-0.5 flex-shrink-0"}),s.jsx("span",{children:"Control access to printer settings and user management"})]})]}),s.jsxs(Se,{type:"button",onClick:xe=>{xe.preventDefault(),e("/setup")},className:"w-full",children:[s.jsx(kA,{className:"w-4 h-4"}),"Activate Authentication"]})]})]})})})]}),u&&s.jsxs("div",{children:[s.jsxs("div",{className:"mb-6",children:[s.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[s.jsx(P1,{className:"w-5 h-5 text-bambu-green"}),"Role Permissions"]}),s.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:"Overview of what each role can do."})]}),s.jsxs("div",{className:"space-y-4",children:[s.jsxs(Mt,{children:[s.jsx(mr,{children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("div",{className:"w-8 h-8 rounded-full bg-purple-500/20 flex items-center justify-center",children:s.jsx(P1,{className:"w-4 h-4 text-purple-300"})}),s.jsx("h3",{className:"text-white font-medium",children:"Admin"})]})}),s.jsx(Et,{children:s.jsxs("ul",{className:"space-y-2 text-sm text-bambu-gray",children:[s.jsxs("li",{className:"flex items-start gap-2",children:[s.jsx(Dn,{className:"w-4 h-4 text-bambu-green mt-0.5 flex-shrink-0"}),s.jsx("span",{children:"Manage printer settings"})]}),s.jsxs("li",{className:"flex items-start gap-2",children:[s.jsx(Dn,{className:"w-4 h-4 text-bambu-green mt-0.5 flex-shrink-0"}),s.jsx("span",{children:"Create, edit, and delete users"})]}),s.jsxs("li",{className:"flex items-start gap-2",children:[s.jsx(Dn,{className:"w-4 h-4 text-bambu-green mt-0.5 flex-shrink-0"}),s.jsx("span",{children:"Access all system features"})]})]})})]}),s.jsxs(Mt,{children:[s.jsx(mr,{children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("div",{className:"w-8 h-8 rounded-full bg-blue-500/20 flex items-center justify-center",children:s.jsx(Wh,{className:"w-4 h-4 text-blue-300"})}),s.jsx("h3",{className:"text-white font-medium",children:"User"})]})}),s.jsx(Et,{children:s.jsxs("ul",{className:"space-y-2 text-sm text-bambu-gray",children:[s.jsxs("li",{className:"flex items-start gap-2",children:[s.jsx(Dn,{className:"w-4 h-4 text-bambu-green mt-0.5 flex-shrink-0"}),s.jsx("span",{children:"Send print jobs"})]}),s.jsxs("li",{className:"flex items-start gap-2",children:[s.jsx(Dn,{className:"w-4 h-4 text-bambu-green mt-0.5 flex-shrink-0"}),s.jsx("span",{children:"Manage files and archives"})]}),s.jsxs("li",{className:"flex items-start gap-2",children:[s.jsx(Dn,{className:"w-4 h-4 text-bambu-green mt-0.5 flex-shrink-0"}),s.jsx("span",{children:"Manage filament"})]})]})})]})]})]})]}),qe&&s.jsx(Ln,{title:"Disable Authentication",message:"Are you sure you want to disable authentication? This will make your Bambuddy instance accessible without login. All users will remain in the database but authentication will be disabled.",confirmText:"Disable Authentication",variant:"danger",onConfirm:async()=>{try{await pe.disableAuth(),o("Authentication disabled successfully","success"),await f(),Je(!1),window.location.href="/"}catch(xe){const st=xe instanceof Error?xe.message:"Failed to disable authentication";o(st,"error")}},onCancel:()=>Je(!1)})]})}const hre=t=>{const e=parseFloat(t);return(Math.trunc(e*1e3)/1e3).toFixed(3)},rKe=t=>t.startsWith("HH")?"HF":"S",iKe=t=>{const e=t.match(/^([A-Z]{2}\d{2})/);return e?e[1]:"HH00"},LR=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:a,note:o}){const l=rKe(t.nozzle_id),c=t.nozzle_diameter,u=()=>{r&&a?a():e()};return s.jsxs("div",{className:"flex items-center gap-2",children:[r&&s.jsx("button",{onClick:a,className:"text-bambu-gray hover:text-white transition-colors p-1",children:i?s.jsx(eu,{className:"w-4 h-4 text-bambu-green"}):s.jsx(Ol,{className:"w-4 h-4"})}),s.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:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"text-bambu-green font-mono text-sm font-bold whitespace-nowrap",children:hre(t.k_value)}),s.jsx("span",{className:"text-white text-sm truncate flex-1",title:t.name,children:t.name||"Unnamed"}),o&&s.jsx("span",{title:"Has note",children:s.jsx(tq,{className:"w-3 h-3 text-yellow-500"})}),s.jsxs("span",{className:"text-xs text-bambu-gray whitespace-nowrap",children:[l," ",c]})]}),o&&s.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&&s.jsx("button",{onClick:d=>{d.stopPropagation(),n()},className:"text-bambu-gray hover:text-white transition-colors p-1",title:"Copy profile",children:s.jsx(Jo,{className:"w-4 h-4"})})]})}function xj({profile:t,printerId:e,nozzleDiameter:n,existingProfiles:r=[],isDualNozzle:i=!1,initialNote:a="",initialNoteKey:o=null,onClose:l,onSave:c,onSaveNote:u}){const{showToast:d}=$n(),[f,m]=w.useState(t?.name||""),[g,x]=w.useState(t?.k_value?hre(t.k_value):"0.020"),[y,b]=w.useState(t?.filament_id||""),[v,M]=w.useState(t?.nozzle_id?iKe(t.nozzle_id):"HH00"),[S,A]=w.useState(t?.nozzle_diameter||n),[E,k]=w.useState(t?[t.extruder_id]:i?[0,1]:[0]),[C,R]=w.useState(!1),[T,P]=w.useState({current:0,total:0}),[F,L]=w.useState(a),X=jr.useMemo(()=>{const oe=new Map;for(const B of r)if(B.filament_id&&!oe.has(B.filament_id)){const G=LR(B.name||"");oe.set(B.filament_id,{id:B.filament_id,name:G||B.filament_id})}return Array.from(oe.values()).sort((B,G)=>B.name.localeCompare(G.name))},[r]),D=ft({mutationFn:oe=>(console.log("[KProfile] Calling API..."),pe.setKProfile(e,oe)),onSuccess:oe=>{if(console.log("[KProfile] Save success:",oe),d("K-profile saved"),u&&F!==a){let B;F===""&&o?B=o:t&&t.slot_id>0?B=t.setting_id||`slot_${t.slot_id}_${t.filament_id}_${t.extruder_id}`:B=`name_${f}_${y}`,u(B,F)}R(!0),setTimeout(()=>{R(!1),c()},2500)},onError:oe=>{console.error("[KProfile] Save error:",oe),d(oe.message,"error"),R(!1)}}),K=ft({mutationFn:oe=>(console.log("[KProfile] Deleting profile..."),pe.deleteKProfile(e,oe)),onSuccess:oe=>{console.log("[KProfile] Delete success:",oe),d("K-profile deleted"),R(!0),setTimeout(()=>{R(!1),l()},4e3)},onError:oe=>{console.error("[KProfile] Delete error:",oe),d(oe.message,"error"),R(!1)}}),[Y,q]=w.useState(!1),Z=()=>{t&&K.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})},re=async oe=>{if(oe.preventDefault(),i&&!t&&E.length===0){d("Please select at least one extruder","error");return}const B=parseFloat(g).toFixed(6),G=`${v}-${S}`;if(t||E.length===1){const te={name:f,k_value:B,filament_id:y,nozzle_id:G,nozzle_diameter:S,extruder_id:t?t.extruder_id:E[0],setting_id:t?.setting_id,slot_id:t?.slot_id??0};console.log("[KProfile] Saving profile:",te),D.mutate(te);return}R(!0),P({current:1,total:E.length});const J=E.map(te=>({name:f,k_value:B,filament_id:y,nozzle_id:G,nozzle_diameter:S,extruder_id:te,setting_id:void 0,slot_id:0}));console.log(`[KProfile] Saving ${J.length} profiles in batch:`,J);try{if(await pe.setKProfilesBatch(e,J),d(`K-profile saved to ${E.length} extruders`),u&&F){const te=`name_${f}_${y}`;u(te,F)}}catch(te){console.error("[KProfile] Failed to save batch:",te),d("Failed to save K-profiles","error"),R(!1),P({current:0,total:0});return}P({current:E.length,total:E.length}),setTimeout(()=>{R(!1),P({current:0,total:0}),c()},3e3)};return s.jsxs("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",children:[s.jsxs(Mt,{className:"w-full max-w-md relative",children:[C&&s.jsxs("div",{className:"absolute inset-0 bg-bambu-dark-secondary/90 flex flex-col items-center justify-center z-10 rounded-lg",children:[s.jsx(mt,{className:"w-8 h-8 text-bambu-green animate-spin mb-3"}),s.jsx("p",{className:"text-white font-medium",children:T.total>1?`Saving to extruder ${T.current}/${T.total}...`:"Syncing with printer..."}),s.jsx("p",{className:"text-bambu-gray text-sm mt-1",children:"Please wait"})]}),s.jsxs(Et,{className:"p-0",children:[s.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[s.jsx("h2",{className:"text-xl font-semibold text-white",children:t?"Edit K-Profile":"Add K-Profile"}),s.jsx("button",{onClick:l,className:"text-bambu-gray hover:text-white transition-colors",disabled:C,children:s.jsx(Ut,{className:"w-5 h-5"})})]}),s.jsxs("form",{onSubmit:re,className:"p-4 space-y-4",children:[s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Profile Name"}),s.jsx("input",{type:"text",value:f,onChange:oe=>m(oe.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:"My PLA Profile",required:!t})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"K-Value"}),s.jsx("input",{type:"text",inputMode:"decimal",value:g,onChange:oe=>{const B=oe.target.value;(B===""||/^\d*\.?\d*$/.test(B))&&x(B)},onBlur:oe=>{const B=parseFloat(oe.target.value);isNaN(B)||x((Math.trunc(B*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:"0.020",required:!0}),s.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Typical range: 0.01 - 0.06 for PLA, 0.02 - 0.10 for PETG"})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Filament"}),s.jsxs("select",{value:y,onChange:oe=>{const B=oe.target.value;if(b(B),!t&&B&&!f){const G=X.find(J=>J.id===B);G&&m(`${v==="HH00"?"HF":"S"} ${G.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:[s.jsx("option",{value:"",children:"Select filament..."}),t?.filament_id&&s.jsx("option",{value:t.filament_id,children:X.find(oe=>oe.id===t.filament_id)?.name||t.filament_id},t.filament_id),!t&&X.map(oe=>s.jsx("option",{value:oe.id,children:oe.name},oe.id))]}),!t&&X.length===0&&s.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"No filaments found. Create a K-profile in Bambu Studio first."})]}),s.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Flow Type"}),s.jsxs("select",{value:v,onChange:oe=>{const B=oe.target.value;if(M(B),!t&&y&&!f){const G=X.find(J=>J.id===y);G&&m(`${B==="HS00"?"HF":"S"} ${G.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:[s.jsx("option",{value:"HH00",children:"High Flow"}),s.jsx("option",{value:"HS00",children:"Standard"})]})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Nozzle Size"}),s.jsxs("select",{value:S,onChange:oe=>A(oe.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:[s.jsx("option",{value:"0.2",children:"0.2mm"}),s.jsx("option",{value:"0.4",children:"0.4mm"}),s.jsx("option",{value:"0.6",children:"0.6mm"}),s.jsx("option",{value:"0.8",children:"0.8mm"})]})]})]}),i&&s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:t?"Extruder":"Extruders"}),t?s.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?"Left":"Right"}):s.jsxs("div",{className:"flex gap-4",children:[s.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[s.jsx("input",{type:"checkbox",checked:E.includes(1),onChange:oe=>{oe.target.checked?k([...E,1]):k(E.filter(B=>B!==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"}),s.jsx("span",{className:"text-white",children:"Left"})]}),s.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[s.jsx("input",{type:"checkbox",checked:E.includes(0),onChange:oe=>{oe.target.checked?k([...E,0]):k(E.filter(B=>B!==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"}),s.jsx("span",{className:"text-white",children:"Right"})]})]})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Notes (stored locally)"}),s.jsx("textarea",{value:F,onChange:oe=>L(oe.target.value),placeholder:"Add notes about this profile...",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"}),s.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Notes are saved in Bambuddy, not on the printer"})]}),s.jsxs("div",{className:"flex gap-2 pt-4",children:[t&&s.jsx(Se,{type:"button",variant:"secondary",onClick:()=>q(!0),disabled:K.isPending||C,className:"text-red-500 hover:bg-red-500/10",children:K.isPending?s.jsx(mt,{className:"w-4 h-4 animate-spin"}):s.jsx(an,{className:"w-4 h-4"})}),s.jsx(Se,{type:"button",variant:"secondary",onClick:l,disabled:C,className:"flex-1",children:"Cancel"}),s.jsxs(Se,{type:"submit",disabled:D.isPending||C,className:"flex-1",children:[D.isPending?s.jsx(mt,{className:"w-4 h-4 animate-spin"}):s.jsx(j2,{className:"w-4 h-4"}),"Save"]})]})]})]})]}),Y&&s.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-[60]",children:s.jsx(Mt,{className:"w-full max-w-sm",children:s.jsxs(Et,{className:"p-6",children:[s.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[s.jsx("div",{className:"w-10 h-10 rounded-full bg-red-500/20 flex items-center justify-center",children:s.jsx(an,{className:"w-5 h-5 text-red-500"})}),s.jsxs("div",{children:[s.jsx("h3",{className:"text-lg font-semibold text-white",children:"Delete Profile"}),s.jsx("p",{className:"text-sm text-bambu-gray",children:"This cannot be undone"})]})]}),s.jsxs("p",{className:"text-bambu-gray mb-6",children:["Are you sure you want to delete ",s.jsxs("span",{className:"text-white font-medium",children:['"',t?.name,'"']})," from the printer?"]}),s.jsxs("div",{className:"flex gap-3",children:[s.jsx(Se,{variant:"secondary",onClick:()=>q(!1),className:"flex-1",children:"Cancel"}),s.jsxs(Se,{onClick:()=>{q(!1),Z()},disabled:K.isPending,className:"flex-1 bg-red-500 hover:bg-red-600 text-white",children:[K.isPending?s.jsx(mt,{className:"w-4 h-4 animate-spin"}):s.jsx(an,{className:"w-4 h-4"}),"Delete"]})]})]})})})]})}const C1={NOZZLE_DIAMETER:"bambusy_kprofiles_nozzle",SORT_OPTION:"bambusy_kprofiles_sort"};function aKe(){const{showToast:t}=$n(),[e,n]=w.useState(null),[r,i]=w.useState(()=>localStorage.getItem(C1.NOZZLE_DIAMETER)||"0.4"),[a,o]=w.useState(null),[l,c]=w.useState(!1),[u,d]=w.useState(null),[f,m]=w.useState(""),[g,x]=w.useState("all"),[y,b]=w.useState("all"),[v,M]=w.useState(()=>localStorage.getItem(C1.SORT_OPTION)||"name"),[S,A]=w.useState(!1),[E,k]=w.useState(new Set),[C,R]=w.useState(!1),[T,P]=w.useState(!1),F=w.useCallback(U=>`${U.slot_id}_${U.extruder_id}`,[]);w.useEffect(()=>{localStorage.setItem(C1.NOZZLE_DIAMETER,r)},[r]),w.useEffect(()=>{localStorage.setItem(C1.SORT_OPTION,v)},[v]);const{data:L,isLoading:X}=ct({queryKey:["printers"],queryFn:pe.getPrinters}),{data:D,isLoading:K,isFetching:Y,error:q,refetch:Z}=ct({queryKey:["kprofiles",e,r],queryFn:async()=>{console.log("[KProfiles] Fetching profiles for printer",e,"nozzle",r);const U=await pe.getKProfiles(e,r);return console.log("[KProfiles] Received profiles:",U?.profiles?.length||0,"profiles"),U},enabled:!!e,retry:!1,staleTime:0,gcTime:0,refetchOnMount:"always"}),{data:re}=ct({queryKey:["kprofiles",e,"0.4"],queryFn:()=>pe.getKProfiles(e,"0.4"),enabled:!!e,staleTime:6e4}),{data:oe,refetch:B}=ct({queryKey:["kprofile-notes",e],queryFn:()=>pe.getKProfileNotes(e),enabled:!!e,staleTime:3e4}),G=q?.message?.includes("not connected");w.useEffect(()=>{if(!e&&L&&L.length>0){const U=L.find(V=>V.is_active);U&&n(U.id)}},[e,L]),w.useEffect(()=>{if(e){const U=setTimeout(()=>{Z()},150);return()=>clearTimeout(U)}},[e,r]);const J=L?.filter(U=>U.is_active)||[],te=jr.useMemo(()=>D?.profiles?D.profiles.filter(V=>{const Q=f.toLowerCase(),Ee=!Q||V.name.toLowerCase().includes(Q)||V.filament_id.toLowerCase().includes(Q),Ce=g==="all"||g==="left"&&V.extruder_id===1||g==="right"&&V.extruder_id===0,Ne=y==="all"||y==="hf"&&V.nozzle_id.startsWith("HH")||y==="s"&&V.nozzle_id.startsWith("HS");return Ee&&Ce&&Ne}).sort((V,Q)=>{switch(v){case"k_value":return parseFloat(V.k_value)-parseFloat(Q.k_value);case"filament":return LR(V.name).localeCompare(LR(Q.name));case"name":default:return V.name.localeCompare(Q.name)}}):[],[D?.profiles,f,g,y,v]),ae=L?.find(U=>U.id===e),de=ae?.nozzle_count===2;w.useEffect(()=>{const U=V=>{V.target instanceof HTMLInputElement||V.target instanceof HTMLTextAreaElement||V.target instanceof HTMLSelectElement||a||l||u||(V.key==="r"||V.key==="R"?(V.preventDefault(),Z()):V.key==="n"||V.key==="N"?(V.preventDefault(),c(!0)):V.key==="Escape"&&S&&(V.preventDefault(),A(!1),k(new Set)))};return window.addEventListener("keydown",U),()=>window.removeEventListener("keydown",U)},[a,l,u,S,Z]);const fe=w.useCallback(()=>{if(!D?.profiles||D.profiles.length===0){t("No profiles to export","error");return}const U={version:1,exported_at:new Date().toISOString(),printer:ae?.name||"Unknown",nozzle_diameter:r,profiles:D.profiles.map(Ce=>({name:Ce.name,k_value:Ce.k_value,filament_id:Ce.filament_id,nozzle_id:Ce.nozzle_id,nozzle_diameter:Ce.nozzle_diameter,extruder_id:Ce.extruder_id}))},V=new Blob([JSON.stringify(U,null,2)],{type:"application/json"}),Q=URL.createObjectURL(V),Ee=document.createElement("a");Ee.href=Q,Ee.download=`kprofiles_${ae?.name||"printer"}_${r}mm_${new Date().toISOString().split("T")[0]}.json`,document.body.appendChild(Ee),Ee.click(),document.body.removeChild(Ee),URL.revokeObjectURL(Q),t(`Exported ${D.profiles.length} profiles`)},[D?.profiles,ae,r,t]),Ae=w.useCallback(()=>{const U=document.createElement("input");U.type="file",U.accept=".json",U.onchange=async V=>{const Q=V.target.files?.[0];if(Q)try{const Ee=await Q.text(),Ce=JSON.parse(Ee);if(!Ce.profiles||!Array.isArray(Ce.profiles)){t("Invalid file format","error");return}let Ne=0;for(const H of Ce.profiles)if(!(!H.name||!H.k_value||!H.filament_id))try{await pe.setKProfile(e,{name:H.name,k_value:parseFloat(H.k_value).toFixed(6),filament_id:H.filament_id,nozzle_id:H.nozzle_id||`HH00-${r}`,nozzle_diameter:H.nozzle_diameter||r,extruder_id:H.extruder_id??0,slot_id:0}),Ne++,await new Promise(O=>setTimeout(O,500))}catch(O){console.error("Failed to import profile:",H.name,O)}t(`Imported ${Ne} of ${Ce.profiles.length} profiles`),Z()}catch(Ee){console.error("Import error:",Ee),t("Failed to parse import file","error")}},U.click()},[e,r,t,Z]),ge=w.useCallback(U=>{k(V=>{const Q=new Set(V);return Q.has(U)?Q.delete(U):Q.add(U),Q})},[]),Me=w.useCallback(()=>{k(new Set(te.map(U=>F(U))))},[te,F]),je=w.useCallback(()=>{E.size!==0&&R(!0)},[E.size]),ne=w.useCallback(async()=>{const U=te.filter(Q=>E.has(F(Q)));P(!0);let V=0;for(const Q of U)try{await pe.deleteKProfile(e,{slot_id:Q.slot_id,extruder_id:Q.extruder_id,nozzle_id:Q.nozzle_id,nozzle_diameter:Q.nozzle_diameter,filament_id:Q.filament_id,setting_id:Q.setting_id}),V++,await new Promise(Ee=>setTimeout(Ee,300))}catch(Ee){console.error("Failed to delete profile:",Q.name,Ee)}t(`Deleted ${V} profiles`),P(!1),R(!1),A(!1),k(new Set),Z()},[e,E,te,t,Z,F]),Ke=w.useCallback(U=>{const V=[];return U.setting_id&&V.push(U.setting_id),V.push(`slot_${U.slot_id}_${U.filament_id}_${U.extruder_id}`),V.push(`name_${U.name}_${U.filament_id}`),V},[]),$=w.useCallback(async(U,V)=>{if(e)try{await pe.setKProfileNote(e,U,V),B()}catch(Q){console.error("Failed to save note:",Q),t("Failed to save note","error")}},[e,B,t]),z=w.useCallback(U=>{if(!oe?.notes)return{note:"",key:null};const V=Ke(U);for(const Q of V)if(oe.notes[Q])return{note:oe.notes[Q],key:Q};return{note:"",key:null}},[oe,Ke]),W=w.useCallback(U=>z(U).note,[z]);return X?s.jsx("div",{className:"flex justify-center py-12",children:s.jsx(mt,{className:"w-8 h-8 text-bambu-green animate-spin"})}):!L||L.length===0?s.jsx(Mt,{children:s.jsxs(Et,{className:"py-12 text-center",children:[s.jsx(ea,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),s.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:"No Printers Configured"}),s.jsx("p",{className:"text-bambu-gray",children:"Add a printer in Settings to manage K-profiles"})]})}):J.length===0?s.jsx(Mt,{children:s.jsxs(Et,{className:"py-12 text-center",children:[s.jsx(Ir,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),s.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:"No Active Printers"}),s.jsx("p",{className:"text-bambu-gray",children:"Enable a printer connection to view its K-profiles"})]})}):s.jsxs(s.Fragment,{children:[Y&&!K&&s.jsxs("div",{className:"fixed inset-0 bg-black/50 flex flex-col items-center justify-center z-40",children:[s.jsx(mt,{className:"w-10 h-10 text-bambu-green animate-spin mb-3"}),s.jsx("p",{className:"text-white font-medium",children:"Loading K-Profiles..."})]}),s.jsxs("div",{className:"flex flex-wrap gap-4 mb-6",children:[s.jsxs("div",{className:"flex-1 min-w-48",children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Printer"}),s.jsx("select",{value:e||"",onChange:U=>n(parseInt(U.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:J.map(U=>s.jsx("option",{value:U.id,children:U.name},U.id))})]}),s.jsxs("div",{className:"w-32",children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Nozzle"}),s.jsxs("select",{value:r,onChange:U=>i(U.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[s.jsx("option",{value:"0.2",children:"0.2mm"}),s.jsx("option",{value:"0.4",children:"0.4mm"}),s.jsx("option",{value:"0.6",children:"0.6mm"}),s.jsx("option",{value:"0.8",children:"0.8mm"})]})]}),s.jsxs("div",{className:"flex items-end gap-2",children:[s.jsxs(Se,{variant:"secondary",onClick:()=>Z(),disabled:Y,children:[s.jsx(yr,{className:`w-4 h-4 ${Y?"animate-spin":""}`}),"Refresh"]}),s.jsxs(Se,{onClick:()=>c(!0),children:[s.jsx(Kn,{className:"w-4 h-4"}),"Add Profile"]})]})]}),s.jsxs("div",{className:"flex flex-wrap gap-4 mb-4",children:[s.jsxs("div",{className:"flex-1 min-w-48 relative",children:[s.jsx(xa,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray"}),s.jsx("input",{type:"text",value:f,onChange:U=>m(U.target.value),placeholder:"Search by name or filament...",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"})]}),de&&s.jsx("div",{className:"w-36",children:s.jsxs("select",{value:g,onChange:U=>x(U.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:[s.jsx("option",{value:"all",children:"All Extruders"}),s.jsx("option",{value:"left",children:"Left Only"}),s.jsx("option",{value:"right",children:"Right Only"})]})}),s.jsx("div",{className:"w-32",children:s.jsxs("select",{value:y,onChange:U=>b(U.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:[s.jsx("option",{value:"all",children:"All Flow"}),s.jsx("option",{value:"hf",children:"HF Only"}),s.jsx("option",{value:"s",children:"S Only"})]})}),s.jsx("div",{className:"w-32",children:s.jsxs("select",{value:v,onChange:U=>M(U.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[s.jsx("option",{value:"name",children:"Sort: Name"}),s.jsx("option",{value:"k_value",children:"Sort: K-Value"}),s.jsx("option",{value:"filament",children:"Sort: Filament"})]})})]}),s.jsxs("div",{className:"flex flex-wrap gap-2 mb-6",children:[s.jsxs(Se,{variant:"secondary",onClick:fe,disabled:!D?.profiles?.length,title:"Export profiles to JSON",children:[s.jsx(Jr,{className:"w-4 h-4"}),"Export"]}),s.jsxs(Se,{variant:"secondary",onClick:Ae,title:"Import profiles from JSON",children:[s.jsx(bi,{className:"w-4 h-4"}),"Import"]}),s.jsx("div",{className:"flex-1"}),S?s.jsxs(s.Fragment,{children:[s.jsxs(Se,{variant:"secondary",onClick:Me,title:"Select all visible profiles",children:[s.jsx(eu,{className:"w-4 h-4"}),"Select All"]}),s.jsxs(Se,{variant:"secondary",onClick:je,disabled:E.size===0,className:"text-red-500 hover:bg-red-500/10",title:`Delete ${E.size} selected profiles`,children:[s.jsx(an,{className:"w-4 h-4"}),"Delete (",E.size,")"]}),s.jsxs(Se,{variant:"secondary",onClick:()=>{A(!1),k(new Set)},children:[s.jsx(Ut,{className:"w-4 h-4"}),"Cancel"]})]}):s.jsxs(Se,{variant:"secondary",onClick:()=>A(!0),disabled:!te.length,title:"Enter selection mode for bulk delete",children:[s.jsx(eu,{className:"w-4 h-4"}),"Select"]})]}),K?s.jsx("div",{className:"flex justify-center py-12",children:s.jsx(mt,{className:"w-8 h-8 text-bambu-green animate-spin"})}):G?s.jsx(Mt,{children:s.jsxs(Et,{className:"py-12 text-center",children:[s.jsx(Pg,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),s.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:"Printer Offline"}),s.jsx("p",{className:"text-bambu-gray mb-4",children:"The selected printer is not connected. Power it on to view K-profiles."}),s.jsxs(Se,{variant:"secondary",onClick:()=>Z(),children:[s.jsx(yr,{className:"w-4 h-4"}),"Retry"]})]})}):te.length>0?de?s.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[s.jsxs("div",{children:[s.jsx("h3",{className:"text-sm font-medium text-bambu-gray mb-2 px-1",children:"Left Extruder"}),s.jsx("div",{className:"space-y-1",children:te.filter(U=>U.extruder_id===1).map(U=>s.jsx(gj,{profile:U,onEdit:()=>o(U),onCopy:()=>d(U),selectionMode:S,isSelected:E.has(F(U)),onToggleSelect:()=>ge(F(U)),note:W(U)},F(U)))})]}),s.jsxs("div",{children:[s.jsx("h3",{className:"text-sm font-medium text-bambu-gray mb-2 px-1",children:"Right Extruder"}),s.jsx("div",{className:"space-y-1",children:te.filter(U=>U.extruder_id===0).map(U=>s.jsx(gj,{profile:U,onEdit:()=>o(U),onCopy:()=>d(U),selectionMode:S,isSelected:E.has(F(U)),onToggleSelect:()=>ge(F(U)),note:W(U)},F(U)))})]})]}):s.jsx("div",{className:"space-y-1",children:te.map(U=>s.jsx(gj,{profile:U,onEdit:()=>o(U),onCopy:()=>d(U),selectionMode:S,isSelected:E.has(F(U)),onToggleSelect:()=>ge(F(U)),note:W(U)},F(U)))}):f||g!=="all"||y!=="all"?s.jsx(Mt,{children:s.jsxs(Et,{className:"py-12 text-center",children:[s.jsx(xa,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),s.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:"No Matching Profiles"}),s.jsx("p",{className:"text-bambu-gray",children:"No profiles match your search criteria"})]})}):s.jsx(Mt,{children:s.jsxs(Et,{className:"py-12 text-center",children:[s.jsx(j2,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),s.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:"No K-Profiles"}),s.jsxs("p",{className:"text-bambu-gray mb-4",children:["No pressure advance profiles found for ",r,"mm nozzle"]}),s.jsxs(Se,{onClick:()=>c(!0),children:[s.jsx(Kn,{className:"w-4 h-4"}),"Create First Profile"]})]})}),a&&e&&(()=>{const{note:U,key:V}=z(a);return s.jsx(xj,{profile:a,printerId:e,nozzleDiameter:r,existingProfiles:re?.profiles||D?.profiles,isDualNozzle:de,initialNote:U,initialNoteKey:V,onSaveNote:$,onClose:()=>{console.log("[KProfiles] Edit modal onClose - refetching profiles..."),o(null),Z()},onSave:()=>{o(null),Z()}})})(),l&&e&&s.jsx(xj,{printerId:e,nozzleDiameter:r,existingProfiles:re?.profiles||D?.profiles,isDualNozzle:de,onSaveNote:$,onClose:()=>{c(!1),Z()},onSave:()=>{c(!1),Z()}}),u&&e&&s.jsx(xj,{printerId:e,nozzleDiameter:r,existingProfiles:re?.profiles||D?.profiles,isDualNozzle:de,onSaveNote:$,profile:{...u,slot_id:0,name:`${u.name} (Copy)`},onClose:()=>{d(null),Z()},onSave:()=>{d(null),Z()}}),C&&s.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",children:s.jsx(Mt,{className:"w-full max-w-sm",children:s.jsxs(Et,{className:"p-6",children:[s.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[s.jsx("div",{className:"w-10 h-10 rounded-full bg-red-500/20 flex items-center justify-center",children:s.jsx(an,{className:"w-5 h-5 text-red-500"})}),s.jsxs("div",{children:[s.jsx("h3",{className:"text-lg font-semibold text-white",children:"Delete Profiles"}),s.jsx("p",{className:"text-sm text-bambu-gray",children:"This cannot be undone"})]})]}),s.jsxs("p",{className:"text-bambu-gray mb-6",children:["Are you sure you want to delete ",s.jsx("span",{className:"text-white font-medium",children:E.size})," selected profiles from the printer?"]}),s.jsxs("div",{className:"flex gap-3",children:[s.jsx(Se,{variant:"secondary",onClick:()=>R(!1),disabled:T,className:"flex-1",children:"Cancel"}),s.jsxs(Se,{onClick:ne,disabled:T,className:"flex-1 bg-red-500 hover:bg-red-600 text-white",children:[T?s.jsx(mt,{className:"w-4 h-4 animate-spin"}):s.jsx(an,{className:"w-4 h-4"}),"Delete"]})]})]})})})]})}function RL(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,a=n.match(/(\d+\.?\d*)\s*(?:mm\s*)?nozzle|nozzle\s*(\d+\.?\d*)/i),o=a?(a[1]||a[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 W0(t){return/^(P[FPM]US|PF\d|PP\d)/.test(t)}function sKe(t){const e=mi(t);if(!e)return"";const r=new Date().getTime()-e.getTime(),i=Math.floor(r/6e4),a=Math.floor(r/36e5),o=Math.floor(r/864e5);return i<1?"Just now":i<60?`${i}m ago`:a<24?`${a}h ago`:o<7?`${o}d ago`:e.toLocaleDateString()}function oKe({onSuccess:t}){const{showToast:e}=$n(),[n,r]=w.useState("email"),[i,a]=w.useState(""),[o,l]=w.useState(""),[c,u]=w.useState(""),[d,f]=w.useState(""),[m,g]=w.useState("global"),x=ft({mutationFn:()=>pe.cloudLogin(i,o,m),onSuccess:S=>{S.success?(e("Logged in successfully"),t()):S.needs_verification?(e("Verification code sent to your email"),r("code")):e(S.message,"error")},onError:S=>e(S.message,"error")}),y=ft({mutationFn:()=>pe.cloudVerify(i,c),onSuccess:S=>{S.success?(e("Logged in successfully"),t()):e(S.message,"error")},onError:S=>e(S.message,"error")}),b=ft({mutationFn:()=>pe.cloudSetToken(d),onSuccess:()=>{e("Token set successfully"),t()},onError:S=>e(S.message,"error")}),v=S=>{S.preventDefault(),n==="email"?x.mutate():n==="code"?y.mutate():n==="token"&&b.mutate()},M=x.isPending||y.isPending||b.isPending;return s.jsx(Mt,{className:"max-w-md mx-auto",children:s.jsxs(Et,{children:[s.jsxs("div",{className:"text-center mb-6",children:[s.jsx("div",{className:"inline-flex items-center justify-center w-12 h-12 rounded-xl bg-bambu-green/20 mb-3",children:s.jsx(A2,{className:"w-6 h-6 text-bambu-green"})}),s.jsx("h2",{className:"text-xl font-semibold text-white",children:"Connect to Bambu Cloud"}),s.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:"Sync your slicer presets across devices"})]}),s.jsxs("form",{onSubmit:v,className:"space-y-4",children:[n==="email"&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Email"}),s.jsx("input",{type:"email",value:i,onChange:S=>a(S.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})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Password"}),s.jsx("input",{type:"password",value:o,onChange:S=>l(S.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})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Region"}),s.jsxs("select",{value:m,onChange:S=>g(S.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:[s.jsx("option",{value:"global",children:"Global"}),s.jsx("option",{value:"china",children:"China"})]})]})]}),n==="code"&&s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Verification Code"}),s.jsxs("p",{className:"text-xs text-bambu-gray mb-2",children:["Check your email (",i,") for a 6-digit code"]}),s.jsx("input",{type:"text",value:c,onChange:S=>u(S.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})]}),n==="token"&&s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Access Token"}),s.jsx("p",{className:"text-xs text-bambu-gray mb-2",children:"Paste your Bambu Lab access token (from Bambu Studio)"}),s.jsx("textarea",{value:d,onChange:S=>f(S.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})]}),s.jsxs("div",{className:"flex gap-2",children:[n==="code"&&s.jsx(Se,{type:"button",variant:"secondary",onClick:()=>r("email"),className:"flex-1",children:"Back"}),s.jsxs(Se,{type:"submit",disabled:M,className:"flex-1",children:[M?s.jsx(mt,{className:"w-4 h-4 animate-spin"}):s.jsx(hz,{className:"w-4 h-4"}),n==="email"?"Login":n==="code"?"Verify":"Set Token"]})]}),n==="email"&&s.jsx("div",{className:"pt-4 border-t border-bambu-dark-tertiary",children:s.jsxs("button",{type:"button",onClick:()=>r("token"),className:"text-sm text-bambu-gray hover:text-white flex items-center gap-2 transition-colors",children:[s.jsx(Gh,{className:"w-4 h-4"}),"Use access token instead"]})}),n==="token"&&s.jsx("div",{className:"pt-4 border-t border-bambu-dark-tertiary",children:s.jsxs("button",{type:"button",onClick:()=>r("email"),className:"text-sm text-bambu-gray hover:text-white flex items-center gap-2 transition-colors",children:[s.jsx(hz,{className:"w-4 h-4"}),"Login with email instead"]})})]})]})})}function xp({label:t,value:e,options:n,onChange:r}){const[i,a]=w.useState(!1),o=n.find(l=>l.value===e);return s.jsxs("div",{className:"relative",children:[s.jsxs("button",{onClick:()=>a(!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:[s.jsxs("span",{className:"text-bambu-gray",children:[t,":"]}),s.jsx("span",{children:o?.label||"All"}),s.jsx(Ji,{className:`w-4 h-4 text-bambu-gray transition-transform ${i?"rotate-180":""}`})]}),i&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"fixed inset-0 z-10",onClick:()=>a(!1)}),s.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=>s.jsxs("button",{onClick:()=>{r(l.value),a(!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:[s.jsx("span",{children:l.label}),l.count!==void 0&&s.jsx("span",{className:"text-bambu-gray text-xs",children:l.count})]},l.value))})]})]})}function lKe(){const[t,e]=w.useState(!1);w.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?s.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:s.jsx(Kp,{className:"w-5 h-5"})}):null}function bj({setting:t,onClick:e,onDuplicate:n,compareMode:r,isCompareSelected:i,compareIndex:a,compareDisabled:o}){const l=RL(t.name),c=W0(t.setting_id);return s.jsxs("div",{className:"flex items-center gap-2 group",children:[s.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:s.jsxs("div",{className:"flex items-center gap-2",children:[i&&a!==void 0&&s.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:a+1}),!i&&c&&s.jsx("span",{className:"flex-shrink-0 w-1.5 h-1.5 rounded-full bg-bambu-green",title:"My preset (editable)"}),s.jsx("span",{className:"text-white text-sm truncate flex-1",title:t.name,children:t.name}),l.filamentType&&t.type==="filament"&&s.jsx("span",{className:"text-xs text-bambu-gray whitespace-nowrap",children:l.filamentType}),l.layerHeight&&t.type==="process"&&s.jsx("span",{className:"text-xs text-bambu-gray whitespace-nowrap",children:l.layerHeight}),l.printer&&s.jsx("span",{className:"text-xs text-bambu-gray whitespace-nowrap",children:l.printer})]})}),s.jsx("button",{onClick:u=>{u.stopPropagation(),n()},className:"opacity-0 group-hover:opacity-100 text-bambu-gray hover:text-white transition-all p-1",title:"Duplicate",children:s.jsx(Jo,{className:"w-4 h-4"})})]})}function IR(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 7ad8f868b..8feec1e3d 100644 --- a/static/index.html +++ b/static/index.html @@ -23,7 +23,7 @@ - +