diff --git a/CHANGELOG.md b/CHANGELOG.md index 39a3c119d..4bd58a1ab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ All notable changes to Bambuddy will be documented in this file. - **Print Queue Scheduler Diagnostics** ([#616](https://github.com/maziggy/bambuddy/issues/616)) — Added diagnostic logging to the print queue scheduler to help diagnose why queued prints aren't starting. After each queue check, the scheduler now logs a skip summary (how many items were skipped due to manual_start, scheduled_time, etc.) and for each busy printer, logs the exact state preventing it from being considered idle (connected status, printer state, plate_cleared flag). Previously the scheduler only logged "found N pending items" with no visibility into why items were skipped. ### Fixed +- **PWA Install Not Available in Chrome** ([#629](https://github.com/maziggy/bambuddy/issues/629)) — Chrome did not show the PWA install prompt because the manifest icons had incorrect dimensions (e.g. 190px wide declared as 192px) and the manifest was missing the `screenshots` entries required for Chrome's richer install UI. Resized all three icons (`android-chrome-192x192.png`, `android-chrome-512x512.png`, `apple-touch-icon.png`) to their declared sizes, split the discouraged `"any maskable"` purpose into a dedicated `"maskable"` entry, and added mobile and desktop screenshots to the manifest. Reported by @SebSeifert. - **Project Statistics Count Archived Files as Printed** ([#630](https://github.com/maziggy/bambuddy/issues/630)) — Files added to a project from the archive were counted in project statistics (completed prints, parts progress) as if they had already been printed. Only files with `status="completed"` (actually printed via a printer) now count toward completion stats. Files with `status="archived"` (stored but not yet printed) are no longer included. Reported by @SebSeifert. - **Python 3.10 Compatibility** — Bambuddy failed to start on Python 3.10 with `ImportError: cannot import name 'StrEnum' from 'enum'` because `enum.StrEnum` was added in Python 3.11. Added a compatibility shim that falls back to `(str, Enum)` on Python < 3.11, matching the documented requirement of Python 3.10+. - **Bug Report Bubble Overlapping Toasts** — Moved toast notifications and upload progress up so they stack above the bug report bubble instead of overlapping on top of each other. diff --git a/frontend/public/img/android-chrome-192x192.png b/frontend/public/img/android-chrome-192x192.png index b0a45c6c0..cbd04d89d 100644 Binary files a/frontend/public/img/android-chrome-192x192.png and b/frontend/public/img/android-chrome-192x192.png differ diff --git a/frontend/public/img/android-chrome-512x512.png b/frontend/public/img/android-chrome-512x512.png index 5f871b422..19c81cc63 100644 Binary files a/frontend/public/img/android-chrome-512x512.png and b/frontend/public/img/android-chrome-512x512.png differ diff --git a/frontend/public/img/apple-touch-icon.png b/frontend/public/img/apple-touch-icon.png index 63cb2e2f6..c0502d04f 100644 Binary files a/frontend/public/img/apple-touch-icon.png and b/frontend/public/img/apple-touch-icon.png differ diff --git a/frontend/public/img/screenshot-desktop.png b/frontend/public/img/screenshot-desktop.png new file mode 100644 index 000000000..f706fee31 Binary files /dev/null and b/frontend/public/img/screenshot-desktop.png differ diff --git a/frontend/public/img/screenshot-mobile.png b/frontend/public/img/screenshot-mobile.png new file mode 100644 index 000000000..2edc73f29 Binary files /dev/null and b/frontend/public/img/screenshot-mobile.png differ diff --git a/frontend/public/manifest.json b/frontend/public/manifest.json index 48eb8eef3..7ce8fd63a 100644 --- a/frontend/public/manifest.json +++ b/frontend/public/manifest.json @@ -35,7 +35,23 @@ "src": "/img/apple-touch-icon.png", "sizes": "180x180", "type": "image/png", - "purpose": "any maskable" + "purpose": "maskable" + } + ], + "screenshots": [ + { + "src": "/img/screenshot-mobile.png", + "sizes": "1080x1920", + "type": "image/png", + "form_factor": "narrow", + "label": "Bambuddy on mobile" + }, + { + "src": "/img/screenshot-desktop.png", + "sizes": "1920x1080", + "type": "image/png", + "form_factor": "wide", + "label": "Bambuddy on desktop" } ], "categories": ["utilities", "productivity"], diff --git a/static/assets/index-CskDBRt4.js b/static/assets/index-4rCw-7Dd.js similarity index 96% rename from static/assets/index-CskDBRt4.js rename to static/assets/index-4rCw-7Dd.js index 630dbaf29..c687fb757 100644 --- a/static/assets/index-CskDBRt4.js +++ b/static/assets/index-4rCw-7Dd.js @@ -8694,7 +8694,7 @@ Accuracy: ${t.time_accuracy.toFixed(0)}%`:t.actual_time_seconds?`Actual: ${js(t. ${!d&&!W?"border-bambu-dark-tertiary hover:border-bambu-dark-tertiary/80":""} ${ie?"sm:cursor-default":""} `,onClick:ie?()=>{window.innerWidth<640&&u()}:void 0,children:[ie&&d&&i.jsx("div",{className:"sm:hidden absolute left-0 top-3 bottom-3 w-1 rounded-full bg-bambu-green"}),i.jsxs("div",{className:"flex items-start sm:items-center gap-2 sm:gap-4 p-3 sm:p-4",children:[O&&u&&i.jsx("button",{onClick:Y=>{Y.stopPropagation(),u()},className:`hidden sm:flex items-center justify-center w-6 h-6 rounded border transition-colors shrink-0 ${d?"bg-bambu-green border-bambu-green text-white":"border-white/30 bg-black/30 hover:border-bambu-green/50"}`,children:d&&i.jsx(Vr,{className:"w-4 h-4"})}),O?i.jsx("div",{...P,...k,className:"hidden sm:flex items-center justify-center w-8 h-8 rounded-lg bg-bambu-dark cursor-grab active:cursor-grabbing hover:bg-bambu-dark-tertiary transition-colors touch-manipulation shrink-0",children:i.jsx(qm,{className:"w-4 h-4 text-bambu-gray"})}):e!==void 0?i.jsxs("div",{className:"hidden sm:flex items-center justify-center w-8 h-8 rounded-lg bg-bambu-dark text-bambu-gray text-sm font-medium shrink-0",children:["#",e]}):i.jsx("div",{className:"hidden sm:block w-8 shrink-0"}),i.jsx("div",{className:"w-10 h-10 sm:w-14 sm:h-14 flex-shrink-0 bg-bambu-dark rounded-lg overflow-hidden",children:t.archive_thumbnail?i.jsx("img",{src:t.plate_id!=null?fe.getArchivePlateThumbnail(t.archive_id,t.plate_id):fe.getArchiveThumbnail(t.archive_id),alt:"",className:"w-full h-full object-cover"}):t.library_file_thumbnail?i.jsx("img",{src:t.plate_id!=null?fe.getLibraryFilePlateThumbnail(t.library_file_id,t.plate_id):fe.getLibraryFileThumbnailUrl(t.library_file_id),alt:"",className:"w-full h-full object-cover"}):i.jsx("div",{className:"w-full h-full flex items-center justify-center text-bambu-gray",children:i.jsx(Gi,{className:"w-5 h-5 sm:w-6 sm:h-6"})})}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[i.jsxs("p",{className:"text-sm sm:text-base text-white font-medium truncate",children:[t.archive_name||t.library_file_name||`File #${t.archive_id||t.library_file_id}`,(N?.is_multi_plate??!1)&&t.plate_id!==void 0&&t.plate_id!==null&&` • ${C.find(Y=>Y.index===t.plate_id)?.name||x("queue.plateNumber",{index:t.plate_id})}`]}),t.archive_id?i.jsx(eo,{to:`/archives?highlight=${t.archive_id}`,className:"text-bambu-gray hover:text-bambu-green transition-colors flex-shrink-0",title:x("queue.viewArchive"),children:i.jsx(ei,{className:"w-3.5 h-3.5"})}):t.library_file_id?i.jsx(eo,{to:`/library?highlight=${t.library_file_id}`,className:"text-bambu-gray hover:text-bambu-green transition-colors flex-shrink-0",title:x("queue.viewInFileManager"),children:i.jsx(ei,{className:"w-3.5 h-3.5"})}):null]}),i.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1 text-xs sm:text-sm text-bambu-gray",children:[i.jsxs("span",{className:`flex items-center gap-1 sm:gap-1.5 ${t.printer_id===null&&!t.target_model?"text-orange-400":""} ${t.target_model?"text-blue-400":""}`,children:[i.jsx(_r,{className:"w-3 h-3 sm:w-3.5 sm:h-3.5"}),i.jsx("span",{className:"truncate max-w-[120px] sm:max-w-none",children:t.target_model?`${x("queue.filter.any")} ${t.target_model}${t.target_location?` @ ${t.target_location}`:""}${t.required_filament_types?.length?` (${t.required_filament_types.join(", ")})`:""}`:t.printer_id===null?x("queue.filter.unassigned"):t.printer_name||`${x("common.printer")} #${t.printer_id}`})]}),t.print_time_seconds&&i.jsxs("span",{className:"flex items-center gap-1 sm:gap-1.5",children:[i.jsx(Gd,{className:"w-3 h-3 sm:w-3.5 sm:h-3.5"}),js(t.print_time_seconds)]}),t.filament_used_grams&&i.jsxs("span",{className:"flex items-center gap-1 sm:gap-1.5",children:[i.jsx(nX,{className:"w-3 h-3 sm:w-3.5 sm:h-3.5"}),Ase(t.filament_used_grams)]}),t.created_by_username&&i.jsxs("span",{className:"hidden sm:flex items-center gap-1.5",title:x("queue.addedBy",{name:t.created_by_username}),children:[i.jsx(uu,{className:"w-3.5 h-3.5"}),t.created_by_username]}),O&&!t.manual_start&&i.jsxs("span",{className:"flex items-center gap-1.5",children:[i.jsx(Xn,{className:"w-3.5 h-3.5"}),t.scheduled_time?(er(t.scheduled_time)?.getTime()??0)-Date.now()<-6e4?x?.("queue.time.overdue")??"Overdue":Iv(t.scheduled_time,c,x):x?.("queue.time.asap")??"ASAP"]})]}),i.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 sm:gap-2 mt-1.5 sm:mt-2",children:[t.manual_start&&i.jsxs("span",{className:"text-[10px] sm:text-xs px-1.5 sm: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:[i.jsx(WY,{className:"w-2.5 h-2.5 sm:w-3 sm:h-3"}),x("queue.badges.staged")]}),t.require_previous_success&&i.jsx("span",{className:"text-[10px] sm:text-xs px-1.5 sm:px-2 py-0.5 bg-orange-500/10 text-orange-400 rounded-full border border-orange-500/20",children:x("queue.badges.requiresPrevious")}),t.auto_off_after&&i.jsxs("span",{className:"text-[10px] sm:text-xs px-1.5 sm: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:[i.jsx(Su,{className:"w-2.5 h-2.5 sm:w-3 sm:h-3"}),x("queue.badges.autoPowerOff")]})]}),W&&v&&i.jsxs("div",{className:"mt-2 sm:mt-3",children:[i.jsxs("div",{className:"flex items-center justify-between text-xs sm:text-sm",children:[i.jsx("div",{className:"flex-1 bg-bambu-dark-tertiary rounded-full h-1.5 sm:h-2 mr-3",children:i.jsx("div",{className:"bg-bambu-green h-1.5 sm:h-2 rounded-full transition-all",style:{width:`${v.progress||0}%`}})}),i.jsxs("span",{className:"text-white",children:[Math.round(v.progress||0),"%"]})]}),i.jsxs("div",{className:"flex flex-wrap items-center gap-2 sm:gap-3 mt-1.5 sm:mt-2 text-[10px] sm:text-xs text-bambu-gray",children:[v.remaining_time!=null&&v.remaining_time>0&&i.jsxs(i.Fragment,{children:[i.jsxs("span",{className:"flex items-center gap-1",children:[i.jsx(Xn,{className:"w-3 h-3"}),js(v.remaining_time*60)]}),i.jsxs("span",{className:"text-bambu-green font-medium",title:x("printers.estimatedCompletion"),children:["ETA ",tL(v.remaining_time,c,x)]})]}),v.layer_num!=null&&v.total_layers!=null&&v.total_layers>0&&i.jsxs("span",{className:"flex items-center gap-1",children:[i.jsx(Gi,{className:"w-3 h-3"}),v.layer_num,"/",v.total_layers]})]})]}),t.waiting_reason&&t.status==="pending"&&i.jsxs("p",{className:"text-[10px] sm:text-xs text-purple-400 mt-1.5 sm:mt-2 flex items-start gap-1",children:[i.jsx(zi,{className:"w-3 h-3 mt-0.5 flex-shrink-0"}),i.jsx("span",{children:t.waiting_reason})]}),t.error_message&&i.jsxs("p",{className:"text-[10px] sm:text-xs text-red-400 mt-1.5 sm:mt-2 flex items-center gap-1",children:[i.jsx(zi,{className:"w-3 h-3"}),t.error_message]})]}),i.jsxs("div",{className:"flex flex-col sm:flex-row items-end sm:items-center gap-2 sm:gap-1 shrink-0",onClick:Y=>Y.stopPropagation(),children:[i.jsx(TZe,{status:t.status,waitingReason:t.waiting_reason,printerState:f,t:x}),i.jsxs("div",{className:"flex items-center gap-0.5 sm:gap-1",children:[W&&i.jsx(Oe,{variant:"ghost",size:"sm",onClick:s,disabled:!m("printers:control"),title:m("printers:control")?x("queue.actions.stopPrint"):x("queue.permissions.noStopPrint"),className:"text-red-400 hover:text-red-300 hover:bg-red-500/10 p-1.5 sm:p-2",children:i.jsx(lhe,{className:"w-4 h-4"})}),O&&i.jsxs(i.Fragment,{children:[t.manual_start&&i.jsx(Oe,{variant:"ghost",size:"sm",onClick:l,disabled:!m("printers:control"),title:m("printers:control")?x("queue.actions.startPrint"):x("queue.permissions.noStartPrint"),className:"text-bambu-green hover:text-bambu-green-light hover:bg-bambu-green/10 p-1.5 sm:p-2",children:i.jsx(uo,{className:"w-4 h-4"})}),i.jsx(Oe,{variant:"ghost",size:"sm",onClick:n,disabled:!p("queue","update",t.created_by_id),title:p("queue","update",t.created_by_id)?x("common.edit"):x("queue.permissions.noEdit"),className:"p-1.5 sm:p-2",children:i.jsx(Ki,{className:"w-4 h-4"})}),i.jsx(Oe,{variant:"ghost",size:"sm",onClick:r,disabled:!p("queue","delete",t.created_by_id),title:p("queue","delete",t.created_by_id)?x("common.cancel"):x("queue.permissions.noCancel"),className:"text-red-400 hover:text-red-300 hover:bg-red-500/10 p-1.5 sm:p-2",children:i.jsx(zt,{className:"w-4 h-4"})})]}),te&&i.jsxs(i.Fragment,{children:[i.jsx(Oe,{variant:"ghost",size:"sm",onClick:o,disabled:!m("queue:create"),title:m("queue:create")?x("queue.actions.requeue"):x("queue.permissions.noRequeue"),className:"text-bambu-green hover:text-bambu-green/80 hover:bg-bambu-green/10 p-1.5 sm:p-2",children:i.jsx(Sr,{className:"w-4 h-4"})}),i.jsx(Oe,{variant:"ghost",size:"sm",onClick:a,disabled:!p("queue","delete",t.created_by_id),title:p("queue","delete",t.created_by_id)?x("common.remove"):x("queue.permissions.noRemove"),className:"p-1.5 sm:p-2",children:i.jsx(Qt,{className:"w-4 h-4"})})]})]})]})]})]})}function AZe(){const{t}=Mt(),e=Zt(),{showToast:n}=hn(),{hasPermission:r,hasAnyPermission:a,canModify:s}=Dr(),[o,l]=w.useState(null),[c,d]=w.useState(""),[u,m]=w.useState(""),[p,f]=w.useState(!1),[x,v]=w.useState(null),[g,y]=w.useState(null),[_,N]=w.useState(null),[C,T]=w.useState([]),[P,k]=w.useState(!1),[D,A]=w.useState(()=>localStorage.getItem("queue.historySortBy")||"date"),[R,$]=w.useState(()=>{const I=localStorage.getItem("queue.historySortAsc");return I!==null?I==="true":!1}),[U,W]=w.useState(()=>localStorage.getItem("queue.pendingSortBy")||"position"),[O,te]=w.useState(()=>{const I=localStorage.getItem("queue.pendingSortAsc");return I!==null?I==="true":!0});w.useEffect(()=>{localStorage.setItem("queue.historySortBy",D)},[D]),w.useEffect(()=>{localStorage.setItem("queue.historySortAsc",String(R))},[R]),w.useEffect(()=>{localStorage.setItem("queue.pendingSortBy",U)},[U]),w.useEffect(()=>{localStorage.setItem("queue.pendingSortAsc",String(O))},[O]);const ie=ise(Jk(qT,{activationConstraint:{distance:8}}),Jk($T,{coordinateGetter:Tse})),{data:Y}=Ze({queryKey:["settings"],queryFn:fe.getSettings}),ae=Y?.time_format||"system",{data:de,isLoading:pe}=Ze({queryKey:["queue",o,c],queryFn:()=>fe.getQueue(o||void 0,c||void 0),refetchInterval:5e3}),{data:Q}=Ze({queryKey:["printers"],queryFn:()=>fe.getPrinters()}),oe=dt({mutationFn:I=>fe.cancelQueueItem(I),onSuccess:()=>{e.invalidateQueries({queryKey:["queue"]}),n(t("queue.toast.cancelled"))},onError:()=>n(t("queue.toast.cancelFailed"),"error")}),me=dt({mutationFn:I=>fe.removeFromQueue(I),onSuccess:()=>{e.invalidateQueries({queryKey:["queue"]}),n(t("queue.toast.removed"))},onError:()=>n(t("queue.toast.removeFailed"),"error")}),we=dt({mutationFn:I=>fe.stopQueueItem(I),onSuccess:()=>{e.invalidateQueries({queryKey:["queue"]}),n(t("queue.toast.stopped"))},onError:()=>n(t("queue.toast.stopFailed"),"error")}),Ee=dt({mutationFn:I=>fe.startQueueItem(I),onSuccess:()=>{e.invalidateQueries({queryKey:["queue"]}),n(t("queue.toast.released"))},onError:()=>n(t("queue.toast.startFailed"),"error")}),q=dt({mutationFn:I=>fe.reorderQueue(I),onSuccess:()=>{e.invalidateQueries({queryKey:["queue"]})},onError:()=>n(t("queue.toast.reorderFailed"),"error")}),K=dt({mutationFn:async()=>{const I=de?.filter(F=>["completed","failed","skipped","cancelled"].includes(F.status))||[];for(const F of I)await fe.removeFromQueue(F.id);return I.length},onSuccess:I=>{e.invalidateQueries({queryKey:["queue"]}),n(t("queue.toast.historyCleared",{count:I}))},onError:()=>n(t("queue.toast.clearHistoryFailed"),"error")}),E=dt({mutationFn:I=>fe.bulkUpdateQueue(I),onSuccess:I=>{e.invalidateQueries({queryKey:["queue"]}),T([]),k(!1),n(I.message)},onError:()=>n(t("queue.toast.updateFailed"),"error")}),j=dt({mutationFn:async I=>{for(const F of I)await fe.cancelQueueItem(F);return I.length},onSuccess:I=>{e.invalidateQueries({queryKey:["queue"]}),T([]),n(t("queue.toast.bulkCancelled",{count:I}))},onError:()=>n(t("queue.toast.bulkCancelFailed"),"error")}),L=I=>{T(F=>F.includes(I)?F.filter(Z=>Z!==I):[...F,I])},G=w.useMemo(()=>{const I=new Set;return Q?.forEach(F=>{F.location&&I.add(F.location)}),de?.forEach(F=>{F.target_location&&I.add(F.target_location)}),Array.from(I).sort()},[Q,de]),B=w.useCallback(I=>u?I.target_location?I.target_location===u:I.printer_id?Q?.find(Z=>Z.id===I.printer_id)?.location===u:!1:!0,[u,Q]),re=w.useMemo(()=>{let I=de?.filter(Z=>Z.status==="pending")||[];u&&(I=I.filter(B));const F=Z=>{if(!Z.scheduled_time)return 0;const xe=er(Z.scheduled_time)?.getTime()??0,he=Date.now()+4320*60*60*1e3;return xe>he?0:xe};return[...I].sort((Z,xe)=>{let he;if(U==="name"){const ce=Z.archive_name||Z.library_file_name||"",Ae=xe.archive_name||xe.library_file_name||"";he=ce.localeCompare(Ae)}else U==="printer"?he=(Z.printer_name||"").localeCompare(xe.printer_name||""):U==="time"?he=F(Z)-F(xe):he=Z.position-xe.position;return O?he:-he})},[de,U,O,B,u]),z=()=>{const I=re.map(F=>F.id);C.length===I.length?T([]):T(I)},V=w.useMemo(()=>{let I=de?.filter(F=>F.status==="printing")||[];return u&&(I=I.filter(B)),I},[de,u,B]),ee=w.useMemo(()=>{const I=new Set;return V.forEach(F=>{F.printer_id&&I.add(F.printer_id)}),Array.from(I)},[V]),J=ox({queries:ee.map(I=>({queryKey:["printerStatus",I],queryFn:()=>fe.getPrinterStatus(I),refetchInterval:5e3}))}),ne=w.useMemo(()=>{const I={};return ee.forEach((F,Z)=>{const xe=J[Z];xe?.data?.state&&(I[F]=xe.data.state)}),I},[ee,J]),se=w.useMemo(()=>{let I=de?.filter(F=>["completed","failed","skipped","cancelled"].includes(F.status))||[];return u&&(I=I.filter(B)),[...I].sort((F,Z)=>{let xe;if(D==="name"){const he=F.archive_name||F.library_file_name||"",ce=Z.archive_name||Z.library_file_name||"";xe=he.localeCompare(ce)}else D==="printer"?xe=(F.printer_name||"").localeCompare(Z.printer_name||""):xe=(er(Z.completed_at||Z.created_at)?.getTime()??0)-(er(F.completed_at||F.created_at)?.getTime()??0);return R?-xe:xe})},[de,D,R,B,u]),ue=w.useMemo(()=>re.reduce((I,F)=>I+(F.print_time_seconds||0),0),[re]),ge=w.useMemo(()=>re.reduce((I,F)=>I+(F.filament_used_grams||0),0),[re]),le=I=>{const{active:F,over:Z}=I;if(!Z||F.id===Z.id)return;const xe=re.findIndex(ce=>ce.id===F.id),he=re.findIndex(ce=>ce.id===Z.id);if(xe!==-1&&he!==-1){const Ae=WT(re,xe,he).map((_e,Ue)=>({id:_e.id,position:Ue+1}));q.mutate(Ae)}};return i.jsxs("div",{className:"p-4 md:p-8",children:[i.jsx("div",{className:"flex items-center justify-between mb-8",children:i.jsxs("div",{children:[i.jsxs("h1",{className:"text-2xl font-bold text-white flex items-center gap-3",children:[i.jsx(KY,{className:"w-7 h-7 text-bambu-green"}),t("queue.title")]}),i.jsx("p",{className:"text-bambu-gray mt-1",children:t("queue.subtitle")})]})}),i.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-5 gap-2 sm:gap-3 lg:gap-4 mb-8",children:[i.jsx(Tt,{className:"bg-gradient-to-br from-blue-500/10 to-transparent border-blue-500/20",children:i.jsx(Pt,{className:"p-3 sm:p-4",children:i.jsxs("div",{className:"flex items-center gap-2 sm:gap-3",children:[i.jsx("div",{className:"w-8 h-8 sm:w-10 sm:h-10 rounded-lg bg-blue-500/20 flex items-center justify-center shrink-0",children:i.jsx(uo,{className:"w-4 h-4 sm:w-5 sm:h-5 text-blue-400"})}),i.jsxs("div",{className:"min-w-0",children:[i.jsx("p",{className:"text-xl sm:text-2xl font-bold text-white truncate",children:V.length}),i.jsx("p",{className:"text-xs sm:text-sm text-bambu-gray truncate",children:t("queue.summary.printing")})]})]})})}),i.jsx(Tt,{className:"bg-gradient-to-br from-yellow-500/10 to-transparent border-yellow-500/20",children:i.jsx(Pt,{className:"p-3 sm:p-4",children:i.jsxs("div",{className:"flex items-center gap-2 sm:gap-3",children:[i.jsx("div",{className:"w-8 h-8 sm:w-10 sm:h-10 rounded-lg bg-yellow-500/20 flex items-center justify-center shrink-0",children:i.jsx(Xn,{className:"w-4 h-4 sm:w-5 sm:h-5 text-yellow-400"})}),i.jsxs("div",{className:"min-w-0",children:[i.jsx("p",{className:"text-xl sm:text-2xl font-bold text-white truncate",children:re.length}),i.jsx("p",{className:"text-xs sm:text-sm text-bambu-gray truncate",children:t("queue.summary.queued")})]})]})})}),i.jsx(Tt,{className:"bg-gradient-to-br from-bambu-green/10 to-transparent border-bambu-green/20",children:i.jsx(Pt,{className:"p-3 sm:p-4",children:i.jsxs("div",{className:"flex items-center gap-2 sm:gap-3",children:[i.jsx("div",{className:"w-8 h-8 sm:w-10 sm:h-10 rounded-lg bg-bambu-green/20 flex items-center justify-center shrink-0",children:i.jsx(Gd,{className:"w-4 h-4 sm:w-5 sm:h-5 text-bambu-green"})}),i.jsxs("div",{className:"min-w-0",children:[i.jsx("p",{className:"text-xl sm:text-2xl font-bold text-white truncate",children:js(ue)}),i.jsx("p",{className:"text-xs sm:text-sm text-bambu-gray truncate",children:t("queue.summary.totalTime")})]})]})})}),i.jsx(Tt,{className:"bg-gradient-to-br from-purple-500/10 to-transparent border-purple-500/20",children:i.jsx(Pt,{className:"p-3 sm:p-4",children:i.jsxs("div",{className:"flex items-center gap-2 sm:gap-3",children:[i.jsx("div",{className:"w-8 h-8 sm:w-10 sm:h-10 rounded-lg bg-purple-500/20 flex items-center justify-center shrink-0",children:i.jsx(nX,{className:"w-4 h-4 sm:w-5 sm:h-5 text-purple-500"})}),i.jsxs("div",{className:"min-w-0",children:[i.jsx("p",{className:"text-xl sm:text-2xl font-bold text-white truncate",children:Ase(ge)}),i.jsx("p",{className:"text-xs sm:text-sm text-bambu-gray truncate",children:t("queue.summary.totalWeight")})]})]})})}),i.jsx(Tt,{className:"col-span-2 sm:col-span-1 bg-gradient-to-br from-gray-500/10 to-transparent border-gray-500/20",children:i.jsx(Pt,{className:"p-3 sm:p-4",children:i.jsxs("div",{className:"flex items-center gap-2 sm:gap-3",children:[i.jsx("div",{className:"w-8 h-8 sm:w-10 sm:h-10 rounded-lg bg-gray-500/20 flex items-center justify-center shrink-0",children:i.jsx(pr,{className:"w-4 h-4 sm:w-5 sm:h-5 text-gray-400"})}),i.jsxs("div",{className:"min-w-0",children:[i.jsx("p",{className:"text-xl sm:text-2xl font-bold text-white truncate",children:se.length}),i.jsx("p",{className:"text-xs sm:text-sm text-bambu-gray truncate",children:t("queue.summary.history")})]})]})})})]}),i.jsxs("div",{className:"flex flex-wrap items-center gap-2 sm:gap-4 mb-6",children:[i.jsxs("select",{className:"px-2 sm:px-3 py-2 text-sm sm:text-base bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none min-w-0 flex-1 sm:flex-none",value:o===-1?"unassigned":o||"",onChange:I=>{const F=I.target.value;l(F==="unassigned"?-1:F===""?null:Number(F))},children:[i.jsx("option",{value:"",children:t("queue.filter.allPrinters")}),i.jsx("option",{value:"unassigned",children:t("queue.filter.unassigned")}),Q?.map(I=>i.jsx("option",{value:I.id,children:I.name},I.id))]}),i.jsxs("select",{className:"px-2 sm:px-3 py-2 text-sm sm:text-base bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none min-w-0 flex-1 sm:flex-none",value:c,onChange:I=>d(I.target.value),children:[i.jsx("option",{value:"",children:t("queue.filter.allStatus")}),i.jsx("option",{value:"pending",children:t("queue.status.pending")}),i.jsx("option",{value:"printing",children:t("queue.status.printing")}),i.jsx("option",{value:"completed",children:t("queue.status.completed")}),i.jsx("option",{value:"failed",children:t("queue.status.failed")}),i.jsx("option",{value:"skipped",children:t("queue.status.skipped")}),i.jsx("option",{value:"cancelled",children:t("queue.status.cancelled")})]}),G.length>0&&i.jsxs("select",{className:"px-2 sm:px-3 py-2 text-sm sm:text-base bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none min-w-0 flex-1 sm:flex-none",value:u,onChange:I=>m(I.target.value),children:[i.jsx("option",{value:"",children:t("queue.filter.allLocations")}),G.map(I=>i.jsx("option",{value:I,children:I},I))]}),i.jsx("div",{className:"hidden sm:block flex-1"}),se.length>0&&i.jsxs(Oe,{className:"w-full sm:w-auto",variant:"secondary",size:"sm",onClick:()=>f(!0),disabled:!r("queue:delete_all"),title:r("queue:delete_all")?void 0:t("queue.permissions.noClearHistory"),children:[i.jsx(Qt,{className:"w-4 h-4"}),t("queue.clearHistory")]})]}),pe?i.jsx("div",{className:"text-center py-12 text-bambu-gray",children:t("common.loading")}):de?.length===0?i.jsxs(Tt,{className:"p-12 text-center border-dashed",children:[i.jsx(Xr,{className:"w-16 h-16 text-bambu-gray mx-auto mb-4 opacity-50"}),i.jsx("h3",{className:"text-xl font-medium text-white mb-2",children:t("queue.empty.title")}),i.jsx("p",{className:"text-bambu-gray max-w-md mx-auto",children:t("queue.empty.description")})]}):i.jsxs("div",{className:"space-y-6 sm:space-y-8",children:[V.length>0&&i.jsxs("div",{children:[i.jsxs("h2",{className:"text-base sm:text-lg font-semibold text-white mb-3 sm:mb-4 flex items-center gap-2",children:[i.jsx("div",{className:"w-2 h-2 rounded-full bg-blue-400 animate-pulse"}),t("queue.sections.currentlyPrinting")]}),i.jsx("div",{className:"space-y-2 sm:space-y-3",children:V.map(I=>i.jsx(Vj,{item:I,onEdit:()=>{},onCancel:()=>{},onRemove:()=>{},onStop:()=>N({type:"stop",item:I}),onRequeue:()=>{},onStart:()=>{},timeFormat:ae,hasPermission:r,canModify:s,printerState:I.printer_id?ne[I.printer_id]:null,t},I.id))})]}),re.length>0&&i.jsxs("div",{children:[i.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 mb-3 sm:mb-4",children:[i.jsxs("h2",{className:"text-base sm:text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(Xn,{className:"w-4 h-4 sm:w-5 sm:h-5 text-yellow-400"}),t("queue.sections.queued"),i.jsxs("span",{className:"text-xs sm:text-sm font-normal text-bambu-gray",children:["(",t("queue.itemCount",{count:re.length}),")"]}),i.jsx("span",{className:"hidden sm:inline text-xs text-bambu-gray ml-2",title:t("queue.reorderHint"),children:t("queue.dragToReorder")})]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsxs("select",{className:"px-2 sm:px-3 py-1.5 text-xs sm:text-sm bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",value:U,onChange:I=>W(I.target.value),children:[i.jsx("option",{value:"position",children:t("queue.sort.byPosition")}),i.jsx("option",{value:"name",children:t("queue.sort.byName")}),i.jsx("option",{value:"printer",children:t("queue.sort.byPrinter")}),i.jsx("option",{value:"time",children:t("queue.sort.bySchedule")})]}),i.jsx(Oe,{variant:"ghost",size:"sm",onClick:()=>te(!O),title:t(O?"common.ascending":"common.descending"),className:"px-2",children:O?i.jsx($p,{className:"w-4 h-4"}):i.jsx(Tb,{className:"w-4 h-4"})})]})]}),i.jsxs("div",{className:"flex flex-wrap items-center gap-2 sm:gap-3 mb-3 sm:mb-4 p-2 sm:p-3 bg-bambu-dark rounded-lg",children:[i.jsxs(Oe,{variant:"ghost",size:"sm",onClick:z,className:"flex items-center gap-1.5 sm:gap-2 text-xs sm:text-sm",children:[C.length===re.length&&re.length>0?i.jsx(ho,{className:"w-4 h-4 text-bambu-green"}):i.jsx(Nl,{className:"w-4 h-4"}),C.length===re.length&&re.length>0?t("queue.bulkEdit.deselectAll"):t("queue.bulkEdit.selectAll")]}),C.length>0&&i.jsxs(i.Fragment,{children:[i.jsx("span",{className:"text-xs sm:text-sm text-bambu-gray",children:t("queue.bulkEdit.selected",{count:C.length})}),i.jsx("div",{className:"hidden sm:block h-4 w-px bg-bambu-dark-tertiary"}),i.jsxs(Oe,{variant:"ghost",size:"sm",onClick:()=>k(!0),className:"flex items-center gap-1.5 sm:gap-2 text-xs sm:text-sm text-bambu-green hover:text-bambu-green-light",disabled:!a("queue:update_own","queue:update_all"),title:a("queue:update_own","queue:update_all")?t("queue.bulkEdit.editSelected"):t("queue.permissions.noEditItems"),children:[i.jsx(Ki,{className:"w-3.5 h-3.5 sm:w-4 sm:h-4"}),i.jsx("span",{className:"hidden sm:inline",children:t("queue.bulkEdit.editSelected")})]}),i.jsxs(Oe,{variant:"ghost",size:"sm",onClick:()=>j.mutate(C),className:"flex items-center gap-1.5 sm:gap-2 text-xs sm:text-sm text-red-400 hover:text-red-300",disabled:j.isPending||!a("queue:delete_own","queue:delete_all"),title:a("queue:delete_own","queue:delete_all")?t("queue.bulkEdit.cancelSelected"):t("queue.permissions.noCancelItems"),children:[i.jsx(zt,{className:"w-3.5 h-3.5 sm:w-4 sm:h-4"}),i.jsx("span",{className:"hidden sm:inline",children:t("queue.bulkEdit.cancelSelected")})]})]})]}),i.jsx(wse,{sensors:ie,collisionDetection:lse,onDragEnd:le,children:i.jsx(Nse,{items:re.map(I=>I.id),strategy:gZe,children:i.jsx("div",{className:"space-y-2 sm:space-y-3",children:re.map((I,F)=>i.jsx(Vj,{item:I,position:F+1,onEdit:()=>v(I),onCancel:()=>N({type:"cancel",item:I}),onRemove:()=>{},onStop:()=>{},onRequeue:()=>{},onStart:()=>Ee.mutate(I.id),timeFormat:ae,isSelected:C.includes(I.id),onToggleSelect:()=>L(I.id),hasPermission:r,canModify:s,t},I.id))})})})]}),se.length>0&&i.jsxs("div",{children:[i.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 mb-3 sm:mb-4",children:[i.jsxs("h2",{className:"text-base sm:text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(pr,{className:"w-4 h-4 sm:w-5 sm:h-5 text-bambu-gray"}),t("queue.sections.history"),i.jsxs("span",{className:"text-xs sm:text-sm font-normal text-bambu-gray",children:["(",t("queue.itemCount",{count:se.length}),")"]})]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsxs("select",{className:"px-2 sm:px-3 py-1.5 text-xs sm:text-sm bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",value:D,onChange:I=>A(I.target.value),children:[i.jsx("option",{value:"date",children:t("queue.sort.byDate")}),i.jsx("option",{value:"name",children:t("queue.sort.byName")}),i.jsx("option",{value:"printer",children:t("queue.sort.byPrinter")})]}),i.jsx(Oe,{variant:"ghost",size:"sm",onClick:()=>$(!R),title:t(R?"queue.sort.ascendingOldest":"queue.sort.descendingNewest"),className:"px-2",children:R?i.jsx($p,{className:"w-4 h-4"}):i.jsx(Tb,{className:"w-4 h-4"})})]})]}),i.jsx("div",{className:"space-y-2 sm:space-y-3",children:se.slice(0,20).map((I,F)=>i.jsx(Vj,{item:I,position:F+1,onEdit:()=>{},onCancel:()=>{},onRemove:()=>N({type:"remove",item:I}),onStop:()=>{},onRequeue:()=>y(I),onStart:()=>{},timeFormat:ae,hasPermission:r,canModify:s,t},I.id))})]})]}),x&&i.jsx(Vc,{mode:"edit-queue-item",archiveId:x.archive_id??void 0,libraryFileId:x.library_file_id??void 0,archiveName:x.archive_name||x.library_file_name||`File #${x.archive_id||x.library_file_id}`,queueItem:x,onClose:()=>v(null)}),g&&i.jsx(Vc,{mode:"add-to-queue",archiveId:g.archive_id??void 0,libraryFileId:g.library_file_id??void 0,archiveName:g.archive_name||g.library_file_name||`File #${g.archive_id||g.library_file_id}`,onClose:()=>y(null)}),_&&i.jsx(_n,{title:_.type==="cancel"?t("queue.confirm.cancelTitle"):_.type==="stop"?t("queue.confirm.stopTitle"):t("queue.confirm.removeTitle"),message:_.type==="cancel"?t("queue.confirm.cancelMessage",{name:_.item.archive_name||_.item.library_file_name||t("queue.confirm.thisPrint")}):_.type==="stop"?t("queue.confirm.stopMessage",{name:_.item.archive_name||_.item.library_file_name||t("queue.confirm.thisPrint")}):t("queue.confirm.removeMessage",{name:_.item.archive_name||_.item.library_file_name||t("queue.confirm.thisItem")}),confirmText:_.type==="cancel"?t("queue.confirm.cancelButton"):_.type==="stop"?t("queue.confirm.stopButton"):t("common.remove"),variant:"danger",onConfirm:()=>{_.type==="cancel"?oe.mutate(_.item.id):_.type==="stop"?we.mutate(_.item.id):me.mutate(_.item.id),N(null)},onCancel:()=>N(null)}),p&&i.jsx(_n,{title:t("queue.confirm.clearHistoryTitle"),message:t("queue.confirm.clearHistoryMessage",{count:se.length}),confirmText:t("queue.clearHistory"),variant:"danger",onConfirm:()=>{K.mutate(),f(!1)},onCancel:()=>f(!1)}),P&&i.jsx(PZe,{selectedCount:C.length,printers:Q?.map(I=>({id:I.id,name:I.name}))||[],onSave:I=>{Object.keys(I).length>0&&E.mutate({item_ids:C,...I})},onClose:()=>k(!1),isSaving:E.isPending,canControlPrinter:r("printers:control"),t})]})}function MZe({printDates:t,months:e=3}){const n=w.useRef(null),[r,a]=w.useState(0);w.useEffect(()=>{const _=n.current;if(!_)return;const N=new ResizeObserver(C=>{const T=C[0]?.contentRect.width||0;a(T)});return N.observe(_),()=>N.disconnect()},[]);const{weeks:s,monthLabels:o,printCounts:l}=w.useMemo(()=>{const _={};t.forEach($=>{const U=$.split("T")[0];_[U]=(_[U]||0)+1});const N=new Date,C=new Date(N);C.setMonth(C.getMonth()-e),C.setDate(C.getDate()-C.getDay());const T=[],P=[];let k=[],D=-1;const A=new Date(C);let R=0;for(;A<=N;)A.getDay()===0&&k.length>0&&(T.push(k),k=[],R++),A.getMonth()!==D&&(P.push({month:A.toLocaleDateString("en-US",{month:"short"}),weekIndex:R}),D=A.getMonth()),k.push(new Date(A)),A.setDate(A.getDate()+1);return k.length>0&&T.push(k),{weeks:T,monthLabels:P,printCounts:_}},[t,e]),c=Math.max(1,...Object.values(l)),d=_=>{if(_===0)return"bg-bambu-dark";const N=_/c;return N<=.25?"bg-bambu-green/30":N<=.5?"bg-bambu-green/50":N<=.75?"bg-bambu-green/75":"bg-bambu-green"},u=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],m=s.length,p=32,f=2,x=r-p-16,v=m>0?Math.floor((x-(m-1)*f)/m):12,g=Math.max(8,Math.min(20,v)),y=g<=10?10:12;return i.jsx("div",{ref:n,className:"w-full flex justify-center",children:r>0&&i.jsxs("div",{children:[i.jsx("div",{className:"flex mb-1",style:{marginLeft:p+4},children:o.map(({month:_,weekIndex:N},C)=>i.jsx("div",{className:"text-bambu-gray",style:{fontSize:y,marginLeft:C===0?0:`${(N-(o[C-1]?.weekIndex||0))*(g+f)-24}px`},children:_},C))}),i.jsxs("div",{className:"flex",style:{gap:f},children:[i.jsx("div",{className:"flex flex-col",style:{gap:f,marginRight:4,width:p},children:u.map((_,N)=>i.jsx("div",{className:"text-bambu-gray flex items-center",style:{width:p,height:g,fontSize:y,visibility:N%2===1?"visible":"hidden"},children:_},_))}),s.map((_,N)=>i.jsx("div",{className:"flex flex-col",style:{gap:f},children:[0,1,2,3,4,5,6].map(C=>{const T=_.find(A=>A.getDay()===C);if(!T)return i.jsx("div",{style:{width:g,height:g}},C);const P=T.toISOString().split("T")[0],k=l[P]||0,D=P===new Date().toISOString().split("T")[0];return i.jsx("div",{className:`rounded-sm ${d(k)} ${D?"ring-1 ring-white":""}`,style:{width:g,height:g},title:`${T.toLocaleDateString()}: ${k} print${k!==1?"s":""}`},C)})},N))]}),i.jsxs("div",{className:"flex items-center gap-2 mt-3 text-bambu-gray",style:{fontSize:y},children:[i.jsx("span",{children:"Less"}),i.jsxs("div",{className:"flex",style:{gap:f},children:[i.jsx("div",{className:"rounded-sm bg-bambu-dark",style:{width:g,height:g}}),i.jsx("div",{className:"rounded-sm bg-bambu-green/30",style:{width:g,height:g}}),i.jsx("div",{className:"rounded-sm bg-bambu-green/50",style:{width:g,height:g}}),i.jsx("div",{className:"rounded-sm bg-bambu-green/75",style:{width:g,height:g}}),i.jsx("div",{className:"rounded-sm bg-bambu-green",style:{width:g,height:g}})]}),i.jsx("span",{children:"More"})]})]})})}const kK=["weight","prints","time"];function nC({value:t,onChange:e,exclude:n}){const{t:r}=Mt(),a={weight:r("stats.filamentByWeight"),prints:r("stats.filamentByPrints"),time:r("stats.filamentByTime")},s=n?kK.filter(o=>!n.includes(o)):kK;return i.jsx("div",{className:"flex gap-0.5 bg-bambu-dark rounded-lg p-0.5",children:s.map(o=>i.jsx("button",{onClick:()=>e(o),className:`px-2 py-0.5 text-xs rounded-md transition-colors ${t===o?"bg-bambu-green text-white":"text-bambu-gray hover:text-white"}`,children:a[o]},o))})}function Am(t){if(t>=1e6){const e=t/1e6;return`${e%1===0?e.toFixed(0):e.toFixed(1)}t`}if(t>=1e3){const e=t/1e3;return`${e%1===0?e.toFixed(0):e.toFixed(1)}kg`}return`${Math.round(t)}g`}const n1=["#00ae42","#3b82f6","#f59e0b","#ef4444","#8b5cf6","#ec4899","#14b8a6","#f97316"],EZe=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],CK=["12am","1am","2am","3am","4am","5am","6am","7am","8am","9am","10am","11am","12pm","1pm","2pm","3pm","4pm","5pm","6pm","7pm","8pm","9pm","10pm","11pm"];function jZe({archives:t,currency:e="$",dateFrom:n,dateTo:r}){const{t:a}=Mt(),[s,o]=w.useState("weight"),[l,c]=w.useState("weight"),d=w.useMemo(()=>{const D=new Map;return t.forEach(A=>{const R=er(A.completed_at||A.created_at)||new Date,$=`${R.getFullYear()}-${String(R.getMonth()+1).padStart(2,"0")}-${String(R.getDate()).padStart(2,"0")}`,U=D.get($)||{date:$,filament:0,cost:0,prints:0};U.filament+=A.filament_used_grams||0,U.cost+=A.cost||0,U.prints+=A.quantity||1,D.set($,U)}),Array.from(D.values()).sort((A,R)=>A.date.localeCompare(R.date)).map(A=>({...A,dateLabel:new Date(A.date).toLocaleDateString("en-US",{month:"short",day:"numeric"})}))},[t]),u=w.useMemo(()=>{if(n&&r)return Math.max((new Date(r).getTime()-new Date(n).getTime())/864e5,0)+1;if(n)return Math.max((Date.now()-new Date(n).getTime())/864e5,0)+1;if(t.length<2)return 0;const D=t.map(A=>new Date(A.completed_at||A.created_at).getTime());return(Math.max(...D)-Math.min(...D))/864e5},[t,n,r]),m=w.useMemo(()=>{if(u>7)return[];const D=new Map,A=u>1;return t.forEach(R=>{const $=er(R.completed_at||R.created_at)||new Date,U=$.getHours(),W=`${$.getFullYear()}-${String($.getMonth()+1).padStart(2,"0")}-${String($.getDate()).padStart(2,"0")}T${String(U).padStart(2,"0")}`,O=D.get(W)||{date:W,filament:0,cost:0,prints:0};O.filament+=R.filament_used_grams||0,O.cost+=R.cost||0,O.prints+=R.quantity||1,D.set(W,O)}),Array.from(D.values()).sort((R,$)=>R.date.localeCompare($.date)).map(R=>{const[$,U]=R.date.split("T"),W=new Date($),O=parseInt(U,10),te=A?`${EZe[W.getDay()]} ${CK[O]}`:CK[O];return{...R,dateLabel:te}})},[t,u]),p=w.useMemo(()=>{if(d.length<=60)return d;const D=new Map;return d.forEach(A=>{const R=new Date(A.date),$=new Date(R);$.setDate(R.getDate()-R.getDay());const U=`${$.getFullYear()}-${String($.getMonth()+1).padStart(2,"0")}-${String($.getDate()).padStart(2,"0")}`,W=D.get(U)||{week:U,filament:0,cost:0,prints:0};W.filament+=A.filament,W.cost+=A.cost,W.prints+=A.prints,D.set(U,W)}),Array.from(D.values()).sort((A,R)=>A.week.localeCompare(R.week)).map(A=>({date:A.week,dateLabel:`Week of ${new Date(A.week).toLocaleDateString("en-US",{month:"short",day:"numeric"})}`,...A}))},[d]),f=w.useMemo(()=>{const D=new Map;return t.forEach(A=>{const $=(A.filament_type||"Unknown").split(", ");$.forEach(U=>{const W=(A.filament_used_grams||0)/$.length;D.set(U,(D.get(U)||0)+W)})}),Array.from(D.entries()).map(([A,R])=>({name:A,value:Math.round(R)})).sort((A,R)=>R.value-A.value)},[t]),x=w.useMemo(()=>{const D=new Map;return t.forEach(A=>{(A.filament_type||"Unknown").split(", ").forEach(U=>{D.set(U,(D.get(U)||0)+1)})}),Array.from(D.entries()).map(([A,R])=>({name:A,value:R})).sort((A,R)=>R.value-A.value)},[t]),v=w.useMemo(()=>{const D=new Map;return t.forEach(A=>{const $=(A.filament_type||"Unknown").split(", "),U=(A.actual_time_seconds||A.print_time_seconds||0)/$.length;$.forEach(W=>{D.set(W,(D.get(W)||0)+U)})}),Array.from(D.entries()).map(([A,R])=>({name:A,value:Math.round(R/3600*10)/10})).sort((A,R)=>R.value-A.value)},[t]),g=w.useMemo(()=>{const D=new Map;return t.forEach(A=>{if(A.status!=="completed"&&A.status!=="failed")return;(A.filament_type||"Unknown").split(", ").forEach($=>{const U=D.get($)||{completed:0,failed:0};A.status==="completed"?U.completed++:U.failed++,D.set($,U)})}),Array.from(D.entries()).filter(([,A])=>A.completed+A.failed>=2).map(([A,R])=>{const $=R.completed+R.failed,U=Math.round(R.completed/$*100);return{name:A,rate:U,total:$}}).sort((A,R)=>R.rate-A.rate)},[t]),y=w.useMemo(()=>{const D=new Map;return t.forEach(A=>{if(!A.filament_color)return;const R=A.filament_color.split(",").map(U=>U.trim()),$=(A.filament_used_grams||0)/R.length;R.forEach(U=>{const W=D.get(U)||{count:0,weight:0};W.count++,W.weight+=$,D.set(U,W)})}),Array.from(D.entries()).map(([A,R])=>({hex:A,value:l==="prints"?R.count:Math.round(R.weight)})).sort((A,R)=>R.value-A.value)},[t,l]),_=s==="weight"?f:s==="prints"?x:v,N=u<=7&&m.length>0?m:p,C=t.reduce((D,A)=>D+(A.filament_used_grams||0),0),T=t.reduce((D,A)=>D+(A.cost||0),0),P=t.reduce((D,A)=>D+(A.quantity||1),0),k=new Set(t.map(D=>D.printer_id).filter(Boolean)).size;return i.jsxs("div",{className:"space-y-4",children:[i.jsxs("div",{className:"grid grid-cols-3 gap-2 max-[640px]:grid-cols-1",children:[i.jsxs("div",{className:"bg-bambu-dark rounded-lg p-4",children:[i.jsxs("div",{className:"flex items-center justify-between gap-2",children:[i.jsx("p",{className:"text-sm text-bambu-gray leading-none",children:a("stats.periodFilament")}),i.jsx("p",{className:"text-2xl font-bold text-white leading-none",children:Am(C)})]}),i.jsxs("p",{className:"text-xs text-bambu-gray",children:[k," ",a("nav.printers").toLowerCase()]})]}),i.jsxs("div",{className:"bg-bambu-dark rounded-lg p-4",children:[i.jsxs("div",{className:"flex items-center justify-between gap-2",children:[i.jsx("p",{className:"text-sm text-bambu-gray leading-none",children:a("stats.periodCost")}),i.jsxs("p",{className:"text-2xl font-bold text-white leading-none",children:[e,T.toFixed(2)]})]}),i.jsxs("p",{className:"text-xs text-bambu-gray",children:[P," ",a("common.prints")]})]}),i.jsxs("div",{className:"bg-bambu-dark rounded-lg p-4",children:[i.jsxs("div",{className:"flex items-center justify-between gap-2",children:[i.jsx("p",{className:"text-sm text-bambu-gray leading-none",children:a("stats.avgPerPrint")}),i.jsxs("p",{className:"text-2xl font-bold text-white leading-none",children:[P>0?(C/P).toFixed(0):0,"g"]})]}),i.jsxs("p",{className:"text-xs text-bambu-gray",children:[e,P>0?(T/P).toFixed(2):"0.00"," avg"]})]})]}),N.length>0?i.jsxs("div",{className:"bg-bambu-dark rounded-lg p-4",children:[i.jsx("h4",{className:"text-sm font-medium text-bambu-gray mb-4",children:a("stats.usageOverTime")}),i.jsx(Fm,{width:"100%",height:250,children:i.jsxs(F$e,{data:N,children:[i.jsx("defs",{children:i.jsxs("linearGradient",{id:"colorFilament",x1:"0",y1:"0",x2:"0",y2:"1",children:[i.jsx("stop",{offset:"5%",stopColor:"#00ae42",stopOpacity:.3}),i.jsx("stop",{offset:"95%",stopColor:"#00ae42",stopOpacity:0})]})}),i.jsx(xp,{strokeDasharray:"3 3",stroke:"#3d3d3d"}),i.jsx(yp,{dataKey:"dateLabel",stroke:"#9ca3af",tick:{fontSize:12},interval:"preserveStartEnd"}),i.jsx(vp,{stroke:"#9ca3af",tick:{fontSize:12},tickFormatter:D=>`${D}g`}),i.jsx(Lm,{contentStyle:{backgroundColor:"#2d2d2d",border:"1px solid #3d3d3d",borderRadius:"8px"},labelStyle:{color:"#fff"},formatter:D=>[`${Number(D??0).toFixed(0)}g`,"Filament"]}),i.jsx(Cne,{type:"monotone",dataKey:"filament",stroke:"#00ae42",strokeWidth:2,fillOpacity:1,fill:"url(#colorFilament)"})]})})]}):i.jsx("div",{className:"bg-bambu-dark rounded-lg p-8 text-center text-bambu-gray",children:a("stats.noPrintDataInRange")}),i.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-4",children:[i.jsxs("div",{className:"bg-bambu-dark rounded-lg p-4",children:[i.jsxs("div",{className:"flex items-center justify-between mb-4",children:[i.jsx("h4",{className:"text-sm font-medium text-bambu-gray",children:a("stats.byMaterial")}),i.jsx(nC,{value:s,onChange:o})]}),_.length>0?i.jsxs("div",{className:"flex items-center gap-4",children:[i.jsx(Fm,{width:160,height:160,children:i.jsxs(gG,{children:[i.jsx(AR,{data:_,cx:"50%",cy:"50%",innerRadius:40,outerRadius:70,paddingAngle:2,dataKey:"value",children:_.map((D,A)=>i.jsx(Kb,{fill:n1[A%n1.length]},`cell-${A}`))}),i.jsx(Lm,{contentStyle:{backgroundColor:"#2d2d2d",border:"1px solid #3d3d3d",borderRadius:"8px"},formatter:D=>[s==="weight"?Am(Number(D??0)):s==="time"?`${Number(D??0)}h`:`${D??0}`,s==="weight"?"Usage":s==="time"?"Time":"Prints"]})]})}),i.jsx("div",{className:"flex-1 space-y-2 overflow-hidden",children:_.map((D,A)=>{const R=_.reduce((U,W)=>U+W.value,0),$=R>0?(D.value/R*100).toFixed(0):0;return i.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[i.jsx("div",{className:"w-3 h-3 rounded-sm flex-shrink-0",style:{backgroundColor:n1[A%n1.length]}}),i.jsx("span",{className:"text-white truncate flex-1",children:D.name}),i.jsxs("span",{className:"text-bambu-gray flex-shrink-0",children:[s==="weight"?Am(D.value):s==="time"?`${D.value}h`:D.value," · ",$,"%"]})]},D.name)})})]}):i.jsx("div",{className:"h-[160px] flex items-center justify-center text-bambu-gray",children:a("stats.noFilamentData")})]}),i.jsxs("div",{className:"bg-bambu-dark rounded-lg p-4",children:[i.jsx("h4",{className:"text-sm font-medium text-bambu-gray mb-4",children:a("stats.filamentSuccess")}),g.length>0?i.jsx("div",{className:"space-y-1.5",children:g.map(D=>i.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[i.jsx("span",{className:"text-white truncate w-20 flex-shrink-0",children:D.name}),i.jsx("div",{className:"flex-1 h-1.5 bg-bambu-dark-secondary rounded-full",children:i.jsx("div",{className:`h-full rounded-full transition-all ${D.rate>=90?"bg-status-ok":D.rate>=70?"bg-status-warning":"bg-status-error"}`,style:{width:`${D.rate}%`}})}),i.jsxs("span",{className:`font-medium flex-shrink-0 tabular-nums ${D.rate>=90?"text-status-ok":D.rate>=70?"text-status-warning":"text-status-error"}`,children:[D.rate,"%"]}),i.jsxs("span",{className:"text-bambu-gray flex-shrink-0 text-xs",children:["(",D.total,")"]})]},D.name))}):i.jsx("div",{className:"h-[160px] flex items-center justify-center text-bambu-gray",children:a("stats.noArchiveData")})]}),i.jsxs("div",{className:"bg-bambu-dark rounded-lg p-4",children:[i.jsxs("div",{className:"flex items-center justify-between mb-4",children:[i.jsx("h4",{className:"text-sm font-medium text-bambu-gray",children:a("stats.colorDistribution")}),i.jsx(nC,{value:l,onChange:c,exclude:["time"]})]}),y.length>0?(()=>{const D=y.reduce((A,R)=>A+R.value,0);return i.jsxs("div",{children:[i.jsxs("div",{className:"relative mx-auto",style:{width:160,height:160},children:[i.jsx(Fm,{width:"100%",height:"100%",children:i.jsxs(gG,{children:[i.jsx(AR,{data:y,cx:"50%",cy:"50%",innerRadius:45,outerRadius:70,paddingAngle:2,dataKey:"value",children:y.map((A,R)=>i.jsx(Kb,{fill:A.hex,stroke:"#1a1a1a",strokeWidth:1},`color-${R}`))}),i.jsx(Lm,{contentStyle:{backgroundColor:"#2d2d2d",border:"1px solid #3d3d3d",borderRadius:"8px"},formatter:A=>[l==="weight"?Am(Number(A??0)):`${A??0}`,a(l==="weight"?"stats.filamentByWeight":"stats.filamentByPrints")]})]})}),i.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center",children:[i.jsx("span",{className:"text-lg font-bold text-white",children:l==="weight"?Am(D):D}),i.jsxs("span",{className:"text-[10px] text-bambu-gray",children:[y.length," ",y.length===1?"color":"colors"]})]})]}),i.jsx("div",{className:"grid grid-cols-2 gap-x-3 gap-y-1 mt-2",children:y.slice(0,8).map(A=>{const R=D>0?(A.value/D*100).toFixed(0):0;return i.jsxs("div",{className:"flex items-center gap-1.5 text-xs min-w-0",children:[i.jsx("div",{className:"w-2.5 h-2.5 rounded-full flex-shrink-0 border border-white/20",style:{backgroundColor:A.hex}}),i.jsxs("span",{className:"text-bambu-gray truncate",children:[R,"%"]})]},A.hex)})}),y.length>8&&i.jsxs("p",{className:"text-[10px] text-bambu-gray mt-1 text-center",children:["+",y.length-8," more"]})]})})():i.jsx("div",{className:"h-[160px] flex items-center justify-center text-bambu-gray",children:a("stats.noColorData")})]})]})]})}function DZe({id:t,title:e,component:n,isHidden:r,size:a,columnSpan:s,onToggleVisibility:o,onToggleSize:l}){const{attributes:c,listeners:d,setNodeRef:u,transform:m,transition:p,isDragging:f}=Cse({id:t}),x={transform:nx.Transform.toString(m),transition:p,opacity:f?.5:1};return r?null:i.jsxs("div",{ref:u,style:{...x,gridColumn:`span ${s}`},className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary overflow-hidden ${f?"ring-2 ring-bambu-green shadow-lg":""}`,children:[i.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-bambu-dark-tertiary bg-bambu-dark/30",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("button",{...c,...d,className:"cursor-grab active:cursor-grabbing p-1 hover:bg-bambu-dark-tertiary rounded transition-colors",title:"Drag to reorder",children:i.jsx(qm,{className:"w-6 h-6 md:w-4 md:h-4 text-bambu-gray"})}),i.jsx("h3",{className:"text-sm font-medium text-white",children:e})]}),i.jsxs("div",{className:"flex items-center gap-1",children:[i.jsx("button",{onClick:l,className:"p-1 hover:bg-bambu-dark-tertiary rounded transition-colors",title:`Size: ${a===1?"1/4":a===2?"1/2":"Full"} - Click to cycle`,children:a===4?i.jsx(KF,{className:"w-4 h-4 text-bambu-gray hover:text-white"}):i.jsx(uC,{className:"w-4 h-4 text-bambu-gray hover:text-white"})}),i.jsx("button",{onClick:o,className:"p-1 hover:bg-bambu-dark-tertiary rounded transition-colors",title:"Hide widget",children:i.jsx(E0,{className:"w-4 h-4 text-bambu-gray hover:text-white"})})]})]}),i.jsx("div",{className:"p-4",children:typeof n=="function"?n(a):n})]})}function RZe({widgets:t,storageKey:e,columns:n=4,stackBelow:r,hideControls:a=!1,onResetLayout:s,renderControls:o}){const l=()=>{const D={};return t.forEach(A=>{D[A.id]=A.defaultSize||4}),D},[c,d]=w.useState(()=>{const D=localStorage.getItem(e);if(D)try{const A=JSON.parse(D);if(!A.sizes)A.sizes=l();else{const R=l();for(const $ in R)$ in A.sizes||(A.sizes[$]=R[$])}return A}catch{}return{order:t.map(A=>A.id),hidden:t.filter(A=>A.defaultVisible===!1).map(A=>A.id),sizes:l()}}),[u,m]=w.useState(!1),[p,f]=w.useState(!1);w.useEffect(()=>{if(!r)return;const D=window.matchMedia(`(max-width: ${r}px)`),A=$=>{f($.matches)};A(D);const R=$=>A($);return D.addEventListener?D.addEventListener("change",R):D.addListener(R),()=>{D.removeEventListener?D.removeEventListener("change",R):D.removeListener(R)}},[r]);const x=r&&p?1:n;w.useEffect(()=>{const D=()=>m(A=>!A);return window.addEventListener("toggle-hidden-panel",D),()=>window.removeEventListener("toggle-hidden-panel",D)},[]),w.useEffect(()=>{localStorage.setItem(e,JSON.stringify(c))},[c,e]),w.useEffect(()=>{const A=t.map(R=>R.id).filter(R=>!c.order.includes(R));A.length>0&&d(R=>({...R,order:[...R.order,...A]}))},[t,c.order]);const v=ise(Jk(qT,{activationConstraint:{distance:8}}),Jk($T,{coordinateGetter:Tse})),g=D=>{const{active:A,over:R}=D;R&&A.id!==R.id&&d($=>{const U=$.order.indexOf(A.id),W=$.order.indexOf(R.id);return{...$,order:WT($.order,U,W)}})},y=D=>{d(A=>({...A,hidden:A.hidden.includes(D)?A.hidden.filter(R=>R!==D):[...A.hidden,D]}))},_=D=>{d(A=>{const R=A.sizes[D]||4,$=R===1?2:R===2?4:1;return{...A,sizes:{...A.sizes,[D]:$}}})},N=()=>{const D={order:t.map(A=>A.id),hidden:t.filter(A=>A.defaultVisible===!1).map(A=>A.id),sizes:l()};d(D),s?.()},C=c.order.map(D=>t.find(A=>A.id===D)).filter(Boolean),T=C.filter(D=>!c.hidden.includes(D.id)),P=C.filter(D=>c.hidden.includes(D.id)),k=o?.({hiddenCount:P.length,showHiddenPanel:u,setShowHiddenPanel:m,resetLayout:N});return i.jsxs("div",{className:"space-y-4",children:[k,!a&&!o&&i.jsxs("div",{className:"flex items-center justify-end gap-2",children:[i.jsxs(Oe,{variant:"secondary",size:"sm",onClick:N,children:[i.jsx(mo,{className:"w-4 h-4"}),"Reset Layout"]}),P.length>0&&i.jsxs(Oe,{variant:"secondary",size:"sm",onClick:()=>m(!u),children:[i.jsx(rc,{className:"w-4 h-4"}),P.length," Hidden"]})]}),u&&P.length>0&&i.jsxs("div",{className:"p-4 bg-bambu-dark rounded-xl border border-bambu-dark-tertiary",children:[i.jsx("p",{className:"text-sm text-bambu-gray mb-3",children:"Hidden widgets (click to show):"}),i.jsx("div",{className:"flex flex-wrap gap-2",children:P.map(D=>i.jsxs("button",{onClick:()=>y(D.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:[i.jsx(rc,{className:"w-3 h-3"}),D.title]},D.id))})]}),i.jsx(wse,{sensors:v,collisionDetection:lse,onDragEnd:g,children:i.jsx(Nse,{items:T.map(D=>D.id),strategy:MI,children:i.jsx("div",{className:"grid gap-6",style:{gridTemplateColumns:`repeat(${x}, minmax(0, 1fr))`},children:T.map(D=>{const A=c.sizes[D.id]||2,R=Math.min(A,x);return i.jsx(DZe,{id:D.id,title:D.title,component:D.component,isHidden:c.hidden.includes(D.id),size:A,columnSpan:R,onToggleVisibility:()=>y(D.id),onToggleSize:()=>_(D.id)},D.id)})})})}),T.length===0&&i.jsxs("div",{className:"text-center py-12 text-bambu-gray",children:[i.jsx("p",{children:"All widgets are hidden."}),i.jsx(Oe,{className:"mt-4",onClick:N,children:"Reset Layout"})]})]})}function FZe(t){const e=new Date,n=e.getUTCFullYear(),r=e.getUTCMonth(),a=e.getUTCDate(),s=l=>l.toISOString().split("T")[0],o=s(e);switch(t){case"today":return{dateFrom:o,dateTo:o};case"this-week":{const l=e.getUTCDay(),c=new Date(Date.UTC(n,r,a-(l===0?6:l-1)));return{dateFrom:s(c),dateTo:o}}case"this-month":return{dateFrom:s(new Date(Date.UTC(n,r,1))),dateTo:o};case"last-7":return{dateFrom:s(new Date(Date.UTC(n,r,a-6))),dateTo:o};case"last-30":return{dateFrom:s(new Date(Date.UTC(n,r,a-29))),dateTo:o};case"last-90":return{dateFrom:s(new Date(Date.UTC(n,r,a-89))),dateTo:o};case"this-year":return{dateFrom:s(new Date(Date.UTC(n,0,1))),dateTo:o};case"all-time":return{dateFrom:void 0,dateTo:void 0};case"custom":return{}}}const LZe=["today","this-week","this-month","last-7","last-30","last-90","this-year","all-time"],OZe=["Mon","Tue","Wed","Thu","Fri","Sat","Sun"],NF=["12am","1am","2am","3am","4am","5am","6am","7am","8am","9am","10am","11am","12pm","1pm","2pm","3pm","4pm","5pm","6pm","7pm","8pm","9pm","10pm","11pm"],Gj=[{key:"<30m",max:1800},{key:"30m-1h",max:3600},{key:"1-2h",max:7200},{key:"2-4h",max:14400},{key:"4-8h",max:28800},{key:"8-12h",max:43200},{key:"12-24h",max:86400},{key:"24h+",max:1/0}],r1={backgroundColor:"#2d2d2d",border:"1px solid #3d3d3d",borderRadius:"8px"};function IZe({stats:t,currency:e}){const{t:n}=Mt(),r=[{icon:oa,color:"text-bambu-green",label:n("stats.totalPrints"),value:`${t?.total_prints||0}`},{icon:Xn,color:"text-blue-400",label:n("stats.printTime"),value:`${t?.total_print_time_hours?.toFixed(1)??"0"}h`},{icon:oa,color:"text-orange-400",label:n("stats.filamentUsed"),value:Am(t?.total_filament_grams||0)},{icon:U1,color:"text-green-400",label:n("stats.filamentCost"),value:`${e} ${t?.total_cost?.toFixed(2)??"0.00"}`},{icon:ac,color:"text-yellow-400",label:n("stats.energyUsed"),value:`${t?.total_energy_kwh?.toFixed(3)??"0.000"} kWh`},{icon:U1,color:"text-yellow-500",label:n("stats.energyCost"),value:`${e} ${t?.total_energy_cost?.toFixed(2)??"0.00"}`}];return i.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 gap-4",children:r.map(a=>i.jsxs("div",{className:"flex items-start gap-3",children:[i.jsx("div",{className:`p-2 rounded-lg bg-bambu-dark ${a.color}`,children:i.jsx(a.icon,{className:"w-5 h-5"})}),i.jsxs("div",{children:[i.jsx("p",{className:"text-xs text-bambu-gray",children:a.label}),i.jsx("p",{className:"text-xl font-bold text-white",children:a.value})]})]},a.label))})}function zZe({stats:t,printerMap:e,size:n=1}){const{t:r}=Mt(),a=(t?.successful_prints||0)+(t?.failed_prints||0),s=a?Math.round(t.successful_prints/a*100):0,o=n===1?112:n===2?128:144,l=o/2-8,c=l*2*Math.PI;return i.jsxs("div",{className:"flex items-center gap-6",children:[i.jsxs("div",{className:"relative flex-shrink-0",style:{width:o,height:o},children:[i.jsxs("svg",{className:"w-full h-full -rotate-90",children:[i.jsx("circle",{cx:o/2,cy:o/2,r:l,fill:"none",stroke:"#3d3d3d",strokeWidth:"10"}),i.jsx("circle",{cx:o/2,cy:o/2,r:l,fill:"none",stroke:"#00ae42",strokeWidth:"10",strokeLinecap:"round",strokeDasharray:`${s/100*c} ${c}`})]}),i.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:i.jsxs("span",{className:`font-bold text-white ${n>=2?"text-2xl":"text-xl"}`,children:[s,"%"]})})]}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsxs("div",{className:"space-y-2",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(pr,{className:"w-4 h-4 text-status-ok flex-shrink-0"}),i.jsx("span",{className:"text-sm text-bambu-gray",children:r("stats.successful")}),i.jsx("span",{className:"text-sm text-white font-medium",children:t?.successful_prints||0})]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(Vi,{className:"w-4 h-4 text-status-error flex-shrink-0"}),i.jsx("span",{className:"text-sm text-bambu-gray",children:r("stats.failed")}),i.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&&i.jsxs("div",{className:"mt-4 pt-4 border-t border-bambu-dark-tertiary",children:[i.jsx("p",{className:"text-xs text-bambu-gray font-medium mb-2",children:r("stats.printsByPrinter")}),i.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(([d,u])=>i.jsxs("div",{className:"flex items-center gap-3 text-sm",children:[i.jsx("span",{className:"text-bambu-gray truncate max-w-[120px]",children:e.get(d)||`${r("common.printer")} ${d}`}),i.jsx("span",{className:"text-white font-medium",children:u})]},d))})]})]})]})}function UZe({stats:t,printerMap:e,size:n=1}){const{t:r}=Mt(),a=t?.average_time_accuracy;if(a==null)return i.jsx("div",{className:"flex items-center justify-center h-full",children:i.jsx("p",{className:"text-bambu-gray text-center py-4",children:r("stats.noTimeAccuracyData")})});const o=(Math.min(150,Math.max(50,a))-50)/100*100,c=(v=>v>=95&&v<=105?"#00ae42":v>105?"#3b82f6":"#f97316")(a),d=a-100,u=n===1?112:n===2?128:144,m=u/2-8,p=m*2*Math.PI,f=n===1?3:n===2?6:999,x=t?.time_accuracy_by_printer?Object.entries(t.time_accuracy_by_printer).slice(0,f):[];return i.jsxs("div",{className:"flex items-center gap-6",children:[i.jsxs("div",{className:"relative flex-shrink-0",style:{width:u,height:u},children:[i.jsxs("svg",{className:"w-full h-full -rotate-90",children:[i.jsx("circle",{cx:u/2,cy:u/2,r:m,fill:"none",stroke:"#3d3d3d",strokeWidth:"10"}),i.jsx("circle",{cx:u/2,cy:u/2,r:m,fill:"none",stroke:c,strokeWidth:"10",strokeLinecap:"round",strokeDasharray:`${o/100*p} ${p}`})]}),i.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center",children:[i.jsxs("span",{className:`font-bold text-white ${n>=2?"text-2xl":"text-xl"}`,children:[a.toFixed(0),"%"]}),i.jsxs("span",{className:`text-xs ${d>=0?"text-blue-400":"text-orange-400"}`,children:[d>=0?"+":"",d.toFixed(0),"%"]})]})]}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsxs("div",{className:"flex items-center gap-2 text-xs text-bambu-gray",children:[i.jsx(eX,{className:"w-3 h-3 flex-shrink-0"}),i.jsx("span",{children:r("stats.perfectEstimate")})]}),x.length>0&&i.jsx("div",{className:`mt-2 ${n===4?"grid grid-cols-3 gap-x-6 gap-y-1":n===2?"grid grid-cols-2 gap-x-6 gap-y-1":"space-y-1"}`,style:{width:"fit-content"},children:x.map(([v,g])=>i.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[i.jsx("span",{className:"text-bambu-gray truncate max-w-[100px]",children:e.get(v)||`${r("common.printer")} ${v}`}),i.jsxs("span",{className:`font-medium ${g>=95&&g<=105?"text-status-ok":g>105?"text-blue-400":"text-status-warning"}`,children:[g.toFixed(0),"%"]})]},v))})]})]})}function BZe({printDates:t,dateFrom:e,dateTo:n}){const{days:r,hourlyCounts:a,maxCount:s}=w.useMemo(()=>{const u=new Date(e+"T00:00:00"),m=new Date(n+"T00:00:00"),p=[],f=y=>`${y.getFullYear()}-${String(y.getMonth()+1).padStart(2,"0")}-${String(y.getDate()).padStart(2,"0")}`,x=new Date(u);for(;x<=m;)p.push({key:f(x),label:x.toLocaleDateString(void 0,{weekday:"short",month:"short",day:"numeric"})}),x.setDate(x.getDate()+1);const v={};let g=0;return t.forEach(y=>{const _=er(y);if(!_)return;const C=`${`${_.getFullYear()}-${String(_.getMonth()+1).padStart(2,"0")}-${String(_.getDate()).padStart(2,"0")}`}-${_.getHours()}`;v[C]=(v[C]||0)+1,v[C]>g&&(g=v[C])}),{days:p,hourlyCounts:v,maxCount:Math.max(1,g)}},[t,e,n]),o=u=>{if(u===0)return"bg-bambu-dark";const m=u/s;return m<=.25?"bg-bambu-green/30":m<=.5?"bg-bambu-green/50":m<=.75?"bg-bambu-green/75":"bg-bambu-green"},l=20,c=2,d=80;return i.jsxs("div",{className:"w-full overflow-x-auto",children:[i.jsxs("div",{className:"inline-flex flex-col",style:{gap:c},children:[i.jsx("div",{className:"flex",style:{gap:c,marginLeft:d+4},children:NF.map((u,m)=>i.jsx("div",{className:"text-bambu-gray text-[10px] text-center",style:{width:l,visibility:m%2===0?"visible":"hidden"},children:u},m))}),r.map(u=>i.jsxs("div",{className:"flex items-center",style:{gap:c},children:[i.jsx("div",{className:"text-bambu-gray text-[10px] flex-shrink-0 truncate",style:{width:d},children:u.label}),Array.from({length:24},(m,p)=>{const f=a[`${u.key}-${p}`]||0;return i.jsx("div",{className:`rounded-sm ${o(f)}`,style:{width:l,height:l},title:`${u.label} ${NF[p]}: ${f} print${f!==1?"s":""}`},p)})]},u.key))]}),i.jsxs("div",{className:"flex items-center gap-2 mt-3 text-bambu-gray text-xs",children:[i.jsx("span",{children:"Less"}),i.jsxs("div",{className:"flex",style:{gap:c},children:[i.jsx("div",{className:"rounded-sm bg-bambu-dark",style:{width:l,height:l}}),i.jsx("div",{className:"rounded-sm bg-bambu-green/30",style:{width:l,height:l}}),i.jsx("div",{className:"rounded-sm bg-bambu-green/50",style:{width:l,height:l}}),i.jsx("div",{className:"rounded-sm bg-bambu-green/75",style:{width:l,height:l}}),i.jsx("div",{className:"rounded-sm bg-bambu-green",style:{width:l,height:l}})]}),i.jsx("span",{children:"More"})]})]})}function HZe({printDates:t,size:e=2,dateFrom:n,dateTo:r}){const a=w.useMemo(()=>n&&r?Math.max((new Date(r).getTime()-new Date(n).getTime())/864e5,0)+1:n?Math.max((Date.now()-new Date(n).getTime())/864e5,0)+1:1/0,[n,r]);if(a<=7&&n&&r)return i.jsx(BZe,{printDates:t,dateFrom:n,dateTo:r});const o=a===1/0?e===1?3:e===2?6:12:Math.max(1,Math.ceil(a/30));return i.jsx(MZe,{printDates:t,months:o})}function $Ze({stats:t,archives:e,printerMap:n}){const{t:r}=Mt(),[a,s]=w.useState("weight"),[o,l]=w.useState("weight"),c=w.useMemo(()=>{const y=new Map;return t?.prints_by_printer&&Object.entries(t.prints_by_printer).forEach(([_,N])=>{const C=y.get(_)||{prints:0,weight:0,time:0};C.prints=N,y.set(_,C)}),e.forEach(_=>{if(!_.printer_id)return;const N=String(_.printer_id),C=y.get(N)||{prints:0,weight:0,time:0};C.weight+=_.filament_used_grams||0,C.time+=_.actual_time_seconds||_.print_time_seconds||0,t?.prints_by_printer||C.prints++,y.set(N,C)}),Array.from(y.entries()).map(([_,N])=>({name:n.get(_)||`${r("common.printer")} ${_}`,value:a==="prints"?N.prints:a==="weight"?Math.round(N.weight):Math.round(N.time/3600*10)/10})).sort((_,N)=>N.value-_.value)},[t,e,n,a,r]),d=w.useMemo(()=>{const y=Array.from({length:24},(_,N)=>({hour:N,label:NF[N],total:0,failures:0}));return e.forEach(_=>{if(!_.started_at)return;const N=er(_.started_at);if(!N)return;const C=N.getHours();y[C].total++,_.status==="failed"&&y[C].failures++}),y},[e]),u=w.useMemo(()=>{const y=Gj.map(_=>({name:_.key,count:0}));return e.forEach(_=>{const N=_.actual_time_seconds||_.print_time_seconds;if(!(!N||N<=0)){for(let C=0;C{const y=[0,0,0,0,0,0,0],_=new Set;e.forEach(C=>{const T=er(C.created_at)||new Date(C.created_at);let P=T.getDay()-1;P<0&&(P=6),o==="prints"?y[P]++:o==="weight"?y[P]+=C.filament_used_grams||0:y[P]+=(C.actual_time_seconds||C.print_time_seconds||0)/3600;const k=new Date(T);k.setDate(T.getDate()-(T.getDay()+6)%7),_.add(`${k.getFullYear()}-${String(k.getMonth()+1).padStart(2,"0")}-${String(k.getDate()).padStart(2,"0")}`)});const N=Math.max(_.size,1);return OZe.map((C,T)=>({name:C,avg:Math.round(y[T]/N*10)/10}))},[e,o]),p=y=>({unit:y==="weight"?"g":y==="time"?"h":"",color:y==="weight"?"#00ae42":y==="time"?"#3b82f6":"#f59e0b"}),f=p(a),x=r(a==="weight"?"stats.filamentByWeight":a==="time"?"stats.hours":"common.prints"),v=p(o),g=r(o==="weight"?"stats.avgWeight":o==="time"?"stats.avgTime":"stats.avgPrints");return i.jsxs("div",{className:"space-y-4",children:[i.jsxs("div",{className:"bg-bambu-dark rounded-lg p-4",children:[i.jsxs("div",{className:"flex items-center justify-between mb-3",children:[i.jsx("h4",{className:"text-sm font-medium text-bambu-gray",children:r("stats.printsByPrinter")}),i.jsx(nC,{value:a,onChange:s})]}),c.length>0?i.jsx(Fm,{width:"100%",height:Math.max(140,c.length*40),children:i.jsxs(z_,{data:c,layout:"vertical",margin:{left:10},children:[i.jsx(xp,{strokeDasharray:"3 3",stroke:"#3d3d3d"}),i.jsx(yp,{type:"number",stroke:"#9ca3af",tick:{fontSize:11},unit:f.unit}),i.jsx(vp,{type:"category",dataKey:"name",stroke:"#9ca3af",tick:{fontSize:11},width:100}),i.jsx(Lm,{contentStyle:r1,formatter:y=>[a==="weight"?Am(Number(y??0)):`${y??0}${f.unit}`,x]}),i.jsx(Zg,{dataKey:"value",fill:f.color,radius:[0,4,4,0]})]})}):i.jsx("p",{className:"text-bambu-gray text-center py-4",children:r("stats.noPrinterData")})]}),i.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-4",children:[i.jsxs("div",{className:"bg-bambu-dark rounded-lg p-4",children:[i.jsx("h4",{className:"text-sm font-medium text-bambu-gray mb-3",children:r("stats.printDuration")}),e.length>0?i.jsx(Fm,{width:"100%",height:160,children:i.jsxs(z_,{data:u,children:[i.jsx(xp,{strokeDasharray:"3 3",stroke:"#3d3d3d"}),i.jsx(yp,{dataKey:"name",stroke:"#9ca3af",tick:{fontSize:11}}),i.jsx(vp,{stroke:"#9ca3af",tick:{fontSize:11},allowDecimals:!1}),i.jsx(Lm,{contentStyle:r1}),i.jsx(Zg,{dataKey:"count",name:r("common.prints"),fill:"#00ae42",radius:[4,4,0,0]})]})}):i.jsx("p",{className:"text-bambu-gray text-center py-4",children:r("stats.noArchiveData")})]}),i.jsxs("div",{className:"bg-bambu-dark rounded-lg p-4",children:[i.jsxs("div",{className:"flex items-center justify-between mb-3",children:[i.jsx("h4",{className:"text-sm font-medium text-bambu-gray",children:r("stats.printHabits")}),i.jsx(nC,{value:o,onChange:l})]}),e.length>0?i.jsx(Fm,{width:"100%",height:160,children:i.jsxs(z_,{data:m,children:[i.jsx(xp,{strokeDasharray:"3 3",stroke:"#3d3d3d"}),i.jsx(yp,{dataKey:"name",stroke:"#9ca3af",tick:{fontSize:11}}),i.jsx(vp,{stroke:"#9ca3af",tick:{fontSize:11},unit:v.unit}),i.jsx(Lm,{contentStyle:r1,formatter:y=>[`${y??0}${v.unit}`,g]}),i.jsx(Zg,{dataKey:"avg",fill:v.color,radius:[4,4,0,0]})]})}):i.jsx("p",{className:"text-bambu-gray text-center py-4",children:r("stats.noArchiveData")})]}),i.jsxs("div",{className:"bg-bambu-dark rounded-lg p-4",children:[i.jsx("h4",{className:"text-sm font-medium text-bambu-gray mb-3",children:r("stats.printTimeOfDay")}),e.length>0?i.jsx(Fm,{width:"100%",height:160,children:i.jsxs(z_,{data:d,children:[i.jsx(xp,{strokeDasharray:"3 3",stroke:"#3d3d3d"}),i.jsx(yp,{dataKey:"label",stroke:"#9ca3af",tick:{fontSize:10},interval:5}),i.jsx(vp,{stroke:"#9ca3af",tick:{fontSize:11},allowDecimals:!1}),i.jsx(Lm,{contentStyle:r1}),i.jsx(Zg,{dataKey:"total",name:r("stats.totalPrints"),fill:"#00ae42",radius:[2,2,0,0]}),i.jsx(Zg,{dataKey:"failures",name:r("stats.failed"),fill:"#ef4444",radius:[2,2,0,0]})]})}):i.jsx("p",{className:"text-bambu-gray text-center py-4",children:r("stats.noArchiveData")})]})]})]})}function qZe({archives:t,currency:e,dateFrom:n,dateTo:r}){const{t:a}=Mt();return!t||t.length===0?i.jsx("p",{className:"text-bambu-gray text-center py-4",children:a("stats.noPrintData")}):i.jsx(jZe,{archives:t,currency:e,dateFrom:n,dateTo:r})}function VZe({size:t=1,dateFrom:e,dateTo:n}){const{t:r}=Mt(),a=!!(e||n),{data:s,isLoading:o}=Ze({queryKey:["failureAnalysis",e,n],queryFn:()=>fe.getFailureAnalysis({...a?{dateFrom:e,dateTo:n}:{days:30}})});if(o)return i.jsx("div",{className:"flex justify-center py-4",children:i.jsx(lt,{className:"w-6 h-6 text-bambu-green animate-spin"})});if(!s||s.total_prints===0)return i.jsx("p",{className:"text-bambu-gray text-center py-4",children:r(a?"stats.noPrintDataInRange":"stats.noPrintDataLast30Days")});const l=t===1?5:t===2?8:999,c=Object.entries(s.failures_by_reason).sort(([,m],[,p])=>p-m),d=c.slice(0,l),u=c.length>l;return i.jsxs("div",{className:`${t>=2?"flex gap-8":"space-y-4"}`,children:[i.jsxs("div",{className:t>=2?"flex-shrink-0":"",children:[i.jsx("div",{className:"flex items-center gap-4",children:i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(Cn,{className:`w-5 h-5 ${s.failure_rate>20?"text-status-error":s.failure_rate>10?"text-status-warning":"text-status-ok"}`}),i.jsxs("span",{className:`font-bold text-white ${t>=2?"text-3xl":"text-2xl"}`,children:[s.failure_rate.toFixed(1),"%"]})]})}),i.jsx("div",{className:"text-sm text-bambu-gray mt-1",children:r("stats.failedPrintsCount",{failed:s.failed_prints,total:s.total_prints})}),s.trend&&s.trend.length>=2&&i.jsx("div",{className:`${t>=2?"mt-4":"mt-2 pt-2 border-t border-bambu-dark-tertiary"}`,children:i.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[i.jsx(QF,{className:`w-4 h-4 ${s.trend[s.trend.length-1].failure_rate0&&i.jsxs("div",{className:`flex-1 ${t>=2?"border-l border-bambu-dark-tertiary pl-8":"pt-2"}`,children:[i.jsx("p",{className:"text-xs text-bambu-gray font-medium mb-2",children:t>=2?r("stats.failureReasons"):r("stats.topFailureReasons")}),i.jsx("div",{className:`${t===4?"grid grid-cols-2 gap-x-6 gap-y-1":"space-y-1"}`,children:d.map(([m,p])=>i.jsxs("div",{className:"flex items-center justify-between text-sm",children:[i.jsx("span",{className:`text-white truncate ${t===4?"max-w-[200px]":"max-w-[160px]"}`,children:m||r("common.unknown")}),i.jsx("span",{className:"text-bambu-gray ml-2",children:p})]},m))}),u&&i.jsx("p",{className:"text-xs text-bambu-gray mt-2",children:r("common.more",{count:c.length-l})})]})]})}function GZe({archives:t,currency:e}){const{t:n}=Mt(),r=w.useMemo(()=>{const a=[];if(t.length===0)return a;const s=x=>{let v=null,g=0;return t.forEach(y=>{const _=x(y);_&&_>g&&(g=_,v=y)}),{archive:v,value:g}},o=s(x=>x.actual_time_seconds);o.archive&&a.push({icon:Xn,iconColor:"text-blue-400",label:n("stats.longestPrint"),value:js(o.value),detail:o.archive.print_name||null});const l=s(x=>x.filament_used_grams);l.archive&&a.push({icon:oa,iconColor:"text-orange-400",label:n("stats.heaviestPrint"),value:Am(l.value),detail:l.archive.print_name||null});const c=s(x=>x.cost);c.archive&&a.push({icon:U1,iconColor:"text-green-400",label:n("stats.mostExpensivePrint"),value:`${e}${c.value.toFixed(2)}`,detail:c.archive.print_name||null});const d=new Map;t.forEach(x=>{const v=er(x.created_at)||new Date(x.created_at),g=`${v.getFullYear()}-${String(v.getMonth()+1).padStart(2,"0")}-${String(v.getDate()).padStart(2,"0")}`;d.set(g,(d.get(g)||0)+1)});let u="",m=0;d.forEach((x,v)=>{x>m&&(m=x,u=v)}),m>1&&a.push({icon:Xr,iconColor:"text-purple-400",label:n("stats.busiestDay"),value:`${m} ${n("common.prints")}`,detail:(()=>{const[x,v,g]=u.split("-").map(Number);return new Date(x,v-1,g).toLocaleDateString(void 0,{month:"short",day:"numeric",year:"numeric"})})()});const p=[...t].filter(x=>x.status==="completed"||x.status==="failed").sort((x,v)=>new Date(v.completed_at||v.created_at).getTime()-new Date(x.completed_at||x.created_at).getTime());let f=0;for(const x of p)if(x.status==="completed")f++;else break;return f>0&&a.push({icon:ac,iconColor:"text-yellow-400",label:n("stats.successStreak"),value:`${f}`,detail:f===1?n("stats.streakPrint"):n("stats.streakPrints",{count:f})}),a},[t,e,n]);return r.length===0?i.jsx("p",{className:"text-bambu-gray text-center py-4",children:n("stats.noArchiveData")}):i.jsx("div",{className:"space-y-3",children:r.map((a,s)=>i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx("div",{className:`p-1.5 rounded-lg bg-bambu-dark ${a.iconColor}`,children:i.jsx(a.icon,{className:"w-4 h-4"})}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsx("p",{className:"text-xs text-bambu-gray",children:a.label}),i.jsxs("div",{className:"flex items-baseline gap-2",children:[i.jsx("span",{className:"text-sm font-bold text-white",children:a.value}),a.detail&&i.jsx("span",{className:"text-xs text-bambu-gray truncate",children:a.detail})]})]})]},s))})}function WZe(){const{t}=Mt(),{showToast:e}=hn(),{hasPermission:n}=Dr(),[r,a]=w.useState(!1),[s,o]=w.useState(!1),[l,c]=w.useState(0),[d,u]=w.useState(0),[m,p]=w.useState(!1),[f,x]=w.useState(()=>{try{const te=localStorage.getItem("bambusy-stats-timeframe");if(te){const ie=JSON.parse(te);if(ie.preset)return ie}}catch{}return{preset:"all-time",dateFrom:void 0,dateTo:void 0}}),[v,g]=w.useState(!1);w.useEffect(()=>{localStorage.setItem("bambusy-stats-timeframe",JSON.stringify(f))},[f]);const y=w.useMemo(()=>f.preset==="custom"?{dateFrom:f.dateFrom,dateTo:f.dateTo}:FZe(f.preset),[f]);w.useEffect(()=>{const te=()=>{try{const Y=localStorage.getItem("bambusy-dashboard-layout-v2");if(Y){const ae=JSON.parse(Y);u(ae.hidden?.length||0)}}catch{u(0)}};te(),window.addEventListener("storage",te);const ie=setInterval(te,2e3);return()=>{window.removeEventListener("storage",te),clearInterval(ie)}},[l]);const{data:_,isLoading:N,refetch:C}=Ze({queryKey:["archiveStats",y.dateFrom,y.dateTo],queryFn:()=>fe.getArchiveStats({dateFrom:y.dateFrom,dateTo:y.dateTo})}),{data:T}=Ze({queryKey:["printers"],queryFn:fe.getPrinters}),{data:P,refetch:k}=Ze({queryKey:["archivesSlim",y.dateFrom,y.dateTo],queryFn:()=>fe.getArchivesSlim(y.dateFrom,y.dateTo)}),{data:D}=Ze({queryKey:["settings"],queryFn:fe.getSettings}),A=async te=>{o(!1),a(!0);try{const{blob:ie,filename:Y}=await fe.exportStats({format:te,days:90}),ae=URL.createObjectURL(ie),de=document.createElement("a");de.href=ae,de.download=Y,de.click(),URL.revokeObjectURL(ae),e(t("stats.exportDownloaded"))}catch{e(t("stats.exportFailed"),"error")}finally{a(!1)}},R=async()=>{p(!0);try{const te=await fe.recalculateCosts();await Promise.all([C(),k()]),e(t("stats.recalculatedCosts",{count:te.updated}))}catch{e(t("stats.recalculateFailed"),"error")}finally{p(!1)}},$=ol(D?.currency||"USD"),U=new Map(T?.map(te=>[String(te.id),te.name])||[]),W=w.useMemo(()=>P?.map(te=>te.created_at)||[],[P]);if(N)return i.jsx("div",{className:"p-4 md:p-8",children:i.jsx("div",{className:"text-center py-12 text-bambu-gray",children:t("stats.loadingStats")})});const O=[{id:"quick-stats",title:t("stats.quickStats"),component:i.jsx(IZe,{stats:_,currency:$}),defaultSize:2},{id:"success-rate",title:t("stats.successRate"),component:te=>i.jsx(zZe,{stats:_,printerMap:U,size:te}),defaultSize:1},{id:"time-accuracy",title:t("stats.timeAccuracy"),component:te=>i.jsx(UZe,{stats:_,printerMap:U,size:te}),defaultSize:1},{id:"failure-analysis",title:t("stats.failureAnalysis"),component:te=>i.jsx(VZe,{size:te,dateFrom:y.dateFrom,dateTo:y.dateTo}),defaultSize:1},{id:"print-activity",title:t("stats.printActivity"),component:te=>i.jsx(HZe,{printDates:W,size:te,dateFrom:y.dateFrom,dateTo:y.dateTo}),defaultSize:2},{id:"records",title:t("stats.records"),component:i.jsx(GZe,{archives:P||[],currency:$}),defaultSize:1},{id:"printer-stats",title:t("stats.printerStats"),component:i.jsx($Ze,{stats:_,archives:P||[],printerMap:U}),defaultSize:4},{id:"filament-trends",title:t("stats.filamentTrends"),component:i.jsx(qZe,{archives:P||[],currency:$,dateFrom:y.dateFrom,dateTo:y.dateTo}),defaultSize:4}];return i.jsxs("div",{className:"p-4 md:p-8",children:[i.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4 mb-6",children:[i.jsxs("div",{children:[i.jsx("h1",{className:"text-2xl font-bold text-white",children:t("stats.title")}),i.jsx("p",{className:"text-bambu-gray",children:t("stats.subtitle")})]}),i.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[d>0&&i.jsxs(Oe,{variant:"secondary",onClick:()=>{window.dispatchEvent(new CustomEvent("toggle-hidden-panel"))},children:[i.jsx(rc,{className:"w-4 h-4"}),t("stats.hiddenCount",{count:d})]}),i.jsxs(Oe,{variant:"secondary",onClick:()=>{localStorage.removeItem("bambusy-dashboard-layout-v2"),c(te=>te+1),e(t("stats.layoutReset"))},disabled:!n("settings:update"),title:n("settings:update")?void 0:t("stats.noPermissionResetLayout"),children:[i.jsx(mo,{className:"w-4 h-4"}),t("stats.resetLayout")]}),i.jsxs(Oe,{variant:"secondary",onClick:R,disabled:m||!n("archives:update_all"),title:n("archives:update_all")?t("stats.recalculateCostsHint"):t("stats.noPermissionRecalculate"),children:[m?i.jsx(lt,{className:"w-4 h-4 animate-spin"}):i.jsx(Bme,{className:"w-4 h-4"}),t("stats.recalculateCosts")]}),i.jsxs("div",{className:"relative",children:[i.jsxs(Oe,{variant:"secondary",onClick:()=>o(!s),disabled:r,children:[r?i.jsx(lt,{className:"w-4 h-4 animate-spin"}):i.jsx(H1,{className:"w-4 h-4"}),t("stats.exportStats")]}),s&&i.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:[i.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:()=>A("csv"),children:[i.jsx(Ds,{className:"w-4 h-4"}),t("stats.exportAsCsv")]}),i.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:()=>A("xlsx"),children:[i.jsx(H1,{className:"w-4 h-4"}),t("stats.exportAsExcel")]})]})]}),i.jsxs("div",{className:"relative",children:[i.jsxs(Oe,{variant:"secondary",onClick:()=>g(!v),children:[i.jsx(Xr,{className:"w-4 h-4"}),t(`stats.timeframe.${f.preset}`),i.jsx(jn,{className:"w-3 h-3"})]}),v&&i.jsxs(i.Fragment,{children:[i.jsx("div",{className:"fixed inset-0 z-10",onClick:()=>g(!1)}),i.jsxs("div",{className:"absolute right-0 top-full mt-1 w-64 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl z-20 p-2",children:[LZe.map(te=>i.jsx("button",{className:`w-full px-3 py-2 text-left text-sm rounded-md transition-colors ${f.preset===te?"bg-bambu-green text-white":"text-white hover:bg-bambu-dark-tertiary"}`,onClick:()=>{x({preset:te,dateFrom:void 0,dateTo:void 0}),g(!1)},children:t(`stats.timeframe.${te}`)},te)),i.jsx("div",{className:"border-t border-bambu-dark-tertiary my-2"}),i.jsx("button",{className:`w-full px-3 py-2 text-left text-sm rounded-md transition-colors ${f.preset==="custom"?"bg-bambu-green text-white":"text-white hover:bg-bambu-dark-tertiary"}`,onClick:()=>x(te=>({...te,preset:"custom"})),children:t("stats.timeframe.custom")}),f.preset==="custom"&&i.jsxs("div",{className:"mt-2 px-1 pb-1 space-y-2",children:[i.jsxs("div",{children:[i.jsx("label",{className:"text-xs text-bambu-gray block mb-1",children:t("stats.timeframe.from")}),i.jsx("input",{type:"date",value:f.dateFrom||"",max:f.dateTo||new Date().toISOString().split("T")[0],onChange:te=>x(ie=>({...ie,dateFrom:te.target.value||void 0})),className:"w-full bg-bambu-dark border border-bambu-dark-tertiary rounded-md px-3 py-1.5 text-sm text-white [color-scheme:dark]"})]}),i.jsxs("div",{children:[i.jsx("label",{className:"text-xs text-bambu-gray block mb-1",children:t("stats.timeframe.to")}),i.jsx("input",{type:"date",value:f.dateTo||"",min:f.dateFrom,max:new Date().toISOString().split("T")[0],onChange:te=>x(ie=>({...ie,dateTo:te.target.value||void 0})),className:"w-full bg-bambu-dark border border-bambu-dark-tertiary rounded-md px-3 py-1.5 text-sm text-white [color-scheme:dark]"})]}),i.jsx(Oe,{variant:"primary",onClick:()=>g(!1),className:"w-full",children:t("common.apply")})]})]})]})]})]})]}),i.jsx(RZe,{widgets:O,storageKey:"bambusy-dashboard-layout-v2",stackBelow:640,hideControls:!0},l)]})}function KZe({plug:t,onEdit:e}){const{t:n}=Mt(),r=Zt(),{showToast:a}=hn(),[s,o]=w.useState(!1),[l,c]=w.useState(!1),[d,u]=w.useState(!1),[m,p]=w.useState(!1),{data:f,isLoading:x}=Ze({queryKey:["smart-plug-status",t.id],queryFn:()=>fe.getSmartPlugStatus(t.id),refetchInterval:3e4}),{data:v}=Ze({queryKey:["printers"],queryFn:fe.getPrinters}),g=v?.find(R=>R.id===t.printer_id),y=dt({mutationFn:R=>fe.controlSmartPlug(t.id,R),onMutate:async R=>{await r.cancelQueries({queryKey:["smart-plug-status",t.id]});const $=r.getQueryData(["smart-plug-status",t.id]),U=R==="on"?"ON":R==="off"||f?.state==="ON"?"OFF":"ON";return r.setQueryData(["smart-plug-status",t.id],W=>({...W,state:U})),{previousStatus:$}},onError:(R,$,U)=>{U?.previousStatus&&r.setQueryData(["smart-plug-status",t.id],U.previousStatus),a(n("smartPlugs.failedToTurn",{action:$,name:t.name}),"error")},onSettled:()=>{setTimeout(()=>{r.invalidateQueries({queryKey:["smart-plug-status",t.id]}),r.invalidateQueries({queryKey:["smart-plugs"]})},1e3)}}),_=dt({mutationFn:R=>fe.updateSmartPlug(t.id,R),onSuccess:()=>{r.invalidateQueries({queryKey:["smart-plugs"]}),t.printer_id&&(r.invalidateQueries({queryKey:["smartPlugByPrinter",t.printer_id]}),r.invalidateQueries({queryKey:["scriptPlugsByPrinter",t.printer_id]}))}}),N=dt({mutationFn:()=>fe.deleteSmartPlug(t.id),onSuccess:()=>{r.invalidateQueries({queryKey:["smart-plugs"]}),t.printer_id&&r.invalidateQueries({queryKey:["scriptPlugsByPrinter",t.printer_id]})}}),C=f?.state==="ON",T=t.plug_type==="mqtt"&&f?.energy?.power!==null&&f?.energy?.power!==void 0,P=(f?.reachable??!1)||T,k=y.isPending,A=(()=>{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 i.jsxs(i.Fragment,{children:[i.jsx(Tt,{className:"relative",children:i.jsxs(Pt,{className:"p-4",children:[i.jsxs("div",{className:"flex items-start justify-between gap-2 mb-3",children:[i.jsxs("div",{className:"flex items-center gap-3 min-w-0 flex-1",children:[i.jsx("div",{className:`p-2 rounded-lg flex-shrink-0 ${t.plug_type==="mqtt"?P?"bg-teal-500/20":"bg-red-500/20":P?C?"bg-bambu-green/20":"bg-bambu-dark":"bg-red-500/20"}`,children:t.plug_type==="mqtt"?i.jsx(YF,{className:`w-5 h-5 ${P?"text-teal-400":"text-red-400"}`}):t.plug_type==="homeassistant"?i.jsx(j0,{className:`w-5 h-5 ${P?C?"text-bambu-green":"text-bambu-gray":"text-red-400"}`}):i.jsx(bl,{className:`w-5 h-5 ${P?C?"text-bambu-green":"text-bambu-gray":"text-red-400"}`})}),i.jsxs("div",{className:"min-w-0",children:[i.jsx("h3",{className:"font-medium text-white truncate",children:t.name}),i.jsx("p",{className:"text-sm text-bambu-gray truncate",title:t.plug_type==="mqtt"?t.mqtt_topic??void 0:t.plug_type==="homeassistant"?t.ha_entity_id??void 0:t.ip_address??void 0,children:t.plug_type==="mqtt"?t.mqtt_topic:t.plug_type==="homeassistant"?t.ha_entity_id:t.ip_address})]})]}),i.jsxs("div",{className:"flex flex-col items-end gap-1 flex-shrink-0",children:[x?i.jsx(lt,{className:"w-4 h-4 text-bambu-gray animate-spin"}):t.plug_type==="mqtt"?i.jsxs("div",{className:"flex items-center gap-1.5 text-sm whitespace-nowrap",children:[i.jsx("span",{className:"px-1.5 py-0.5 bg-teal-500/20 text-teal-400 text-[10px] font-medium rounded flex-shrink-0",children:"MQTT"}),P&&i.jsx("span",{className:"text-status-ok",children:"✓"})]}):t.plug_type==="homeassistant"?i.jsxs("div",{className:"flex items-center gap-1 text-sm",children:[i.jsx("span",{className:"px-1 py-0.5 bg-blue-500/20 text-blue-400 text-[10px] font-medium rounded",children:"HA"}),i.jsx("span",{className:P?C?"text-status-ok":"text-bambu-gray":"text-status-error",children:P?f?.state||"?":n("smartPlugs.offline")})]}):P?i.jsxs("div",{className:"flex items-center gap-1 text-sm",children:[i.jsx(mb,{className:"w-4 h-4 text-status-ok"}),i.jsx("span",{className:C?"text-status-ok":"text-bambu-gray",children:f?.state||n("smartPlugs.unknown")})]}):i.jsxs("div",{className:"flex items-center gap-1 text-sm text-status-error",children:[i.jsx(rh,{className:"w-4 h-4"}),i.jsx("span",{children:n("smartPlugs.offline")})]}),A&&i.jsxs("a",{href:A,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:n("smartPlugs.openPlugAdminPage"),children:[i.jsx(ei,{className:"w-3 h-3"}),n("smartPlugs.admin")]})]})]}),g&&i.jsxs("div",{className:"mb-3 px-2 py-1.5 bg-bambu-dark rounded-lg",children:[i.jsxs("span",{className:"text-xs text-bambu-gray",children:[n("smartPlugs.linkedTo")," "]}),i.jsx("span",{className:"text-sm text-white",children:g.name})]}),(t.power_alert_enabled||t.schedule_enabled||t.plug_type==="mqtt")&&i.jsxs("div",{className:"flex flex-wrap gap-1.5 mb-3",children:[t.plug_type==="mqtt"&&i.jsxs("span",{className:"flex items-center gap-1 px-2 py-0.5 bg-teal-500/20 text-teal-400 text-xs rounded-full",children:[i.jsx(rc,{className:"w-3 h-3"}),n("smartPlugs.monitorOnly")]}),t.power_alert_enabled&&i.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:[i.jsx(db,{className:"w-3 h-3"}),n("smartPlugs.alerts")]}),t.schedule_enabled&&i.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:[i.jsx(Xr,{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?n("smartPlugs.scheduleOn",{time:t.schedule_on_time}):n("smartPlugs.scheduleOff",{time:t.schedule_off_time})]})]}),t.plug_type!=="mqtt"&&i.jsxs("div",{className:"flex gap-2 mb-3",children:[i.jsxs(Oe,{size:"sm",variant:C?"primary":"secondary",disabled:!P||k,onClick:()=>c(!0),className:"flex-1",children:[k?i.jsx(lt,{className:"w-4 h-4 animate-spin"}):i.jsx(Su,{className:"w-4 h-4"}),n("smartPlugs.on")]}),i.jsxs(Oe,{size:"sm",variant:C?"secondary":"primary",disabled:!P||k,onClick:()=>u(!0),className:"flex-1",children:[k?i.jsx(lt,{className:"w-4 h-4 animate-spin"}):i.jsx(pC,{className:"w-4 h-4"}),n("smartPlugs.off")]})]}),t.plug_type==="mqtt"&&f?.energy&&i.jsxs("div",{className:"flex gap-2 mb-3 px-3 py-2 bg-bambu-dark rounded-lg",children:[f.energy.power!==null&&f.energy.power!==void 0&&i.jsxs("div",{className:"flex-1 text-center",children:[i.jsxs("p",{className:"text-lg font-semibold text-white",children:[Math.round(f.energy.power),"W"]}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("smartPlugs.power")})]}),f.energy.today!==null&&f.energy.today!==void 0&&i.jsxs("div",{className:"flex-1 text-center border-l border-bambu-dark-tertiary",children:[i.jsx("p",{className:"text-lg font-semibold text-white",children:f.energy.today.toFixed(3)}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("smartPlugs.kwhToday")})]})]}),i.jsxs("button",{onClick:()=>p(!m),className:"w-full flex items-center justify-between py-2 text-sm text-bambu-gray hover:text-white transition-colors",children:[i.jsxs("span",{className:"flex items-center gap-2",children:[i.jsx(cu,{className:"w-4 h-4"}),t.plug_type==="mqtt"?n("smartPlugs.settings"):n("smartPlugs.automationSettings")]}),i.jsx("span",{children:m?"-":"+"})]}),m&&i.jsxs("div",{className:"pt-3 border-t border-bambu-dark-tertiary space-y-4",children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(D0,{className:"w-4 h-4 text-bambu-green"}),i.jsxs("div",{children:[i.jsx("p",{className:"text-sm text-white",children:n("smartPlugs.showInSwitchbar")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("smartPlugs.quickAccessSidebar")})]})]}),i.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:t.show_in_switchbar,onChange:R=>_.mutate({show_in_switchbar:R.target.checked}),className:"sr-only peer"}),i.jsx("div",{className:"w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green"})]})]}),t.plug_type!=="mqtt"&&i.jsxs(i.Fragment,{children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-sm text-white",children:n("smartPlugs.enabled")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("smartPlugs.enableAutomation")})]}),i.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:t.enabled,onChange:R=>_.mutate({enabled:R.target.checked}),className:"sr-only peer"}),i.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"})]})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-sm text-white",children:n("smartPlugs.autoOn")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("smartPlugs.autoOnDescription")})]}),i.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:t.auto_on,onChange:R=>_.mutate({auto_on:R.target.checked}),className:"sr-only peer"}),i.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"})]})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-sm text-white",children:n("smartPlugs.autoOff")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("smartPlugs.autoOffDescription")})]}),i.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:t.auto_off,onChange:R=>_.mutate({auto_off:R.target.checked}),className:"sr-only peer"}),i.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&&i.jsxs("div",{className:"space-y-3 pl-4 border-l-2 border-bambu-dark-tertiary",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-sm text-white mb-2",children:n("smartPlugs.turnOffDelayMode")}),i.jsxs("div",{className:"flex gap-2",children:[i.jsxs("button",{onClick:()=>_.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:[i.jsx(Xn,{className:"w-4 h-4"}),n("smartPlugs.time")]}),i.jsxs("button",{onClick:()=>_.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:[i.jsx(bC,{className:"w-4 h-4"}),n("smartPlugs.temp")]})]})]}),t.off_delay_mode==="time"?i.jsxs("div",{children:[i.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:n("smartPlugs.delayMinutes")}),i.jsx("input",{type:"number",min:"1",max:"60",value:t.off_delay_minutes,onChange:R=>_.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"})]}):i.jsxs("div",{children:[i.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:n("smartPlugs.tempThreshold")}),i.jsx("input",{type:"number",min:"30",max:"100",value:t.off_temp_threshold,onChange:R=>_.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"}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:n("smartPlugs.tempThresholdDescription")})]})]})]}),i.jsxs("div",{className:"flex gap-2 pt-2",children:[i.jsxs(Oe,{size:"sm",variant:"secondary",onClick:()=>e(t),className:"flex-1",children:[i.jsx(Mm,{className:"w-4 h-4"}),n("smartPlugs.edit")]}),i.jsx(Oe,{size:"sm",variant:"secondary",onClick:()=>o(!0),className:"text-red-400 hover:text-red-300",children:i.jsx(Qt,{className:"w-4 h-4"})})]})]})]})}),s&&i.jsx(_n,{title:n("smartPlugs.deleteSmartPlug"),message:n("smartPlugs.deleteConfirm",{name:t.name}),confirmText:n("smartPlugs.delete"),variant:"danger",onConfirm:()=>{N.mutate(),o(!1)},onCancel:()=>o(!1)}),l&&i.jsx(_n,{title:n("smartPlugs.turnOnSmartPlug"),message:n("smartPlugs.turnOnConfirm",{name:t.name}),confirmText:n("smartPlugs.turnOn"),variant:"default",onConfirm:()=>{y.mutate("on"),c(!1)},onCancel:()=>c(!1)}),d&&i.jsx(_n,{title:n("smartPlugs.turnOffSmartPlug"),message:n("smartPlugs.turnOffConfirm",{name:t.name}),confirmText:n("smartPlugs.turnOff"),variant:"danger",onConfirm:()=>{y.mutate("off"),u(!1)},onCancel:()=>u(!1)})]})}function YZe({plug:t,onClose:e}){const{t:n}=Mt(),r=Zt(),a=!!t,[s,o]=w.useState(t?.plug_type||"tasmota"),[l,c]=w.useState(t?.name||""),[d,u]=w.useState(t?.ip_address||""),[m,p]=w.useState(t?.username||""),[f,x]=w.useState(t?.password||""),[v,g]=w.useState(t?.ha_entity_id||""),[y,_]=w.useState(t?.mqtt_power_topic||t?.mqtt_topic||""),[N,C]=w.useState(t?.mqtt_power_path||""),[T,P]=w.useState((t?.mqtt_power_multiplier??t?.mqtt_multiplier??1).toString()),[k,D]=w.useState(t?.mqtt_energy_topic||""),[A,R]=w.useState(t?.mqtt_energy_path||""),[$,U]=w.useState((t?.mqtt_energy_multiplier??1).toString()),[W,O]=w.useState(t?.mqtt_state_topic||""),[te,ie]=w.useState(t?.mqtt_state_path||""),[Y,ae]=w.useState(t?.mqtt_state_on_value||""),[de,pe]=w.useState(t?.ha_power_entity||""),[Q,oe]=w.useState(t?.ha_energy_today_entity||""),[me,we]=w.useState(t?.ha_energy_total_entity||""),[Ee,q]=w.useState(""),[K,E]=w.useState(""),[j,L]=w.useState(!1),G=w.useRef(null),[B,re]=w.useState(""),[z,V]=w.useState(!1),ee=w.useRef(null),[J,ne]=w.useState(""),[se,ue]=w.useState(!1),ge=w.useRef(null),[le,I]=w.useState(""),[F,Z]=w.useState(!1),xe=w.useRef(null),[he,ce]=w.useState(t?.printer_id||null),[Ae,_e]=w.useState(null),[Ue,$e]=w.useState(null),[Fe,ke]=w.useState(t?.power_alert_enabled||!1),[Me,Ne]=w.useState(t?.power_alert_high?.toString()||""),[Pe,We]=w.useState(t?.power_alert_low?.toString()||""),[be,He]=w.useState(t?.schedule_enabled||!1),[Ce,Ve]=w.useState(t?.schedule_on_time||""),[je,Re]=w.useState(t?.schedule_off_time||""),[ve,Ge]=w.useState(t?.show_in_switchbar||!1),[rt,vt]=w.useState(t?.show_on_printer_card??!0),[_t,kt]=w.useState(!1),[qe,ht]=w.useState({scanned:0,total:0}),[ft,Bt]=w.useState([]),tn=w.useRef(null),{data:sn}=Ze({queryKey:["printers"],queryFn:fe.getPrinters}),{data:Sn}=Ze({queryKey:["smart-plugs"],queryFn:fe.getSmartPlugs}),{data:on}=Ze({queryKey:["settings"],queryFn:fe.getSettings}),xn=!!(on?.ha_enabled&&on?.ha_url&&on?.ha_token);w.useEffect(()=>{const Ie=setTimeout(()=>{E(Ee)},300);return()=>clearTimeout(Ie)},[Ee]),w.useEffect(()=>{const Ie=ut=>{G.current&&!G.current.contains(ut.target)&&L(!1),ee.current&&!ee.current.contains(ut.target)&&V(!1),ge.current&&!ge.current.contains(ut.target)&&ue(!1),xe.current&&!xe.current.contains(ut.target)&&Z(!1)};return document.addEventListener("mousedown",Ie),()=>document.removeEventListener("mousedown",Ie)},[]);const{data:Rn,isLoading:Qn,error:Fn}=Ze({queryKey:["ha-entities",K],queryFn:()=>fe.getHAEntities(K||void 0),enabled:s==="homeassistant"&&xn,retry:!1,staleTime:0}),{data:Be}=Ze({queryKey:["ha-sensor-entities"],queryFn:fe.getHASensorEntities,enabled:s==="homeassistant"&&xn,retry:!1,staleTime:0});w.useEffect(()=>{const Ie=ut=>{ut.key==="Escape"&&e()};return window.addEventListener("keydown",Ie),()=>{window.removeEventListener("keydown",Ie),tn.current&&clearInterval(tn.current)}},[e]);const De=async()=>{kt(!0),Bt([]),ht({scanned:0,total:0}),$e(null);try{await fe.startTasmotaScan();const Ie=async()=>{try{const ut=await fe.getTasmotaScanStatus();ht({scanned:ut.scanned,total:ut.total});const ot=await fe.getDiscoveredTasmotaDevices();Bt(ot),ut.running||(kt(!1),tn.current&&(clearInterval(tn.current),tn.current=null))}catch(ut){console.error("Polling error:",ut)}};await Ie(),tn.current=setInterval(Ie,500)}catch(Ie){kt(!1);const ut=Ie instanceof Error?Ie.message:typeof Ie=="string"?Ie:JSON.stringify(Ie);$e(ut||n("smartPlugs.failedToStartScan"))}},Je=async()=>{try{await fe.stopTasmotaScan()}catch{}kt(!1),tn.current&&(clearInterval(tn.current),tn.current=null)},tt=Ie=>{u(Ie.ip_address),c(Ie.name),_e(null)},Ye=dt({mutationFn:()=>fe.testSmartPlugConnection(d,m||null,f||null),onSuccess:Ie=>{_e(Ie),$e(null),!l&&Ie.device_name&&c(Ie.device_name)},onError:Ie=>{_e(null),$e(Ie.message)}}),Rt=dt({mutationFn:Ie=>fe.createSmartPlug(Ie),onSuccess:()=>{r.invalidateQueries({queryKey:["smart-plugs"]}),r.invalidateQueries({queryKey:["scriptPlugsByPrinter"]}),e()},onError:Ie=>{$e(Ie.message)}}),Te=dt({mutationFn:Ie=>fe.updateSmartPlug(t.id,Ie),onSuccess:()=>{r.invalidateQueries({queryKey:["smart-plugs"]}),r.invalidateQueries({queryKey:["scriptPlugsByPrinter"]}),e()},onError:Ie=>{$e(Ie.message)}}),Ke=sn?.filter(Ie=>s==="tasmota"?!Sn?.some(ot=>ot.printer_id===Ie.id&&ot.id!==t?.id&&ot.plug_type==="tasmota"):!0),et=Ie=>{if(Ie.preventDefault(),$e(null),!l.trim()){$e(n("smartPlugs.nameRequired"));return}if(s==="tasmota"&&!d.trim()){$e("IP address is required for Tasmota plugs");return}if(s==="homeassistant"&&!v){$e(n("smartPlugs.entityRequired"));return}if(s==="mqtt"){const ot=y.trim(),nt=k.trim(),St=W.trim();if(!ot&&!nt&&!St){$e(n("smartPlugs.mqttTopicRequired"));return}}const ut={name:l.trim(),plug_type:s,ip_address:s==="tasmota"?d.trim():null,ha_entity_id:s==="homeassistant"?v:null,ha_power_entity:s==="homeassistant"&&de||null,ha_energy_today_entity:s==="homeassistant"&&Q||null,ha_energy_total_entity:s==="homeassistant"&&me||null,mqtt_power_topic:s==="mqtt"&&y.trim()||null,mqtt_power_path:s==="mqtt"&&N.trim()||null,mqtt_power_multiplier:s==="mqtt"&&parseFloat(T)||1,mqtt_energy_topic:s==="mqtt"&&k.trim()||null,mqtt_energy_path:s==="mqtt"&&A.trim()||null,mqtt_energy_multiplier:s==="mqtt"&&parseFloat($)||1,mqtt_state_topic:s==="mqtt"&&W.trim()||null,mqtt_state_path:s==="mqtt"&&te.trim()||null,mqtt_state_on_value:s==="mqtt"&&Y.trim()||null,username:s==="tasmota"&&m.trim()||null,password:s==="tasmota"&&f.trim()||null,printer_id:he,power_alert_enabled:Fe,power_alert_high:Me?parseFloat(Me):null,power_alert_low:Pe?parseFloat(Pe):null,schedule_enabled:be,schedule_on_time:Ce||null,schedule_off_time:je||null,show_in_switchbar:ve,show_on_printer_card:rt};a?Te.mutate(ut):Rt.mutate(ut)},Qe=Rt.isPending||Te.isPending;return i.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",onClick:e,children:i.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:Ie=>Ie.stopPropagation(),children:[i.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary flex-shrink-0",children:[i.jsx("h2",{className:"text-lg font-semibold text-white",children:n(a?"smartPlugs.editTitle":"smartPlugs.addTitle")}),i.jsx("button",{onClick:e,className:"text-bambu-gray hover:text-white transition-colors",children:i.jsx(zt,{className:"w-5 h-5"})})]}),i.jsxs("form",{onSubmit:et,className:"p-6 space-y-4 overflow-y-auto",children:[Ue&&i.jsx("div",{className:"p-3 bg-red-500/20 border border-red-500/50 rounded-lg text-sm text-red-400",children:Ue}),!a&&i.jsxs("div",{className:"flex gap-2 mb-2",children:[i.jsxs("button",{type:"button",onClick:()=>{o("tasmota"),_e(null),$e(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2.5 rounded-lg font-medium transition-colors ${s==="tasmota"?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white border border-bambu-dark-tertiary"}`,children:[i.jsx(bl,{className:"w-4 h-4"}),"Tasmota"]}),i.jsxs("button",{type:"button",onClick:()=>{o("homeassistant"),_e(null),$e(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2.5 rounded-lg font-medium transition-colors ${s==="homeassistant"?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white border border-bambu-dark-tertiary"}`,children:[i.jsx(j0,{className:"w-4 h-4"}),"HA"]}),i.jsxs("button",{type:"button",onClick:()=>{o("mqtt"),_e(null),$e(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2.5 rounded-lg font-medium transition-colors ${s==="mqtt"?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white border border-bambu-dark-tertiary"}`,children:[i.jsx(YF,{className:"w-4 h-4"}),"MQTT"]})]}),!a&&s==="tasmota"&&i.jsxs("div",{className:"space-y-3",children:[_t?i.jsxs(Oe,{type:"button",variant:"secondary",onClick:Je,className:"w-full",children:[i.jsx(zt,{className:"w-4 h-4"}),n("smartPlugs.stopScanning")]}):i.jsxs(Oe,{type:"button",variant:"primary",onClick:De,className:"w-full",children:[i.jsx(jr,{className:"w-4 h-4"}),n("smartPlugs.discoverTasmota")]}),_t&&qe.total>0&&i.jsxs("div",{className:"space-y-1",children:[i.jsxs("div",{className:"flex justify-between text-xs text-bambu-gray",children:[i.jsx("span",{children:n("smartPlugs.addSmartPlug.scanningNetwork")}),i.jsxs("span",{children:[qe.scanned," / ",qe.total]})]}),i.jsx("div",{className:"w-full bg-bambu-dark-tertiary rounded-full h-2",children:i.jsx("div",{className:"bg-bambu-green h-2 rounded-full transition-all duration-300",style:{width:`${qe.scanned/qe.total*100}%`}})})]}),ft.length>0&&i.jsxs("div",{className:"space-y-2",children:[i.jsx("p",{className:"text-xs text-bambu-gray",children:n("smartPlugs.foundDevices",{count:ft.length})}),i.jsx("div",{className:"max-h-40 overflow-y-auto space-y-1",children:ft.map(Ie=>i.jsxs("button",{type:"button",onClick:()=>tt(Ie),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:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(bl,{className:"w-4 h-4 text-bambu-green"}),i.jsxs("div",{children:[i.jsx("p",{className:"text-sm text-white",children:Ie.name}),i.jsx("p",{className:"text-xs text-bambu-gray",children:Ie.ip_address})]})]}),Ie.state&&i.jsxs("span",{className:`flex items-center gap-1 text-xs ${Ie.state==="ON"?"text-bambu-green":"text-bambu-gray"}`,children:[i.jsx(Su,{className:"w-3 h-3"}),Ie.state]})]},Ie.ip_address))})]}),!_t&&ft.length===0&&qe.total>0&&i.jsx("p",{className:"text-xs text-bambu-gray text-center py-2",children:n("smartPlugs.noDevicesFound")})]}),s==="homeassistant"&&i.jsxs("div",{className:"space-y-3",children:[!xn&&i.jsxs("div",{className:"space-y-3",children:[i.jsxs("div",{className:"p-3 bg-yellow-500/20 border border-yellow-500/50 rounded-lg text-sm text-yellow-400",children:[n("smartPlugs.haNotConfigured")," ",i.jsx("span",{className:"font-medium",children:n("smartPlugs.haSettingsPath")})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1 opacity-50",children:n("smartPlugs.selectEntity")}),i.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:i.jsx("option",{children:n("smartPlugs.addSmartPlug.chooseEntity")})})]})]}),xn&&i.jsxs(i.Fragment,{children:[Qn&&i.jsxs("div",{className:"flex items-center justify-center py-4 text-bambu-gray",children:[i.jsx(lt,{className:"w-5 h-5 animate-spin mr-2"}),n("smartPlugs.loadingEntities")]}),Fn&&i.jsx("div",{className:"p-3 bg-red-500/20 border border-red-500/50 rounded-lg text-sm text-red-400",children:n("smartPlugs.failedToLoadEntities",{error:Fn.message})}),(()=>{const Ie=Sn?.filter(nt=>nt.ha_entity_id&&nt.id!==t?.id).map(nt=>nt.ha_entity_id)||[],ut=(Rn||[]).filter(nt=>!Ie.includes(nt.entity_id)),ot=Rn?.find(nt=>nt.entity_id===v);return i.jsxs("div",{ref:G,className:"relative",children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.selectEntity")}),i.jsxs("div",{className:"relative",children:[i.jsx(jr,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"}),i.jsx("input",{type:"text",value:j?Ee:ot?`${ot.friendly_name} (${ot.entity_id})`:"",onChange:nt=>{q(nt.target.value),j||L(!0)},onFocus:()=>{L(!0),q("")},placeholder:n("smartPlugs.addSmartPlug.placeholders.searchEntities"),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"}),v&&!j&&i.jsx("button",{type:"button",onClick:()=>{g(""),q("")},className:"absolute right-2 top-1/2 -translate-y-1/2 p-1 hover:bg-bambu-dark-tertiary rounded",children:i.jsx(zt,{className:"w-4 h-4 text-bambu-gray hover:text-white"})}),Qn&&i.jsx(lt,{className:"absolute right-2 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray animate-spin"})]}),j&&i.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:[Qn&&i.jsxs("div",{className:"px-3 py-2 text-sm text-bambu-gray flex items-center gap-2",children:[i.jsx(lt,{className:"w-4 h-4 animate-spin"}),n("smartPlugs.loading")]}),!Qn&&ut.length===0&&i.jsx("div",{className:"px-3 py-2 text-sm text-bambu-gray",children:K?n("smartPlugs.noEntitiesMatching",{search:K}):n("smartPlugs.noEntitiesAvailable")}),!Qn&&ut.map(nt=>i.jsxs("button",{type:"button",onClick:()=>{g(nt.entity_id),L(!1),q(""),l||c(nt.friendly_name)},className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary transition-colors ${nt.entity_id===v?"bg-bambu-green/20 text-bambu-green":"text-white"}`,children:[i.jsx("div",{className:"font-medium",children:nt.friendly_name}),i.jsxs("div",{className:"text-xs text-bambu-gray flex items-center justify-between",children:[i.jsx("span",{children:nt.entity_id}),i.jsx("span",{className:nt.state==="on"?"text-bambu-green":"",children:nt.state})]})]},nt.entity_id))]}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:K?n("smartPlugs.searchingEntities",{count:ut.length}):n("smartPlugs.showingEntities",{count:ut.length})})]})})(),v&&Be&&Be.length>0&&i.jsxs("div",{className:"border-t border-bambu-dark-tertiary pt-4 mt-4 space-y-3",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-white font-medium mb-1",children:n("smartPlugs.energyMonitoringOptional")}),i.jsx("p",{className:"text-xs text-bambu-gray mb-3",children:n("smartPlugs.energyMonitoringHint")})]}),(()=>{const Ie=Be.filter(nt=>nt.unit_of_measurement==="W"||nt.unit_of_measurement==="kW"||nt.unit_of_measurement==="mW"),ut=B?Ie.filter(nt=>nt.entity_id.toLowerCase().includes(B.toLowerCase())||nt.friendly_name.toLowerCase().includes(B.toLowerCase())):Ie,ot=Be.find(nt=>nt.entity_id===de);return i.jsxs("div",{ref:ee,className:"relative",children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.powerSensorW")}),i.jsxs("div",{className:"relative",children:[i.jsx(jr,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"}),i.jsx("input",{type:"text",value:z?B:ot?`${ot.friendly_name} (${ot.state} ${ot.unit_of_measurement})`:"",onChange:nt=>{re(nt.target.value),z||V(!0)},onFocus:()=>{V(!0),re("")},placeholder:n("smartPlugs.addSmartPlug.placeholders.searchPowerSensors"),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"}),de&&!z&&i.jsx("button",{type:"button",onClick:()=>{pe(""),re("")},className:"absolute right-2 top-1/2 -translate-y-1/2 p-1 hover:bg-bambu-dark-tertiary rounded",children:i.jsx(zt,{className:"w-4 h-4 text-bambu-gray hover:text-white"})})]}),z&&i.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:[i.jsx("button",{type:"button",onClick:()=>{pe(""),V(!1),re("")},className:"w-full px-3 py-2 text-left text-sm text-bambu-gray hover:bg-bambu-dark-tertiary",children:n("smartPlugs.none")}),ut.map(nt=>i.jsxs("button",{type:"button",onClick:()=>{pe(nt.entity_id),V(!1),re("")},className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary ${nt.entity_id===de?"bg-bambu-green/20 text-bambu-green":"text-white"}`,children:[i.jsx("div",{className:"font-medium",children:nt.friendly_name}),i.jsxs("div",{className:"text-xs text-bambu-gray",children:[nt.entity_id," • ",nt.state," ",nt.unit_of_measurement]})]},nt.entity_id)),ut.length===0&&i.jsx("div",{className:"px-3 py-2 text-sm text-bambu-gray",children:n("smartPlugs.noMatchingSensors")})]})]})})(),(()=>{const Ie=Be.filter(nt=>nt.unit_of_measurement==="kWh"||nt.unit_of_measurement==="Wh"||nt.unit_of_measurement==="MWh"),ut=J?Ie.filter(nt=>nt.entity_id.toLowerCase().includes(J.toLowerCase())||nt.friendly_name.toLowerCase().includes(J.toLowerCase())):Ie,ot=Be.find(nt=>nt.entity_id===Q);return i.jsxs("div",{ref:ge,className:"relative",children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.energyTodayKwh")}),i.jsxs("div",{className:"relative",children:[i.jsx(jr,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"}),i.jsx("input",{type:"text",value:se?J:ot?`${ot.friendly_name} (${ot.state} ${ot.unit_of_measurement})`:"",onChange:nt=>{ne(nt.target.value),se||ue(!0)},onFocus:()=>{ue(!0),ne("")},placeholder:n("smartPlugs.addSmartPlug.placeholders.searchEnergySensors"),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"}),Q&&!se&&i.jsx("button",{type:"button",onClick:()=>{oe(""),ne("")},className:"absolute right-2 top-1/2 -translate-y-1/2 p-1 hover:bg-bambu-dark-tertiary rounded",children:i.jsx(zt,{className:"w-4 h-4 text-bambu-gray hover:text-white"})})]}),se&&i.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:[i.jsx("button",{type:"button",onClick:()=>{oe(""),ue(!1),ne("")},className:"w-full px-3 py-2 text-left text-sm text-bambu-gray hover:bg-bambu-dark-tertiary",children:n("smartPlugs.none")}),ut.map(nt=>i.jsxs("button",{type:"button",onClick:()=>{oe(nt.entity_id),ue(!1),ne("")},className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary ${nt.entity_id===Q?"bg-bambu-green/20 text-bambu-green":"text-white"}`,children:[i.jsx("div",{className:"font-medium",children:nt.friendly_name}),i.jsxs("div",{className:"text-xs text-bambu-gray",children:[nt.entity_id," • ",nt.state," ",nt.unit_of_measurement]})]},nt.entity_id)),ut.length===0&&i.jsx("div",{className:"px-3 py-2 text-sm text-bambu-gray",children:n("smartPlugs.noMatchingSensors")})]})]})})(),(()=>{const Ie=Be.filter(nt=>nt.unit_of_measurement==="kWh"||nt.unit_of_measurement==="Wh"||nt.unit_of_measurement==="MWh"),ut=le?Ie.filter(nt=>nt.entity_id.toLowerCase().includes(le.toLowerCase())||nt.friendly_name.toLowerCase().includes(le.toLowerCase())):Ie,ot=Be.find(nt=>nt.entity_id===me);return i.jsxs("div",{ref:xe,className:"relative",children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.totalEnergyKwh")}),i.jsxs("div",{className:"relative",children:[i.jsx(jr,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"}),i.jsx("input",{type:"text",value:F?le:ot?`${ot.friendly_name} (${ot.state} ${ot.unit_of_measurement})`:"",onChange:nt=>{I(nt.target.value),F||Z(!0)},onFocus:()=>{Z(!0),I("")},placeholder:n("smartPlugs.addSmartPlug.placeholders.searchEnergySensors"),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"}),me&&!F&&i.jsx("button",{type:"button",onClick:()=>{we(""),I("")},className:"absolute right-2 top-1/2 -translate-y-1/2 p-1 hover:bg-bambu-dark-tertiary rounded",children:i.jsx(zt,{className:"w-4 h-4 text-bambu-gray hover:text-white"})})]}),F&&i.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:[i.jsx("button",{type:"button",onClick:()=>{we(""),Z(!1),I("")},className:"w-full px-3 py-2 text-left text-sm text-bambu-gray hover:bg-bambu-dark-tertiary",children:n("smartPlugs.none")}),ut.map(nt=>i.jsxs("button",{type:"button",onClick:()=>{we(nt.entity_id),Z(!1),I("")},className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary ${nt.entity_id===me?"bg-bambu-green/20 text-bambu-green":"text-white"}`,children:[i.jsx("div",{className:"font-medium",children:nt.friendly_name}),i.jsxs("div",{className:"text-xs text-bambu-gray",children:[nt.entity_id," • ",nt.state," ",nt.unit_of_measurement]})]},nt.entity_id)),ut.length===0&&i.jsx("div",{className:"px-3 py-2 text-sm text-bambu-gray",children:n("smartPlugs.noMatchingSensors")})]})]})})()]})]})]}),s==="mqtt"&&i.jsxs("div",{className:"space-y-3",children:[!on?.mqtt_broker&&i.jsxs("div",{className:"p-3 bg-yellow-500/20 border border-yellow-500/50 rounded-lg text-sm text-yellow-400",children:[n("smartPlugs.mqttNotConfigured")," ",i.jsx("span",{className:"font-medium",children:n("smartPlugs.mqttSettingsPath")})," ",n("smartPlugs.mqttNotConfiguredSuffix")]}),on?.mqtt_broker&&i.jsxs(i.Fragment,{children:[i.jsxs("div",{className:"p-3 bg-blue-500/10 border border-blue-500/30 rounded-lg text-sm text-blue-300",children:[i.jsx("p",{className:"font-medium mb-1",children:n("smartPlugs.monitorOnly")}),i.jsx("p",{className:"text-xs opacity-80",children:n("smartPlugs.mqttMonitorOnlyDescription")})]}),i.jsxs("div",{className:"space-y-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary",children:[i.jsx("p",{className:"text-white font-medium text-sm",children:n("smartPlugs.powerMonitoring")}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.topic")}),i.jsx("input",{type:"text",value:y,onChange:Ie=>_(Ie.target.value),placeholder:"zigbee2mqtt/shelly-working-room",className:"w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none"})]}),i.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.jsonPath")}),i.jsx("input",{type:"text",value:N,onChange:Ie=>C(Ie.target.value),placeholder:"power_l1",className:"w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none"})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.multiplier")}),i.jsx("input",{type:"text",value:T,onChange:Ie=>P(Ie.target.value),placeholder:"1",className:"w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none"})]})]}),i.jsx("p",{className:"text-xs text-bambu-gray",style:{whiteSpace:"pre-line"},children:n("smartPlugs.mqttPowerHint")})]}),i.jsxs("div",{className:"space-y-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary",children:[i.jsxs("p",{className:"text-white font-medium text-sm",children:[n("smartPlugs.energyMonitoring")," ",i.jsxs("span",{className:"text-bambu-gray font-normal",children:["(",n("smartPlugs.optional"),")"]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.topic")}),i.jsx("input",{type:"text",value:k,onChange:Ie=>D(Ie.target.value),placeholder:"Same as power topic, or different",className:"w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none"})]}),i.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.jsonPath")}),i.jsx("input",{type:"text",value:A,onChange:Ie=>R(Ie.target.value),placeholder:"energy_l1",className:"w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none"})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.multiplier")}),i.jsx("input",{type:"text",value:$,onChange:Ie=>U(Ie.target.value),placeholder:"1",className:"w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none"})]})]}),i.jsx("p",{className:"text-xs text-bambu-gray",style:{whiteSpace:"pre-line"},children:n("smartPlugs.mqttEnergyHint")})]}),i.jsxs("div",{className:"space-y-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary",children:[i.jsxs("p",{className:"text-white font-medium text-sm",children:[n("smartPlugs.stateMonitoring")," ",i.jsxs("span",{className:"text-bambu-gray font-normal",children:["(",n("smartPlugs.optional"),")"]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.topic")}),i.jsx("input",{type:"text",value:W,onChange:Ie=>O(Ie.target.value),placeholder:"Same as power topic, or different",className:"w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none"})]}),i.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.jsonPath")}),i.jsx("input",{type:"text",value:te,onChange:Ie=>ie(Ie.target.value),placeholder:"state_l1",className:"w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none"})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.onValue")}),i.jsx("input",{type:"text",value:Y,onChange:Ie=>ae(Ie.target.value),placeholder:n("smartPlugs.addSmartPlug.placeholders.mqttStateOnValue"),className:"w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none"})]})]}),i.jsx("p",{className:"text-xs text-bambu-gray",style:{whiteSpace:"pre-line"},children:n("smartPlugs.mqttStateHint")})]})]})]}),s==="tasmota"&&i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.ipAddress")}),i.jsxs("div",{className:"flex gap-2",children:[i.jsx("input",{type:"text",value:d,onChange:Ie=>{u(Ie.target.value),_e(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"}),i.jsxs(Oe,{type:"button",variant:"secondary",onClick:()=>Ye.mutate(),disabled:!d.trim()||Ye.isPending,children:[Ye.isPending?i.jsx(lt,{className:"w-4 h-4 animate-spin"}):i.jsx(mb,{className:"w-4 h-4"}),n("smartPlugs.test")]})]})]}),s==="tasmota"&&Ae&&i.jsx("div",{className:`p-3 rounded-lg flex items-center gap-2 ${Ae.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:Ae.success?i.jsxs(i.Fragment,{children:[i.jsx(pr,{className:"w-5 h-5"}),i.jsxs("div",{children:[i.jsx("p",{className:"font-medium",children:n("smartPlugs.connectedResult")}),i.jsxs("p",{className:"text-sm opacity-80",children:[Ae.device_name&&n("smartPlugs.deviceLabel",{name:Ae.device_name}),n("smartPlugs.stateLabel",{state:Ae.state})]})]})]}):i.jsxs(i.Fragment,{children:[i.jsx(rh,{className:"w-5 h-5"}),i.jsx("span",{children:n("smartPlugs.addSmartPlug.connectionFailed")})]})}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.nameLabel")}),i.jsx("input",{type:"text",value:l,onChange:Ie=>c(Ie.target.value),placeholder:n("smartPlugs.addSmartPlug.placeholders.plugName"),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==="tasmota"&&i.jsxs(i.Fragment,{children:[i.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.username")}),i.jsx("input",{type:"text",value:m,onChange:Ie=>p(Ie.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"})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.password")}),i.jsx("input",{type:"password",value:f,onChange:Ie=>x(Ie.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"})]})]}),i.jsx("p",{className:"text-xs text-bambu-gray -mt-2",children:n("smartPlugs.authHint")})]}),s!=="mqtt"&&i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.linkToPrinter")}),i.jsxs("select",{value:he??"",onChange:Ie=>ce(Ie.target.value?Number(Ie.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:[i.jsx("option",{value:"",children:n("smartPlugs.noPrinter")}),Ke?.map(Ie=>i.jsx("option",{value:Ie.id,children:Ie.name},Ie.id))]}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:n("smartPlugs.linkingDescription")})]}),i.jsxs("div",{className:"border-t border-bambu-dark-tertiary pt-4",children:[i.jsxs("div",{className:"flex items-center justify-between mb-3",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(db,{className:"w-4 h-4 text-bambu-green"}),i.jsx("span",{className:"text-white font-medium",children:n("smartPlugs.powerAlerts")})]}),i.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:Fe,onChange:Ie=>ke(Ie.target.checked),className:"sr-only peer"}),i.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"})]})]}),Fe&&i.jsxs("div",{className:"space-y-3",children:[i.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.alertAbove")}),i.jsx("input",{type:"number",value:Me,onChange:Ie=>Ne(Ie.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"})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.alertBelow")}),i.jsx("input",{type:"number",value:Pe,onChange:Ie=>We(Ie.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"})]})]}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("smartPlugs.alertDescription")})]})]}),s!=="mqtt"&&i.jsxs("div",{className:"border-t border-bambu-dark-tertiary pt-4",children:[i.jsxs("div",{className:"flex items-center justify-between mb-3",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(Xn,{className:"w-4 h-4 text-bambu-green"}),i.jsx("span",{className:"text-white font-medium",children:n("smartPlugs.dailySchedule")})]}),i.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:be,onChange:Ie=>He(Ie.target.checked),className:"sr-only peer"}),i.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"})]})]}),be&&i.jsxs("div",{className:"space-y-3",children:[i.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.turnOnAt")}),i.jsx("input",{type:"time",value:Ce,onChange:Ie=>Ve(Ie.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"})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.turnOffAt")}),i.jsx("input",{type:"time",value:je,onChange:Ie=>Re(Ie.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"})]})]}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("smartPlugs.scheduleDescription")})]})]}),i.jsx("div",{className:"border-t border-bambu-dark-tertiary pt-4",children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(D0,{className:"w-4 h-4 text-bambu-green"}),i.jsxs("div",{children:[i.jsx("span",{className:"text-white font-medium",children:n("smartPlugs.showInSwitchbar")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("smartPlugs.quickAccessSidebar")})]})]}),i.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:ve,onChange:Ie=>Ge(Ie.target.checked),className:"sr-only peer"}),i.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==="homeassistant"&&i.jsx("div",{className:"border-t border-bambu-dark-tertiary pt-4",children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(rc,{className:"w-4 h-4 text-bambu-green"}),i.jsxs("div",{children:[i.jsx("span",{className:"text-white font-medium",children:n("smartPlugs.showOnPrinterCard")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("smartPlugs.displayOnPrinterCard")})]})]}),i.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:rt,onChange:Ie=>vt(Ie.target.checked),className:"sr-only peer"}),i.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]})}),i.jsxs("div",{className:"flex gap-3 pt-2",children:[i.jsx(Oe,{type:"button",variant:"secondary",onClick:e,className:"flex-1",children:n("smartPlugs.cancel")}),i.jsxs(Oe,{type:"submit",disabled:Qe,className:"flex-1",children:[Qe?i.jsx(lt,{className:"w-4 h-4 animate-spin"}):i.jsx(gs,{className:"w-4 h-4"}),n(a?"smartPlugs.save":"smartPlugs.add")]})]})]})]})})}function $n({checked:t,onChange:e,disabled:n}){const r=a=>{a.preventDefault(),a.stopPropagation(),n||e(!t)};return i.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:i.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"}`})})}function XZe({provider:t,onEdit:e}){const{t:n}=Mt(),r=Zt(),[a,s]=w.useState(!1),[o,l]=w.useState(!1),[c,d]=w.useState(null),{data:u}=Ze({queryKey:["printers"],queryFn:fe.getPrinters}),m=u?.find(g=>g.id===t.printer_id),p=dt({mutationFn:g=>fe.updateNotificationProvider(t.id,g),onSuccess:()=>{r.invalidateQueries({queryKey:["notification-providers"]})}}),f=dt({mutationFn:()=>fe.deleteNotificationProvider(t.id),onSuccess:()=>{r.invalidateQueries({queryKey:["notification-providers"]})}}),x=dt({mutationFn:()=>fe.testNotificationProvider(t.id),onSuccess:g=>{d(g),r.invalidateQueries({queryKey:["notification-providers"]})},onError:g=>{d({success:!1,message:g.message})}}),v=g=>g||"";return i.jsxs(i.Fragment,{children:[i.jsx(Tt,{className:"relative",children:i.jsxs(Pt,{className:"p-4",children:[i.jsxs("div",{className:"flex items-start justify-between mb-3",children:[i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx("div",{className:`p-2 rounded-lg ${t.enabled?"bg-bambu-green/20":"bg-bambu-dark"}`,children:i.jsx(db,{className:`w-5 h-5 ${t.enabled?"text-bambu-green":"text-bambu-gray"}`})}),i.jsxs("div",{children:[i.jsx("h3",{className:"font-medium text-white",children:t.name}),i.jsx("p",{className:"text-sm text-bambu-gray",children:n(`notifications.providerTypes.${t.provider_type}`,t.provider_type)})]})]}),i.jsxs("div",{className:"flex items-center gap-3",children:[t.last_success&&i.jsx("span",{className:"text-xs text-status-ok hidden sm:inline",children:n("notifications.lastSuccess",{date:Wp(t.last_success)})}),t.last_error&&t.last_error_at&&(!t.last_success||(er(t.last_error_at)?.getTime()||0)>(er(t.last_success)?.getTime()||0))&&i.jsx("span",{className:"text-xs text-status-error",title:t.last_error,children:n("notifications.error")}),i.jsx($n,{checked:t.enabled,onChange:g=>p.mutate({enabled:g})})]})]}),m&&i.jsxs("div",{className:"mb-3 px-2 py-1.5 bg-bambu-dark rounded-lg",children:[i.jsxs("span",{className:"text-xs text-bambu-gray",children:[n("notifications.printer")," "]}),i.jsx("span",{className:"text-sm text-white",children:m.name})]}),!m&&!t.printer_id&&i.jsx("div",{className:"mb-3 px-2 py-1.5 bg-bambu-dark rounded-lg",children:i.jsx("span",{className:"text-xs text-bambu-gray",children:n("notifications.allPrinters")})}),i.jsxs("div",{className:"mb-3 flex flex-wrap gap-1",children:[t.on_print_start&&i.jsx("span",{className:"px-2 py-0.5 bg-blue-500/20 text-blue-400 text-xs rounded",children:n("notifications.start")}),t.on_plate_not_empty&&i.jsx("span",{className:"px-2 py-0.5 bg-rose-600/20 text-rose-300 text-xs rounded",children:n("notifications.plateCheck")}),t.on_print_complete&&i.jsx("span",{className:"px-2 py-0.5 bg-bambu-green/20 text-bambu-green text-xs rounded",children:n("notifications.complete")}),t.on_print_failed&&i.jsx("span",{className:"px-2 py-0.5 bg-red-500/20 text-red-400 text-xs rounded",children:n("notifications.failed")}),t.on_print_stopped&&i.jsx("span",{className:"px-2 py-0.5 bg-orange-500/20 text-orange-400 text-xs rounded",children:n("notifications.stopped")}),t.on_print_progress&&i.jsx("span",{className:"px-2 py-0.5 bg-yellow-500/20 text-yellow-400 text-xs rounded",children:n("notifications.progress")}),t.on_printer_offline&&i.jsx("span",{className:"px-2 py-0.5 bg-gray-500/20 text-gray-400 text-xs rounded",children:n("notifications.offline")}),t.on_printer_error&&i.jsx("span",{className:"px-2 py-0.5 bg-rose-500/20 text-rose-400 text-xs rounded",children:n("notifications.error")}),t.on_filament_low&&i.jsx("span",{className:"px-2 py-0.5 bg-cyan-500/20 text-cyan-400 text-xs rounded",children:n("notifications.lowFilament")}),t.on_maintenance_due&&i.jsx("span",{className:"px-2 py-0.5 bg-purple-500/20 text-purple-400 text-xs rounded",children:n("notifications.maintenance")}),t.on_ams_humidity_high&&i.jsx("span",{className:"px-2 py-0.5 bg-blue-600/20 text-blue-300 text-xs rounded",children:n("notifications.amsHumidity")}),t.on_ams_temperature_high&&i.jsx("span",{className:"px-2 py-0.5 bg-orange-600/20 text-orange-300 text-xs rounded",children:n("notifications.amsTemp")}),t.on_ams_ht_humidity_high&&i.jsx("span",{className:"px-2 py-0.5 bg-cyan-600/20 text-cyan-300 text-xs rounded",children:n("notifications.amsHtHumidity")}),t.on_ams_ht_temperature_high&&i.jsx("span",{className:"px-2 py-0.5 bg-amber-600/20 text-amber-300 text-xs rounded",children:n("notifications.amsHtTemp")}),t.on_bed_cooled&&i.jsx("span",{className:"px-2 py-0.5 bg-teal-500/20 text-teal-400 text-xs rounded",children:n("notifications.bedCooled")}),t.quiet_hours_enabled&&i.jsxs("span",{className:"px-2 py-0.5 bg-indigo-500/20 text-indigo-400 text-xs rounded flex items-center gap-1",children:[i.jsx(q1,{className:"w-3 h-3"}),n("notifications.quiet")]}),t.daily_digest_enabled&&i.jsxs("span",{className:"px-2 py-0.5 bg-emerald-500/20 text-emerald-400 text-xs rounded flex items-center gap-1",children:[i.jsx(Xr,{className:"w-3 h-3"}),n("notifications.digest",{time:t.daily_digest_time})]})]}),i.jsx("div",{className:"mb-3",children:i.jsxs(Oe,{size:"sm",variant:"secondary",disabled:x.isPending,onClick:()=>{d(null),x.mutate()},className:"w-full",children:[x.isPending?i.jsx(lt,{className:"w-4 h-4 animate-spin"}):i.jsx(fC,{className:"w-4 h-4"}),n("notifications.sendTestNotification")]})}),c&&i.jsxs("div",{className:`mb-3 p-2 rounded-lg flex items-center gap-2 text-sm ${c.success?"bg-bambu-green/20 text-bambu-green":"bg-red-500/20 text-red-400"}`,children:[c.success?i.jsx(pr,{className:"w-4 h-4"}):i.jsx(Vi,{className:"w-4 h-4"}),i.jsx("span",{children:c.message})]}),i.jsxs("button",{onClick:()=>l(!o),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:[i.jsxs("span",{className:"flex items-center gap-2",children:[i.jsx(cu,{className:"w-4 h-4"}),n("notifications.eventSettings")]}),o?i.jsx(Sl,{className:"w-4 h-4"}):i.jsx(jn,{className:"w-4 h-4"})]}),o&&i.jsxs("div",{className:"pt-3 border-t border-bambu-dark-tertiary space-y-4",children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-sm text-white",children:n("notifications.enabled")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("notifications.sendFromProvider")})]}),i.jsx($n,{checked:t.enabled,onChange:g=>p.mutate({enabled:g})})]}),i.jsxs("div",{className:"space-y-2",children:[i.jsx("p",{className:"text-xs text-bambu-gray uppercase tracking-wide",children:n("notifications.printEvents")}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("p",{className:"text-sm text-white",children:n("notifications.printStarted")}),i.jsx($n,{checked:t.on_print_start,onChange:g=>p.mutate({on_print_start:g})})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-sm text-white",children:n("notifications.plateNotEmpty")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("notifications.plateNotEmptyDescription")})]}),i.jsx($n,{checked:t.on_plate_not_empty??!0,onChange:g=>p.mutate({on_plate_not_empty:g})})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("p",{className:"text-sm text-white",children:n("notifications.printCompleted")}),i.jsx($n,{checked:t.on_print_complete,onChange:g=>p.mutate({on_print_complete:g})})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-sm text-white",children:n("notifications.bedCooledLabel")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("notifications.bedCooledDescription")})]}),i.jsx($n,{checked:t.on_bed_cooled??!1,onChange:g=>p.mutate({on_bed_cooled:g})})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("p",{className:"text-sm text-white",children:n("notifications.printFailed")}),i.jsx($n,{checked:t.on_print_failed,onChange:g=>p.mutate({on_print_failed:g})})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("p",{className:"text-sm text-white",children:n("notifications.printStopped")}),i.jsx($n,{checked:t.on_print_stopped,onChange:g=>p.mutate({on_print_stopped:g})})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-sm text-white",children:n("notifications.progressMilestones")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("notifications.progressMilestonesDescription")})]}),i.jsx($n,{checked:t.on_print_progress,onChange:g=>p.mutate({on_print_progress:g})})]})]}),i.jsxs("div",{className:"space-y-2",children:[i.jsx("p",{className:"text-xs text-bambu-gray uppercase tracking-wide",children:n("notifications.printerStatus")}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("p",{className:"text-sm text-white",children:n("notifications.printerOffline")}),i.jsx($n,{checked:t.on_printer_offline,onChange:g=>p.mutate({on_printer_offline:g})})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("p",{className:"text-sm text-white",children:n("notifications.printerError")}),i.jsx($n,{checked:t.on_printer_error,onChange:g=>p.mutate({on_printer_error:g})})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("p",{className:"text-sm text-white",children:n("notifications.lowFilamentLabel")}),i.jsx($n,{checked:t.on_filament_low,onChange:g=>p.mutate({on_filament_low:g})})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-sm text-white",children:n("notifications.maintenanceDue")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("notifications.maintenanceDueDescription")})]}),i.jsx($n,{checked:t.on_maintenance_due??!1,onChange:g=>p.mutate({on_maintenance_due:g})})]})]}),i.jsxs("div",{className:"space-y-2",children:[i.jsx("p",{className:"text-xs text-bambu-gray uppercase tracking-wide",children:n("notifications.amsAlarms")}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-sm text-white",children:n("notifications.amsHumidityHigh")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("notifications.amsHumidityHighDescription")})]}),i.jsx($n,{checked:t.on_ams_humidity_high??!1,onChange:g=>p.mutate({on_ams_humidity_high:g})})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-sm text-white",children:n("notifications.amsTemperatureHigh")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("notifications.amsTemperatureHighDescription")})]}),i.jsx($n,{checked:t.on_ams_temperature_high??!1,onChange:g=>p.mutate({on_ams_temperature_high:g})})]})]}),i.jsxs("div",{className:"space-y-2",children:[i.jsx("p",{className:"text-xs text-bambu-gray uppercase tracking-wide",children:n("notifications.amsHtAlarms")}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-sm text-white",children:n("notifications.amsHtHumidityHigh")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("notifications.amsHtHumidityHighDescription")})]}),i.jsx($n,{checked:t.on_ams_ht_humidity_high??!1,onChange:g=>p.mutate({on_ams_ht_humidity_high:g})})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-sm text-white",children:n("notifications.amsHtTemperatureHigh")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("notifications.amsHtTemperatureHighDescription")})]}),i.jsx($n,{checked:t.on_ams_ht_temperature_high??!1,onChange:g=>p.mutate({on_ams_ht_temperature_high:g})})]})]}),i.jsxs("div",{className:"space-y-2",children:[i.jsx("p",{className:"text-xs text-bambu-gray uppercase tracking-wide",children:n("notifications.printQueue")}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-sm text-white",children:n("notifications.jobAdded")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("notifications.jobAddedDescription")})]}),i.jsx($n,{checked:t.on_queue_job_added??!1,onChange:g=>p.mutate({on_queue_job_added:g})})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-sm text-white",children:n("notifications.jobAssigned")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("notifications.jobAssignedDescription")})]}),i.jsx($n,{checked:t.on_queue_job_assigned??!1,onChange:g=>p.mutate({on_queue_job_assigned:g})})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-sm text-white",children:n("notifications.jobStarted")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("notifications.jobStartedDescription")})]}),i.jsx($n,{checked:t.on_queue_job_started??!1,onChange:g=>p.mutate({on_queue_job_started:g})})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-sm text-white",children:n("notifications.jobWaiting")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("notifications.jobWaitingDescription")})]}),i.jsx($n,{checked:t.on_queue_job_waiting??!0,onChange:g=>p.mutate({on_queue_job_waiting:g})})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-sm text-white",children:n("notifications.jobSkipped")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("notifications.jobSkippedDescription")})]}),i.jsx($n,{checked:t.on_queue_job_skipped??!0,onChange:g=>p.mutate({on_queue_job_skipped:g})})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-sm text-white",children:n("notifications.jobFailed")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("notifications.jobFailedDescription")})]}),i.jsx($n,{checked:t.on_queue_job_failed??!0,onChange:g=>p.mutate({on_queue_job_failed:g})})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-sm text-white",children:n("notifications.queueComplete")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("notifications.queueCompleteDescription")})]}),i.jsx($n,{checked:t.on_queue_completed??!1,onChange:g=>p.mutate({on_queue_completed:g})})]})]}),i.jsxs("div",{className:"space-y-2",children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(q1,{className:"w-4 h-4 text-purple-400"}),i.jsx("p",{className:"text-sm text-white",children:n("notifications.quietHours")})]}),i.jsx($n,{checked:t.quiet_hours_enabled,onChange:g=>p.mutate({quiet_hours_enabled:g})})]}),t.quiet_hours_enabled&&i.jsxs("div",{className:"pl-4 border-l-2 border-bambu-dark-tertiary space-y-2",children:[i.jsx("p",{className:"text-xs text-bambu-gray",children:n("notifications.noNotificationsDuring")}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(Xn,{className:"w-4 h-4 text-bambu-gray"}),i.jsxs("span",{className:"text-sm text-white",children:[v(t.quiet_hours_start)||"22:00"," - ",v(t.quiet_hours_end)||"07:00"]})]}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("notifications.editProviderToChangeQuietHours")})]})]}),i.jsxs("div",{className:"space-y-2",children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(Xr,{className:"w-4 h-4 text-emerald-400"}),i.jsx("p",{className:"text-sm text-white",children:n("notifications.dailyDigest")})]}),i.jsx($n,{checked:t.daily_digest_enabled,onChange:g=>p.mutate({daily_digest_enabled:g})})]}),t.daily_digest_enabled&&i.jsxs("div",{className:"pl-4 border-l-2 border-bambu-dark-tertiary space-y-2",children:[i.jsx("p",{className:"text-xs text-bambu-gray",children:n("notifications.batchNotifications")}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(Xn,{className:"w-4 h-4 text-bambu-gray"}),i.jsx("span",{className:"text-sm text-white",children:n("notifications.sendAt",{time:v(t.daily_digest_time)||"08:00"})})]}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("notifications.editProviderToChangeDigestTime")})]})]}),i.jsxs("div",{className:"flex gap-2 pt-2",children:[i.jsxs(Oe,{size:"sm",variant:"secondary",onClick:()=>e(t),className:"flex-1",children:[i.jsx(Mm,{className:"w-4 h-4"}),n("notifications.edit")]}),i.jsx(Oe,{size:"sm",variant:"secondary",onClick:()=>s(!0),className:"text-red-400 hover:text-red-300",children:i.jsx(Qt,{className:"w-4 h-4"})})]})]})]})}),a&&i.jsx(_n,{title:n("notifications.deleteProvider"),message:n("notifications.deleteConfirm",{name:t.name}),confirmText:n("notifications.delete"),variant:"danger",onConfirm:()=>{f.mutate(),s(!1)},onCancel:()=>s(!1)})]})}const QZe=["email","telegram","discord","ntfy","pushover","callmebot","webhook"];function ZZe({provider:t,onClose:e}){const{t:n}=Mt(),r=Zt(),a=!!t,[s,o]=w.useState(t?.name||""),[l,c]=w.useState(t?.provider_type||"email"),[d,u]=w.useState(t?.printer_id||null),[m,p]=w.useState(t?.quiet_hours_enabled||!1),[f,x]=w.useState(t?.quiet_hours_start||"22:00"),[v,g]=w.useState(t?.quiet_hours_end||"07:00"),[y,_]=w.useState(t?.daily_digest_enabled||!1),[N,C]=w.useState(t?.daily_digest_time||"08:00"),[T,P]=w.useState(t?.on_print_start??!1),[k,D]=w.useState(t?.on_print_complete??!0),[A,R]=w.useState(t?.on_print_failed??!0),[$,U]=w.useState(t?.on_print_stopped??!0),[W,O]=w.useState(t?.on_print_progress??!1),[te,ie]=w.useState(t?.on_printer_offline??!1),[Y,ae]=w.useState(t?.on_printer_error??!1),[de,pe]=w.useState(t?.on_filament_low??!1),[Q,oe]=w.useState(t?.on_maintenance_due??!1),[me,we]=w.useState(t?.on_bed_cooled??!1),[Ee,q]=w.useState(t?.config?Object.fromEntries(Object.entries(t.config).map(([ue,ge])=>[ue,String(ge)])):{}),[K,E]=w.useState(null),[j,L]=w.useState(null),{data:G}=Ze({queryKey:["printers"],queryFn:fe.getPrinters});w.useEffect(()=>{const ue=ge=>{ge.key==="Escape"&&e()};return window.addEventListener("keydown",ue),()=>window.removeEventListener("keydown",ue)},[e]);const B=dt({mutationFn:()=>fe.testNotificationConfig({provider_type:l,config:Ee}),onSuccess:ue=>{E(ue),L(null)},onError:ue=>{E({success:!1,message:ue.message})}}),re=dt({mutationFn:ue=>fe.createNotificationProvider(ue),onSuccess:()=>{r.invalidateQueries({queryKey:["notification-providers"]}),e()},onError:ue=>{L(ue.message)}}),z=dt({mutationFn:ue=>fe.updateNotificationProvider(t.id,ue),onSuccess:()=>{r.invalidateQueries({queryKey:["notification-providers"]}),e()},onError:ue=>{L(ue.message)}}),V=ue=>{if(ue.preventDefault(),L(null),!s.trim()){L(n("notifications.nameRequired"));return}const ge=ne(l);for(const I of ge)if(!Ee[I.key]?.trim()){L(n("notifications.fieldRequired",{field:I.label}));return}const le={name:s.trim(),provider_type:l,config:Ee,printer_id:d,quiet_hours_enabled:m,quiet_hours_start:m?f:null,quiet_hours_end:m?v:null,daily_digest_enabled:y,daily_digest_time:y?N:null,on_print_start:T,on_print_complete:k,on_print_failed:A,on_print_stopped:$,on_print_progress:W,on_printer_offline:te,on_printer_error:Y,on_filament_low:de,on_maintenance_due:Q,on_bed_cooled:me};a?z.mutate(le):re.mutate(le)},ee=re.isPending||z.isPending,J=ue=>{switch(ue){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:ge=>ge.payload_format!=="slack"},{key:"field_message",label:"Message Field Name",placeholder:"message",type:"text",required:!1,showIf:ge=>ge.payload_format!=="slack"}];default:return[]}},ne=ue=>J(ue).filter(ge=>ge.required),se=J(l);return i.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4 overflow-y-auto",onClick:e,children:i.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:ue=>ue.stopPropagation(),children:[i.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary",children:[i.jsx("h2",{className:"text-lg font-semibold text-white",children:n(a?"notifications.editTitle":"notifications.addTitle")}),i.jsx("button",{onClick:e,className:"text-bambu-gray hover:text-white transition-colors",children:i.jsx(zt,{className:"w-5 h-5"})})]}),i.jsxs("form",{onSubmit:V,className:"p-6 space-y-4",children:[j&&i.jsx("div",{className:"p-3 bg-red-500/20 border border-red-500/50 rounded-lg text-sm text-red-400",children:j}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("notifications.nameLabel")}),i.jsx("input",{type:"text",value:s,onChange:ue=>o(ue.target.value),placeholder:n("notifications.namePlaceholder"),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.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("notifications.providerTypeLabel")}),i.jsx("select",{value:l,onChange:ue=>{c(ue.target.value),q({}),E(null)},disabled:a,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:QZe.map(ue=>i.jsx("option",{value:ue,children:n(`notifications.providerTypes.${ue}`,ue)},ue))}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:n(`notifications.providerDescriptions.${l}`,"")})]}),i.jsxs("div",{className:"space-y-3",children:[i.jsx("p",{className:"text-sm text-bambu-gray",children:n("notifications.configuration")}),se.filter(ue=>!("showIf"in ue)||ue.showIf?.(Ee)!==!1).map(ue=>i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[ue.label," ",ue.required&&"*"]}),ue.type==="select"&&"options"in ue&&ue.options?i.jsx("select",{value:Ee[ue.key]||ue.options[0]?.value||"",onChange:ge=>{q({...Ee,[ue.key]:ge.target.value}),E(null)},className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:ue.options.map(ge=>i.jsx("option",{value:ge.value,children:ge.label},ge.value))}):i.jsx("input",{type:ue.type,value:Ee[ue.key]||"",onChange:ge=>{q({...Ee,[ue.key]:ge.target.value}),E(null)},placeholder:ue.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"})]},ue.key))]}),i.jsx("div",{className:"flex gap-2",children:i.jsxs(Oe,{type:"button",variant:"secondary",onClick:()=>{E(null),B.mutate()},disabled:B.isPending||!Ee[ne(l)[0]?.key],className:"flex-1",children:[B.isPending?i.jsx(lt,{className:"w-4 h-4 animate-spin"}):i.jsx(fC,{className:"w-4 h-4"}),n("notifications.testConfiguration")]})}),K&&i.jsx("div",{className:`p-3 rounded-lg flex items-center gap-2 ${K.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:K.success?i.jsxs(i.Fragment,{children:[i.jsx(pr,{className:"w-5 h-5"}),i.jsx("span",{children:K.message})]}):i.jsxs(i.Fragment,{children:[i.jsx(Vi,{className:"w-5 h-5"}),i.jsx("span",{children:K.message})]})}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("notifications.printerFilter")}),i.jsxs("select",{value:d??"",onChange:ue=>u(ue.target.value?Number(ue.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:[i.jsx("option",{value:"",children:n("notifications.allPrinters")}),G?.map(ue=>i.jsx("option",{value:ue.id,children:ue.name},ue.id))]}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:n("notifications.onlyFromPrinter")})]}),i.jsxs("div",{className:"space-y-2",children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("label",{className:"text-sm text-white",children:n("notifications.quietHoursDnd")}),i.jsx($n,{checked:m,onChange:p})]}),m&&i.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:n("notifications.quietStart")}),i.jsx("input",{type:"time",value:f,onChange:ue=>x(ue.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"})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:n("notifications.quietEnd")}),i.jsx("input",{type:"time",value:v,onChange:ue=>g(ue.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"})]})]})]}),i.jsxs("div",{className:"space-y-2",children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("label",{className:"text-sm text-white",children:n("notifications.dailyDigestLabel")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("notifications.batchNotifications")})]}),i.jsx($n,{checked:y,onChange:_})]}),y&&i.jsxs("div",{children:[i.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:n("notifications.sendDigestAt")}),i.jsx("input",{type:"time",value:N,onChange:ue=>C(ue.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"}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:n("notifications.digestCollected")})]})]}),i.jsxs("div",{className:"space-y-3",children:[i.jsx("p",{className:"text-sm text-bambu-gray",children:n("notifications.notificationEvents")}),i.jsxs("div",{className:"space-y-2 p-3 bg-bambu-dark rounded-lg",children:[i.jsx("p",{className:"text-xs text-bambu-gray uppercase tracking-wide mb-2",children:n("notifications.printEvents")}),i.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("span",{className:"text-sm text-white",children:n("notifications.start")}),i.jsx($n,{checked:T,onChange:P})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("span",{className:"text-sm text-white",children:n("notifications.complete")}),i.jsx($n,{checked:k,onChange:D})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("span",{className:"text-sm text-white",children:n("notifications.failed")}),i.jsx($n,{checked:A,onChange:R})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("span",{className:"text-sm text-white",children:n("notifications.stopped")}),i.jsx($n,{checked:$,onChange:U})]}),i.jsxs("div",{className:"flex items-center justify-between col-span-2",children:[i.jsxs("div",{children:[i.jsx("span",{className:"text-sm text-white",children:n("notifications.progress")}),i.jsx("span",{className:"text-xs text-bambu-gray ml-1",children:n("notifications.progressPercent")})]}),i.jsx($n,{checked:W,onChange:O})]}),i.jsxs("div",{className:"flex items-center justify-between col-span-2",children:[i.jsxs("div",{children:[i.jsx("span",{className:"text-sm text-white",children:n("notifications.bedCooled")}),i.jsx("span",{className:"text-xs text-bambu-gray ml-1",children:n("notifications.bedCooledAfterPrint")})]}),i.jsx($n,{checked:me,onChange:we})]})]})]}),i.jsxs("div",{className:"space-y-2 p-3 bg-bambu-dark rounded-lg",children:[i.jsx("p",{className:"text-xs text-bambu-gray uppercase tracking-wide mb-2",children:n("notifications.printerStatus")}),i.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("span",{className:"text-sm text-white",children:n("notifications.offline")}),i.jsx($n,{checked:te,onChange:ie})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("span",{className:"text-sm text-white",children:n("notifications.error")}),i.jsx($n,{checked:Y,onChange:ae})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("span",{className:"text-sm text-white",children:n("notifications.lowFilament")}),i.jsx($n,{checked:de,onChange:pe})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("span",{className:"text-sm text-white",children:n("notifications.maintenance")}),i.jsx($n,{checked:Q,onChange:oe})]})]})]})]}),i.jsxs("div",{className:"flex gap-3 pt-2",children:[i.jsx(Oe,{type:"button",variant:"secondary",onClick:e,className:"flex-1",children:n("notifications.cancel")}),i.jsxs(Oe,{type:"submit",disabled:ee,className:"flex-1",children:[ee?i.jsx(lt,{className:"w-4 h-4 animate-spin"}):i.jsx(gs,{className:"w-4 h-4"}),n(a?"notifications.save":"notifications.add")]})]})]})]})})}function JZe({template:t,onClose:e}){const{t:n}=Mt(),r=Zt(),a=w.useRef(null),[s,o]=w.useState(t.title_template),[l,c]=w.useState(t.body_template),[d,u]=w.useState(null),[m,p]=w.useState(!0),{data:f}=Ze({queryKey:["template-variables"],queryFn:fe.getTemplateVariables}),x=f?.find(P=>P.event_type===t.event_type),{data:v,isLoading:g}=Ze({queryKey:["template-preview",t.event_type,s,l],queryFn:()=>fe.previewTemplate({event_type:t.event_type,title_template:s,body_template:l}),enabled:m&&s.length>0&&l.length>0});w.useEffect(()=>{const P=k=>{k.key==="Escape"&&e()};return window.addEventListener("keydown",P),()=>window.removeEventListener("keydown",P)},[e]);const y=dt({mutationFn:P=>fe.updateNotificationTemplate(t.id,P),onSuccess:()=>{r.invalidateQueries({queryKey:["notification-templates"]}),e()},onError:P=>{u(P.message)}}),_=dt({mutationFn:()=>fe.resetNotificationTemplate(t.id),onSuccess:P=>{o(P.title_template),c(P.body_template),r.invalidateQueries({queryKey:["notification-templates"]})},onError:P=>{u(P.message)}}),N=P=>{if(P.preventDefault(),u(null),!s.trim()){u(n("notifications.titleRequired"));return}if(!l.trim()){u(n("notifications.bodyRequired"));return}y.mutate({title_template:s,body_template:l})},C=P=>{const k=a.current;if(!k)return;const D=k.selectionStart,A=k.selectionEnd,R=l,$=R.substring(0,D),U=R.substring(A),W=$+`{${P}}`+U;c(W),setTimeout(()=>{k.focus();const O=D+P.length+2;k.setSelectionRange(O,O)},0)},T=s!==t.title_template||l!==t.body_template;return i.jsx("div",{className:"fixed inset-0 bg-black/80 flex items-center justify-center z-50 p-4",children:i.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg w-full max-w-2xl max-h-[90vh] flex flex-col",children:[i.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary shrink-0",children:[i.jsx("h2",{className:"text-lg font-semibold text-white",children:n("notifications.editTemplate",{name:t.name})}),i.jsx("button",{onClick:e,className:"p-1 hover:bg-bambu-dark-tertiary rounded transition-colors",children:i.jsx(zt,{className:"w-5 h-5 text-bambu-gray"})})]}),i.jsxs("form",{onSubmit:N,className:"flex-1 overflow-y-auto p-4 space-y-4",children:[d&&i.jsx("div",{className:"p-3 bg-red-500/20 border border-red-500/50 rounded text-red-400 text-sm",children:d}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-bambu-gray mb-1",children:n("notifications.titleLabel")}),i.jsx("input",{type:"text",value:s,onChange:P=>o(P.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:n("notifications.titlePlaceholder")})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-bambu-gray mb-1",children:n("notifications.bodyLabel")}),i.jsx("textarea",{ref:a,value:l,onChange:P=>c(P.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:n("notifications.bodyPlaceholder")})]}),x&&i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-bambu-gray mb-2",children:n("notifications.availableVariables")}),i.jsx("div",{className:"flex flex-wrap gap-2",children:x.variables.map(P=>i.jsxs("button",{type:"button",onClick:()=>C(P),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:[i.jsx(rr,{className:"w-3 h-3"}),P]},P))}),i.jsx("p",{className:"text-xs text-bambu-gray/60 mt-1",children:n("notifications.clickToInsert")})]}),i.jsxs("div",{children:[i.jsxs("div",{className:"flex items-center justify-between mb-2",children:[i.jsxs("label",{className:"text-sm font-medium text-bambu-gray flex items-center gap-2",children:[i.jsx(rc,{className:"w-4 h-4"}),n("notifications.livePreview")]}),i.jsx("button",{type:"button",onClick:()=>p(!m),className:"text-xs text-bambu-green hover:text-bambu-green-light",children:n(m?"notifications.hide":"notifications.show")})]}),m&&i.jsx("div",{className:"bg-bambu-dark border border-bambu-dark-tertiary rounded p-3 space-y-2",children:g?i.jsxs("div",{className:"flex items-center gap-2 text-bambu-gray text-sm",children:[i.jsx(lt,{className:"w-4 h-4 animate-spin"}),n("notifications.loadingPreview")]}):v?i.jsxs(i.Fragment,{children:[i.jsxs("div",{children:[i.jsx("span",{className:"text-xs text-bambu-gray",children:n("notifications.titlePreview")}),i.jsx("div",{className:"text-white font-medium",children:v.title})]}),i.jsxs("div",{children:[i.jsx("span",{className:"text-xs text-bambu-gray",children:n("notifications.bodyPreview")}),i.jsx("div",{className:"text-white whitespace-pre-wrap text-sm",children:v.body})]})]}):i.jsx("div",{className:"text-bambu-gray text-sm",children:n("notifications.enterTemplateContent")})})]})]}),i.jsxs("div",{className:"flex items-center justify-between p-4 border-t border-bambu-dark-tertiary shrink-0",children:[i.jsxs(Oe,{type:"button",variant:"ghost",onClick:()=>_.mutate(),disabled:_.isPending,className:"text-orange-400 hover:text-orange-300",children:[_.isPending?i.jsx(lt,{className:"w-4 h-4 animate-spin mr-2"}):i.jsx(mo,{className:"w-4 h-4 mr-2"}),n("notifications.resetToDefault")]}),i.jsxs("div",{className:"flex gap-2",children:[i.jsx(Oe,{type:"button",variant:"secondary",onClick:e,children:n("notifications.cancel")}),i.jsxs(Oe,{onClick:N,disabled:y.isPending||!T,children:[y.isPending?i.jsx(lt,{className:"w-4 h-4 animate-spin mr-2"}):i.jsx(gs,{className:"w-4 h-4 mr-2"}),n("notifications.save")]})]})]})]})})}const eJe={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 tJe({onClose:t}){const{t:e}=Mt(),n=Zt(),{showToast:r}=hn(),[a,s]=w.useState(7),[o,l]=w.useState(null),[c,d]=w.useState(!1),{data:u}=Ze({queryKey:["settings"],queryFn:fe.getSettings}),m=u?.time_format||"system",{data:p,isLoading:f,refetch:x,isRefetching:v}=Ze({queryKey:["notification-logs",a,c],queryFn:()=>fe.getNotificationLogs({days:a,limit:100,success:c?!1:void 0})}),{data:g}=Ze({queryKey:["notification-log-stats",a],queryFn:()=>fe.getNotificationLogStats(a)}),y=dt({mutationFn:()=>fe.clearNotificationLogs(30),onSuccess:N=>{r(N.message,"success"),n.invalidateQueries({queryKey:["notification-logs"]}),n.invalidateQueries({queryKey:["notification-log-stats"]})},onError:N=>{r(`Failed to clear logs: ${N.message}`,"error")}}),_=N=>{const C=er(N);if(!C)return"";const P=new Date().getTime()-C.getTime();return P<6e4?e("notifications.justNow"):P<36e5?`${Math.floor(P/6e4)}m ago`:P<864e5?`${Math.floor(P/36e5)}h ago`:C.toLocaleDateString()+" "+cX(C,m)};return i.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",children:i.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:[i.jsxs("div",{className:"p-4 border-b border-bambu-dark-tertiary flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx(Fv,{className:"w-5 h-5 text-bambu-green"}),i.jsx("h2",{className:"text-lg font-semibold text-white",children:e("notifications.notificationLog")})]}),i.jsx("button",{onClick:t,className:"text-bambu-gray hover:text-white transition-colors",children:"×"})]}),g&&i.jsx("div",{className:"px-4 py-3 border-b border-bambu-dark-tertiary bg-bambu-dark/50",children:i.jsxs("div",{className:"flex items-center gap-6 text-sm",children:[i.jsxs("span",{className:"text-bambu-gray",children:[e("notifications.statsSummary",{days:a})," ",i.jsx("span",{className:"text-white font-medium",children:g.total})," ",e("notifications.statsNotifications")]}),i.jsxs("span",{className:"flex items-center gap-1 text-bambu-green",children:[i.jsx(pr,{className:"w-4 h-4"}),e("notifications.statsSent",{count:g.success_count})]}),g.failure_count>0&&i.jsxs("span",{className:"flex items-center gap-1 text-red-400",children:[i.jsx(Vi,{className:"w-4 h-4"}),e("notifications.statsFailed",{count:g.failure_count})]})]})}),i.jsxs("div",{className:"px-4 py-3 border-b border-bambu-dark-tertiary flex items-center gap-4",children:[i.jsxs("select",{value:a,onChange:N=>s(Number(N.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:[i.jsx("option",{value:1,children:e("notifications.last24Hours")}),i.jsx("option",{value:7,children:e("notifications.last7Days")}),i.jsx("option",{value:30,children:e("notifications.last30Days")}),i.jsx("option",{value:90,children:e("notifications.last90Days")})]}),i.jsxs("label",{className:"flex items-center gap-2 text-sm text-bambu-gray cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:c,onChange:N=>d(N.target.checked),className:"rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),e("notifications.showFailedOnly")]}),i.jsx("div",{className:"flex-1"}),i.jsxs(Oe,{size:"sm",variant:"secondary",onClick:()=>x(),disabled:v,children:[v?i.jsx(lt,{className:"w-4 h-4 animate-spin"}):i.jsx(Sr,{className:"w-4 h-4"}),e("notifications.refresh")]}),i.jsxs(Oe,{size:"sm",variant:"secondary",onClick:()=>y.mutate(),disabled:y.isPending,className:"text-red-400 hover:text-red-300",children:[y.isPending?i.jsx(lt,{className:"w-4 h-4 animate-spin"}):i.jsx(Qt,{className:"w-4 h-4"}),e("notifications.clearOld")]})]}),i.jsx("div",{className:"flex-1 overflow-y-auto p-4",children:f?i.jsx("div",{className:"flex justify-center py-12",children:i.jsx(lt,{className:"w-6 h-6 text-bambu-green animate-spin"})}):p&&p.length>0?i.jsx("div",{className:"space-y-2",children:p.map(N=>i.jsx(nJe,{log:N,isExpanded:o===N.id,onToggle:()=>l(o===N.id?null:N.id),formatDate:_,formatFullDate:C=>Kp(C,m)},N.id))}):i.jsxs("div",{className:"text-center py-12 text-bambu-gray",children:[i.jsx(Fv,{className:"w-12 h-12 mx-auto mb-3 opacity-30"}),i.jsx("p",{className:"text-sm",children:e(c?"notifications.noFailedNotifications":"notifications.noNotificationsLogged")})]})})]})})}function nJe({log:t,isExpanded:e,onToggle:n,formatDate:r,formatFullDate:a}){const{t:s}=Mt();return i.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:[i.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?i.jsx(pr,{className:"w-4 h-4 text-bambu-green shrink-0"}):i.jsx(Vi,{className:"w-4 h-4 text-red-400 shrink-0"}),i.jsx("span",{className:`text-xs font-medium ${eJe[t.event_type]||"text-bambu-gray"}`,children:s(`notifications.eventTypes.${t.event_type}`,t.event_type)}),i.jsx("span",{className:"text-sm text-white truncate flex-1",children:t.provider_name||s("notifications.unknownProvider")}),t.printer_name&&i.jsx("span",{className:"text-xs text-bambu-gray",children:t.printer_name}),i.jsx("span",{className:"text-xs text-bambu-gray shrink-0",children:r(t.created_at)}),e?i.jsx(Sl,{className:"w-4 h-4 text-bambu-gray shrink-0"}):i.jsx(jn,{className:"w-4 h-4 text-bambu-gray shrink-0"})]}),e&&i.jsxs("div",{className:"px-3 py-2 border-t border-bambu-dark-tertiary bg-bambu-dark/20 space-y-2",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-xs text-bambu-gray mb-1",children:s("notifications.logTitle")}),i.jsx("p",{className:"text-sm text-white",children:t.title})]}),i.jsxs("div",{children:[i.jsx("p",{className:"text-xs text-bambu-gray mb-1",children:s("notifications.logMessage")}),i.jsx("p",{className:"text-sm text-white whitespace-pre-wrap",children:t.message})]}),!t.success&&t.error_message&&i.jsxs("div",{children:[i.jsx("p",{className:"text-xs text-red-400 mb-1",children:s("notifications.logError")}),i.jsx("p",{className:"text-sm text-red-300",children:t.error_message})]}),i.jsxs("div",{className:"flex gap-4 text-xs text-bambu-gray pt-1",children:[i.jsx("span",{children:s("notifications.logProvider",{type:t.provider_type})}),i.jsx("span",{children:s("notifications.logTime",{time:a(t.created_at)})})]})]})]})}function rJe({formData:t,setFormData:e,groups:n,onClose:r,onCreate:a,isCreating:s,isCreateButtonDisabled:o}){const{t:l}=Mt();w.useEffect(()=>{const d=u=>{u.key==="Escape"&&r()};return window.addEventListener("keydown",d),()=>window.removeEventListener("keydown",d)},[r]);const c=d=>{e({...t,group_ids:t.group_ids.includes(d)?t.group_ids.filter(u=>u!==d):[...t.group_ids,d]})};return i.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",onClick:r,children:i.jsxs(Tt,{className:"w-full max-w-md",onClick:d=>d.stopPropagation(),children:[i.jsx(qn,{children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex flex-col gap-1",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(Sm,{className:"w-5 h-5 text-bambu-green"}),i.jsx("h2",{className:"text-lg font-semibold text-white",children:l("users.modal.createUser")})]}),i.jsx("p",{className:"text-sm text-bambu-gray ml-7",children:l("users.modal.advancedAuthSubtitle")||"with Advanced Authentication"})]}),i.jsx(Oe,{variant:"ghost",size:"sm",onClick:r,children:i.jsx(zt,{className:"w-5 h-5"})})]})}),i.jsxs(Pt,{children:[i.jsxs("div",{className:"space-y-4",children:[i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm font-medium text-white mb-2",children:[l("users.form.username")," ",i.jsx("span",{className:"text-red-400",children:"*"})]}),i.jsx("input",{type:"text",value:t.username,onChange:d=>e({...t,username:d.target.value}),className:"w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors",placeholder:l("users.form.usernamePlaceholder"),autoComplete:"username",required:!0})]}),i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm font-medium text-white mb-2",children:[l("users.form.email")||"Email"," ",i.jsx("span",{className:"text-red-400",children:"*"})]}),i.jsx("input",{type:"email",value:t.email,onChange:d=>e({...t,email:d.target.value}),className:"w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors",placeholder:l("users.form.emailPlaceholder")||"user@example.com",required:!0})]}),i.jsx("div",{className:"bg-bambu-dark-secondary/50 border border-bambu-green/20 rounded-lg p-3",children:i.jsx("p",{className:"text-sm text-bambu-gray",children:l("users.form.autoGeneratedPassword")||"A secure password will be automatically generated and emailed to the user."})}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:l("users.form.groups")}),i.jsxs("div",{className:"space-y-2 max-h-40 overflow-y-auto p-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg",children:[n.map(d=>i.jsxs("label",{className:"flex items-center gap-3 px-2 py-1.5 rounded hover:bg-bambu-dark-tertiary cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:t.group_ids.includes(d.id),onChange:()=>c(d.id),className:"w-4 h-4 rounded border-bambu-gray text-bambu-green focus:ring-bambu-green focus:ring-offset-0 bg-bambu-dark"}),i.jsx("span",{className:"text-sm text-white",children:d.name}),d.is_system&&i.jsxs("span",{className:"text-xs text-yellow-400",children:["(",l("users.system"),")"]})]},d.id)),n.length===0&&i.jsx("p",{className:"text-sm text-bambu-gray",children:l("users.noGroupsAvailable")})]})]})]}),i.jsxs("div",{className:"mt-6 flex justify-end gap-3",children:[i.jsx(Oe,{variant:"secondary",onClick:r,children:l("users.modal.cancel")}),i.jsx(Oe,{onClick:a,disabled:o,children:s?i.jsxs(i.Fragment,{children:[i.jsx(lt,{className:"w-4 h-4 animate-spin"}),l("users.modal.creating")]}):i.jsxs(i.Fragment,{children:[i.jsx(rr,{className:"w-4 h-4"}),l("users.modal.createUser")]})})]})]})]})})}function iJe(){const{t}=Mt(),e=Zt(),{showToast:n}=hn(),[r,a]=w.useState(!1),[s,o]=w.useState(""),[l,c]=w.useState("auto"),[d,u]=w.useState(!1),[m,p]=w.useState(!0),[f,x]=w.useState("all"),[v,g]=w.useState(!1),[y,_]=w.useState(!1),[N,C]=w.useState(!1),{data:T,isLoading:P}=Ze({queryKey:["spoolman-settings"],queryFn:fe.getSpoolmanSettings}),{data:k,isLoading:D,refetch:A}=Ze({queryKey:["spoolman-status"],queryFn:fe.getSpoolmanStatus,refetchInterval:3e4}),{data:R}=Ze({queryKey:["printers"],queryFn:fe.getPrinters});w.useEffect(()=>{T&&(a(T.spoolman_enabled==="true"),o(T.spoolman_url||""),c(T.spoolman_sync_mode||"auto"),u(T.spoolman_disable_weight_sync==="true"),p(T.spoolman_report_partial_usage!=="false"),g(!0))},[T]),w.useEffect(()=>{if(!v||!T)return;if(T.spoolman_enabled==="true"!==r||(T.spoolman_url||"")!==s||(T.spoolman_sync_mode||"auto")!==l||T.spoolman_disable_weight_sync==="true"!==d||T.spoolman_report_partial_usage!=="false"!==m){const oe=setTimeout(()=>{$.mutate()},500);return()=>clearTimeout(oe)}},[r,s,l,d,m,v]);const $=dt({mutationFn:()=>fe.updateSpoolmanSettings({spoolman_enabled:r?"true":"false",spoolman_url:s,spoolman_sync_mode:l,spoolman_disable_weight_sync:d?"true":"false",spoolman_report_partial_usage:m?"true":"false"}),onSuccess:()=>{e.invalidateQueries({queryKey:["spoolman-settings"]}),e.invalidateQueries({queryKey:["spoolman-status"]}),e.invalidateQueries({queryKey:["spool-assignments"]}),n(t("settings.toast.settingsSaved"))}}),U=dt({mutationFn:fe.connectSpoolman,onSuccess:()=>{A()}}),W=dt({mutationFn:fe.disconnectSpoolman,onSuccess:()=>{A()}}),O=dt({mutationFn:fe.syncAllPrintersAms,onSuccess:Q=>{Q.success}}),te=dt({mutationFn:Q=>fe.syncPrinterAms(Q),onSuccess:Q=>{Q.success}}),ie=()=>{f==="all"?O.mutate():te.mutate(f)},Y=dt({mutationFn:fe.syncWeightsFromAms,onSuccess:Q=>{e.invalidateQueries({queryKey:["spools"]}),e.invalidateQueries({queryKey:["inventory-spools"]}),n(t("settings.amsSyncSuccess",{synced:Q.synced,skipped:Q.skipped}),"success"),C(!1)},onError:()=>{n(t("settings.amsSyncError"),"error"),C(!1)}}),ae=O.isPending||te.isPending,de=f==="all"?O.data:te.data,pe=f==="all"?O.isSuccess:te.isSuccess;return P?i.jsxs(Tt,{children:[i.jsx(qn,{children:i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(Uc,{className:"w-5 h-5 text-bambu-green"}),i.jsx("h2",{className:"text-lg font-semibold text-white",children:t("settings.filamentTracking")})]})}),i.jsx(Pt,{children:i.jsx("div",{className:"flex justify-center py-8",children:i.jsx(lt,{className:"w-6 h-6 text-bambu-green animate-spin"})})})]}):i.jsxs(Tt,{children:[i.jsx(qn,{children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(Uc,{className:"w-5 h-5 text-bambu-green"}),i.jsx("h2",{className:"text-lg font-semibold text-white",children:t("settings.filamentTracking")})]}),$.isPending&&i.jsx(lt,{className:"w-4 h-4 text-bambu-green animate-spin"})]})}),i.jsxs(Pt,{className:"space-y-4",children:[i.jsx("p",{className:"text-sm text-bambu-gray",children:t("settings.filamentTrackingDesc")}),i.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[i.jsxs("button",{type:"button",onClick:()=>a(!1),className:`p-3 rounded-lg border-2 text-left transition-colors ${r?"border-bambu-dark-tertiary bg-bambu-dark hover:border-bambu-gray/50":"border-bambu-green bg-bambu-green/10"}`,children:[i.jsxs("div",{className:"flex items-center gap-2 mb-1.5",children:[i.jsx(oa,{className:`w-4 h-4 ${r?"text-bambu-gray":"text-bambu-green"}`}),i.jsx("span",{className:`text-sm font-medium ${r?"text-bambu-gray":"text-white"}`,children:t("settings.trackingModeBuiltIn")})]}),i.jsx("p",{className:`text-xs ${r?"text-bambu-gray/60":"text-bambu-gray"}`,children:t("settings.trackingModeBuiltInDesc")}),!r&&i.jsxs("div",{className:"flex items-center gap-1 mt-2",children:[i.jsx(Vr,{className:"w-3 h-3 text-bambu-green"}),i.jsx("span",{className:"text-xs text-bambu-green",children:t("common.enabled")})]})]}),i.jsxs("button",{type:"button",onClick:()=>a(!0),className:`p-3 rounded-lg border-2 text-left transition-colors ${r?"border-bambu-green bg-bambu-green/10":"border-bambu-dark-tertiary bg-bambu-dark hover:border-bambu-gray/50"}`,children:[i.jsxs("div",{className:"flex items-center gap-2 mb-1.5",children:[i.jsx(ei,{className:`w-4 h-4 ${r?"text-bambu-green":"text-bambu-gray"}`}),i.jsx("span",{className:`text-sm font-medium ${r?"text-white":"text-bambu-gray"}`,children:"Spoolman"})]}),i.jsx("p",{className:`text-xs ${r?"text-bambu-gray":"text-bambu-gray/60"}`,children:t("settings.trackingModeSpoolmanDesc")}),r&&i.jsxs("div",{className:"flex items-center gap-1 mt-2",children:[i.jsx(Vr,{className:"w-3 h-3 text-bambu-green"}),i.jsx("span",{className:"text-xs text-bambu-green",children:t("common.enabled")})]})]})]}),!r&&i.jsxs("div",{className:"space-y-3",children:[i.jsx("div",{className:"p-3 bg-bambu-green/5 border border-bambu-green/20 rounded-lg",children:i.jsxs("div",{className:"flex gap-2",children:[i.jsx(Rs,{className:"w-4 h-4 text-bambu-green flex-shrink-0 mt-0.5"}),i.jsx("div",{className:"text-xs text-bambu-gray",children:i.jsxs("ul",{className:"list-disc list-inside space-y-0.5",children:[i.jsx("li",{children:t("settings.builtInFeatureRfid")}),i.jsx("li",{children:t("settings.builtInFeatureUsage")}),i.jsx("li",{children:t("settings.builtInFeatureCatalog")}),i.jsx("li",{children:t("settings.builtInFeatureThirdParty")})]})})]})}),i.jsxs(Oe,{variant:"secondary",size:"sm",onClick:()=>C(!0),disabled:Y.isPending,children:[Y.isPending?i.jsx(lt,{className:"w-4 h-4 mr-2 animate-spin"}):i.jsx(Sr,{className:"w-4 h-4 mr-2"}),t("settings.amsSyncButton")]})]}),r&&i.jsxs("div",{className:"space-y-4",children:[i.jsx("div",{className:"p-3 bg-blue-500/10 border border-blue-500/30 rounded-lg",children:i.jsxs("div",{className:"flex gap-2",children:[i.jsx(Rs,{className:"w-4 h-4 text-blue-400 flex-shrink-0 mt-0.5"}),i.jsxs("div",{className:"text-xs text-blue-300",children:[i.jsx("p",{className:"font-medium mb-1",children:t("settings.howSyncWorks")}),i.jsxs("ul",{className:"list-disc list-inside space-y-0.5 text-blue-300/80",children:[i.jsx("li",{children:t("settings.syncInfoRfidOnly")}),i.jsx("li",{children:t("settings.syncInfoAutoCreate")}),i.jsx("li",{children:t("settings.syncInfoThirdPartySkipped")})]}),i.jsx("p",{className:"font-medium mt-2 mb-1",children:t("settings.linkingExistingSpools")}),i.jsx("p",{className:"text-blue-300/80",children:t("settings.linkingExistingSpoolsDesc")})]})]})}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:t("settings.spoolmanUrl")}),i.jsx("input",{type:"text",placeholder:"http://192.168.1.100:7912",value:s,onChange:Q=>o(Q.target.value),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"}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:t("settings.spoolmanUrlHint")})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:t("settings.syncMode")}),i.jsxs("select",{value:l,onChange:Q=>c(Q.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[i.jsx("option",{value:"auto",children:t("settings.syncModeAuto")}),i.jsx("option",{value:"manual",children:t("settings.syncModeManual")})]}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:t(l==="auto"?"settings.syncModeAutoDesc":"settings.syncModeManualDesc")})]}),l==="auto"&&i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-white",children:t("spoolman.disableWeightSync")}),i.jsx("p",{className:"text-sm text-bambu-gray",children:t("spoolman.disableWeightSyncDesc")})]}),i.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:d,onChange:Q=>u(Q.target.checked),className:"sr-only peer"}),i.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"})]})]}),d&&i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-white",children:t("spoolman.reportPartialUsage")}),i.jsx("p",{className:"text-sm text-bambu-gray",children:t("spoolman.reportPartialUsageDesc")})]}),i.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:m,onChange:Q=>p(Q.target.checked),className:"sr-only peer"}),i.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]}),i.jsxs("div",{className:"pt-2 border-t border-bambu-dark-tertiary",children:[i.jsxs("div",{className:"flex items-center justify-between mb-3",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsxs("span",{className:"text-sm text-bambu-gray",children:[t("settings.status"),":"]}),D?i.jsx(lt,{className:"w-4 h-4 text-bambu-gray animate-spin"}):k?.connected?i.jsxs("span",{className:"flex items-center gap-1 text-sm text-green-500",children:[i.jsx(Vr,{className:"w-4 h-4"}),t("settings.spoolmanConnected")]}):i.jsxs("span",{className:"flex items-center gap-1 text-sm text-red-500",children:[i.jsx(zt,{className:"w-4 h-4"}),t("settings.spoolmanDisconnected")]})]}),i.jsx("div",{className:"flex gap-2",children:k?.connected?i.jsxs(Oe,{variant:"secondary",size:"sm",onClick:()=>W.mutate(),disabled:W.isPending,children:[W.isPending?i.jsx(lt,{className:"w-4 h-4 animate-spin"}):i.jsx(Bpe,{className:"w-4 h-4"}),t("settings.disconnect")]}):i.jsxs(Oe,{size:"sm",onClick:()=>U.mutate(),disabled:U.isPending||!s,children:[U.isPending?i.jsx(lt,{className:"w-4 h-4 animate-spin"}):i.jsx(Vm,{className:"w-4 h-4"}),t("settings.connect")]})})]}),U.isError&&i.jsx("div",{className:"mb-3 p-2 bg-red-500/20 border border-red-500/50 rounded text-sm text-red-400",children:U.error.message}),k?.connected&&i.jsxs("div",{className:"space-y-3",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-sm text-white",children:t("settings.syncAmsData")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:t("settings.syncAmsDataDesc")})]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsxs("div",{className:"relative flex-1",children:[i.jsxs("select",{value:f,onChange:Q=>x(Q.target.value==="all"?"all":Number(Q.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:[i.jsx("option",{value:"all",children:t("settings.allPrinters")}),R?.map(Q=>i.jsx("option",{value:Q.id,children:Q.name},Q.id))]}),i.jsx(jn,{className:"absolute right-2 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}),i.jsxs(Oe,{variant:"secondary",size:"sm",onClick:ie,disabled:ae,children:[ae?i.jsx(lt,{className:"w-4 h-4 animate-spin"}):i.jsx(Sr,{className:"w-4 h-4"}),t("spoolman.sync")]})]})]}),pe&&de&&i.jsxs("div",{className:"mt-3 space-y-2",children:[i.jsx("div",{className:`p-2 rounded text-sm ${de.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:de.success?`Synced ${de.synced_count} spool${de.synced_count!==1?"s":""} successfully`:`Synced ${de.synced_count} spool${de.synced_count!==1?"s":""} with ${de.errors.length} error${de.errors.length!==1?"s":""}`}),de.skipped_count>0&&i.jsxs("div",{className:"p-2 bg-amber-500/10 border border-amber-500/30 rounded text-sm",children:[i.jsxs("div",{className:"flex items-center justify-between text-amber-400 mb-1",children:[i.jsxs("div",{className:"flex items-center gap-1.5",children:[i.jsx(Cn,{className:"w-3.5 h-3.5"}),i.jsxs("span",{className:"font-medium",children:[de.skipped_count," spool",de.skipped_count!==1?"s":""," skipped"]})]}),de.skipped_count>5&&i.jsx("button",{onClick:()=>_(!y),className:"text-xs text-amber-400 hover:text-amber-300 underline",children:y?"Show less":"Show all"})]}),i.jsxs("ul",{className:"text-xs text-amber-300/80 space-y-0.5",children:[(y?de.skipped:de.skipped.slice(0,5)).map((Q,oe)=>i.jsxs("li",{className:"flex items-center gap-2",children:[Q.color&&i.jsx("span",{className:"w-3 h-3 rounded-full border border-white/20",style:{backgroundColor:`#${Q.color}`}}),i.jsx("span",{children:Q.location}),i.jsxs("span",{className:"text-amber-300/60",children:["- ",Q.reason]})]},oe)),!y&&de.skipped_count>5&&i.jsxs("li",{className:"text-amber-300/60 italic",children:["...and ",de.skipped_count-5," more"]})]})]}),de.errors.length>0&&i.jsxs("div",{className:"p-2 bg-red-500/10 border border-red-500/30 rounded text-sm",children:[i.jsx("div",{className:"text-red-400 font-medium mb-1",children:"Errors:"}),i.jsx("ul",{className:"text-xs text-red-300/80 space-y-0.5",children:de.errors.map((Q,oe)=>i.jsx("li",{children:Q},oe))})]})]})]})]})]}),N&&i.jsx(_n,{title:t("settings.amsSyncTitle"),message:t("settings.amsSyncMessage"),confirmText:t("settings.amsSyncButton"),variant:"warning",isLoading:Y.isPending,loadingText:t("settings.amsSyncing"),onConfirm:()=>Y.mutate(),onCancel:()=>C(!1)})]})}function aJe(){const{t}=Mt(),{showToast:e}=hn(),[n,r]=w.useState([]),[a,s]=w.useState(!0),[o,l]=w.useState(""),c=w.useRef(null),[d,u]=w.useState(!1),[m,p]=w.useState(null),[f,x]=w.useState(""),[v,g]=w.useState(""),[y,_]=w.useState(!1),[N,C]=w.useState(null),[T,P]=w.useState(!1),k=w.useCallback(async()=>{try{const Y=await fe.getSpoolCatalog();r(Y)}catch{e(t("settings.catalog.loadFailed"),"error")}finally{s(!1)}},[e,t]);w.useEffect(()=>{k()},[k]);const D=n.filter(Y=>Y.name.toLowerCase().includes(o.toLowerCase())),A=async()=>{if(!f.trim()||!v){e(t("settings.catalog.nameWeightRequired"),"error");return}_(!0);try{const Y=await fe.addCatalogEntry({name:f.trim(),weight:parseInt(v)});r(ae=>[...ae,Y].sort((de,pe)=>de.name.localeCompare(pe.name))),u(!1),x(""),g(""),e(t("settings.catalog.entryAdded"),"success")}catch{e(t("settings.catalog.addFailed"),"error")}finally{_(!1)}},R=Y=>{p(Y.id),x(Y.name),g(Y.weight.toString())},$=()=>{p(null),x(""),g("")},U=async Y=>{if(!f.trim()||!v){e(t("settings.catalog.nameWeightRequired"),"error");return}_(!0);try{const ae=await fe.updateCatalogEntry(Y,{name:f.trim(),weight:parseInt(v)});r(de=>de.map(pe=>pe.id===Y?ae:pe).sort((pe,Q)=>pe.name.localeCompare(Q.name))),p(null),x(""),g(""),e(t("settings.catalog.entryUpdated"),"success")}catch{e(t("settings.catalog.updateFailed"),"error")}finally{_(!1)}},W=async()=>{if(N)try{await fe.deleteCatalogEntry(N.id),r(Y=>Y.filter(ae=>ae.id!==N.id)),e(t("settings.catalog.entryDeleted"),"success")}catch{e(t("settings.catalog.deleteFailed"),"error")}finally{C(null)}},O=async()=>{P(!1),s(!0);try{await fe.resetSpoolCatalog(),await k(),e(t("settings.catalog.resetSuccess"),"success")}catch{e(t("settings.catalog.resetFailed"),"error"),s(!1)}},te=()=>{const Y=n.map(({name:Q,weight:oe})=>({name:Q,weight:oe})),ae=new Blob([JSON.stringify(Y,null,2)],{type:"application/json"}),de=URL.createObjectURL(ae),pe=document.createElement("a");pe.href=de,pe.download="spool-catalog.json",document.body.appendChild(pe),pe.click(),document.body.removeChild(pe),URL.revokeObjectURL(de),e(t("settings.catalog.exported",{count:n.length}),"success")},ie=async Y=>{const ae=Y.target.files?.[0];if(ae){try{const de=await ae.text(),pe=JSON.parse(de);if(!Array.isArray(pe))throw new Error("Invalid format");let Q=0,oe=0;for(const me of pe){if(!me.name||typeof me.weight!="number"){oe++;continue}if(n.some(Ee=>Ee.name.toLowerCase()===me.name.toLowerCase())){oe++;continue}try{const Ee=await fe.addCatalogEntry({name:me.name,weight:me.weight});r(q=>[...q,Ee].sort((K,E)=>K.name.localeCompare(E.name))),Q++}catch{oe++}}e(t("settings.catalog.imported",{added:Q,skipped:oe}),"success")}catch{e(t("settings.catalog.importFailed"),"error")}c.current&&(c.current.value="")}};return i.jsxs(Tt,{children:[i.jsxs(qn,{children:[i.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[i.jsx(Uc,{className:"w-5 h-5 text-bambu-gray"}),i.jsx("h2",{className:"text-lg font-semibold text-white",children:t("settings.catalog.spoolCatalog")}),i.jsxs("span",{className:"text-sm text-bambu-gray",children:["(",n.length,")"]})]}),i.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[i.jsxs("button",{onClick:te,className:"px-3 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray hover:text-white transition-colors flex items-center gap-1.5",title:t("settings.catalog.exportTooltip"),children:[i.jsx(hi,{className:"w-4 h-4"}),i.jsx("span",{className:"hidden sm:inline",children:t("common.export")})]}),i.jsxs("button",{onClick:()=>c.current?.click(),className:"px-3 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray hover:text-white transition-colors flex items-center gap-1.5",title:t("settings.catalog.importTooltip"),children:[i.jsx(Si,{className:"w-4 h-4"}),i.jsx("span",{className:"hidden sm:inline",children:t("common.import")})]}),i.jsx("input",{ref:c,type:"file",accept:".json",className:"hidden",onChange:ie}),i.jsxs("button",{onClick:()=>P(!0),className:"px-3 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray hover:text-white transition-colors flex items-center gap-1.5",title:t("settings.catalog.resetTooltip"),children:[i.jsx(mo,{className:"w-4 h-4"}),i.jsx("span",{className:"hidden sm:inline",children:t("common.reset")})]}),i.jsxs("button",{onClick:()=>u(!0),className:"px-3 py-1.5 text-sm bg-bambu-green text-white rounded-lg hover:bg-bambu-green/80 transition-colors flex items-center gap-1.5",children:[i.jsx(rr,{className:"w-4 h-4"}),i.jsx("span",{className:"hidden sm:inline",children:t("common.add")})]})]})]}),i.jsxs(Pt,{className:"space-y-4",children:[i.jsx("p",{className:"text-sm text-bambu-gray",children:t("settings.catalog.spoolCatalogDescription")}),i.jsxs("div",{className:"relative",children:[i.jsx(jr,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray"}),i.jsx("input",{type:"text",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",placeholder:t("settings.catalog.searchCatalog"),value:o,onChange:Y=>l(Y.target.value)})]}),d&&i.jsxs("div",{className:"p-4 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary",children:[i.jsx("h3",{className:"text-sm font-medium text-white mb-3",children:t("settings.catalog.addNewEntry")}),i.jsxs("div",{className:"flex gap-2 items-center",children:[i.jsx("div",{className:"flex-1 min-w-0",children:i.jsx("input",{type:"text",className:"w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none",placeholder:t("settings.catalog.namePlaceholder"),value:f,onChange:Y=>x(Y.target.value)})}),i.jsx("input",{type:"number",className:"w-20 px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white text-center focus:border-bambu-green focus:outline-none",placeholder:"g",value:v,onChange:Y=>g(Y.target.value)}),i.jsx("span",{className:"text-bambu-gray shrink-0",children:"g"}),i.jsxs("button",{onClick:A,disabled:y,className:"px-3 py-2 bg-bambu-green text-white rounded-lg hover:bg-bambu-green/80 flex items-center gap-1 shrink-0",children:[y?i.jsx(lt,{className:"w-4 h-4 animate-spin"}):i.jsx(Vr,{className:"w-4 h-4"}),t("common.add")]}),i.jsx("button",{onClick:()=>{u(!1),x(""),g("")},className:"p-2 rounded-lg text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary",children:i.jsx(zt,{className:"w-4 h-4"})})]})]}),a?i.jsxs("div",{className:"flex items-center justify-center py-8 text-bambu-gray",children:[i.jsx(lt,{className:"w-5 h-5 animate-spin mr-2"}),t("common.loading")]}):i.jsx("div",{className:"max-h-[600px] overflow-y-auto border border-bambu-dark-tertiary rounded-lg",children:i.jsxs("table",{className:"w-full text-sm",children:[i.jsx("thead",{className:"bg-bambu-dark sticky top-0",children:i.jsxs("tr",{children:[i.jsx("th",{className:"px-4 py-2 text-left text-bambu-gray font-medium",children:t("common.name")}),i.jsx("th",{className:"px-4 py-2 text-right text-bambu-gray font-medium w-24",children:t("settings.catalog.weight")}),i.jsx("th",{className:"px-4 py-2 text-center text-bambu-gray font-medium w-20",children:t("settings.catalog.type")}),i.jsx("th",{className:"px-4 py-2 w-24"})]})}),i.jsx("tbody",{children:D.length===0?i.jsx("tr",{children:i.jsx("td",{colSpan:4,className:"px-4 py-8 text-center text-bambu-gray",children:t(o?"settings.catalog.noMatch":"settings.catalog.empty")})}):D.map(Y=>i.jsx("tr",{className:"border-t border-bambu-dark-tertiary hover:bg-bambu-dark",children:m===Y.id?i.jsxs(i.Fragment,{children:[i.jsx("td",{className:"px-4 py-2",children:i.jsx("input",{type:"text",className:"w-full px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white focus:border-bambu-green focus:outline-none",value:f,onChange:ae=>x(ae.target.value)})}),i.jsx("td",{className:"px-4 py-2",children:i.jsx("input",{type:"number",className:"w-full px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-right focus:border-bambu-green focus:outline-none",value:v,onChange:ae=>g(ae.target.value)})}),i.jsx("td",{className:"px-4 py-2 text-center",children:i.jsx("span",{className:"text-xs text-bambu-gray",children:"-"})}),i.jsx("td",{className:"px-4 py-2",children:i.jsxs("div",{className:"flex justify-end gap-1",children:[i.jsx("button",{onClick:()=>U(Y.id),disabled:y,className:"p-1.5 rounded hover:bg-green-500/20 text-green-500",children:y?i.jsx(lt,{className:"w-4 h-4 animate-spin"}):i.jsx(Vr,{className:"w-4 h-4"})}),i.jsx("button",{onClick:$,className:"p-1.5 rounded hover:bg-bambu-dark-tertiary text-bambu-gray",children:i.jsx(zt,{className:"w-4 h-4"})})]})})]}):i.jsxs(i.Fragment,{children:[i.jsx("td",{className:"px-4 py-2 text-white",children:Y.name}),i.jsxs("td",{className:"px-4 py-2 text-right font-mono text-white",children:[Y.weight,"g"]}),i.jsx("td",{className:"px-4 py-2 text-center",children:Y.is_default?i.jsx("span",{className:"text-xs px-2 py-0.5 rounded bg-bambu-dark-tertiary text-bambu-gray",children:t("settings.catalog.default")}):i.jsx("span",{className:"text-xs px-2 py-0.5 rounded bg-bambu-green/20 text-bambu-green",children:t("settings.catalog.custom")})}),i.jsx("td",{className:"px-4 py-2",children:i.jsxs("div",{className:"flex justify-end gap-1",children:[i.jsx("button",{onClick:()=>R(Y),className:"p-1.5 rounded hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white",children:i.jsx(Ki,{className:"w-4 h-4"})}),i.jsx("button",{onClick:()=>C(Y),className:"p-1.5 rounded bg-red-500/10 hover:bg-red-500/20 text-red-500",children:i.jsx(Qt,{className:"w-4 h-4"})})]})})]})},Y.id))})]})})]}),N&&i.jsx(_n,{title:t("settings.catalog.deleteEntry"),message:t("settings.catalog.deleteConfirm",{name:N.name}),confirmText:t("common.delete"),variant:"danger",onConfirm:W,onCancel:()=>C(null)}),T&&i.jsx(_n,{title:t("settings.catalog.resetCatalog"),message:t("settings.catalog.resetConfirm"),confirmText:t("common.reset"),variant:"danger",onConfirm:O,onCancel:()=>P(!1)})]})}function sJe(){const{t}=Mt(),{showToast:e}=hn(),[n,r]=w.useState([]),[a,s]=w.useState(!0),[o,l]=w.useState(""),[c,d]=w.useState("Bambu Lab"),u=w.useRef(null),[m,p]=w.useState(!1),[f,x]=w.useState(null),[v,g]=w.useState(""),[y,_]=w.useState(""),[N,C]=w.useState("#FFFFFF"),[T,P]=w.useState(""),[k,D]=w.useState(!1),[A,R]=w.useState(!1),[$,U]=w.useState(null),[W,O]=w.useState(null),[te,ie]=w.useState(!1),Y=w.useCallback(async()=>{try{const L=await fe.getColorCatalog();r(L)}catch{e(t("settings.colorCatalog.loadFailed"),"error")}finally{s(!1)}},[e,t]);w.useEffect(()=>{Y()},[Y]);const ae=[...new Set(n.map(L=>L.manufacturer))].sort(),de=n.filter(L=>{const G=o===""||L.manufacturer.toLowerCase().includes(o.toLowerCase())||L.color_name.toLowerCase().includes(o.toLowerCase())||(L.material?.toLowerCase().includes(o.toLowerCase())??!1),B=c===""||L.manufacturer===c;return G&&B}),pe=()=>{g(""),_(""),C("#FFFFFF"),P("")},Q=async()=>{if(!v.trim()||!y.trim()||!N){e(t("settings.colorCatalog.fieldsRequired"),"error");return}D(!0);try{const L=await fe.addColorEntry({manufacturer:v.trim(),color_name:y.trim(),hex_color:N,material:T.trim()||null});r(G=>[...G,L].sort((B,re)=>B.manufacturer.localeCompare(re.manufacturer)||(B.material||"").localeCompare(re.material||"")||B.color_name.localeCompare(re.color_name))),p(!1),pe(),e(t("settings.colorCatalog.colorAdded"),"success")}catch{e(t("settings.colorCatalog.addFailed"),"error")}finally{D(!1)}},oe=L=>{x(L.id),g(L.manufacturer),_(L.color_name),C(L.hex_color),P(L.material||"")},me=()=>{x(null),pe()},we=async L=>{if(!v.trim()||!y.trim()||!N){e(t("settings.colorCatalog.fieldsRequired"),"error");return}D(!0);try{const G=await fe.updateColorEntry(L,{manufacturer:v.trim(),color_name:y.trim(),hex_color:N,material:T.trim()||null});r(B=>B.map(re=>re.id===L?G:re).sort((re,z)=>re.manufacturer.localeCompare(z.manufacturer)||(re.material||"").localeCompare(z.material||"")||re.color_name.localeCompare(z.color_name))),x(null),pe(),e(t("settings.colorCatalog.colorUpdated"),"success")}catch{e(t("settings.colorCatalog.updateFailed"),"error")}finally{D(!1)}},Ee=async()=>{if(W)try{await fe.deleteColorEntry(W.id),r(L=>L.filter(G=>G.id!==W.id)),e(t("settings.colorCatalog.colorDeleted"),"success")}catch{e(t("settings.colorCatalog.deleteFailed"),"error")}finally{O(null)}},q=async()=>{ie(!1),s(!0);try{await fe.resetColorCatalog(),await Y(),e(t("settings.colorCatalog.resetSuccess"),"success")}catch{e(t("settings.colorCatalog.resetFailed"),"error"),s(!1)}},K=async()=>{R(!0),U(null);try{const L={},G=mu();G&&(L.Authorization=`Bearer ${G}`);const B=await fetch("/api/v1/inventory/colors/sync",{method:"POST",headers:L});if(!B.ok)throw new Error("Failed to start sync");const re=B.body?.getReader();if(!re)throw new Error("No response body");const z=new TextDecoder;let V="";for(;;){const{done:ee,value:J}=await re.read();if(ee)break;V+=z.decode(J,{stream:!0});const ne=V.split(` -`);V=ne.pop()||"";for(const se of ne)if(se.startsWith("data: "))try{const ue=JSON.parse(se.slice(6));ue.type==="progress"?U({fetched:ue.total_fetched,total:ue.total_available}):ue.type==="complete"?ue.added===0?e(t("settings.colorCatalog.syncUpToDate",{count:ue.total_fetched}),"success"):e(t("settings.colorCatalog.syncComplete",{added:ue.added,skipped:ue.skipped}),"success"):ue.type==="error"&&e(`${t("settings.colorCatalog.syncError")}: ${ue.error}`,"error")}catch{}}await Y()}catch{e(t("settings.colorCatalog.syncFailed"),"error")}finally{R(!1),U(null)}},E=()=>{const L=n.map(({manufacturer:z,color_name:V,hex_color:ee,material:J})=>({manufacturer:z,color_name:V,hex_color:ee,material:J})),G=new Blob([JSON.stringify(L,null,2)],{type:"application/json"}),B=URL.createObjectURL(G),re=document.createElement("a");re.href=B,re.download="color-catalog.json",document.body.appendChild(re),re.click(),document.body.removeChild(re),URL.revokeObjectURL(B),e(t("settings.colorCatalog.exported",{count:n.length}),"success")},j=async L=>{const G=L.target.files?.[0];if(G){try{const B=await G.text(),re=JSON.parse(B);if(!Array.isArray(re))throw new Error("Invalid format");let z=0,V=0;for(const ee of re){if(!ee.manufacturer||!ee.color_name||!ee.hex_color){V++;continue}if(n.some(ne=>ne.manufacturer.toLowerCase()===ee.manufacturer.toLowerCase()&&ne.color_name.toLowerCase()===ee.color_name.toLowerCase()&&(ne.material||"").toLowerCase()===(ee.material||"").toLowerCase())){V++;continue}try{const ne=await fe.addColorEntry({manufacturer:ee.manufacturer,color_name:ee.color_name,hex_color:ee.hex_color,material:ee.material||null});r(se=>[...se,ne].sort((ue,ge)=>ue.manufacturer.localeCompare(ge.manufacturer)||(ue.material||"").localeCompare(ge.material||"")||ue.color_name.localeCompare(ge.color_name))),z++}catch{V++}}e(t("settings.colorCatalog.imported",{added:z,skipped:V}),"success")}catch{e(t("settings.colorCatalog.importFailed"),"error")}u.current&&(u.current.value="")}};return i.jsxs(Tt,{children:[i.jsxs(qn,{children:[i.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[i.jsx(mC,{className:"w-5 h-5 text-bambu-gray"}),i.jsx("h2",{className:"text-lg font-semibold text-white",children:t("settings.colorCatalog.title")}),i.jsxs("span",{className:"text-sm text-bambu-gray",children:["(",n.length,")"]})]}),i.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[i.jsxs("button",{onClick:E,className:"px-3 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray hover:text-white transition-colors flex items-center gap-1.5",children:[i.jsx(hi,{className:"w-4 h-4"}),i.jsx("span",{className:"hidden sm:inline",children:t("common.export")})]}),i.jsxs("button",{onClick:()=>u.current?.click(),className:"px-3 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray hover:text-white transition-colors flex items-center gap-1.5",children:[i.jsx(Si,{className:"w-4 h-4"}),i.jsx("span",{className:"hidden sm:inline",children:t("common.import")})]}),i.jsx("input",{ref:u,type:"file",accept:".json",className:"hidden",onChange:j}),i.jsxs("button",{onClick:K,disabled:A,className:"px-3 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray hover:text-white transition-colors flex items-center gap-1.5",title:t("settings.colorCatalog.syncTooltip"),children:[A?i.jsx(lt,{className:"w-4 h-4 animate-spin"}):i.jsx(lx,{className:"w-4 h-4"}),i.jsx("span",{className:"hidden sm:inline",children:A?$?`${Math.min($.fetched,$.total)} / ${$.total}`:t("settings.colorCatalog.starting"):t("settings.colorCatalog.sync")})]}),i.jsxs("button",{onClick:()=>ie(!0),className:"px-3 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray hover:text-white transition-colors flex items-center gap-1.5",children:[i.jsx(mo,{className:"w-4 h-4"}),i.jsx("span",{className:"hidden sm:inline",children:t("common.reset")})]}),i.jsxs("button",{onClick:()=>p(!0),className:"px-3 py-1.5 text-sm bg-bambu-green text-white rounded-lg hover:bg-bambu-green/80 transition-colors flex items-center gap-1.5",children:[i.jsx(rr,{className:"w-4 h-4"}),i.jsx("span",{className:"hidden sm:inline",children:t("common.add")})]})]})]}),i.jsxs(Pt,{className:"space-y-4",children:[i.jsx("p",{className:"text-sm text-bambu-gray",children:t("settings.colorCatalog.description")}),i.jsxs("div",{className:"flex gap-2 flex-wrap",children:[i.jsxs("div",{className:"relative flex-1 min-w-[200px]",children:[i.jsx(jr,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray"}),i.jsx("input",{type:"text",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",placeholder:t("settings.colorCatalog.searchColors"),value:o,onChange:L=>l(L.target.value)})]}),i.jsxs("select",{className:"px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",value:c,onChange:L=>d(L.target.value),children:[i.jsx("option",{value:"",children:t("settings.colorCatalog.allManufacturers")}),ae.map(L=>i.jsx("option",{value:L,children:L},L))]})]}),m&&i.jsxs("div",{className:"p-4 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary",children:[i.jsx("h3",{className:"text-sm font-medium text-white mb-3",children:t("settings.colorCatalog.addNewColor")}),i.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-5 gap-2 items-end",children:[i.jsx("input",{type:"text",className:"px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none",placeholder:t("settings.colorCatalog.manufacturer"),value:v,onChange:L=>g(L.target.value)}),i.jsx("input",{type:"text",className:"px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none",placeholder:t("settings.colorCatalog.colorName"),value:y,onChange:L=>_(L.target.value)}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("input",{type:"color",className:"w-20 h-10 rounded cursor-pointer border border-bambu-dark-tertiary",value:N,onChange:L=>C(L.target.value)}),i.jsx("input",{type:"text",className:"w-32 px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none",placeholder:"#FFFFFF",value:N,onChange:L=>C(L.target.value)})]}),i.jsxs("div",{className:"flex items-center gap-1",children:[i.jsx("input",{type:"text",className:"flex-1 max-w-lg min-w-[200px] px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none",placeholder:t("settings.colorCatalog.materialOptional"),value:T,onChange:L=>P(L.target.value)}),i.jsxs("button",{onClick:Q,disabled:k,className:"w-24 px-3 py-2 bg-bambu-green text-white rounded-lg hover:bg-bambu-green/80 flex items-center justify-center gap-3",children:[k?i.jsx(lt,{className:"w-4 h-4 animate-spin"}):i.jsx(Vr,{className:"w-4 h-4"}),t("common.add")]}),i.jsx("button",{onClick:()=>{p(!1),pe()},className:"p-2 ml-2 rounded-lg text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary",children:i.jsx(zt,{className:"w-4 h-4"})})]})]})]}),(o||c)&&i.jsx("div",{className:"text-xs text-bambu-gray",children:t("settings.colorCatalog.showing",{filtered:de.length,total:n.length})}),a?i.jsxs("div",{className:"flex items-center justify-center py-8 text-bambu-gray",children:[i.jsx(lt,{className:"w-5 h-5 animate-spin mr-2"}),t("common.loading")]}):i.jsx("div",{className:"max-h-[600px] overflow-auto border border-bambu-dark-tertiary rounded-lg",children:i.jsxs("table",{className:"w-full text-sm",children:[i.jsx("thead",{className:"bg-bambu-dark sticky top-0",children:i.jsxs("tr",{children:[i.jsx("th",{className:"px-3 py-2 text-left text-bambu-gray font-medium w-12"}),i.jsx("th",{className:"px-3 py-2 text-left text-bambu-gray font-medium",children:t("settings.colorCatalog.manufacturer")}),i.jsx("th",{className:"px-3 py-2 text-left text-bambu-gray font-medium",children:t("inventory.material")}),i.jsx("th",{className:"px-3 py-2 text-left text-bambu-gray font-medium",children:t("settings.colorCatalog.colorName")}),i.jsx("th",{className:"px-3 py-2 text-left text-bambu-gray font-medium w-24",children:t("settings.colorCatalog.hex")}),i.jsx("th",{className:"px-3 py-2 w-16"})]})}),i.jsx("tbody",{children:de.length===0?i.jsx("tr",{children:i.jsx("td",{colSpan:6,className:"px-3 py-8 text-center text-bambu-gray",children:t(o||c?"settings.colorCatalog.noMatch":"settings.colorCatalog.empty")})}):de.map(L=>i.jsx("tr",{className:"border-t border-bambu-dark-tertiary hover:bg-bambu-dark",children:f===L.id?i.jsxs(i.Fragment,{children:[i.jsx("td",{className:"px-3 py-2",children:i.jsx("input",{type:"color",className:"w-8 h-8 rounded cursor-pointer border border-bambu-dark-tertiary",value:N,onChange:G=>C(G.target.value)})}),i.jsx("td",{className:"px-3 py-2",children:i.jsx("input",{type:"text",className:"w-full px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none",value:v,onChange:G=>g(G.target.value)})}),i.jsx("td",{className:"px-3 py-2",children:i.jsx("input",{type:"text",className:"w-full px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none",value:T,onChange:G=>P(G.target.value)})}),i.jsx("td",{className:"px-3 py-2",children:i.jsx("input",{type:"text",className:"w-full px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none",value:y,onChange:G=>_(G.target.value)})}),i.jsx("td",{className:"px-3 py-2",children:i.jsx("input",{type:"text",className:"w-full px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none",value:N,onChange:G=>C(G.target.value)})}),i.jsx("td",{className:"px-3 py-2",children:i.jsxs("div",{className:"flex justify-end gap-1",children:[i.jsx("button",{onClick:()=>we(L.id),disabled:k,className:"p-1.5 rounded hover:bg-green-500/20 text-green-500",children:k?i.jsx(lt,{className:"w-4 h-4 animate-spin"}):i.jsx(Vr,{className:"w-4 h-4"})}),i.jsx("button",{onClick:me,className:"p-1.5 rounded hover:bg-bambu-dark-tertiary text-bambu-gray",children:i.jsx(zt,{className:"w-4 h-4"})})]})})]}):i.jsxs(i.Fragment,{children:[i.jsx("td",{className:"px-3 py-2",children:i.jsx("div",{className:"w-8 h-8 rounded border border-bambu-dark-tertiary",style:{backgroundColor:L.hex_color},title:L.hex_color})}),i.jsx("td",{className:"px-3 py-2 text-white",children:L.manufacturer}),i.jsx("td",{className:"px-3 py-2 text-bambu-gray",children:L.material||"-"}),i.jsx("td",{className:"px-3 py-2 text-white",children:L.color_name}),i.jsx("td",{className:"px-3 py-2 font-mono text-xs text-bambu-gray",children:L.hex_color}),i.jsx("td",{className:"px-3 py-2",children:i.jsxs("div",{className:"flex justify-end gap-1",children:[i.jsx("button",{onClick:()=>oe(L),className:"p-1.5 rounded hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white",children:i.jsx(Ki,{className:"w-4 h-4"})}),i.jsx("button",{onClick:()=>O(L),className:"p-1.5 rounded bg-red-500/10 hover:bg-red-500/20 text-red-500",children:i.jsx(Qt,{className:"w-4 h-4"})})]})})]})},L.id))})]})})]}),W&&i.jsx(_n,{title:t("settings.colorCatalog.deleteColor"),message:t("settings.colorCatalog.deleteConfirm",{name:`${W.manufacturer} - ${W.color_name}`}),confirmText:t("common.delete"),variant:"danger",onConfirm:Ee,onCancel:()=>O(null)}),te&&i.jsx(_n,{title:t("settings.colorCatalog.resetCatalog"),message:t("settings.colorCatalog.resetConfirm"),confirmText:t("common.reset"),variant:"danger",onConfirm:q,onCancel:()=>ie(!1)})]})}function oJe({link:t,onClose:e}){const{t:n}=Mt(),r=Zt(),a=!!t,s=w.useRef(null),[o,l]=w.useState(t?.name||""),[c,d]=w.useState(t?.url||""),[u,m]=w.useState(t?.icon||"link"),[p,f]=w.useState(t?.open_in_new_tab||!1),[x,v]=w.useState(!!t?.custom_icon),[g,y]=w.useState(t?.custom_icon?fe.getExternalLinkIconUrl(t.id):null),[_,N]=w.useState(null),[C,T]=w.useState(null);w.useEffect(()=>{const W=O=>{O.key==="Escape"&&e()};return window.addEventListener("keydown",W),()=>window.removeEventListener("keydown",W)},[e]);const P=dt({mutationFn:async W=>{const O=await fe.createExternalLink(W);return _?await fe.uploadExternalLinkIcon(O.id,_):O},onSuccess:()=>{r.invalidateQueries({queryKey:["external-links"]}),e()},onError:W=>{T(W.message)}}),k=dt({mutationFn:async W=>{let O=await fe.updateExternalLink(t.id,W);return _?O=await fe.uploadExternalLinkIcon(t.id,_):!x&&t?.custom_icon&&(O=await fe.deleteExternalLinkIcon(t.id)),O},onSuccess:()=>{r.invalidateQueries({queryKey:["external-links"]}),e()},onError:W=>{T(W.message)}}),D=W=>{const O=W.target.files?.[0];if(O){if(!["image/png","image/jpeg","image/gif","image/svg+xml","image/webp","image/x-icon"].includes(O.type)){T("Please select a valid image file (PNG, JPG, GIF, SVG, WebP, or ICO)");return}if(O.size>1024*1024){T("Image file must be less than 1MB");return}N(O),v(!0);const ie=new FileReader;ie.onload=Y=>{y(Y.target?.result)},ie.readAsDataURL(O)}},A=()=>{N(null),y(null),v(!1),s.current&&(s.current.value="")},R=W=>{if(W.preventDefault(),T(null),!o.trim()){T("Name is required");return}if(!c.trim()){T("URL is required");return}if(!c.startsWith("http://")&&!c.startsWith("https://")){T("URL must start with http:// or https://");return}const O={name:o.trim(),url:c.trim(),icon:u,open_in_new_tab:p};a?k.mutate(O):P.mutate(O)},$=P.isPending||k.isPending,U=yC(u);return i.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",onClick:e,children:i.jsxs("div",{className:"bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-md",onClick:W=>W.stopPropagation(),children:[i.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary",children:[i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx("div",{className:"p-2 rounded-full bg-bambu-green/20 text-bambu-green",children:x&&g?i.jsx("img",{src:g,alt:"",className:"w-5 h-5 rounded"}):i.jsx(U,{className:"w-5 h-5"})}),i.jsx("h2",{className:"text-lg font-semibold text-white",children:a?"Edit Link":"Add External Link"})]}),i.jsx("button",{onClick:e,className:"text-bambu-gray hover:text-white transition-colors",children:i.jsx(zt,{className:"w-5 h-5"})})]}),i.jsxs("form",{onSubmit:R,className:"p-6 space-y-4",children:[C&&i.jsx("div",{className:"p-3 bg-red-500/20 border border-red-500/50 rounded-lg text-sm text-red-400",children:C}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Name *"}),i.jsx("input",{type:"text",value:o,onChange:W=>l(W.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"})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"URL *"}),i.jsx("input",{type:"text",value:c,onChange:W=>d(W.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"})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("label",{className:"text-sm text-bambu-gray",children:n("externalLinks.openInNewTab")}),i.jsx("button",{type:"button",onClick:()=>f(!p),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors ${p?"bg-bambu-green":"bg-bambu-dark-tertiary"}`,children:i.jsx("span",{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${p?"translate-x-6":"translate-x-1"}`})})]}),i.jsxs("div",{className:"space-y-3",children:[i.jsx("label",{className:"block text-sm text-bambu-gray",children:"Icon"}),i.jsxs("div",{className:"p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary",children:[i.jsxs("div",{className:"flex items-center justify-between mb-2",children:[i.jsx("span",{className:"text-sm text-white",children:"Custom Icon"}),i.jsx("input",{ref:s,type:"file",accept:"image/png,image/jpeg,image/gif,image/svg+xml,image/webp,image/x-icon",className:"hidden",onChange:D}),x&&g?i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("img",{src:g,alt:"Custom icon",className:"w-8 h-8 rounded border border-bambu-dark-tertiary"}),i.jsx("button",{type:"button",onClick:A,className:"p-1 text-red-400 hover:text-red-300 transition-colors",title:"Remove custom icon",children:i.jsx(Qt,{className:"w-4 h-4"})})]}):i.jsxs(Oe,{type:"button",variant:"secondary",size:"sm",onClick:()=>s.current?.click(),children:[i.jsx(Si,{className:"w-4 h-4"}),"Upload"]})]}),i.jsx("p",{className:"text-xs text-bambu-gray",children:"PNG, JPG, GIF, SVG, WebP, or ICO. Max 1MB."})]}),!x&&i.jsxs("div",{children:[i.jsx("span",{className:"text-sm text-bambu-gray block mb-2",children:"Or choose a preset icon"}),i.jsx(nbe,{value:u,onChange:m})]})]}),i.jsxs("div",{className:"flex gap-3 pt-2",children:[i.jsx(Oe,{type:"button",variant:"secondary",onClick:e,className:"flex-1",children:"Cancel"}),i.jsxs(Oe,{type:"submit",disabled:$,className:"flex-1",children:[$?i.jsx(lt,{className:"w-4 h-4 animate-spin"}):i.jsx(gs,{className:"w-4 h-4"}),a?"Save":"Add"]})]})]})]})})}function lJe(){const{t}=Mt(),e=Zt(),[n,r]=w.useState(!1),[a,s]=w.useState(null),[o,l]=w.useState(null),[c,d]=w.useState(null),{data:u,isLoading:m}=Ze({queryKey:["external-links"],queryFn:fe.getExternalLinks}),p=dt({mutationFn:N=>fe.deleteExternalLink(N),onSuccess:()=>{e.invalidateQueries({queryKey:["external-links"]})}}),f=dt({mutationFn:N=>fe.reorderExternalLinks(N),onSuccess:()=>{e.invalidateQueries({queryKey:["external-links"]})}}),x=(N,C)=>{d(C),N.dataTransfer.effectAllowed="move"},v=N=>{N.preventDefault(),N.dataTransfer.dropEffect="move"},g=(N,C)=>{if(N.preventDefault(),c===null||c===C||!u)return;const T=u.map(A=>A.id),P=T.indexOf(c),k=T.indexOf(C);if(P===-1||k===-1)return;const D=[...T];D.splice(P,1),D.splice(k,0,c),f.mutate(D),d(null)},y=N=>{l(N)},_=()=>{o&&(p.mutate(o.id),l(null))};return i.jsxs(i.Fragment,{children:[i.jsxs(Tt,{children:[i.jsx(qn,{children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(Vm,{className:"w-5 h-5 text-bambu-green"}),i.jsx("h2",{className:"text-lg font-semibold text-white",children:"Sidebar Links"})]}),i.jsxs(Oe,{size:"sm",onClick:()=>r(!0),children:[i.jsx(rr,{className:"w-4 h-4"}),"Add Link"]})]})}),i.jsxs(Pt,{children:[i.jsx("p",{className:"text-sm text-bambu-gray mb-4",children:"Add external links to the sidebar navigation. Drag to reorder."}),m?i.jsx("div",{className:"flex justify-center py-8",children:i.jsx(lt,{className:"w-6 h-6 text-bambu-green animate-spin"})}):u&&u.length>0?i.jsx("div",{className:"space-y-2",children:u.map(N=>{const C=yC(N.icon);return i.jsxs("div",{draggable:!0,onDragStart:T=>x(T,N.id),onDragOver:v,onDrop:T=>g(T,N.id),className:`flex items-center gap-3 p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary transition-colors ${c===N.id?"opacity-50":""}`,children:[i.jsx(qm,{className:"w-6 h-6 md:w-4 md:h-4 text-bambu-gray cursor-grab flex-shrink-0"}),i.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark-tertiary text-bambu-gray",children:i.jsx(C,{className:"w-4 h-4"})}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("span",{className:"text-white font-medium truncate",children:N.name}),i.jsx(ei,{className:"w-3 h-3 text-bambu-gray flex-shrink-0"})]}),i.jsx("span",{className:"text-sm text-bambu-gray truncate block",children:N.url})]}),i.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[i.jsx("button",{onClick:()=>s(N),className:"p-2 rounded-lg hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white transition-colors",title:t("common.edit"),children:i.jsx(Ki,{className:"w-4 h-4"})}),i.jsx("button",{onClick:()=>y(N),disabled:p.isPending,className:"p-2 rounded-lg hover:bg-red-500/20 text-bambu-gray hover:text-red-400 transition-colors disabled:opacity-50",title:t("externalLinks.deleteLink"),children:i.jsx(Qt,{className:"w-4 h-4"})})]})]},N.id)})}):i.jsxs("div",{className:"text-center py-8 text-bambu-gray",children:[i.jsx(Vm,{className:"w-8 h-8 mx-auto mb-2 opacity-50"}),i.jsx("p",{children:t("externalLinks.noLinksConfigured")}),i.jsx("p",{className:"text-sm",children:'Click "Add Link" to add one'})]})]})]}),(n||a)&&i.jsx(oJe,{link:a,onClose:()=>{r(!1),s(null)}}),o&&i.jsx(_n,{title:"Delete Link",message:`Are you sure you want to delete "${o.name}"? This action cannot be undone.`,confirmText:"Delete",cancelText:"Cancel",variant:"danger",onConfirm:_,onCancel:()=>l(null)})]})}const Wj={immediate:"archive",review:"review",print_queue:"queue",proxy:"proxy"};function cJe({printer:t,models:e}){const{t:n}=Mt(),r=Zt(),{showToast:a}=hn(),[s,o]=w.useState(!0),[l,c]=w.useState(t.enabled),[d,u]=w.useState(t.name),[m,p]=w.useState(""),[f,x]=w.useState(t.mode==="queue"?"review":t.mode),[v,g]=w.useState(t.target_printer_id),[y,_]=w.useState(t.bind_ip||""),[N,C]=w.useState(t.remote_interface_ip||""),[T,P]=w.useState(t.model||""),[k,D]=w.useState(!1),[A,R]=w.useState(null),[$,U]=w.useState(!1);w.useEffect(()=>{A||(c(t.enabled),x(t.mode==="queue"?"review":t.mode),u(t.name),g(t.target_printer_id),_(t.bind_ip||""),C(t.remote_interface_ip||""),P(t.model||""))},[t,A]);const{data:W}=Ze({queryKey:["printers"],queryFn:fe.getPrinters}),{data:O}=Ze({queryKey:["network-interfaces"],queryFn:()=>fe.getNetworkInterfaces().then(K=>K.interfaces)}),te=dt({mutationFn:K=>G1.update(t.id,K),onSuccess:()=>{r.invalidateQueries({queryKey:["virtual-printers"]}),a(n("virtualPrinter.toast.updated")),R(null)},onError:K=>{a(K.message||n("virtualPrinter.toast.failedToUpdate"),"error"),c(t.enabled),x(t.mode==="queue"?"review":t.mode),g(t.target_printer_id),_(t.bind_ip||""),R(null)}}),ie=dt({mutationFn:()=>G1.remove(t.id),onSuccess:()=>{r.invalidateQueries({queryKey:["virtual-printers"]}),a(n("virtualPrinter.toast.deleted")),U(!1)},onError:K=>{a(K.message||n("virtualPrinter.toast.failedToDelete"),"error"),U(!1)}}),Y=K=>{K.stopPropagation();const E=!l;if(E){if(!y){a(n("virtualPrinter.toast.bindIpRequired"),"error");return}if(f==="proxy"){if(!v){a(n("virtualPrinter.toast.targetPrinterRequired"),"error");return}}else if(!m&&!t.access_code_set){a(n("virtualPrinter.toast.accessCodeRequired"),"error");return}}c(E),R("toggle"),te.mutate({enabled:E})},ae=()=>{d.trim()&&(R("name"),te.mutate({name:d.trim()}))},de=()=>{if(!m){a(n("virtualPrinter.toast.accessCodeEmpty"),"error");return}if(m.length!==8){a(n("virtualPrinter.toast.accessCodeLength"),"error");return}R("accessCode"),te.mutate({access_code:m}),p("")},pe=K=>{x(K),R("mode"),te.mutate({mode:K})},Q=K=>{P(K),R("model"),te.mutate({model:K})},oe=K=>{g(K),R("targetPrinter"),te.mutate({target_printer_id:K})},me=K=>{C(K),R("remoteInterface"),te.mutate({remote_interface_ip:K})},we=t.status?.running||!1,Ee=n(`virtualPrinter.mode.${Wj[f]||"archive"}`),q=W?.find(K=>K.id===v)?.name;return i.jsxs(i.Fragment,{children:[i.jsxs(Tt,{children:[i.jsxs("div",{className:"px-4 py-3 flex items-center gap-3 cursor-pointer select-none",onClick:()=>o(!s),children:[i.jsx("button",{className:"text-bambu-gray flex-shrink-0",children:s?i.jsx(jn,{className:"w-4 h-4"}):i.jsx(fa,{className:"w-4 h-4"})}),i.jsx("span",{className:`w-2 h-2 rounded-full flex-shrink-0 ${we?"bg-green-400 animate-pulse":"bg-gray-500"}`}),i.jsx("span",{className:"text-white font-medium truncate",children:t.name}),i.jsx("span",{className:"text-xs text-bambu-gray flex-shrink-0",children:Ee}),t.model_name&&i.jsx("span",{className:"text-xs text-bambu-gray flex-shrink-0",children:t.model_name}),q&&i.jsxs("span",{className:"text-xs text-bambu-gray flex-shrink-0 truncate",children:[f==="proxy"&&i.jsx(SD,{className:"w-3 h-3 inline mr-1"}),q]}),y&&i.jsx("span",{className:"text-[10px] text-bambu-gray flex-shrink-0 font-mono",children:y}),N&&i.jsx("span",{className:"text-[10px] text-bambu-gray flex-shrink-0 font-mono",children:N}),i.jsx("div",{className:"ml-auto flex items-center gap-2 flex-shrink-0",onClick:K=>K.stopPropagation(),children:i.jsx("button",{onClick:Y,disabled:A==="toggle",className:`relative w-10 h-5 rounded-full transition-colors ${l?"bg-bambu-green":"bg-bambu-dark-tertiary"} ${A==="toggle"?"opacity-50":""}`,children:i.jsx("span",{className:`absolute top-0.5 left-0.5 w-4 h-4 bg-white rounded-full transition-transform ${l?"translate-x-5":""}`})})})]}),s&&i.jsxs(Pt,{className:"pt-0 space-y-4",children:[i.jsx("div",{className:"border-t border-bambu-dark-tertiary"}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("input",{type:"text",value:d,onChange:K=>u(K.target.value),onBlur:ae,onKeyDown:K=>K.key==="Enter"&&ae(),className:"flex-1 text-sm text-white bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-1.5 focus:border-bambu-green focus:outline-none"}),i.jsx("span",{className:"text-xs text-bambu-gray font-mono",children:t.serial}),i.jsx("button",{onClick:()=>U(!0),className:"p-1.5 text-bambu-gray hover:text-red-400 transition-colors",title:n("common.delete"),children:i.jsx(Qt,{className:"w-4 h-4"})})]}),i.jsxs("div",{children:[i.jsx("div",{className:"text-white text-sm font-medium mb-2",children:n("virtualPrinter.mode.title")}),i.jsx("div",{className:"grid grid-cols-2 gap-2",children:["immediate","review","print_queue","proxy"].map(K=>i.jsxs("button",{onClick:()=>pe(K),disabled:A==="mode",className:`p-2 rounded-lg border text-left transition-colors ${f===K?K==="proxy"?"border-blue-500 bg-blue-500/10":"border-bambu-green bg-bambu-green/10":"border-bambu-dark-tertiary hover:border-bambu-gray"}`,children:[i.jsxs("div",{className:"flex items-center gap-1.5 text-white text-xs font-medium",children:[K==="proxy"&&i.jsx(SD,{className:"w-3 h-3"}),n(`virtualPrinter.mode.${Wj[K]}`)]}),i.jsx("div",{className:"text-[10px] text-bambu-gray",children:n(`virtualPrinter.mode.${Wj[K]}Desc`)})]},K))})]}),f!=="proxy"&&i.jsxs("div",{className:"pt-2 border-t border-bambu-dark-tertiary",children:[i.jsx("div",{className:"text-white text-sm font-medium mb-1",children:n("virtualPrinter.model.title")}),i.jsx("p",{className:"text-xs text-bambu-gray mb-2",children:n("virtualPrinter.model.description")}),i.jsxs("div",{className:"relative",children:[i.jsx("select",{value:T,onChange:K=>Q(K.target.value),disabled:A==="model",className:"w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-1.5 text-white text-sm appearance-none cursor-pointer disabled:opacity-50 pr-10",children:Object.entries(e).map(([K,E])=>i.jsxs("option",{value:K,children:[E," (",K,")"]},K))}),i.jsx(jn,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]})]}),f==="proxy"&&i.jsx("div",{className:"pt-2 border-t border-bambu-dark-tertiary",children:i.jsxs("div",{className:"flex items-start gap-2 p-2 rounded bg-blue-500/10 border border-blue-500/30",children:[i.jsx(Rs,{className:"w-4 h-4 text-blue-400 flex-shrink-0 mt-0.5"}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("virtualPrinter.proxy.accessCodeHint")})]})}),f!=="proxy"&&i.jsxs("div",{className:"pt-2 border-t border-bambu-dark-tertiary",children:[i.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[i.jsx("div",{className:"text-white text-sm font-medium",children:n("virtualPrinter.accessCode.title")}),t.access_code_set?i.jsxs("span",{className:"flex items-center gap-1 text-xs text-green-400",children:[i.jsx(Vr,{className:"w-3 h-3"}),n("virtualPrinter.accessCode.isSet")]}):i.jsxs("span",{className:"flex items-center gap-1 text-xs text-yellow-400",children:[i.jsx(Cn,{className:"w-3 h-3"}),n("virtualPrinter.accessCode.notSet")]})]}),i.jsxs("div",{className:"flex gap-2",children:[i.jsxs("div",{className:"relative flex-1",children:[i.jsx("input",{type:k?"text":"password",value:m,onChange:K=>p(K.target.value),placeholder:t.access_code_set?n("virtualPrinter.accessCode.placeholderChange"):n("virtualPrinter.accessCode.placeholder"),maxLength:8,className:"w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-1.5 text-white text-sm placeholder-bambu-gray pr-10 font-mono"}),i.jsx("button",{onClick:()=>D(!k),className:"absolute right-2 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white",children:k?i.jsx(E0,{className:"w-4 h-4"}):i.jsx(rc,{className:"w-4 h-4"})})]}),i.jsx(Oe,{onClick:de,disabled:!m||A==="accessCode",variant:"primary",children:A==="accessCode"?i.jsx(lt,{className:"w-4 h-4 animate-spin"}):n("common.save")})]}),m&&i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:i.jsx("span",{className:m.length===8?"text-green-400":"text-yellow-400",children:n("virtualPrinter.accessCode.charCount",{count:m.length})})})]}),i.jsxs("div",{className:"pt-2 border-t border-bambu-dark-tertiary",children:[i.jsx("div",{className:"text-white text-sm font-medium mb-2",children:n("virtualPrinter.targetPrinter.title")}),i.jsxs("div",{className:"relative",children:[i.jsxs("select",{value:v??"",onChange:K=>{const E=parseInt(K.target.value,10);isNaN(E)||oe(E)},disabled:A==="targetPrinter",className:"w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-1.5 text-white text-sm appearance-none cursor-pointer disabled:opacity-50 pr-10",children:[i.jsx("option",{value:"",children:n("virtualPrinter.targetPrinter.placeholder")}),W?.map(K=>i.jsxs("option",{value:K.id,children:[K.name," (",K.ip_address,")"]},K.id))]}),i.jsx(jn,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]})]}),i.jsxs("div",{className:"pt-2 border-t border-bambu-dark-tertiary",children:[i.jsx("div",{className:"text-white text-sm font-medium mb-1",children:n("virtualPrinter.bindIp.title")}),i.jsxs("div",{className:"relative",children:[i.jsxs("select",{value:y,onChange:K=>{_(K.target.value),R("bindIp"),te.mutate({bind_ip:K.target.value})},disabled:A==="bindIp",className:"w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-1.5 text-white text-sm appearance-none cursor-pointer disabled:opacity-50 pr-10",children:[i.jsx("option",{value:"",children:n("virtualPrinter.bindIp.placeholder")}),O?.map(K=>i.jsxs("option",{value:K.ip,children:[K.name," (",K.ip,")",K.is_alias?" [alias]":""," - ",K.subnet]},K.ip))]}),i.jsx(jn,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:n("virtualPrinter.bindIp.hint")})]}),i.jsxs("div",{className:"pt-2 border-t border-bambu-dark-tertiary",children:[i.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[i.jsx("div",{className:"text-white text-sm font-medium",children:n("virtualPrinter.remoteInterface.title")}),N?i.jsx("span",{className:"flex items-center gap-1 text-xs text-green-400",children:i.jsx(Vr,{className:"w-3 h-3"})}):i.jsx("span",{className:"flex items-center gap-1 text-xs text-bambu-gray",title:n("virtualPrinter.remoteInterface.optional"),children:i.jsx(Rs,{className:"w-3 h-3"})})]}),i.jsxs("div",{className:"relative",children:[i.jsxs("select",{value:N,onChange:K=>me(K.target.value),disabled:A==="remoteInterface",className:"w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-1.5 text-white text-sm appearance-none cursor-pointer disabled:opacity-50 pr-10",children:[i.jsx("option",{value:"",children:n("virtualPrinter.remoteInterface.placeholder")}),O?.map(K=>i.jsxs("option",{value:K.ip,children:[K.name," (",K.ip,") - ",K.subnet]},K.ip))]}),i.jsx(jn,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]})]})]})]}),$&&i.jsx(_n,{title:n("virtualPrinter.deleteConfirm.title"),message:n("virtualPrinter.deleteConfirm.message",{name:t.name}),variant:"danger",confirmText:n("common.delete"),isLoading:ie.isPending,onConfirm:()=>ie.mutate(),onCancel:()=>U(!1)})]})}const TK={immediate:"archive",review:"review",print_queue:"queue",proxy:"proxy"};function dJe({onClose:t}){const{t:e}=Mt(),n=Zt(),{showToast:r}=hn(),[a,s]=w.useState(""),[o,l]=w.useState("immediate"),[c,d]=w.useState(null),{data:u}=Ze({queryKey:["printers"],queryFn:fe.getPrinters}),m=dt({mutationFn:()=>G1.create({name:a.trim()||"Bambuddy",mode:o,target_printer_id:o==="proxy"?c??void 0:void 0}),onSuccess:()=>{n.invalidateQueries({queryKey:["virtual-printers"]}),r(e("virtualPrinter.toast.created")),t()},onError:p=>{r(p.message||e("virtualPrinter.toast.failedToCreate"),"error")}});return i.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",onClick:t,children:i.jsx(Tt,{className:"w-full max-w-md",onClick:p=>p.stopPropagation(),children:i.jsxs(Pt,{className:"p-6 space-y-4",children:[i.jsx("h3",{className:"text-lg font-semibold text-white",children:e("virtualPrinter.addDialog.title")}),i.jsxs("div",{children:[i.jsx("label",{className:"text-sm text-white font-medium block mb-1",children:e("virtualPrinter.addDialog.name")}),i.jsx("input",{type:"text",value:a,onChange:p=>s(p.target.value),placeholder:"Bambuddy",className:"w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-2 text-white text-sm placeholder-bambu-gray",autoFocus:!0})]}),i.jsxs("div",{children:[i.jsx("label",{className:"text-sm text-white font-medium block mb-1",children:e("virtualPrinter.mode.title")}),i.jsx("div",{className:"grid grid-cols-2 gap-2",children:["immediate","review","print_queue","proxy"].map(p=>i.jsxs("button",{onClick:()=>l(p),className:`p-2 rounded-lg border text-left transition-colors ${o===p?p==="proxy"?"border-blue-500 bg-blue-500/10":"border-bambu-green bg-bambu-green/10":"border-bambu-dark-tertiary hover:border-bambu-gray"}`,children:[i.jsxs("div",{className:"flex items-center gap-1.5 text-white text-xs font-medium",children:[p==="proxy"&&i.jsx(SD,{className:"w-3 h-3"}),e(`virtualPrinter.mode.${TK[p]}`)]}),i.jsx("div",{className:"text-[10px] text-bambu-gray",children:e(`virtualPrinter.mode.${TK[p]}Desc`)})]},p))})]}),o==="proxy"&&i.jsxs("div",{children:[i.jsx("label",{className:"text-sm text-white font-medium block mb-1",children:e("virtualPrinter.targetPrinter.title")}),i.jsxs("div",{className:"relative",children:[i.jsxs("select",{value:c??"",onChange:p=>{const f=parseInt(p.target.value,10);d(isNaN(f)?null:f)},className:"w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-2 text-white text-sm appearance-none cursor-pointer pr-10",children:[i.jsx("option",{value:"",children:e("virtualPrinter.targetPrinter.placeholder")}),u?.map(p=>i.jsxs("option",{value:p.id,children:[p.name," (",p.ip_address,")"]},p.id))]}),i.jsx(jn,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]})]}),i.jsx("p",{className:"text-xs text-bambu-gray",children:e("virtualPrinter.addDialog.hint")}),i.jsxs("div",{className:"flex gap-3 pt-2",children:[i.jsx(Oe,{variant:"secondary",onClick:t,className:"flex-1",disabled:m.isPending,children:e("common.cancel")}),i.jsx(Oe,{variant:"primary",onClick:()=>m.mutate(),className:"flex-1",disabled:m.isPending,children:m.isPending?i.jsx(lt,{className:"w-4 h-4 animate-spin"}):e("virtualPrinter.addDialog.create")})]})]})})})}function uJe(){const{t}=Mt(),[e,n]=w.useState(!1),{data:r,isLoading:a}=Ze({queryKey:["virtual-printers"],queryFn:G1.list,refetchInterval:1e4});if(a)return i.jsx(Tt,{children:i.jsx(Pt,{className:"py-8 flex justify-center",children:i.jsx(lt,{className:"w-6 h-6 animate-spin text-bambu-green"})})});const s=r?.printers||[],o=r?.models||{};return i.jsxs("div",{className:"space-y-4",children:[i.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-4 gap-4 items-stretch",children:[i.jsx(Tt,{className:"border-l-4 border-l-yellow-500",children:i.jsx(Pt,{className:"py-3 px-4",children:i.jsxs("div",{className:"flex items-start gap-2",children:[i.jsx(Cn,{className:"w-4 h-4 text-yellow-500 flex-shrink-0 mt-0.5"}),i.jsxs("div",{className:"text-xs",children:[i.jsx("p",{className:"text-white font-medium",children:t("virtualPrinter.setupRequired.title")}),i.jsx("p",{className:"text-bambu-gray mt-1",children:t("virtualPrinter.setupRequired.description")}),i.jsxs("a",{href:"https://wiki.bambuddy.cool/features/virtual-printer/",target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1.5 mt-2 px-3 py-1.5 bg-yellow-500/20 border border-yellow-500/50 rounded text-yellow-400 hover:bg-yellow-500/30 transition-colors text-xs",children:[i.jsx(ei,{className:"w-3 h-3"}),t("virtualPrinter.setupRequired.readGuide")]})]})]})})}),i.jsx(Tt,{className:"lg:col-span-3",children:i.jsx(Pt,{className:"py-3 px-4",children:i.jsxs("div",{className:"flex items-start gap-2",children:[i.jsx(Rs,{className:"w-4 h-4 text-blue-400 flex-shrink-0 mt-0.5"}),i.jsxs("div",{className:"text-xs text-bambu-gray",children:[i.jsx("p",{className:"text-white font-medium mb-1",children:t("virtualPrinter.howItWorks.title")}),i.jsxs("ul",{className:"space-y-1 list-disc list-inside",children:[i.jsx("li",{children:t("virtualPrinter.howItWorks.step1")}),i.jsx("li",{children:t("virtualPrinter.howItWorks.step2")}),i.jsx("li",{children:t("virtualPrinter.howItWorks.step3")})]})]})]})})})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(_r,{className:"w-5 h-5 text-bambu-green"}),i.jsx("h2",{className:"text-lg font-semibold text-white",children:t("virtualPrinter.list.title")}),i.jsxs("span",{className:"text-sm text-bambu-gray",children:["(",s.length,")"]})]}),i.jsxs(Oe,{variant:"primary",onClick:()=>n(!0),children:[i.jsx(rr,{className:"w-4 h-4 mr-1"}),t("virtualPrinter.list.add")]})]}),s.length===0?i.jsx(Tt,{children:i.jsxs(Pt,{className:"py-8 text-center",children:[i.jsx(_r,{className:"w-12 h-12 text-bambu-gray mx-auto mb-3"}),i.jsx("p",{className:"text-bambu-gray mb-4",children:t("virtualPrinter.list.empty")}),i.jsxs(Oe,{variant:"primary",onClick:()=>n(!0),children:[i.jsx(rr,{className:"w-4 h-4 mr-1"}),t("virtualPrinter.list.addFirst")]})]})}):i.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-4 items-start",children:s.map(l=>i.jsx(cJe,{printer:l,models:o},l.id))}),e&&i.jsx(dJe,{onClose:()=>n(!1)})]})}function mJe(t){return t?new Date(t).toLocaleString():"-"}function PK({status:t}){if(!t)return null;const e={success:"bg-green-500/20 text-green-400",failed:"bg-red-500/20 text-red-400",skipped:"bg-yellow-500/20 text-yellow-400",running:"bg-blue-500/20 text-blue-400"},n={success:i.jsx(pr,{className:"w-3 h-3"}),failed:i.jsx(Vi,{className:"w-3 h-3"}),skipped:i.jsx(XF,{className:"w-3 h-3"}),running:i.jsx(lt,{className:"w-3 h-3 animate-spin"})};return i.jsxs("span",{className:`inline-flex items-center gap-1 px-2 py-0.5 rounded text-xs font-medium ${e[t]||"bg-gray-500/20 text-gray-400"}`,children:[n[t],t.charAt(0).toUpperCase()+t.slice(1)]})}function hJe(){const t=Zt(),{showToast:e}=hn(),{t:n}=Mt(),[r,a]=w.useState(""),[s,o]=w.useState(""),[l,c]=w.useState("main"),[d,u]=w.useState(!1),[m,p]=w.useState("daily"),[f,x]=w.useState(!0),[v,g]=w.useState(!0),[y,_]=w.useState(!1),[N,C]=w.useState(!0),[T,P]=w.useState(!1),[k,D]=w.useState(!1),[A,R]=w.useState(""),[$,U]=w.useState(!1),[W,O]=w.useState(null),[te,ie]=w.useState(null),Y=w.useRef(null);w.useEffect(()=>{if(T||k){const I=F=>(F.preventDefault(),F.returnValue="A backup operation is in progress. Are you sure you want to leave?",F.returnValue);return window.addEventListener("beforeunload",I),()=>window.removeEventListener("beforeunload",I)}},[T,k]);const[ae,de]=w.useState(!1),[pe,Q]=w.useState(null),oe=w.useRef(null),me=w.useRef(!1),{data:we,isLoading:Ee}=Ze({queryKey:["github-backup-config"],queryFn:fe.getGitHubBackupConfig}),{data:q}=Ze({queryKey:["github-backup-status"],queryFn:fe.getGitHubBackupStatus,refetchInterval:le=>le.state.data?.is_running?500:1e4}),{data:K}=Ze({queryKey:["github-backup-logs"],queryFn:()=>fe.getGitHubBackupLogs(20)}),{data:E}=Ze({queryKey:["cloud-status"],queryFn:fe.getCloudStatus}),{data:j}=Ze({queryKey:["printers"],queryFn:fe.getPrinters}),L=ox({queries:(j??[]).map(le=>({queryKey:["printerStatus",le.id],queryFn:()=>fe.getPrinterStatus(le.id),staleTime:1e4,refetchInterval:3e4}))}),G=(j??[]).map((le,I)=>({printer:le,connected:L[I]?.data?.connected??!1})),B=G.length,re=G.filter(le=>le.connected).length,z=B>0&&re===0,V=re>0&&re{we&&(a(we.repository_url),c(we.branch),u(we.schedule_enabled),p(we.schedule_type),x(we.backup_kprofiles),g(we.backup_cloud_profiles),_(we.backup_settings),C(we.enabled),o(""),setTimeout(()=>{me.current=!0},100))},[we]);const ee=w.useCallback(async(le=!1)=>{if(we?.has_token)try{le&&s?(await fe.saveGitHubBackupConfig({repository_url:r,access_token:s,branch:l,schedule_enabled:d,schedule_type:m,backup_kprofiles:f,backup_cloud_profiles:v,backup_settings:y,enabled:N}),o(""),e(n("backup.tokenUpdated"))):(await fe.updateGitHubBackupConfig({repository_url:r,branch:l,schedule_enabled:d,schedule_type:m,backup_kprofiles:f,backup_cloud_profiles:v,backup_settings:y,enabled:N}),e(n("backup.settingsSaved"))),t.invalidateQueries({queryKey:["github-backup-config"]}),t.invalidateQueries({queryKey:["github-backup-status"]})}catch(I){e(n("backup.failedToSave",{message:I.message}),"error")}},[we?.has_token,r,s,l,d,m,f,v,y,N,t,e]);w.useEffect(()=>{if(!(!me.current||!we?.has_token))return oe.current&&clearTimeout(oe.current),oe.current=setTimeout(()=>{ee(!1)},500),()=>{oe.current&&clearTimeout(oe.current)}},[r,l,d,m,f,v,y,N,ee,we?.has_token]),w.useEffect(()=>{if(!(!me.current||!we?.has_token||!s))return oe.current&&clearTimeout(oe.current),oe.current=setTimeout(()=>{ee(!0)},1e3),()=>{oe.current&&clearTimeout(oe.current)}},[s,ee,we?.has_token]);const J=dt({mutationFn:le=>fe.saveGitHubBackupConfig(le),onSuccess:()=>{t.invalidateQueries({queryKey:["github-backup-config"]}),t.invalidateQueries({queryKey:["github-backup-status"]}),e(n("backup.githubBackupEnabled")),o(""),me.current=!0},onError:le=>{e(n("backup.failedToSave",{message:le.message}),"error")}}),ne=dt({mutationFn:fe.triggerGitHubBackup,onSuccess:le=>{t.invalidateQueries({queryKey:["github-backup-status"]}),t.invalidateQueries({queryKey:["github-backup-logs"]}),le.success?le.files_changed>0?e(n("backup.backupCompleteFiles",{count:le.files_changed})):e(n("backup.backupSkippedNoChanges")):e(n("backup.backupFailed2",{message:le.message}),"error")},onError:le=>{e(n("backup.backupFailed2",{message:le.message}),"error")}}),se=dt({mutationFn:()=>fe.clearGitHubBackupLogs(0),onSuccess:le=>{t.invalidateQueries({queryKey:["github-backup-logs"]}),e(n("backup.clearedLogs",{count:le.deleted}))},onError:le=>{e(n("backup.failedToClearLogs",{message:le.message}),"error")}}),ue=async()=>{de(!0),Q(null);try{let le;if(s){if(!r){e(n("backup.enterRepoUrl"),"error"),de(!1);return}le=await fe.testGitHubConnection(r,s)}else if(we?.has_token)le=await fe.testGitHubStoredConnection();else{e(n("backup.enterRepoAndToken"),"error"),de(!1);return}Q({success:le.success,message:le.message})}catch(le){Q({success:!1,message:le.message})}finally{de(!1)}},ge=()=>{if(!r){e(n("backup.repoRequired"),"error");return}if(!s){e(n("backup.tokenRequired"),"error");return}J.mutate({repository_url:r,access_token:s,branch:l,schedule_enabled:d,schedule_type:m,backup_kprofiles:f,backup_cloud_profiles:v,backup_settings:y,enabled:N})};return Ee?i.jsx("div",{className:"flex items-center justify-center py-12",children:i.jsx(lt,{className:"w-8 h-8 animate-spin text-bambu-green"})}):i.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[i.jsxs("div",{className:"space-y-6",children:[i.jsxs(Tt,{children:[i.jsx(qn,{children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(ND,{className:"w-5 h-5 text-gray-400"}),i.jsx("h2",{className:"text-lg font-semibold text-white",children:n("backup.githubBackup")})]}),we&&E?.is_authenticated&&i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("span",{className:"text-sm text-bambu-gray",children:n("backup.enabled")}),i.jsx($n,{checked:N,onChange:C})]})]})}),i.jsx(Pt,{className:"space-y-4",children:E?.is_authenticated?i.jsxs(i.Fragment,{children:[i.jsx("p",{className:"text-sm text-bambu-gray",children:n("backup.githubDescription")}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("backup.repositoryUrl")}),i.jsx("input",{type:"text",value:r,onChange:le=>{a(le.target.value),Q(null)},placeholder:"https://github.com/username/bambuddy-backup",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]}),i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[n("backup.personalAccessToken")," ",we?.has_token&&i.jsx("span",{className:"text-green-400",children:n("backup.tokenSaved")})]}),i.jsx("input",{type:"password",value:s,onChange:le=>{o(le.target.value),Q(null)},placeholder:we?.has_token?n("backup.enterNewToken"):"ghp_xxxxxxxxxxxx",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:n("backup.tokenHint")})]}),i.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("backup.branch")}),i.jsx("input",{type:"text",value:l,onChange:le=>c(le.target.value),placeholder:"main",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("backup.autoBackup")}),i.jsxs("select",{value:d?m:"disabled",onChange:le=>{le.target.value==="disabled"?u(!1):(u(!0),p(le.target.value))},className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[i.jsx("option",{value:"disabled",children:n("backup.manualOnly")}),i.jsx("option",{value:"hourly",children:n("backup.hourly")}),i.jsx("option",{value:"daily",children:n("backup.daily")}),i.jsx("option",{value:"weekly",children:n("backup.weekly")})]})]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-2",children:n("backup.includeInBackup")}),i.jsxs("div",{className:"space-y-2",children:[i.jsxs("label",{className:`flex items-start gap-2 ${z?"cursor-not-allowed opacity-60":"cursor-pointer"}`,children:[i.jsx("input",{type:"checkbox",checked:f,onChange:le=>x(le.target.checked),className:"w-4 h-4 mt-0.5 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green",disabled:z}),i.jsxs("div",{className:"flex-1",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("span",{className:`text-sm ${z?"text-bambu-gray":"text-white"}`,children:n("backup.kProfiles")}),z&&i.jsxs("span",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-xs bg-yellow-500/20 text-yellow-400",children:[i.jsx(Cn,{className:"w-3 h-3"}),n("backup.noPrintersConnected")]}),V&&i.jsxs("span",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-xs bg-yellow-500/20 text-yellow-400",children:[i.jsx(Cn,{className:"w-3 h-3"}),n("backup.printersConnected",{connected:re,total:B})]})]}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("backup.kProfilesDescription")})]})]}),i.jsxs("label",{className:"flex items-start gap-2 cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:v,onChange:le=>g(le.target.checked),className:"w-4 h-4 mt-0.5 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green",disabled:!E?.is_authenticated}),i.jsxs("div",{children:[i.jsx("span",{className:`text-sm ${E?.is_authenticated?"text-white":"text-bambu-gray"}`,children:n("backup.cloudProfiles")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("backup.cloudProfilesDescription")})]})]}),i.jsxs("label",{className:"flex items-start gap-2 cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:y,onChange:le=>_(le.target.checked),className:"w-4 h-4 mt-0.5 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),i.jsxs("div",{children:[i.jsx("span",{className:"text-white text-sm",children:n("backup.appSettings")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("backup.appSettingsDescription")})]})]})]})]}),i.jsxs("div",{className:"border-t border-bambu-dark-tertiary pt-4 space-y-3",children:[q?.configured&&i.jsxs("div",{className:"flex items-center justify-between text-sm",children:[i.jsx("div",{className:"flex items-center gap-2 text-bambu-gray",children:q.last_backup_at?i.jsxs(i.Fragment,{children:[i.jsxs("span",{children:[n("backup.lastBackupAt")," ",Iv(q.last_backup_at,"system",n)]}),i.jsx(PK,{status:q.last_backup_status})]}):i.jsx("span",{children:n("backup.noBackupsYet")})}),q.next_scheduled_run&&i.jsxs("span",{className:"text-bambu-gray",children:[i.jsx(Xn,{className:"w-3 h-3 inline mr-1"}),n("backup.next")," ",Iv(q.next_scheduled_run,"system",n)]})]}),pe&&i.jsxs("div",{className:`text-sm flex items-center gap-1 ${pe.success?"text-green-400":"text-red-400"}`,children:[pe.success?i.jsx(pr,{className:"w-4 h-4"}):i.jsx(Vi,{className:"w-4 h-4"}),pe.message]}),i.jsx("div",{className:"flex flex-wrap items-center gap-2",children:q?.configured?i.jsx(i.Fragment,{children:ne.isPending||q.is_running?i.jsxs("div",{className:"flex items-center gap-2 text-bambu-green",children:[i.jsx(lt,{className:"w-4 h-4 animate-spin"}),i.jsx("span",{className:"text-sm",children:q.progress||n("backup.startingBackup")})]}):i.jsxs(i.Fragment,{children:[i.jsxs(Oe,{variant:"primary",size:"sm",onClick:()=>ne.mutate(),disabled:!we?.enabled,children:[i.jsx(uo,{className:"w-4 h-4"}),n("backup.backupNow")]}),i.jsxs(Oe,{variant:"secondary",size:"sm",onClick:ue,disabled:ae,children:[ae?i.jsx(lt,{className:"w-4 h-4 animate-spin"}):i.jsx(Sr,{className:"w-4 h-4"}),n("backup.test")]})]})}):i.jsxs(i.Fragment,{children:[i.jsxs(Oe,{variant:"primary",size:"sm",onClick:ge,disabled:J.isPending||!r||!s,children:[J.isPending?i.jsx(lt,{className:"w-4 h-4 animate-spin"}):i.jsx(pr,{className:"w-4 h-4"}),n("backup.enableBackup")]}),i.jsxs(Oe,{variant:"secondary",size:"sm",onClick:ue,disabled:ae||!r||!s,children:[ae?i.jsx(lt,{className:"w-4 h-4 animate-spin"}):i.jsx(Sr,{className:"w-4 h-4"}),n("backup.testConnection")]})]})})]})]}):i.jsxs("div",{className:"flex items-start gap-2 p-3 bg-yellow-500/10 border border-yellow-500/30 rounded-lg",children:[i.jsx(Cn,{className:"w-4 h-4 text-yellow-400 mt-0.5 flex-shrink-0"}),i.jsx("p",{className:"text-sm text-yellow-400",children:n("backup.cloudLoginRequired")})]})})]}),K&&K.length>0&&i.jsxs(Tt,{children:[i.jsx(qn,{children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(Fv,{className:"w-5 h-5 text-gray-400"}),i.jsx("h2",{className:"text-lg font-semibold text-white",children:n("backup.history")})]}),i.jsxs(Oe,{variant:"ghost",size:"sm",onClick:()=>se.mutate(),disabled:se.isPending,children:[i.jsx(Qt,{className:"w-4 h-4"}),n("backup.clear")]})]})}),i.jsx(Pt,{children:i.jsx("div",{className:"overflow-x-auto",children:i.jsxs("table",{className:"w-full text-sm",children:[i.jsx("thead",{children:i.jsxs("tr",{className:"text-bambu-gray border-b border-bambu-dark-tertiary",children:[i.jsx("th",{className:"text-left py-2 px-2",children:n("backup.date")}),i.jsx("th",{className:"text-left py-2 px-2",children:n("backup.status")}),i.jsx("th",{className:"text-left py-2 px-2",children:n("backup.commit")})]})}),i.jsx("tbody",{children:K.slice(0,10).map(le=>i.jsxs("tr",{className:"border-b border-bambu-dark-tertiary/50 hover:bg-bambu-dark-secondary",children:[i.jsx("td",{className:"py-2 px-2 text-white",children:mJe(le.started_at)}),i.jsx("td",{className:"py-2 px-2",children:i.jsx(PK,{status:le.status})}),i.jsx("td",{className:"py-2 px-2",children:le.commit_sha?i.jsxs("a",{href:`${we?.repository_url}/commit/${le.commit_sha}`,target:"_blank",rel:"noopener noreferrer",className:"text-bambu-green hover:underline inline-flex items-center gap-1",children:[le.commit_sha.substring(0,7),i.jsx(ei,{className:"w-3 h-3"})]}):i.jsx("span",{className:"text-bambu-gray",children:"-"})})]},le.id))})]})})})]})]}),i.jsx("div",{className:"space-y-6",children:i.jsxs(Tt,{children:[i.jsx(qn,{children:i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(Uc,{className:"w-5 h-5 text-gray-400"}),i.jsx("h2",{className:"text-lg font-semibold text-white",children:n("backup.localBackup")})]})}),i.jsxs(Pt,{className:"space-y-4",children:[i.jsx("p",{className:"text-sm text-bambu-gray",children:n("backup.localBackupDescription")}),i.jsxs("div",{className:"flex items-center justify-between py-3 border-b border-bambu-dark-tertiary",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-white",children:n("backup.downloadBackupLabel")}),i.jsx("p",{className:"text-sm text-bambu-gray",children:n("backup.completeBackupZip")})]}),i.jsxs(Oe,{variant:"secondary",size:"sm",disabled:T||k,onClick:async()=>{P(!0),R(n("backup.preparingBackup"));try{R(n("backup.creatingArchive"));const{blob:le,filename:I}=await fe.exportBackup();R(n("backup.downloadingFile"));const F=URL.createObjectURL(le),Z=document.createElement("a");Z.href=F,Z.download=I,Z.click(),URL.revokeObjectURL(F),e(n("backup.backupDownloaded"))}catch(le){e(n("backup.failedToCreateBackup",{message:le instanceof Error?le.message:"Unknown error"}),"error")}finally{P(!1),R("")}},children:[i.jsx(hi,{className:"w-4 h-4"}),n("backup.download")]})]}),i.jsxs("div",{className:"flex items-center justify-between py-3 border-b border-bambu-dark-tertiary",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-white",children:n("backup.restoreBackup")}),i.jsx("p",{className:"text-sm text-bambu-gray",children:n("backup.restoreDescription")}),i.jsx("p",{className:"text-xs text-bambu-gray-light mt-1",children:n("backup.restoreNote")})]}),i.jsx("input",{ref:Y,type:"file",accept:".zip",className:"hidden",onChange:le=>{const I=le.target.files?.[0];I&&(O(I),U(!0)),le.target.value=""}}),i.jsxs(Oe,{variant:"secondary",size:"sm",disabled:k||T,onClick:()=>Y.current?.click(),children:[i.jsx(Si,{className:"w-4 h-4"}),n("backup.restore")]})]}),te&&i.jsx("div",{className:`p-3 rounded-lg ${te.success?"bg-green-500/10 border border-green-500/30":"bg-red-500/10 border border-red-500/30"}`,children:i.jsxs("div",{className:"flex items-start gap-2 text-sm",children:[te.success?i.jsx(pr,{className:"w-4 h-4 text-green-400 mt-0.5 flex-shrink-0"}):i.jsx(Vi,{className:"w-4 h-4 text-red-400 mt-0.5 flex-shrink-0"}),i.jsxs("div",{className:te.success?"text-green-200":"text-red-200",children:[te.message,te.success&&i.jsx("div",{className:"mt-2",children:i.jsxs(Oe,{size:"sm",onClick:()=>window.location.reload(),children:[i.jsx(mo,{className:"w-3 h-3"}),n("backup.reloadNow")]})})]})]})}),i.jsx("div",{className:"p-3 rounded-lg bg-yellow-500/10 border border-yellow-500/30",children:i.jsxs("div",{className:"flex items-start gap-2 text-sm",children:[i.jsx(Cn,{className:"w-4 h-4 text-yellow-400 mt-0.5 flex-shrink-0"}),i.jsxs("div",{className:"text-yellow-200",children:[i.jsx("span",{className:"font-medium",children:n("backup.restoreReplacesAll")})," ",i.jsx("span",{className:"text-yellow-200/70",children:n("backup.restoreReplacesAllDetail")})]})]})})]})]})}),$&&W&&i.jsx(_n,{title:n("backup.restoreConfirmTitle"),message:n("backup.restoreConfirmMessage",{filename:W.name}),confirmText:n("backup.restoreConfirmButton"),variant:"danger",onConfirm:async()=>{U(!1),D(!0),ie(null);try{R(n("backup.uploadingFile"));const le=await fe.importBackup(W);ie(le),le.success?e(n("backup.backupRestoredRestart"),"success"):e(le.message,"error")}catch(le){const I=le instanceof Error?le.message:n("backup.failedToRestore");ie({success:!1,message:I}),e(I,"error")}finally{D(!1),R(""),O(null)}},onCancel:()=>{U(!1),O(null)}}),(T||k)&&i.jsx("div",{className:"fixed inset-0 bg-black/80 flex items-center justify-center z-[100]",children:i.jsxs("div",{className:"bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl p-8 max-w-md w-full mx-4 text-center",children:[i.jsx("div",{className:"flex justify-center mb-4",children:i.jsxs("div",{className:"relative",children:[i.jsx("div",{className:"w-16 h-16 border-4 border-bambu-dark-tertiary rounded-full"}),i.jsx("div",{className:"w-16 h-16 border-4 border-bambu-green border-t-transparent rounded-full absolute inset-0 animate-spin"})]})}),i.jsx("h3",{className:"text-xl font-semibold text-white mb-2",children:n(T?"backup.creatingBackup":"backup.restoringBackup")}),i.jsx("p",{className:"text-bambu-gray mb-4",children:A||n(T?"backup.preparing":"backup.processing")}),i.jsx("div",{className:"p-3 rounded-lg bg-yellow-500/10 border border-yellow-500/30",children:i.jsxs("div",{className:"flex items-start gap-2 text-sm",children:[i.jsx(Cn,{className:"w-4 h-4 text-yellow-400 mt-0.5 flex-shrink-0"}),i.jsx("p",{className:"text-yellow-200 text-left",children:n("backup.doNotClosePage")})]})})]})})]})}const pJe={starttls:587,ssl:465,none:25},fJe={587:"starttls",465:"ssl",25:"none"};function gJe(){const{t}=Mt(),{showToast:e}=hn(),n=Zt(),[r,a]=w.useState({smtp_host:"",smtp_port:587,smtp_username:"",smtp_password:"",smtp_security:"starttls",smtp_auth_enabled:!0,smtp_from_email:"",smtp_from_name:"BamBuddy"}),[s,o]=w.useState(""),{data:l,isLoading:c}=Ze({queryKey:["smtpSettings"],queryFn:()=>fe.getSMTPSettings()}),{data:d}=Ze({queryKey:["advancedAuthStatus"],queryFn:()=>fe.getAdvancedAuthStatus()});w.useEffect(()=>{l&&a({...l,smtp_password:""})},[l]);const u=P=>{a({...r,smtp_security:P,smtp_port:pJe[P]})},m=P=>{const k=fJe[P];a({...r,smtp_port:P,...k?{smtp_security:k}:{}})},p=P=>{a({...r,smtp_auth_enabled:P,...P?{}:{smtp_username:"",smtp_password:""}})},f=dt({mutationFn:P=>fe.saveSMTPSettings(P),onSuccess:()=>{n.invalidateQueries({queryKey:["smtpSettings"]}),n.invalidateQueries({queryKey:["advancedAuthStatus"]}),e(t("settings.email.success.settingsSaved"),"success")},onError:P=>{e(P.message,"error")}}),x=dt({mutationFn:P=>fe.testSMTP(P),onSuccess:P=>{e(P.message,P.success?"success":"error")},onError:P=>{e(P.message,"error")}}),v=dt({mutationFn:P=>P?fe.enableAdvancedAuth():fe.disableAdvancedAuth(),onSuccess:P=>{n.invalidateQueries({queryKey:["advancedAuthStatus"]}),e(P.message,"success")},onError:P=>{e(P.message,"error")}}),g=()=>{if(!r.smtp_host||!r.smtp_from_email){e(t("settings.email.errors.requiredFields"),"error");return}if(r.smtp_auth_enabled&&!r.smtp_username){e(t("settings.email.errors.usernameRequired"),"error");return}f.mutate(r)},y=()=>{if(!s){e(t("settings.email.errors.enterTestEmail"),"error");return}if(!r.smtp_host||!r.smtp_from_email){e(t("settings.email.errors.smtpServerAndEmail"),"error");return}if(r.smtp_auth_enabled&&(!r.smtp_username||!r.smtp_password)){e(t("settings.email.errors.usernamePasswordRequired"),"error");return}x.mutate({smtp_host:r.smtp_host,smtp_port:r.smtp_port,smtp_username:r.smtp_username,smtp_password:r.smtp_password,smtp_security:r.smtp_security,smtp_auth_enabled:r.smtp_auth_enabled,smtp_from_email:r.smtp_from_email,test_recipient:s})},_=()=>{if(!d?.advanced_auth_enabled&&!d?.smtp_configured){e(t("settings.email.errors.configureSmtpFirst"),"error");return}v.mutate(!d?.advanced_auth_enabled)};if(c)return i.jsx("div",{className:"flex items-center justify-center p-12",children:i.jsx(lt,{className:"w-8 h-8 animate-spin text-bambu-green"})});const N=d?.advanced_auth_enabled??!1,C="w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors",T="w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white/40 placeholder-bambu-gray/40 cursor-not-allowed";return i.jsxs("div",{className:"space-y-6",children:[i.jsxs(Tt,{children:[i.jsx(qn,{children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(Lv,{className:"w-5 h-5 text-bambu-green"}),i.jsx("h2",{className:"text-lg font-semibold text-white",children:t("settings.email.advancedAuth")||"Advanced Authentication"})]}),i.jsx(Oe,{onClick:_,disabled:v.isPending,variant:N?"danger":"primary",children:N?i.jsxs(i.Fragment,{children:[i.jsx(o1,{className:"w-4 h-4"}),t("settings.email.disable")||"Disable"]}):i.jsxs(i.Fragment,{children:[i.jsx(Jh,{className:"w-4 h-4"}),t("settings.email.enable")||"Enable"]})})]})}),i.jsx(Pt,{children:i.jsx("div",{className:"space-y-4",children:N?i.jsx("div",{className:"bg-green-500/10 border border-green-500/30 rounded-lg p-4",children:i.jsxs("div",{className:"flex items-start gap-3",children:[i.jsx(pr,{className:"w-5 h-5 text-green-400 mt-0.5 flex-shrink-0"}),i.jsxs("div",{className:"space-y-2",children:[i.jsx("p",{className:"text-white font-medium",children:t("settings.email.advancedAuthEnabled")||"Advanced Authentication is enabled"}),i.jsxs("ul",{className:"text-sm text-green-300 space-y-1 list-disc list-inside",children:[i.jsx("li",{children:t("settings.email.feature1")||"Passwords are auto-generated and emailed to new users"}),i.jsx("li",{children:t("settings.email.feature2")||"Users can login with username or email"}),i.jsx("li",{children:t("settings.email.feature3")||"Forgot password feature is available"}),i.jsx("li",{children:t("settings.email.feature4")||"Admins can reset user passwords via email"})]})]})]})}):i.jsx("div",{className:"bg-yellow-500/10 border border-yellow-500/30 rounded-lg p-4",children:i.jsxs("div",{className:"flex items-start gap-3",children:[i.jsx(Cn,{className:"w-5 h-5 text-yellow-400 mt-0.5 flex-shrink-0"}),i.jsxs("div",{className:"space-y-2",children:[i.jsx("p",{className:"text-white font-medium",children:t("settings.email.advancedAuthDisabled")||"Advanced Authentication is disabled"}),i.jsx("p",{className:"text-sm text-yellow-300",children:t("settings.email.advancedAuthDisabledDesc")||"Enable advanced authentication to activate email-based features for user management."})]})]})})})})]}),i.jsx("div",{className:N?"":"opacity-50 pointer-events-none",children:i.jsxs(Tt,{children:[i.jsx(qn,{children:i.jsx("h2",{className:"text-lg font-semibold text-white",children:t("settings.email.smtpSettings")||"SMTP Configuration"})}),i.jsx(Pt,{children:i.jsxs("div",{className:"space-y-4",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:t("settings.email.authentication")||"Authentication"}),i.jsxs("select",{value:r.smtp_auth_enabled?"true":"false",onChange:P=>p(P.target.value==="true"),className:C,children:[i.jsx("option",{value:"true",children:t("settings.email.authOptions.enabled")}),i.jsx("option",{value:"false",children:t("settings.email.authOptions.disabled")})]})]}),i.jsxs("div",{className:`grid grid-cols-1 md:grid-cols-2 gap-4 transition-opacity ${r.smtp_auth_enabled?"":"opacity-40 pointer-events-none"}`,children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:t("settings.email.username")||"Username"}),i.jsx("input",{type:"text",value:r.smtp_username||"",onChange:P=>a({...r,smtp_username:P.target.value}),placeholder:"your.email@gmail.com",disabled:!r.smtp_auth_enabled,className:r.smtp_auth_enabled?C:T})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:t("settings.email.password")||"Password"}),i.jsx("input",{type:"password",value:r.smtp_password||"",onChange:P=>a({...r,smtp_password:P.target.value}),placeholder:l?"••••••••":"App password",disabled:!r.smtp_auth_enabled,className:r.smtp_auth_enabled?C:T})]})]}),i.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm font-medium text-white mb-2",children:[t("settings.email.smtpHost")||"SMTP Server"," *"]}),i.jsx("input",{type:"text",value:r.smtp_host,onChange:P=>a({...r,smtp_host:P.target.value}),placeholder:"smtp.gmail.com",className:C})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:t("settings.email.smtpPort")||"SMTP Port"}),i.jsx("input",{type:"number",value:r.smtp_port,onChange:P=>m(parseInt(P.target.value)||587),placeholder:"587",className:C})]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:t("settings.email.security")||"Security"}),i.jsxs("select",{value:r.smtp_security,onChange:P=>u(P.target.value),className:C,children:[i.jsx("option",{value:"starttls",children:t("settings.email.securityOptions.starttls")}),i.jsx("option",{value:"ssl",children:t("settings.email.securityOptions.ssl")}),i.jsx("option",{value:"none",children:t("settings.email.securityOptions.none")})]})]}),i.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm font-medium text-white mb-2",children:[t("settings.email.fromEmail")||"From Email"," *"]}),i.jsx("input",{type:"email",value:r.smtp_from_email,onChange:P=>a({...r,smtp_from_email:P.target.value}),placeholder:"your@email.com",className:C})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:t("settings.email.fromName")||"From Name"}),i.jsx("input",{type:"text",value:r.smtp_from_name,onChange:P=>a({...r,smtp_from_name:P.target.value}),placeholder:"BamBuddy",className:C})]})]}),i.jsx("div",{className:"flex gap-2",children:i.jsx(Oe,{onClick:g,disabled:f.isPending,className:"flex-1",children:f.isPending?i.jsxs(i.Fragment,{children:[i.jsx(lt,{className:"w-4 h-4 animate-spin"}),t("settings.email.saving")||"Saving..."]}):t("settings.email.save")||"Save Settings"})})]})})]})}),i.jsx("div",{className:N?"":"opacity-50 pointer-events-none",children:i.jsxs(Tt,{children:[i.jsx(qn,{children:i.jsx("h2",{className:"text-lg font-semibold text-white",children:t("settings.email.testConnection")||"Test SMTP Connection"})}),i.jsx(Pt,{children:i.jsxs("div",{className:"space-y-4",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:t("settings.email.testRecipient")||"Test Recipient Email"}),i.jsx("input",{type:"email",value:s,onChange:P=>o(P.target.value),placeholder:"test@example.com",className:C})]}),i.jsx(Oe,{onClick:y,disabled:x.isPending,variant:"secondary",children:x.isPending?i.jsxs(i.Fragment,{children:[i.jsx(lt,{className:"w-4 h-4 animate-spin"}),t("settings.email.sending")||"Sending..."]}):i.jsxs(i.Fragment,{children:[i.jsx(fC,{className:"w-4 h-4"}),t("settings.email.sendTest")||"Send Test Email"]})})]})})]})})]})}const bJe={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 xJe(t,e){const n=e.replace("#/","").split("/");let r=t;for(const a of n)r=r[a];return r}function rv(t,e,n=0){if(n>5)return"...";if(e.$ref)return rv(t,xJe(t,e.$ref),n+1);if(e.allOf){const r={};for(const a of e.allOf){const s=rv(t,a,n+1);typeof s=="object"&&s!==null&&Object.assign(r,s)}return r}if(e.example!==void 0)return e.example;if(e.default!==void 0)return e.default;switch(e.type){case"string":return e.enum?e.enum[0]:"string";case"integer":case"number":return 0;case"boolean":return!1;case"array":return e.items?[rv(t,e.items,n+1)]:[];case"object":if(e.properties){const r={};for(const[a,s]of Object.entries(e.properties))r[a]=rv(t,s,n+1);return r}return{};default:return null}}function yJe({path:t,method:e,spec:n,schema:r,apiKey:a}){const[s,o]=w.useState(!1),[l,c]=w.useState({}),[d,u]=w.useState(""),[m,p]=w.useState(null),[f,x]=w.useState(!1),[v,g]=w.useState(!1);w.useEffect(()=>{if(s&&n.parameters){const D={};for(const A of n.parameters)A.schema?.default!==void 0&&(D[A.name]=String(A.schema.default));c(A=>({...D,...A}))}},[s,n.parameters]),w.useEffect(()=>{if(s&&n.requestBody?.content?.["application/json"]?.schema&&!d){const D=n.requestBody.content["application/json"].schema,A=rv(r,D);u(JSON.stringify(A,null,2))}},[s,n.requestBody,r,d]);const _=(()=>{const D=[];for(const A of n.parameters||[])if(A.in==="path"||A.required){const R=l[A.name];(R===void 0||R==="")&&D.push(A.name)}return D})(),N=async()=>{if(_.length>0){p({status:0,statusText:"Validation Error",headers:{},body:`Missing required parameters: ${_.join(", ")}`,duration:0});return}x(!0),p(null);try{let D=t;const A=new URLSearchParams;for(const pe of n.parameters||[]){const Q=l[pe.name];Q!==void 0&&Q!==""&&(pe.in==="path"?D=D.replace(`{${pe.name}}`,encodeURIComponent(Q)):pe.in==="query"&&A.append(pe.name,Q))}const R=A.toString(),$=`${D}${R?`?${R}`:""}`,U={"Content-Type":"application/json"};a&&(U["X-API-Key"]=a);const W={method:e.toUpperCase(),headers:U};["post","put","patch"].includes(e)&&d&&(W.body=d);const O=performance.now(),te=await fetch($,W),ie=Math.round(performance.now()-O),Y={};te.headers.forEach((pe,Q)=>{Y[Q]=pe});let ae;te.headers.get("content-type")?.includes("application/json")?ae=await te.json():ae=await te.text(),p({status:te.status,statusText:te.statusText,headers:Y,body:ae,duration:ie})}catch(D){p({status:0,statusText:"Network Error",headers:{},body:D instanceof Error?D.message:"Unknown error",duration:0})}finally{x(!1)}},C=async()=>{if(m){const D=typeof m.body=="string"?m.body:JSON.stringify(m.body,null,2);try{await navigator.clipboard.writeText(D),g(!0),setTimeout(()=>g(!1),2e3)}catch{const A=document.createElement("textarea");A.value=D,A.style.position="fixed",A.style.left="-999999px",document.body.appendChild(A),A.select(),document.execCommand("copy"),document.body.removeChild(A),g(!0),setTimeout(()=>g(!1),2e3)}}},T=(n.parameters||[]).filter(D=>D.in==="path"),P=(n.parameters||[]).filter(D=>D.in==="query"),k=["post","put","patch"].includes(e)&&n.requestBody;return i.jsxs("div",{className:"border border-bambu-dark-tertiary rounded-lg overflow-hidden",children:[i.jsxs("button",{onClick:()=>o(!s),className:"w-full flex items-center gap-3 p-3 hover:bg-bambu-dark-tertiary/50 transition-colors text-left",children:[s?i.jsx(jn,{className:"w-4 h-4 text-bambu-gray flex-shrink-0"}):i.jsx(fa,{className:"w-4 h-4 text-bambu-gray flex-shrink-0"}),i.jsx("span",{className:`px-2 py-0.5 text-xs font-mono font-semibold uppercase rounded border ${bJe[e]||"bg-gray-500/20 text-gray-400"}`,children:e}),i.jsx("code",{className:"text-sm text-white font-mono flex-1 truncate",children:t}),n.summary&&i.jsx("span",{className:"text-sm text-bambu-gray truncate max-w-[40%]",children:n.summary})]}),s&&i.jsxs("div",{className:"border-t border-bambu-dark-tertiary p-4 space-y-4 bg-bambu-dark/50",children:[n.description&&i.jsx("p",{className:"text-sm text-bambu-gray",children:n.description}),T.length>0&&i.jsxs("div",{className:"space-y-2",children:[i.jsx("h4",{className:"text-sm font-medium text-white",children:"Path Parameters"}),i.jsx("div",{className:"space-y-2",children:T.map(D=>i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsxs("label",{className:"text-sm text-bambu-gray w-32 flex-shrink-0",children:[D.name,D.required&&i.jsx("span",{className:"text-red-400 ml-1",children:"*"})]}),i.jsx("input",{type:"text",value:l[D.name]||"",onChange:A=>c(R=>({...R,[D.name]:A.target.value})),placeholder:D.description||D.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"})]},D.name))})]}),P.length>0&&i.jsxs("div",{className:"space-y-2",children:[i.jsx("h4",{className:"text-sm font-medium text-white",children:"Query Parameters"}),i.jsx("div",{className:"space-y-2",children:P.map(D=>i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsxs("label",{className:"text-sm text-bambu-gray w-32 flex-shrink-0",children:[D.name,D.required&&i.jsx("span",{className:"text-red-400 ml-1",children:"*"})]}),D.schema?.enum?i.jsxs("select",{value:l[D.name]||"",onChange:A=>c(R=>({...R,[D.name]:A.target.value})),className:"flex-1 px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none",children:[i.jsx("option",{value:"",children:"-- Select --"}),D.schema.enum.map(A=>i.jsx("option",{value:A,children:A},A))]}):i.jsx("input",{type:"text",value:l[D.name]||"",onChange:A=>c(R=>({...R,[D.name]:A.target.value})),placeholder:D.description||D.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"})]},D.name))})]}),k&&i.jsxs("div",{className:"space-y-2",children:[i.jsx("h4",{className:"text-sm font-medium text-white",children:"Request Body"}),i.jsx("textarea",{value:d,onChange:D=>u(D.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..."})]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsxs(Oe,{onClick:N,disabled:f,children:[f?i.jsx(lt,{className:"w-4 h-4 animate-spin"}):i.jsx(uo,{className:"w-4 h-4"}),"Execute"]}),_.length>0&&i.jsxs("span",{className:"text-xs text-yellow-400 flex items-center gap-1",children:[i.jsx(zi,{className:"w-3 h-3"}),"Fill in: ",_.join(", ")]})]}),m&&i.jsxs("div",{className:"space-y-2",children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("h4",{className:"text-sm font-medium text-white flex items-center gap-2",children:["Response",i.jsxs("span",{className:`px-2 py-0.5 text-xs rounded ${m.status>=200&&m.status<300?"bg-green-500/20 text-green-400":m.status>=400?"bg-red-500/20 text-red-400":"bg-yellow-500/20 text-yellow-400"}`,children:[m.status," ",m.statusText]}),i.jsxs("span",{className:"text-xs text-bambu-gray",children:[m.duration,"ms"]})]}),i.jsx(Oe,{variant:"secondary",size:"sm",onClick:C,children:v?i.jsx(pr,{className:"w-3 h-3 text-green-400"}):i.jsx(_l,{className:"w-3 h-3"})})]}),i.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 m.body=="string"?m.body:JSON.stringify(m.body,null,2)})]})]})]})}function vJe({apiKey:t=""}){const[e,n]=w.useState(null),[r,a]=w.useState(!0),[s,o]=w.useState(null),[l,c]=w.useState(new Set),[d,u]=w.useState("");if(w.useEffect(()=>{async function g(){try{const y=await fetch("/openapi.json");if(!y.ok)throw new Error("Failed to fetch OpenAPI schema");const _=await y.json();n(_)}catch(y){o(y instanceof Error?y.message:"Unknown error")}finally{a(!1)}}g()},[]),r)return i.jsx("div",{className:"flex justify-center py-12",children:i.jsx(lt,{className:"w-8 h-8 text-bambu-green animate-spin"})});if(s||!e)return i.jsx(Tt,{children:i.jsx(Pt,{className:"py-8",children:i.jsxs("div",{className:"text-center text-red-400",children:[i.jsx(zi,{className:"w-12 h-12 mx-auto mb-3 opacity-50"}),i.jsx("p",{children:"Failed to load API schema"}),i.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:s})]})})});const m={};for(const[g,y]of Object.entries(e.paths))for(const[_,N]of Object.entries(y)){if(_==="parameters")continue;const C=N.tags||["Other"];for(const T of C)m[T]||(m[T]=[]),m[T].push({path:g,method:_,spec:N})}const p=Object.entries(m).map(([g,y])=>{if(!d)return{tag:g,endpoints:y};const _=y.filter(({path:N,method:C,spec:T})=>{const P=d.toLowerCase();return N.toLowerCase().includes(P)||C.toLowerCase().includes(P)||(T.summary?.toLowerCase()||"").includes(P)||(T.description?.toLowerCase()||"").includes(P)});return{tag:g,endpoints:_}}).filter(({endpoints:g})=>g.length>0).sort((g,y)=>g.tag.localeCompare(y.tag)),f=g=>{c(y=>{const _=new Set(y);return _.has(g)?_.delete(g):_.add(g),_})},x=()=>{c(new Set(p.map(g=>g.tag)))},v=()=>{c(new Set)};return i.jsxs("div",{className:"space-y-4",children:[i.jsxs("div",{className:"flex items-center justify-between gap-4",children:[i.jsx("div",{className:"flex-1",children:i.jsx("input",{type:"text",value:d,onChange:g=>u(g.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"})}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(Oe,{variant:"secondary",size:"sm",onClick:x,children:"Expand All"}),i.jsx(Oe,{variant:"secondary",size:"sm",onClick:v,children:"Collapse All"}),i.jsxs("a",{href:"/docs",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1 text-sm text-bambu-green hover:underline",children:[i.jsx(ei,{className:"w-4 h-4"}),"Swagger UI"]})]})]}),i.jsxs("p",{className:"text-sm text-bambu-gray",children:[p.reduce((g,y)=>g+y.endpoints.length,0)," endpoints in ",p.length," categories"]}),i.jsx("div",{className:"space-y-3",children:p.map(({tag:g,endpoints:y})=>i.jsxs(Tt,{children:[i.jsx("button",{onClick:()=>f(g),className:"w-full flex items-center justify-between p-4 hover:bg-bambu-dark-tertiary/30 transition-colors text-left",children:i.jsxs("div",{className:"flex items-center gap-2",children:[l.has(g)?i.jsx(jn,{className:"w-5 h-5 text-bambu-gray"}):i.jsx(fa,{className:"w-5 h-5 text-bambu-gray"}),i.jsx("h3",{className:"text-base font-semibold text-white capitalize",children:g.replace(/-/g," ")}),i.jsx("span",{className:"text-xs bg-bambu-dark-tertiary px-2 py-0.5 rounded-full text-bambu-gray",children:y.length})]})}),l.has(g)&&i.jsx(Pt,{className:"pt-0 space-y-2",children:y.map(({path:_,method:N,spec:C})=>i.jsx(yJe,{path:_,method:N,spec:C,schema:e,apiKey:t},`${N}-${_}`))})]},g))})]})}const wJe=["general","network","plugs","notifications","filament","apikeys","virtual-printer","users","backup"],SJe={database:"bg-blue-600",library_files:"bg-green-500",library_thumbnails:"bg-teal-500",library_other:"bg-emerald-700",archive_timelapses:"bg-red-500",archive_thumbnails:"bg-amber-500",archive_files:"bg-sky-500",virtual_printer_uploads:"bg-purple-500",virtual_printer_upload_cache:"bg-fuchsia-500",virtual_printer_certs:"bg-violet-500",virtual_printer_other:"bg-purple-700",downloads:"bg-cyan-500",plate_calibration:"bg-lime-500",logs:"bg-orange-500",other_data:"bg-yellow-500"},AK=["bg-blue-500","bg-green-500","bg-yellow-500","bg-red-500","bg-orange-500","bg-teal-500","bg-cyan-500","bg-purple-500"],MK=(t,e)=>SJe[t]||AK[e%AK.length];function _Je(){const t=Zt(),e=jl(),[n,r]=OF(),{t:a,i18n:s}=Mt(),{showToast:o}=hn(),{authEnabled:l,user:c,refreshAuth:d}=Dr(),{mode:u,darkStyle:m,darkBackground:p,darkAccent:f,lightStyle:x,lightBackground:v,lightAccent:g,setDarkStyle:y,setDarkBackground:_,setDarkAccent:N,setLightStyle:C,setLightBackground:T,setLightAccent:P}=bf(),[k,D]=w.useState(null),[A,R]=w.useState(!1),[$,U]=w.useState(null),[W,O]=w.useState(!1),[te,ie]=w.useState(null),[Y,ae]=w.useState(null),[de,pe]=w.useState(!1),[Q,oe]=w.useState(dX()),me=n.get("tab"),we=me==="email",Ee=we?"users":me&&wJe.includes(me)?me:"general",[q,K]=w.useState(Ee),[E,j]=w.useState(we?"email":"users"),L=Se=>{K(Se),Se==="users"&&j("users"),Se==="general"?n.delete("tab"):n.set("tab",Se),r(n,{replace:!0})},[G,B]=w.useState(!1),[re,z]=w.useState(""),[V,ee]=w.useState({can_queue:!0,can_control_printer:!1,can_read_status:!0}),[J,ne]=w.useState(null),[se,ue]=w.useState(null),[ge,le]=w.useState(""),[I,F]=w.useState(!1),[Z,xe]=w.useState(!1),[he,ce]=w.useState(null),[Ae,_e]=w.useState(!1),[Ue,$e]=w.useState(!1),[Fe,ke]=w.useState(!1),[Me,Ne]=w.useState({currentPassword:"",newPassword:"",confirmPassword:""}),[Pe,We]=w.useState(!1),[be,He]=w.useState(!1),[Ce,Ve]=w.useState(!1),[je,Re]=w.useState(!1),[ve,Ge]=w.useState(null),[rt,vt]=w.useState(null),[_t,kt]=w.useState(null),[qe,ht]=w.useState(!1),[ft,Bt]=w.useState({username:"",password:"",email:"",confirmPassword:"",role:"user",group_ids:[]}),[tn,sn]=w.useState(null),[Sn,on]=w.useState(null),[xn,Rn]=w.useState(!1),[Qn,Fn]=w.useState({}),[Be,De]=w.useState({}),Je=Se=>{oe(Se),ybe(Se),o(a("settings.toast.settingsSaved"),"success")},tt=()=>{localStorage.removeItem("sidebarOrder"),window.location.reload()},{data:Ye,isLoading:Rt}=Ze({queryKey:["settings"],queryFn:fe.getSettings}),{data:Te,isLoading:Ke,isFetching:et}=Ze({queryKey:["storage-usage"],queryFn:()=>fe.getStorageUsage(),enabled:q==="general",staleTime:1/0,refetchInterval:!1,refetchOnWindowFocus:!1,refetchOnReconnect:!1}),Qe=async()=>{He(!0);try{const Se=await fe.getStorageUsage({refresh:!0});t.setQueryData(["storage-usage"],Se)}catch(Se){const Dt=Se instanceof Error?Se.message:"Failed to refresh storage usage";o(Dt,"error")}finally{He(!1)}},{data:Ie,isLoading:ut}=Ze({queryKey:["smart-plugs"],queryFn:fe.getSmartPlugs}),{data:ot,isLoading:nt}=Ze({queryKey:["smart-plugs-energy",Ie?.map(Se=>Se.id)],queryFn:async()=>{if(!Ie||Ie.length===0)return null;const Se=await Promise.all(Ie.filter(Xi=>Xi.enabled).map(async Xi=>{try{const Wn=await fe.getSmartPlugStatus(Xi.id);return{plug:Xi,status:Wn}}catch{return{plug:Xi,status:null}}}));let Dt=0,sr=0,hr=0,Ti=0,Ua=0;for(const{plug:Xi,status:Wn}of Se){const Cs=Xi.plug_type==="mqtt"&&Wn?.energy?.power!=null;(Wn?.reachable||Cs)&&Wn?.energy&&(Ua++,Wn.energy?.power!=null&&(Dt+=Wn.energy.power),Wn.energy?.today!=null&&(sr+=Wn.energy.today),Wn.energy?.yesterday!=null&&(hr+=Wn.energy.yesterday),Wn.energy?.total!=null&&(Ti+=Wn.energy.total))}return{totalPower:Dt,totalToday:sr,totalYesterday:hr,totalLifetime:Ti,reachableCount:Ua,totalPlugs:Ie.filter(Xi=>Xi.enabled).length}},enabled:q==="plugs"&&!!Ie&&Ie.length>0,refetchInterval:q==="plugs"?1e4:!1}),{data:St,isLoading:Lt}=Ze({queryKey:["notification-providers"],queryFn:fe.getNotificationProviders}),{data:jt,isLoading:Ft}=Ze({queryKey:["api-keys"],queryFn:fe.getAPIKeys}),cn=dt({mutationFn:Se=>fe.createAPIKey(Se),onSuccess:Se=>{ne(Se.key||null),B(!1),z(""),t.invalidateQueries({queryKey:["api-keys"]}),o(a("settings.toast.apiKeyCreated"))},onError:Se=>{o(`Failed to create API key: ${Se.message}`,"error")}}),Jt=dt({mutationFn:Se=>fe.deleteAPIKey(Se),onSuccess:()=>{t.invalidateQueries({queryKey:["api-keys"]}),o(a("settings.toast.apiKeyDeleted"))},onError:Se=>{o(`Failed to delete API key: ${Se.message}`,"error")}}),{data:fn}=Ze({queryKey:["printers"],queryFn:fe.getPrinters}),{data:Pn,isLoading:In}=Ze({queryKey:["notification-templates"],queryFn:fe.getNotificationTemplates}),{data:Xt}=Ze({queryKey:["virtual-printer-settings"],queryFn:Xge.getSettings,refetchInterval:1e4}),vn=Xt?.status?.running??!1,{data:yn}=Ze({queryKey:["ffmpeg-status"],queryFn:fe.checkFfmpeg}),{data:yr}=Ze({queryKey:["version"],queryFn:fe.getVersion}),{data:gn,refetch:ar,isRefetching:li}=Ze({queryKey:["updateCheck"],queryFn:fe.checkForUpdates,enabled:Ye?.check_updates!==!1,staleTime:300*1e3}),{data:Dn,refetch:fi}=Ze({queryKey:["updateStatus"],queryFn:fe.getUpdateStatus,refetchInterval:Se=>{const Dt=Se.state.data;return Dt?.status==="downloading"||Dt?.status==="installing"?1e3:!1}}),{data:Zn}=Ze({queryKey:["mqtt-status"],queryFn:fe.getMQTTStatus,refetchInterval:q==="network"?5e3:!1}),{data:gi}=Ze({queryKey:["github-backup-status"],queryFn:fe.getGitHubBackupStatus}),{data:ni}=Ze({queryKey:["cloud-status"],queryFn:fe.getCloudStatus}),{data:Rr={advanced_auth_enabled:!1,smtp_configured:!1}}=Ze({queryKey:["advancedAuthStatus"],queryFn:()=>fe.getAdvancedAuthStatus()}),{hasPermission:bi}=Dr(),{data:_h=[],isLoading:Nf}=Ze({queryKey:["users"],queryFn:()=>fe.getUsers(),enabled:l&&bi("users:read")}),{data:za=[],isLoading:kf}=Ze({queryKey:["groups"],queryFn:()=>fe.getGroups(),enabled:l&&bi("groups:read")}),mc=dt({mutationFn:Se=>fe.createUser(Se),onSuccess:()=>{t.invalidateQueries({queryKey:["users"]}),t.invalidateQueries({queryKey:["groups"]}),Ve(!1),Bt({username:"",password:"",email:"",confirmPassword:"",role:"user",group_ids:[]}),o(a("settings.toast.userCreated"))},onError:Se=>{o(Se.message,"error")}}),hc=dt({mutationFn:({id:Se,data:Dt})=>fe.updateUser(Se,Dt),onSuccess:()=>{t.invalidateQueries({queryKey:["users"]}),t.invalidateQueries({queryKey:["groups"]}),Re(!1),Ge(null),Bt({username:"",password:"",email:"",confirmPassword:"",role:"user",group_ids:[]}),o(a("settings.toast.userUpdated"))},onError:Se=>{o(Se.message,"error")}}),Yi=dt({mutationFn:({id:Se,deleteItems:Dt})=>fe.deleteUser(Se,Dt),onSuccess:()=>{t.invalidateQueries({queryKey:["users"]}),o(a("settings.toast.userDeleted")),vt(null),kt(null)},onError:Se=>{o(Se.message,"error")}}),Ns=dt({mutationFn:Se=>fe.resetUserPassword({user_id:Se}),onSuccess:Se=>{o(Se.message,"success")},onError:Se=>{o(Se.message,"error")}}),ks=async Se=>{vt(Se),ht(!0);try{const Dt=await fe.getUserItemsCount(Se);kt(Dt)}catch{kt({archives:0,queue_items:0,library_files:0})}finally{ht(!1)}},Vs=dt({mutationFn:Se=>fe.deleteGroup(Se),onSuccess:()=>{t.invalidateQueries({queryKey:["groups"]}),o(a("settings.toast.groupDeleted"))},onError:Se=>{o(Se.message,"error")}}),Rl=()=>{const Se=Rr?.advanced_auth_enabled||!1;if(!ft.username){o(a("settings.toast.fillRequiredFields"),"error");return}if(Se&&!ft.email){o("Email is required when advanced authentication is enabled","error");return}if(!Se){if(!ft.password){o(a("settings.toast.fillRequiredFields"),"error");return}if(ft.password!==ft.confirmPassword){o(a("settings.toast.passwordsDoNotMatch"),"error");return}if(ft.password.length<6){o(a("settings.toast.passwordTooShort"),"error");return}}mc.mutate({username:ft.username,password:Se?void 0:ft.password,email:ft.email||void 0,role:ft.role,group_ids:ft.group_ids.length>0?ft.group_ids:void 0})},Cf=Se=>{if(ft.password){if(ft.password!==ft.confirmPassword){o(a("settings.toast.passwordsDoNotMatch"),"error");return}if(ft.password.length<6){o(a("settings.toast.passwordTooShort"),"error");return}}const Dt={username:ft.username||void 0,password:ft.password||void 0,role:ft.role,group_ids:ft.group_ids};Dt.password||delete Dt.password,hc.mutate({id:Se,data:Dt})},Nh=Se=>{Ge(Se.id),Bt({username:Se.username,password:"",email:Se.email||"",confirmPassword:"",role:Se.role,group_ids:Se.groups?.map(Dt=>Dt.id)||[]}),Re(!0)},pc=Se=>{Bt(Dt=>({...Dt,group_ids:Dt.group_ids.includes(Se)?Dt.group_ids.filter(sr=>sr!==Se):[...Dt.group_ids,Se]}))},Fl=dt({mutationFn:fe.applyUpdate,onSuccess:Se=>{Se.is_docker?o(Se.message,"error"):fi()}}),[ka,ad]=w.useState(null),Ll=dt({mutationFn:fe.testAllNotificationProviders,onSuccess:Se=>{ad(Se),t.invalidateQueries({queryKey:["notification-providers"]}),Se.failed===0?o(`All ${Se.tested} providers tested successfully!`,"success"):o(`${Se.success}/${Se.tested} providers succeeded`,Se.failed>0?"error":"success")},onError:Se=>{o(`Failed to test providers: ${Se.message}`,"error")}}),bt=dt({mutationFn:async Se=>{if(!Ie)return{success:0,failed:0};const Dt=Ie.filter(hr=>hr.enabled),sr=await Promise.all(Dt.map(async hr=>{try{return await fe.controlSmartPlug(hr.id,Se),{success:!0}}catch{return{success:!1}}}));return{success:sr.filter(hr=>hr.success).length,failed:sr.filter(hr=>!hr.success).length}},onSuccess:(Se,Dt)=>{t.invalidateQueries({queryKey:["smart-plugs"]}),t.invalidateQueries({queryKey:["smart-plugs-energy"]}),Se.failed===0?o(`All ${Se.success} plugs turned ${Dt}`,"success"):o(`${Se.success} plugs turned ${Dt}, ${Se.failed} failed`,"error")},onError:Se=>{o(`Failed: ${Se.message}`,"error")}}),It=w.useRef(null),nn=w.useRef(!1),Nt=w.useRef(!0);w.useEffect(()=>{if(Ye&&!k){const Se={...Ye,external_url:Ye.external_url||window.location.origin};D(Se),setTimeout(()=>{Nt.current=!1},100)}},[Ye,k]);const wn=dt({mutationFn:fe.updateSettings,onSuccess:Se=>{t.setQueryData(["settings"],Se),t.invalidateQueries({queryKey:["archiveStats"]}),o(a("settings.toast.settingsSaved"),"success")},onError:Se=>{o(`Failed to save: ${Se.message}`,"error")},onSettled:()=>{nn.current=!1}}),Nr=dt({mutationFn:({id:Se,data:Dt})=>fe.updatePrinter(Se,Dt),onSuccess:()=>{t.invalidateQueries({queryKey:["printers"]}),o(a("settings.toast.cameraSettingsSaved"),"success")},onError:Se=>{o(`Failed to update printer: ${Se.message}`,"error")}});w.useEffect(()=>{if(!(Nt.current||!k||!Ye||!(Ye.auto_archive!==k.auto_archive||Ye.save_thumbnails!==k.save_thumbnails||Ye.capture_finish_photo!==k.capture_finish_photo||Ye.default_filament_cost!==k.default_filament_cost||Ye.currency!==k.currency||Ye.energy_cost_per_kwh!==k.energy_cost_per_kwh||Ye.energy_tracking_mode!==k.energy_tracking_mode||Ye.check_updates!==k.check_updates||(Ye.check_printer_firmware??!0)!==(k.check_printer_firmware??!0)||(Ye.include_beta_updates??!1)!==(k.include_beta_updates??!1)||Ye.notification_language!==k.notification_language||(Ye.bed_cooled_threshold??35)!==(k.bed_cooled_threshold??35)||Ye.ams_humidity_good!==k.ams_humidity_good||Ye.ams_humidity_fair!==k.ams_humidity_fair||Ye.ams_temp_good!==k.ams_temp_good||Ye.ams_temp_fair!==k.ams_temp_fair||Ye.ams_history_retention_days!==k.ams_history_retention_days||Ye.per_printer_mapping_expanded!==k.per_printer_mapping_expanded||Ye.date_format!==k.date_format||Ye.time_format!==k.time_format||Ye.default_printer_id!==k.default_printer_id||Ye.ftp_retry_enabled!==k.ftp_retry_enabled||Ye.ftp_retry_count!==k.ftp_retry_count||Ye.ftp_retry_delay!==k.ftp_retry_delay||Ye.ftp_timeout!==k.ftp_timeout||Ye.mqtt_enabled!==k.mqtt_enabled||Ye.mqtt_broker!==k.mqtt_broker||Ye.mqtt_port!==k.mqtt_port||Ye.mqtt_username!==k.mqtt_username||Ye.mqtt_password!==k.mqtt_password||Ye.mqtt_topic_prefix!==k.mqtt_topic_prefix||Ye.mqtt_use_tls!==k.mqtt_use_tls||Ye.external_url!==k.external_url||Ye.ha_enabled!==k.ha_enabled||Ye.ha_url!==k.ha_url||Ye.ha_token!==k.ha_token||(Ye.library_archive_mode??"ask")!==(k.library_archive_mode??"ask")||Number(Ye.library_disk_warning_gb??5)!==Number(k.library_disk_warning_gb??5)||(Ye.camera_view_mode??"window")!==(k.camera_view_mode??"window")||(Ye.preferred_slicer??"bambu_studio")!==(k.preferred_slicer??"bambu_studio")||Ye.prometheus_enabled!==k.prometheus_enabled||Ye.prometheus_token!==k.prometheus_token))&&!nn.current)return It.current&&clearTimeout(It.current),It.current=setTimeout(()=>{if(nn.current)return;nn.current=!0;const Dt={auto_archive:k.auto_archive,save_thumbnails:k.save_thumbnails,capture_finish_photo:k.capture_finish_photo,default_filament_cost:k.default_filament_cost,currency:k.currency,energy_cost_per_kwh:k.energy_cost_per_kwh,energy_tracking_mode:k.energy_tracking_mode,check_updates:k.check_updates,check_printer_firmware:k.check_printer_firmware,include_beta_updates:k.include_beta_updates,notification_language:k.notification_language,bed_cooled_threshold:k.bed_cooled_threshold,ams_humidity_good:k.ams_humidity_good,ams_humidity_fair:k.ams_humidity_fair,ams_temp_good:k.ams_temp_good,ams_temp_fair:k.ams_temp_fair,ams_history_retention_days:k.ams_history_retention_days,per_printer_mapping_expanded:k.per_printer_mapping_expanded,date_format:k.date_format,time_format:k.time_format,default_printer_id:k.default_printer_id,ftp_retry_enabled:k.ftp_retry_enabled,ftp_retry_count:k.ftp_retry_count,ftp_retry_delay:k.ftp_retry_delay,ftp_timeout:k.ftp_timeout,mqtt_enabled:k.mqtt_enabled,mqtt_broker:k.mqtt_broker,mqtt_port:k.mqtt_port,mqtt_username:k.mqtt_username,mqtt_password:k.mqtt_password,mqtt_topic_prefix:k.mqtt_topic_prefix,mqtt_use_tls:k.mqtt_use_tls,external_url:k.external_url,ha_enabled:k.ha_enabled,ha_url:k.ha_url,ha_token:k.ha_token,library_archive_mode:k.library_archive_mode,library_disk_warning_gb:k.library_disk_warning_gb,camera_view_mode:k.camera_view_mode,preferred_slicer:k.preferred_slicer,prometheus_enabled:k.prometheus_enabled,prometheus_token:k.prometheus_token};wn.mutate(Dt)},500),()=>{It.current&&clearTimeout(It.current)}},[k,Ye,wn]);const $t=w.useCallback((Se,Dt)=>{D(sr=>sr?{...sr,[Se]:Dt}:null)},[]),vr=async(Se,Dt,sr)=>{if(!Dt){o(a("settings.toast.enterCameraUrl"),"error");return}De(hr=>({...hr,[Se]:!0})),Fn(hr=>({...hr,[Se]:null}));try{const hr=await fe.testExternalCamera(Se,Dt,sr);Fn(Ti=>({...Ti,[Se]:hr})),hr.success?o(a("settings.toast.cameraConnected",{resolution:hr.resolution||""}),"success"):o(hr.error||a("settings.toast.connectionFailed"),"error")}catch(hr){const Ti=hr instanceof Error?hr.message:a("settings.toast.testFailed");Fn(Ua=>({...Ua,[Se]:{success:!1,error:Ti}})),o(Ti,"error")}finally{De(hr=>({...hr,[Se]:!1}))}},[xi,rn]=w.useState({}),Ln=w.useRef({}),Ho=w.useRef(new Set);w.useEffect(()=>{if(fn){const Se={};fn.forEach(Dt=>{Dt.external_camera_url&&!Ho.current.has(Dt.id)&&(Se[Dt.id]=Dt.external_camera_url,Ho.current.add(Dt.id))}),Object.keys(Se).length>0&&rn(Dt=>({...Dt,...Se}))}},[fn]);const Gs=(Se,Dt)=>{rn(sr=>({...sr,[Se]:Dt})),Ln.current[Se]&&clearTimeout(Ln.current[Se]),Ln.current[Se]=setTimeout(()=>{Nr.mutate({id:Se,data:{external_camera_url:Dt||null}})},800)},bo=(Se,Dt)=>{const sr={};Dt.type!==void 0&&(sr.external_camera_type=Dt.type||null),Dt.enabled!==void 0&&(sr.external_camera_enabled=Dt.enabled),Nr.mutate({id:Se,data:sr})};return Rt||!k?i.jsx("div",{className:"p-4 md:p-8 flex justify-center",children:i.jsx(lt,{className:"w-8 h-8 text-bambu-green animate-spin"})}):i.jsxs("div",{className:"p-4 md:p-8",children:[i.jsxs("div",{className:"mb-8",children:[i.jsx("h1",{className:"text-2xl font-bold text-white",children:a("settings.title")}),i.jsx("p",{className:"text-bambu-gray",children:a("settings.configureBambuddy")})]}),i.jsxs("div",{className:"flex flex-wrap gap-1 mb-6 border-b border-bambu-dark-tertiary",children:[i.jsx("button",{onClick:()=>L("general"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px ${q==="general"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:a("settings.tabs.general")}),i.jsxs("button",{onClick:()=>L("plugs"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${q==="plugs"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[i.jsx(bl,{className:"w-4 h-4"}),a("settings.tabs.smartPlugs"),Ie&&Ie.length>0&&i.jsx("span",{className:"text-xs bg-bambu-dark-tertiary px-1.5 py-0.5 rounded-full",children:Ie.length})]}),i.jsxs("button",{onClick:()=>L("notifications"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${q==="notifications"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[i.jsx(db,{className:"w-4 h-4"}),a("settings.tabs.notifications"),St&&St.length>0&&i.jsx("span",{className:"text-xs bg-bambu-dark-tertiary px-1.5 py-0.5 rounded-full",children:St.length})]}),i.jsxs("button",{onClick:()=>L("filament"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${q==="filament"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[i.jsx(Dhe,{className:"w-4 h-4"}),a("settings.tabs.filament")]}),i.jsxs("button",{onClick:()=>L("network"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${q==="network"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[i.jsx(mb,{className:"w-4 h-4"}),a("settings.tabs.network"),i.jsx("span",{className:`w-2 h-2 rounded-full ${Zn?.enabled?"bg-green-400":"bg-gray-500"}`})]}),i.jsxs("button",{onClick:()=>L("apikeys"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${q==="apikeys"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[i.jsx(sl,{className:"w-4 h-4"}),a("settings.tabs.apiKeys"),jt&&jt.length>0&&i.jsx("span",{className:"text-xs bg-bambu-dark-tertiary px-1.5 py-0.5 rounded-full",children:jt.length})]}),i.jsxs("button",{onClick:()=>L("virtual-printer"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${q==="virtual-printer"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[i.jsx(_r,{className:"w-4 h-4"}),a("settings.tabs.virtualPrinter"),i.jsx("span",{className:`w-2 h-2 rounded-full ${vn?"bg-green-400":"bg-gray-500"}`})]}),i.jsxs("button",{onClick:()=>L("users"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${q==="users"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[i.jsx(Sm,{className:"w-4 h-4"}),a("settings.tabs.users"),l&&i.jsx("span",{className:"w-2 h-2 rounded-full bg-green-400"})]}),i.jsxs("button",{onClick:()=>L("backup"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${q==="backup"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[i.jsx(Uc,{className:"w-4 h-4"}),a("settings.tabs.backup"),i.jsx("span",{className:`w-2 h-2 rounded-full ${ni?.is_authenticated&&gi?.configured&&gi?.enabled?"bg-green-400":"bg-gray-500"}`})]})]}),q==="general"&&i.jsxs("div",{className:"flex flex-col lg:flex-row gap-6 lg:gap-8",children:[i.jsxs("div",{className:"space-y-6 flex-1 lg:max-w-xl",children:[i.jsxs(Tt,{children:[i.jsx(qn,{children:i.jsx("h2",{className:"text-lg font-semibold text-white",children:a("settings.general")})}),i.jsxs(Pt,{className:"space-y-4",children:[i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[i.jsx($m,{className:"w-4 h-4 inline mr-1"}),a("settings.language")]}),i.jsxs("div",{className:"relative",children:[i.jsx("select",{value:s.language,onChange:Se=>{s.changeLanguage(Se.target.value),fe.updateSettings({language:Se.target.value}),o(a("settings.toast.settingsSaved"),"success")},className:"w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer",children:OB.map(Se=>i.jsxs("option",{value:Se.code,children:[Se.nativeName," (",Se.name,")"]},Se.code))}),i.jsx(jn,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:a("settings.languageDescription")})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:a("settings.defaultView")}),i.jsxs("div",{className:"relative",children:[i.jsx("select",{value:Q,onChange:Se=>Je(Se.target.value),className:"w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer",children:zv.map(Se=>i.jsx("option",{value:Se.to,children:a(Se.labelKey)},Se.id))}),i.jsx(jn,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:a("settings.defaultViewDescription")})]}),i.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:a("settings.dateFormat")}),i.jsxs("div",{className:"relative",children:[i.jsxs("select",{value:k.date_format||"system",onChange:Se=>$t("date_format",Se.target.value),className:"w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer",children:[i.jsx("option",{value:"system",children:a("settings.systemDefault")}),i.jsx("option",{value:"us",children:a("settings.dateFormatUs")}),i.jsx("option",{value:"eu",children:a("settings.dateFormatEu")}),i.jsx("option",{value:"iso",children:a("settings.dateFormatIso")})]}),i.jsx(jn,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:a("settings.timeFormat")}),i.jsxs("div",{className:"relative",children:[i.jsxs("select",{value:k.time_format||"system",onChange:Se=>$t("time_format",Se.target.value),className:"w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer",children:[i.jsx("option",{value:"system",children:a("settings.systemDefault")}),i.jsx("option",{value:"12h",children:a("settings.timeFormat12")}),i.jsx("option",{value:"24h",children:a("settings.timeFormat24")})]}),i.jsx(jn,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]})]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:a("settings.defaultPrinter")}),i.jsxs("div",{className:"relative",children:[i.jsxs("select",{value:k.default_printer_id??"",onChange:Se=>$t("default_printer_id",Se.target.value?Number(Se.target.value):null),className:"w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer",children:[i.jsx("option",{value:"",children:a("settings.noDefaultPrinter")}),fn?.map(Se=>i.jsx("option",{value:Se.id,children:Se.name},Se.id))]}),i.jsx(jn,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:a("settings.defaultPrinterDescription")})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:a("settings.preferredSlicer")}),i.jsxs("div",{className:"relative",children:[i.jsxs("select",{value:k.preferred_slicer??"bambu_studio",onChange:Se=>$t("preferred_slicer",Se.target.value),className:"w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer",children:[i.jsx("option",{value:"bambu_studio",children:a("settings.slicerBambuStudio")}),i.jsx("option",{value:"orcaslicer",children:a("settings.slicerOrcaSlicer")})]}),i.jsx(jn,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:a("settings.preferredSlicerDescription")})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-white",children:a("settings.sidebarOrder")}),i.jsx("p",{className:"text-sm text-bambu-gray",children:a("settings.sidebarOrderDescription")})]}),i.jsxs(Oe,{variant:"secondary",size:"sm",onClick:tt,children:[i.jsx(mo,{className:"w-4 h-4"}),a("settings.reset")]})]})]})]}),i.jsxs(Tt,{children:[i.jsx(qn,{children:i.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(mC,{className:"w-5 h-5"}),a("settings.appearance")]})}),i.jsxs(Pt,{className:"space-y-6",children:[i.jsxs("div",{className:`space-y-3 p-4 rounded-lg border ${u==="dark"?"border-bambu-green bg-bambu-green/5":"border-bambu-dark-tertiary"}`,children:[i.jsxs("h3",{className:"text-sm font-medium text-white flex items-center gap-2",children:[a("settings.darkMode"),u==="dark"&&i.jsx("span",{className:"text-xs text-bambu-green",children:a("settings.active")})]}),i.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:a("settings.background")}),i.jsxs("select",{value:p,onChange:Se=>{_(Se.target.value),o(a("settings.toast.settingsSaved"),"success")},className:"w-full px-2 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[i.jsx("option",{value:"neutral",children:a("settings.bgNeutral")}),i.jsx("option",{value:"warm",children:a("settings.bgWarm")}),i.jsx("option",{value:"cool",children:a("settings.bgCool")}),i.jsx("option",{value:"oled",children:a("settings.bgOled")}),i.jsx("option",{value:"slate",children:a("settings.bgSlate")}),i.jsx("option",{value:"forest",children:a("settings.bgForest")})]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:a("settings.accent")}),i.jsxs("select",{value:f,onChange:Se=>{N(Se.target.value),o(a("settings.toast.settingsSaved"),"success")},className:"w-full px-2 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[i.jsx("option",{value:"green",children:a("settings.accentGreen")}),i.jsx("option",{value:"teal",children:a("settings.accentTeal")}),i.jsx("option",{value:"blue",children:a("settings.accentBlue")}),i.jsx("option",{value:"orange",children:a("settings.accentOrange")}),i.jsx("option",{value:"purple",children:a("settings.accentPurple")}),i.jsx("option",{value:"red",children:a("settings.accentRed")})]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:a("settings.style")}),i.jsxs("select",{value:m,onChange:Se=>{y(Se.target.value),o(a("settings.toast.settingsSaved"),"success")},className:"w-full px-2 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[i.jsx("option",{value:"classic",children:a("settings.styleClassic")}),i.jsx("option",{value:"glow",children:a("settings.styleGlow")}),i.jsx("option",{value:"vibrant",children:a("settings.styleVibrant")})]})]})]})]}),i.jsxs("div",{className:`space-y-3 p-4 rounded-lg border ${u==="light"?"border-bambu-green bg-bambu-green/5":"border-bambu-dark-tertiary"}`,children:[i.jsxs("h3",{className:"text-sm font-medium text-white flex items-center gap-2",children:[a("settings.lightMode"),u==="light"&&i.jsx("span",{className:"text-xs text-bambu-green",children:a("settings.active")})]}),i.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:a("settings.background")}),i.jsxs("select",{value:v,onChange:Se=>{T(Se.target.value),o(a("settings.toast.settingsSaved"),"success")},className:"w-full px-2 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[i.jsx("option",{value:"neutral",children:a("settings.bgNeutral")}),i.jsx("option",{value:"warm",children:a("settings.bgWarm")}),i.jsx("option",{value:"cool",children:a("settings.bgCool")})]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:a("settings.accent")}),i.jsxs("select",{value:g,onChange:Se=>{P(Se.target.value),o(a("settings.toast.settingsSaved"),"success")},className:"w-full px-2 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[i.jsx("option",{value:"green",children:a("settings.accentGreen")}),i.jsx("option",{value:"teal",children:a("settings.accentTeal")}),i.jsx("option",{value:"blue",children:a("settings.accentBlue")}),i.jsx("option",{value:"orange",children:a("settings.accentOrange")}),i.jsx("option",{value:"purple",children:a("settings.accentPurple")}),i.jsx("option",{value:"red",children:a("settings.accentRed")})]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:a("settings.style")}),i.jsxs("select",{value:x,onChange:Se=>{C(Se.target.value),o(a("settings.toast.settingsSaved"),"success")},className:"w-full px-2 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[i.jsx("option",{value:"classic",children:a("settings.styleClassic")}),i.jsx("option",{value:"glow",children:a("settings.styleGlow")}),i.jsx("option",{value:"vibrant",children:a("settings.styleVibrant")})]})]})]})]}),i.jsx("p",{className:"text-xs text-bambu-gray",children:a("settings.themeToggleHint")})]})]}),i.jsxs(Tt,{children:[i.jsx(qn,{children:i.jsx("h2",{className:"text-lg font-semibold text-white",children:a("settings.archiveSettings")})}),i.jsxs(Pt,{className:"space-y-4",children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-white",children:a("settings.autoArchivePrints")}),i.jsx("p",{className:"text-sm text-bambu-gray",children:a("settings.autoArchiveDescription")})]}),i.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:k.auto_archive,onChange:Se=>$t("auto_archive",Se.target.checked),className:"sr-only peer"}),i.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-white",children:a("settings.saveThumbnails")}),i.jsx("p",{className:"text-sm text-bambu-gray",children:a("settings.saveThumbnailsDescription")})]}),i.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:k.save_thumbnails,onChange:Se=>$t("save_thumbnails",Se.target.checked),className:"sr-only peer"}),i.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-white",children:a("settings.captureFinishPhoto")}),i.jsx("p",{className:"text-sm text-bambu-gray",children:a("settings.captureFinishPhotoDescription")})]}),i.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:k.capture_finish_photo,onChange:Se=>$t("capture_finish_photo",Se.target.checked),className:"sr-only peer"}),i.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"})]})]}),k.capture_finish_photo&&yn&&!yn.installed&&i.jsxs("div",{className:"flex items-start gap-2 p-3 bg-yellow-500/10 border border-yellow-500/30 rounded-lg",children:[i.jsx(Cn,{className:"w-5 h-5 text-yellow-500 flex-shrink-0 mt-0.5"}),i.jsxs("div",{className:"text-sm",children:[i.jsx("p",{className:"text-yellow-500 font-medium",children:a("settings.ffmpegNotInstalled")}),i.jsx("p",{className:"text-bambu-gray mt-1",children:a("settings.ffmpegRequired")})]})]})]})]})]}),i.jsxs("div",{className:"space-y-6 flex-1 lg:max-w-md",children:[i.jsxs(Tt,{children:[i.jsx(qn,{children:i.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(ZF,{className:"w-5 h-5 text-bambu-green"}),a("settings.camera")]})}),i.jsxs(Pt,{className:"space-y-4",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:a("settings.cameraViewMode")}),i.jsxs("select",{value:k.camera_view_mode??"window",onChange:Se=>$t("camera_view_mode",Se.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:[i.jsx("option",{value:"window",children:a("settings.newWindow")}),i.jsx("option",{value:"embedded",children:a("settings.embeddedOverlay")})]}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:k.camera_view_mode==="embedded"?a("settings.cameraOverlayDescription"):a("settings.cameraWindowDescription")})]}),i.jsxs("div",{className:"border-t border-bambu-dark-tertiary pt-4 mt-4",children:[i.jsx("h3",{className:"text-sm font-medium text-white mb-2",children:a("settings.externalCameras")}),i.jsx("p",{className:"text-xs text-bambu-gray mb-3",children:a("settings.externalCamerasDescription")}),fn&&fn.length>0?i.jsx("div",{className:"space-y-3",children:fn.map(Se=>i.jsxs("div",{className:"p-3 bg-bambu-dark rounded-lg",children:[i.jsxs("div",{className:"flex items-center justify-between mb-2",children:[i.jsx("span",{className:"text-white font-medium text-sm",children:Se.name}),i.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:Se.external_camera_enabled,onChange:Dt=>bo(Se.id,{enabled:Dt.target.checked}),className:"sr-only peer"}),i.jsx("div",{className:"w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green"})]})]}),Se.external_camera_enabled&&i.jsxs("div",{className:"space-y-2 mt-2",children:[i.jsx("input",{type:"text",placeholder:Se.external_camera_type==="usb"?a("settings.cameraPlaceholderUsb"):a("settings.cameraPlaceholderUrl"),value:xi[Se.id]??Se.external_camera_url??"",onChange:Dt=>Gs(Se.id,Dt.target.value),className:"w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none"}),i.jsxs("div",{className:"flex gap-2",children:[i.jsxs("select",{value:Se.external_camera_type||"mjpeg",onChange:Dt=>bo(Se.id,{type:Dt.target.value}),className:"flex-1 px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none",children:[i.jsx("option",{value:"mjpeg",children:a("settings.cameraTypeMjpeg")}),i.jsx("option",{value:"rtsp",children:a("settings.cameraTypeRtsp")}),i.jsx("option",{value:"snapshot",children:a("settings.cameraTypeSnapshot")}),i.jsx("option",{value:"usb",children:a("settings.cameraTypeUsb")})]}),i.jsx(Oe,{size:"sm",variant:"secondary",onClick:()=>vr(Se.id,xi[Se.id]??Se.external_camera_url??"",Se.external_camera_type||"mjpeg"),disabled:Be[Se.id]||!(xi[Se.id]??Se.external_camera_url),children:Be[Se.id]?i.jsx(lt,{className:"w-4 h-4 animate-spin"}):a("settings.test")})]}),Qn[Se.id]&&i.jsx("div",{className:`text-xs flex items-center gap-1 ${Qn[Se.id]?.success?"text-green-500":"text-red-500"}`,children:Qn[Se.id]?.success?i.jsxs(i.Fragment,{children:[i.jsx(pr,{className:"w-3 h-3"}),a("settings.connected"),Qn[Se.id]?.resolution&&` (${Qn[Se.id]?.resolution})`]}):i.jsxs(i.Fragment,{children:[i.jsx(Vi,{className:"w-3 h-3"}),Qn[Se.id]?.error||a("settings.toast.connectionFailed")]})})]})]},Se.id))}):i.jsx("p",{className:"text-xs text-bambu-gray italic",children:a("settings.noPrintersConfigured")})]})]})]}),i.jsxs(Tt,{children:[i.jsx(qn,{children:i.jsx("h2",{className:"text-lg font-semibold text-white",children:a("settings.costTracking")})}),i.jsxs(Pt,{className:"space-y-4",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:a("settings.currency")}),i.jsx("select",{value:k.currency,onChange:Se=>$t("currency",Se.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:W$e.map(Se=>i.jsx("option",{value:Se.code,children:Se.label},Se.code))})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:a("settings.defaultFilamentCost")}),i.jsxs("div",{className:"relative",children:[i.jsx("span",{className:"absolute left-3 top-1/2 -translate-y-1/2 text-bambu-gray text-sm pointer-events-none",children:ol(k.currency)}),i.jsx("input",{type:"number",step:"0.01",min:"0",value:k.default_filament_cost,onChange:Se=>$t("default_filament_cost",parseFloat(Se.target.value)||0),style:{paddingLeft:`${Math.max(2,ol(k.currency).length*.6+1)}rem`},className:"w-full pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:a("settings.electricityCost")}),i.jsxs("div",{className:"relative",children:[i.jsx("span",{className:"absolute left-3 top-1/2 -translate-y-1/2 text-bambu-gray text-sm pointer-events-none",children:ol(k.currency)}),i.jsx("input",{type:"number",step:"0.001",min:"0",value:k.energy_cost_per_kwh,onChange:Se=>$t("energy_cost_per_kwh",parseFloat(Se.target.value)||0),style:{paddingLeft:`${Math.max(2,ol(k.currency).length*.6+1)}rem`},className:"w-full pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:a("settings.energyDisplayMode")}),i.jsxs("select",{value:k.energy_tracking_mode||"total",onChange:Se=>$t("energy_tracking_mode",Se.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:[i.jsx("option",{value:"print",children:a("settings.printsOnly")}),i.jsx("option",{value:"total",children:a("settings.totalConsumption")})]}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:k.energy_tracking_mode==="print"?a("settings.energyModePrintDescription"):a("settings.energyModeTotalDescription")})]})]})]}),i.jsxs(Tt,{children:[i.jsx(qn,{children:i.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(Ds,{className:"w-5 h-5 text-bambu-green"}),a("settings.fileManager")]})}),i.jsxs(Pt,{className:"space-y-4",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:a("settings.createArchiveEntry")}),i.jsxs("select",{value:k.library_archive_mode??"ask",onChange:Se=>$t("library_archive_mode",Se.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:[i.jsx("option",{value:"always",children:a("settings.archiveMode.always")}),i.jsx("option",{value:"never",children:a("settings.archiveMode.never")}),i.jsx("option",{value:"ask",children:a("settings.archiveMode.ask")})]}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:a("settings.createArchiveEntryDescription")})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:a("settings.lowDiskSpaceWarning")}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("input",{type:"number",min:"0.5",max:"100",step:"0.5",value:k.library_disk_warning_gb??5,onChange:Se=>$t("library_disk_warning_gb",parseFloat(Se.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"}),i.jsx("span",{className:"text-bambu-gray",children:"GB"})]}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:a("settings.lowDiskSpaceDescription")})]})]})]})]}),i.jsxs("div",{className:"space-y-6 flex-1 lg:max-w-sm",children:[i.jsx(lJe,{}),i.jsxs(Tt,{children:[i.jsx(qn,{children:i.jsx("h2",{className:"text-lg font-semibold text-white",children:a("settings.updates")})}),i.jsxs(Pt,{className:"space-y-4",children:[i.jsx("p",{className:"text-xs font-medium text-bambu-gray uppercase tracking-wider",children:a("settings.printerFirmware")}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-white",children:a("settings.checkPrinterFirmware")}),i.jsx("p",{className:"text-sm text-bambu-gray",children:a("settings.checkFirmwareDescription")})]}),i.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:k.check_printer_firmware??!0,onChange:Se=>$t("check_printer_firmware",Se.target.checked),className:"sr-only peer"}),i.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]}),i.jsx("div",{className:"border-t border-bambu-dark-tertiary pt-4",children:i.jsx("p",{className:"text-xs font-medium text-bambu-gray uppercase tracking-wider mb-4",children:a("settings.bambuddySoftware")})}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-white",children:a("settings.checkForUpdatesLabel")}),i.jsx("p",{className:"text-sm text-bambu-gray",children:a("settings.autoCheckDescription")})]}),i.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:k.check_updates,onChange:Se=>$t("check_updates",Se.target.checked),className:"sr-only peer"}),i.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]}),i.jsxs("div",{className:`flex items-center justify-between ${k.check_updates?"":"opacity-50"}`,children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-white",children:a("settings.includeBetaUpdates")}),i.jsx("p",{className:"text-sm text-bambu-gray",children:a("settings.includeBetaUpdatesDesc")})]}),i.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:k.include_beta_updates??!1,onChange:Se=>$t("include_beta_updates",Se.target.checked),disabled:!k.check_updates,className:"sr-only peer"}),i.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]}),i.jsxs("div",{children:[i.jsxs("div",{className:"flex items-center justify-between mb-2",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-white",children:a("settings.currentVersion")}),i.jsxs("p",{className:"text-sm text-bambu-gray",children:["v",yr?.version||"..."]})]}),i.jsxs(Oe,{variant:"secondary",size:"sm",onClick:()=>ar(),disabled:li,children:[li?i.jsx(lt,{className:"w-4 h-4 animate-spin"}):i.jsx(Sr,{className:"w-4 h-4"}),a("settings.checkNow")]})]}),gn?.update_available?i.jsxs("div",{className:"mt-4 p-3 bg-bambu-green/10 border border-bambu-green/30 rounded-lg",children:[i.jsxs("div",{className:"flex items-start justify-between",children:[i.jsxs("div",{children:[i.jsxs("p",{className:"text-bambu-green font-medium",children:["Update available: v",gn.latest_version]}),gn.release_name&&gn.release_name!==gn.latest_version&&i.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:gn.release_name})]}),i.jsxs("div",{className:"flex items-center gap-2",children:[gn.release_notes&&i.jsx("button",{onClick:()=>_e(!0),className:"text-bambu-gray hover:text-white transition-colors text-sm underline",children:a("settings.releaseNotes")}),gn.release_url&&i.jsx("a",{href:gn.release_url,target:"_blank",rel:"noopener noreferrer",className:"text-bambu-gray hover:text-white transition-colors",title:a("settings.viewReleaseOnGitHub"),children:i.jsx(ei,{className:"w-4 h-4"})})]})]}),Dn?.status==="downloading"||Dn?.status==="installing"?i.jsxs("div",{className:"mt-3",children:[i.jsxs("div",{className:"flex items-center gap-2 text-sm text-bambu-gray",children:[i.jsx(lt,{className:"w-4 h-4 animate-spin"}),i.jsx("span",{children:Dn.message})]}),i.jsx("div",{className:"mt-2 w-full bg-bambu-dark-tertiary rounded-full h-2",children:i.jsx("div",{className:"bg-bambu-green h-2 rounded-full transition-all duration-300",style:{width:`${Dn.progress}%`}})})]}):Dn?.status==="complete"?i.jsx("div",{className:"mt-3 p-2 bg-bambu-green/20 rounded text-sm text-bambu-green",children:Dn.message}):Dn?.status==="error"?i.jsx("div",{className:"mt-3 p-2 bg-red-500/20 rounded text-sm text-red-400",children:Dn.error||Dn.message}):gn?.is_docker?i.jsxs("div",{className:"mt-3 p-3 bg-bambu-dark-tertiary rounded-lg",children:[i.jsx("p",{className:"text-sm text-bambu-gray mb-2",children:a("settings.updateViaDocker")}),i.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"})]}):i.jsxs(Oe,{className:"mt-3",onClick:()=>Fl.mutate(),disabled:Fl.isPending,children:[Fl.isPending?i.jsx(lt,{className:"w-4 h-4 animate-spin"}):i.jsx(hi,{className:"w-4 h-4"}),a("settings.installUpdate")]})]}):gn?.error?i.jsx("div",{className:"mt-2 p-2 bg-red-500/10 border border-red-500/30 rounded text-sm text-red-400",children:a("settings.failedToCheckUpdates",{error:gn.error})}):gn&&!gn.update_available?i.jsx("p",{className:"mt-2 text-sm text-bambu-gray",children:a("settings.latestVersionRunning")}):null]})]})]}),i.jsxs(Tt,{children:[i.jsx(qn,{children:i.jsx("h2",{className:"text-lg font-semibold text-white",children:a("settings.dataManagement")})}),i.jsxs(Pt,{className:"space-y-4",children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-white",children:a("settings.clearNotificationLogs")}),i.jsx("p",{className:"text-sm text-bambu-gray",children:a("settings.clearNotificationLogsDescription")})]}),i.jsxs(Oe,{variant:"secondary",size:"sm",onClick:()=>F(!0),children:[i.jsx(Qt,{className:"w-4 h-4"}),a("common.clear")]})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-white",children:a("settings.resetUiPreferences")}),i.jsx("p",{className:"text-sm text-bambu-gray",children:a("settings.resetUiPreferencesDescription")})]}),i.jsxs(Oe,{variant:"secondary",size:"sm",onClick:()=>xe(!0),children:[i.jsx(Qt,{className:"w-4 h-4"}),a("settings.reset")]})]}),i.jsxs("div",{className:"pt-4 border-t border-bambu-dark-tertiary",children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-white",children:a("settings.storageUsage","Storage Usage")}),i.jsx("p",{className:"text-sm text-bambu-gray",children:a("settings.storageUsageDescription","Breakdown of data usage by category")})]}),i.jsxs(Oe,{variant:"secondary",size:"sm",onClick:Qe,disabled:et||be,children:[i.jsx(Sr,{className:`w-4 h-4 ${et||be?"animate-spin":""}`}),a("common.refresh","Refresh")]})]}),i.jsx("div",{className:"mt-3",children:Ke?i.jsxs("div",{className:"flex items-center gap-2 text-sm text-bambu-gray",children:[i.jsx(lt,{className:"w-4 h-4 animate-spin"}),a("common.loading","Loading")]}):Te?i.jsxs(i.Fragment,{children:[i.jsx("div",{className:"w-full h-3 bg-bambu-dark rounded-full overflow-hidden flex",children:Te.categories.filter(Se=>Se.bytes>0).map((Se,Dt)=>i.jsx("div",{className:`${MK(Se.key,Dt)} h-full`,style:{width:`${Se.percent_of_total}%`},title:`${Se.label}: ${Se.formatted}`},Se.key))}),i.jsx("div",{className:"mt-3 flex flex-wrap gap-3",children:Te.categories.filter(Se=>Se.bytes>0).map((Se,Dt)=>i.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[i.jsx("span",{className:`w-3 h-3 rounded-full ${MK(Se.key,Dt)}`}),i.jsx("span",{className:"text-bambu-gray",children:Se.label}),i.jsx("span",{className:"text-white",children:Se.formatted}),i.jsxs("span",{className:"text-bambu-gray",children:["(",Se.percent_of_total.toFixed(1),"%)"]})]},Se.key))}),i.jsxs("div",{className:"mt-2 text-xs text-bambu-gray",children:[a("settings.storageUsageTotal","Total"),": ",i.jsx("span",{className:"text-white",children:Te.total_formatted}),Te.scan_errors>0&&i.jsxs("span",{className:"ml-2 text-amber-400",children:[a("settings.storageUsageErrors","Scan errors"),": ",Te.scan_errors]})]}),Te.other_breakdown?.length>0&&i.jsxs("div",{className:"mt-4",children:[i.jsx("p",{className:"text-xs text-bambu-gray mb-2",children:a("settings.storageUsageOtherBreakdown","Other breakdown")}),i.jsx("div",{className:"space-y-2",children:Te.other_breakdown.map(Se=>i.jsxs("div",{className:"flex items-center justify-between text-xs",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("span",{className:"text-white",children:Se.label}),i.jsx("span",{className:`px-2 py-0.5 rounded-full border ${Se.kind==="system"?"border-slate-500 text-slate-300":"border-bambu-green text-bambu-green"}`,children:Se.kind==="system"?a("settings.storageUsageSystem","System"):a("settings.storageUsageData","Data")})]}),i.jsxs("div",{className:"flex items-center gap-2 text-bambu-gray",children:[i.jsx("span",{className:"text-white",children:Se.formatted}),i.jsxs("span",{children:["(",Se.percent_of_total.toFixed(1),"%)"]})]})]},`${Se.bucket}-${Se.kind}`))})]})]}):i.jsx("p",{className:"text-sm text-bambu-gray",children:a("settings.storageUsageUnavailable","Storage usage data is unavailable")})})]}),i.jsxs("div",{className:"flex items-center justify-between pt-4 border-t border-bambu-dark-tertiary",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-white",children:a("settings.backupRestore")}),i.jsx("p",{className:"text-sm text-bambu-gray",children:a("settings.backupRestoreDescription")})]}),i.jsxs(Oe,{variant:"secondary",size:"sm",onClick:()=>L("backup"),children:[i.jsx(Uc,{className:"w-4 h-4"}),a("settings.goToBackup")]})]})]})]})]})]}),q==="network"&&k&&i.jsxs("div",{className:"flex flex-col lg:flex-row gap-6",children:[i.jsxs("div",{className:"flex-1 lg:max-w-xl space-y-4",children:[i.jsxs(Tt,{children:[i.jsx(qn,{children:i.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx($m,{className:"w-5 h-5 text-blue-400"}),a("settings.externalUrl")]})}),i.jsxs(Pt,{className:"space-y-4",children:[i.jsx("p",{className:"text-sm text-bambu-gray",children:a("settings.externalUrlDescription")}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:a("settings.bambuddyUrl")}),i.jsx("input",{type:"text",value:k.external_url??"",onChange:Se=>$t("external_url",Se.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"}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:a("settings.externalUrlHint")})]})]})]}),i.jsxs(Tt,{children:[i.jsx(qn,{children:i.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(Sr,{className:"w-5 h-5 text-blue-400"}),a("settings.ftpRetry")]})}),i.jsxs(Pt,{className:"space-y-4",children:[i.jsx("p",{className:"text-sm text-bambu-gray",children:a("settings.ftpRetryDescription")}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-white",children:a("settings.enableRetry")}),i.jsx("p",{className:"text-sm text-bambu-gray",children:a("settings.autoRetryDescription")})]}),i.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:k.ftp_retry_enabled??!0,onChange:Se=>$t("ftp_retry_enabled",Se.target.checked),className:"sr-only peer"}),i.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"})]})]}),k.ftp_retry_enabled&&i.jsxs("div",{className:"space-y-4 pt-2 border-t border-bambu-dark-tertiary",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:a("settings.retryAttempts")}),i.jsxs("div",{className:"relative w-44",children:[i.jsx("select",{value:k.ftp_retry_count??3,onChange:Se=>$t("ftp_retry_count",parseInt(Se.target.value)),className:"w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer",children:[1,2,3,4,5,6,7,8,9,10].map(Se=>i.jsx("option",{value:Se,children:a("settings.time",{count:Se})},Se))}),i.jsx(jn,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:a("settings.retryDelay")}),i.jsxs("div",{className:"relative w-44",children:[i.jsx("select",{value:k.ftp_retry_delay??2,onChange:Se=>$t("ftp_retry_delay",parseInt(Se.target.value)),className:"w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer",children:[1,2,3,5,10,15,20,30].map(Se=>i.jsx("option",{value:Se,children:a("settings.second",{count:Se})},Se))}),i.jsx(jn,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:a("settings.connectionTimeout")}),i.jsxs("div",{className:"relative w-44",children:[i.jsx("select",{value:k.ftp_timeout??30,onChange:Se=>$t("ftp_timeout",parseInt(Se.target.value)),className:"w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer",children:[10,15,20,30,45,60,90,120].map(Se=>i.jsx("option",{value:Se,children:a("settings.nSeconds",{count:Se})},Se))}),i.jsx(jn,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:a("settings.increaseForWeakWifi")})]})]})]})]})]}),i.jsxs("div",{className:"flex-1 lg:max-w-xl space-y-4",children:[i.jsxs(Tt,{children:[i.jsx(qn,{children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(j0,{className:"w-5 h-5 text-bambu-green"}),a("settings.homeAssistant")]}),k.ha_enabled&&Sn&&i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("span",{className:`w-2.5 h-2.5 rounded-full ${Sn.success?"bg-green-400":"bg-red-400"}`}),i.jsx("span",{className:`text-sm ${Sn.success?"text-green-400":"text-red-400"}`,children:Sn.success?a("settings.connected"):a("settings.disconnected")})]})]})}),i.jsxs(Pt,{className:"space-y-4",children:[i.jsx("p",{className:"text-sm text-bambu-gray",children:a("settings.homeAssistantFullDescription")}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex-1",children:[i.jsx("p",{className:"text-white",children:a("settings.enableHomeAssistant")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:a("settings.homeAssistantDescription")}),k.ha_env_managed&&i.jsxs("div",{className:"flex items-center gap-1 mt-1",children:[i.jsx(Jh,{className:"w-3 h-3 text-bambu-green"}),i.jsx("span",{className:"text-xs text-bambu-green",children:a("settings.autoEnabledViaEnv")})]})]}),i.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:k.ha_enabled??!1,onChange:Se=>$t("ha_enabled",Se.target.checked),disabled:k.ha_env_managed,className:"sr-only peer"}),i.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 ${k.ha_env_managed?"opacity-60 cursor-not-allowed":""}`})]})]}),k.ha_enabled&&i.jsxs(i.Fragment,{children:[i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[a("settings.homeAssistantUrl"),k.ha_url_from_env&&i.jsx("span",{className:"ml-2 text-xs text-bambu-green",children:a("settings.environmentManagedLabel")})]}),i.jsxs("div",{className:"relative",children:[i.jsx("input",{type:"text",value:k.ha_url??"",onChange:Se=>$t("ha_url",Se.target.value),placeholder:"http://192.168.1.100:8123",disabled:k.ha_url_from_env,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 ${k.ha_url_from_env?"opacity-60 cursor-not-allowed":""}`}),k.ha_url_from_env&&i.jsx(Jh,{className:"absolute right-3 top-2.5 w-4 h-4 text-bambu-gray"})]}),k.ha_url_from_env&&i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:a("settings.urlFromEnvReadOnly")})]}),i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[a("settings.longLivedAccessToken"),k.ha_token_from_env&&i.jsx("span",{className:"ml-2 text-xs text-bambu-green",children:a("settings.environmentManagedLabel")})]}),i.jsxs("div",{className:"relative",children:[i.jsx("input",{type:"password",value:k.ha_token??"",onChange:Se=>$t("ha_token",Se.target.value),placeholder:"eyJ0eXAiOiJKV1QiLC...",disabled:k.ha_token_from_env,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 ${k.ha_token_from_env?"opacity-60 cursor-not-allowed":""}`}),k.ha_token_from_env&&i.jsx(Jh,{className:"absolute right-3 top-2.5 w-4 h-4 text-bambu-gray"})]}),k.ha_token_from_env?i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:a("settings.tokenFromEnvReadOnly")}):i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:a("settings.haTokenHint")})]}),k.ha_url&&k.ha_token&&i.jsx("div",{className:"pt-2 border-t border-bambu-dark-tertiary",children:i.jsxs(Oe,{variant:"secondary",size:"sm",disabled:xn,onClick:async()=>{Rn(!0),on(null);try{const Se=await fe.testHAConnection(k.ha_url,k.ha_token);on(Se)}catch(Se){on({success:!1,message:null,error:Se instanceof Error?Se.message:a("common.unknownError")})}finally{Rn(!1)}},children:[xn?i.jsx(lt,{className:"w-4 h-4 animate-spin"}):i.jsx(mb,{className:"w-4 h-4"}),a("settings.testConnection")]})})]})]})]}),i.jsxs(Tt,{children:[i.jsx(qn,{children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(mb,{className:"w-5 h-5 text-blue-400"}),a("settings.mqttPublishing")]}),Zn?.enabled&&i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("span",{className:`w-2.5 h-2.5 rounded-full ${Zn.connected?"bg-green-400":"bg-red-400"}`}),i.jsx("span",{className:`text-sm ${Zn.connected?"text-green-400":"text-red-400"}`,children:Zn.connected?a("settings.connected"):a("settings.disconnected")})]})]})}),i.jsxs(Pt,{className:"space-y-4",children:[i.jsx("p",{className:"text-sm text-bambu-gray",children:a("settings.mqttDescription")}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-white",children:a("settings.enableMqtt")}),i.jsx("p",{className:"text-sm text-bambu-gray",children:a("settings.mqttEnableDescription")})]}),i.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:k.mqtt_enabled??!1,onChange:Se=>$t("mqtt_enabled",Se.target.checked),className:"sr-only peer"}),i.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"})]})]}),k.mqtt_enabled&&i.jsxs("div",{className:"space-y-4 pt-2 border-t border-bambu-dark-tertiary",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:a("settings.brokerHostname")}),i.jsx("input",{type:"text",value:k.mqtt_broker??"",onChange:Se=>$t("mqtt_broker",Se.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"})]}),i.jsxs("div",{className:"flex items-end gap-4",children:[i.jsxs("div",{className:"flex-1",children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:a("settings.port")}),i.jsx("input",{type:"number",min:"1",max:"65535",value:k.mqtt_port??1883,onChange:Se=>$t("mqtt_port",Math.min(65535,Math.max(1,parseInt(Se.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"})]}),i.jsxs("div",{className:"flex items-center gap-3 pb-2",children:[i.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:k.mqtt_use_tls??!1,onChange:Se=>{const Dt=Se.target.checked;$t("mqtt_use_tls",Dt);const sr=k.mqtt_port??1883;Dt&&sr===1883?$t("mqtt_port",8883):!Dt&&sr===8883&&$t("mqtt_port",1883)},className:"sr-only peer"}),i.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]}),i.jsx("span",{className:"text-white text-sm",children:a("settings.useTls")})]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:a("settings.usernameOptional")}),i.jsx("input",{type:"text",value:k.mqtt_username??"",onChange:Se=>$t("mqtt_username",Se.target.value),placeholder:a("settings.leaveEmptyForAnonymous"),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:a("settings.passwordOptional")}),i.jsx("input",{type:"password",value:k.mqtt_password??"",onChange:Se=>$t("mqtt_password",Se.target.value),placeholder:a("settings.leaveEmptyForAnonymous"),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:a("settings.topicPrefix")}),i.jsx("input",{type:"text",value:k.mqtt_topic_prefix??"bambuddy",onChange:Se=>$t("mqtt_topic_prefix",Se.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"}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:a("settings.topicPrefixHint",{prefix:k.mqtt_topic_prefix||"bambuddy"})})]}),Zn&&i.jsx("div",{className:"pt-3 mt-3 border-t border-bambu-dark-tertiary",children:i.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[i.jsx("span",{className:`w-2 h-2 rounded-full ${Zn.connected?"bg-green-400":"bg-red-400"}`}),i.jsx("span",{className:"text-bambu-gray",children:Zn.connected?i.jsxs(i.Fragment,{children:[a("settings.mqttConnectedTo")," ",i.jsxs("span",{className:"text-white",children:[Zn.broker,":",Zn.port]})]}):a("settings.spoolmanDisconnected")})]})})]})]})]})]}),i.jsx("div",{className:"flex-1 lg:max-w-md space-y-4",children:i.jsxs(Tt,{children:[i.jsx(qn,{children:i.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(MD,{className:"w-5 h-5 text-orange-400"}),a("settings.prometheusMetrics")]})}),i.jsxs(Pt,{className:"space-y-4",children:[i.jsx("p",{className:"text-sm text-bambu-gray",children:a("settings.prometheusEndpointDescription")}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-white",children:a("settings.enableMetricsEndpoint")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:a("settings.prometheusDescription")})]}),i.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:k.prometheus_enabled??!1,onChange:Se=>$t("prometheus_enabled",Se.target.checked),className:"sr-only peer"}),i.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"})]})]}),k.prometheus_enabled&&i.jsxs("div",{className:"space-y-4 pt-2 border-t border-bambu-dark-tertiary",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:a("settings.bearerTokenOptional")}),i.jsx("input",{type:"password",value:k.prometheus_token??"",onChange:Se=>$t("prometheus_token",Se.target.value),placeholder:a("settings.leaveEmptyForNoAuth"),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:a("settings.bearerTokenHint")})]}),i.jsxs("div",{className:"pt-2 border-t border-bambu-dark-tertiary",children:[i.jsx("p",{className:"text-sm text-white mb-2",children:a("settings.availableMetrics")}),i.jsxs("div",{className:"text-xs text-bambu-gray space-y-1",children:[i.jsxs("p",{children:[i.jsx("code",{className:"text-orange-400",children:"bambuddy_printer_connected"})," - ",a("settings.metricsConnectionStatus")]}),i.jsxs("p",{children:[i.jsx("code",{className:"text-orange-400",children:"bambuddy_printer_state"})," - ",a("settings.metricsPrinterState")]}),i.jsxs("p",{children:[i.jsx("code",{className:"text-orange-400",children:"bambuddy_print_progress"})," - ",a("settings.metricsPrintProgress")]}),i.jsxs("p",{children:[i.jsx("code",{className:"text-orange-400",children:"bambuddy_bed_temp_celsius"})," - ",a("settings.metricsBedTemp")]}),i.jsxs("p",{children:[i.jsx("code",{className:"text-orange-400",children:"bambuddy_nozzle_temp_celsius"})," - ",a("settings.metricsNozzleTemp")]}),i.jsxs("p",{children:[i.jsx("code",{className:"text-orange-400",children:"bambuddy_prints_total"})," - ",a("settings.metricsPrintsTotal")]}),i.jsx("p",{className:"text-bambu-gray/70 italic",children:a("settings.metricsMore")})]})]})]})]})]})})]}),Sn&&i.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50",children:i.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg p-6 max-w-md w-full mx-4",children:[i.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[Sn.success?i.jsx(pr,{className:"w-8 h-8 text-green-400"}):i.jsx(Vi,{className:"w-8 h-8 text-red-400"}),i.jsx("h3",{className:"text-lg font-medium text-white",children:Sn.success?a("settings.connectionSuccessful"):a("settings.connectionFailed")})]}),i.jsx("p",{className:"text-bambu-gray mb-6",children:Sn.success?Sn.message||a("settings.haConnectionSuccess"):Sn.error||a("settings.haConnectionFailed")}),i.jsx("div",{className:"flex justify-end",children:i.jsx(Oe,{variant:"primary",onClick:()=>on(null),children:a("settings.ok")})})]})}),q==="plugs"&&i.jsxs("div",{className:"max-w-4xl",children:[i.jsxs("div",{className:"flex items-start justify-between mb-6",children:[i.jsxs("div",{children:[i.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(bl,{className:"w-5 h-5 text-bambu-green"}),a("settings.smartPlugs")]}),i.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:a("settings.smartPlugsDescription")})]}),i.jsxs("div",{className:"flex items-center gap-2 pt-1 shrink-0",children:[Ie&&Ie.filter(Se=>Se.enabled).length>1&&i.jsxs(i.Fragment,{children:[i.jsxs(Oe,{variant:"secondary",size:"sm",className:"whitespace-nowrap",onClick:()=>ce("on"),disabled:bt.isPending,title:a("settings.turnAllPlugsOn"),children:[bt.isPending?i.jsx(lt,{className:"w-4 h-4 animate-spin"}):i.jsx(Su,{className:"w-4 h-4 text-bambu-green"}),a("settings.allOn")]}),i.jsxs(Oe,{variant:"secondary",size:"sm",className:"whitespace-nowrap",onClick:()=>ce("off"),disabled:bt.isPending,title:a("settings.turnAllPlugsOff"),children:[bt.isPending?i.jsx(lt,{className:"w-4 h-4 animate-spin"}):i.jsx(pC,{className:"w-4 h-4 text-red-400"}),a("settings.allOff")]})]}),i.jsxs(Oe,{className:"whitespace-nowrap",onClick:()=>{U(null),R(!0)},children:[i.jsx(rr,{className:"w-4 h-4"}),a("settings.addSmartPlug")]})]})]}),Ie&&Ie.length>0&&i.jsxs(Tt,{className:"mb-6",children:[i.jsx(qn,{children:i.jsxs("h3",{className:"text-base font-semibold text-white flex items-center gap-2",children:[i.jsx(ac,{className:"w-4 h-4 text-yellow-400"}),a("settings.energySummary"),nt&&i.jsx(lt,{className:"w-4 h-4 animate-spin text-bambu-gray ml-2"})]})}),i.jsx(Pt,{children:ot?i.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[i.jsxs("div",{className:"bg-bambu-dark rounded-lg p-3",children:[i.jsxs("div",{className:"flex items-center gap-2 text-bambu-gray text-xs mb-1",children:[i.jsx(ac,{className:"w-3 h-3"}),a("settings.currentPower")]}),i.jsxs("div",{className:"text-xl font-bold text-white",children:[ot.totalPower.toFixed(1),i.jsx("span",{className:"text-sm font-normal text-bambu-gray ml-1",children:"W"})]}),i.jsx("div",{className:"text-xs text-bambu-gray mt-1",children:a("settings.plugsOnline",{reachable:ot.reachableCount,total:ot.totalPlugs})})]}),i.jsxs("div",{className:"bg-bambu-dark rounded-lg p-3",children:[i.jsxs("div",{className:"flex items-center gap-2 text-bambu-gray text-xs mb-1",children:[i.jsx(Xr,{className:"w-3 h-3"}),a("settings.today")]}),i.jsxs("div",{className:"text-xl font-bold text-white",children:[ot.totalToday.toFixed(3),i.jsx("span",{className:"text-sm font-normal text-bambu-gray ml-1",children:"kWh"})]}),(k?.energy_cost_per_kwh??0)>0&&i.jsxs("div",{className:"text-xs text-bambu-gray mt-1",children:["~",(ot.totalToday*(k?.energy_cost_per_kwh??0)).toFixed(2)," ",ol(k?.currency||"USD")]})]}),i.jsxs("div",{className:"bg-bambu-dark rounded-lg p-3",children:[i.jsxs("div",{className:"flex items-center gap-2 text-bambu-gray text-xs mb-1",children:[i.jsx(MD,{className:"w-3 h-3"}),a("settings.yesterday")]}),i.jsxs("div",{className:"text-xl font-bold text-white",children:[ot.totalYesterday.toFixed(3),i.jsx("span",{className:"text-sm font-normal text-bambu-gray ml-1",children:"kWh"})]}),(k?.energy_cost_per_kwh??0)>0&&i.jsxs("div",{className:"text-xs text-bambu-gray mt-1",children:["~",(ot.totalYesterday*(k?.energy_cost_per_kwh??0)).toFixed(2)," ",ol(k?.currency||"USD")]})]}),i.jsxs("div",{className:"bg-bambu-dark rounded-lg p-3",children:[i.jsxs("div",{className:"flex items-center gap-2 text-bambu-gray text-xs mb-1",children:[i.jsx(U1,{className:"w-3 h-3"}),a("settings.total")]}),i.jsxs("div",{className:"text-xl font-bold text-white",children:[ot.totalLifetime.toFixed(1),i.jsx("span",{className:"text-sm font-normal text-bambu-gray ml-1",children:"kWh"})]}),(k?.energy_cost_per_kwh??0)>0&&i.jsxs("div",{className:"text-xs text-bambu-gray mt-1",children:["~",(ot.totalLifetime*(k?.energy_cost_per_kwh??0)).toFixed(2)," ",ol(k?.currency||"USD")]})]})]}):nt?null:i.jsx("p",{className:"text-sm text-bambu-gray",children:a("settings.enablePlugsForSummary")})})]}),ut?i.jsx("div",{className:"flex justify-center py-12",children:i.jsx(lt,{className:"w-8 h-8 text-bambu-green animate-spin"})}):Ie&&Ie.length>0?i.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:Ie.map(Se=>i.jsx(KZe,{plug:Se,onEdit:Dt=>{U(Dt),R(!0)}},Se.id))}):i.jsx(Tt,{children:i.jsx(Pt,{className:"py-12",children:i.jsxs("div",{className:"text-center text-bambu-gray",children:[i.jsx(bl,{className:"w-16 h-16 mx-auto mb-4 opacity-30"}),i.jsx("p",{className:"text-lg font-medium text-white mb-2",children:a("settings.noSmartPlugsTitle")}),i.jsx("p",{className:"text-sm mb-4",children:a("settings.noSmartPlugsDescription")}),i.jsxs(Oe,{onClick:()=>{U(null),R(!0)},children:[i.jsx(rr,{className:"w-4 h-4"}),a("settings.addFirstSmartPlug")]})]})})})]}),q==="notifications"&&i.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-8",children:[i.jsxs("div",{children:[i.jsxs("div",{className:"flex items-center justify-between mb-4",children:[i.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(db,{className:"w-5 h-5 text-bambu-green"}),a("settings.providers")]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsxs(Oe,{size:"sm",variant:"secondary",onClick:()=>pe(!0),children:[i.jsx(Fv,{className:"w-4 h-4"}),a("settings.log")]}),St&&St.length>0&&i.jsxs(Oe,{size:"sm",variant:"secondary",onClick:()=>{ad(null),Ll.mutate()},disabled:Ll.isPending,children:[Ll.isPending?i.jsx(lt,{className:"w-4 h-4 animate-spin"}):i.jsx(fC,{className:"w-4 h-4"}),a("settings.testAll")]}),i.jsxs(Oe,{size:"sm",onClick:()=>{ie(null),O(!0)},children:[i.jsx(rr,{className:"w-4 h-4"}),a("settings.addNotificationProvider")]})]})]}),i.jsx(Tt,{className:"mb-4",children:i.jsx(Pt,{className:"py-3",children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-white text-sm font-medium",children:a("settings.notificationLanguage")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:a("settings.notificationLanguageDescription")})]}),i.jsx("select",{value:k.notification_language||"en",onChange:Se=>$t("notification_language",Se.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:OB.map(Se=>i.jsx("option",{value:Se.code,children:Se.nativeName},Se.code))})]})})}),i.jsx(Tt,{className:"mb-4",children:i.jsx(Pt,{className:"py-3",children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-white text-sm font-medium",children:a("settings.bedCooledThreshold")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:a("settings.bedCooledThresholdDescription")})]}),i.jsxs("div",{className:"flex items-center gap-1",children:[i.jsx("input",{type:"number",min:20,max:80,step:1,value:k.bed_cooled_threshold??35,onChange:Se=>$t("bed_cooled_threshold",Number(Se.target.value)),className:"w-16 px-2 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm text-center focus:outline-none focus:ring-1 focus:ring-bambu-green"}),i.jsx("span",{className:"text-sm text-bambu-gray",children:"°C"})]})]})})}),ka&&i.jsx(Tt,{className:"mb-4",children:i.jsxs(Pt,{className:"py-3",children:[i.jsxs("div",{className:"flex items-center justify-between mb-2",children:[i.jsx("span",{className:"text-sm font-medium text-white",children:a("settings.testResults")}),i.jsx("button",{onClick:()=>ad(null),className:"text-bambu-gray hover:text-white text-xs",children:a("common.dismiss")})]}),i.jsxs("div",{className:"flex items-center gap-4 text-sm mb-2",children:[i.jsxs("span",{className:"flex items-center gap-1 text-bambu-green",children:[i.jsx(pr,{className:"w-4 h-4"}),a("settings.testPassedCount",{count:ka.success})]}),ka.failed>0&&i.jsxs("span",{className:"flex items-center gap-1 text-red-400",children:[i.jsx(Vi,{className:"w-4 h-4"}),a("settings.testFailedCount",{count:ka.failed})]})]}),ka.results.filter(Se=>!Se.success).length>0&&i.jsx("div",{className:"space-y-1 mt-2 pt-2 border-t border-bambu-dark-tertiary",children:ka.results.filter(Se=>!Se.success).map(Se=>i.jsxs("div",{className:"text-xs text-red-400",children:[i.jsxs("span",{className:"font-medium",children:[Se.provider_name,":"]})," ",Se.message]},Se.provider_id))})]})}),Lt?i.jsx("div",{className:"flex justify-center py-12",children:i.jsx(lt,{className:"w-6 h-6 text-bambu-green animate-spin"})}):St&&St.length>0?i.jsx("div",{className:"space-y-3",children:St.map(Se=>i.jsx(XZe,{provider:Se,onEdit:Dt=>{ie(Dt),O(!0)}},Se.id))}):i.jsx(Tt,{children:i.jsx(Pt,{className:"py-8",children:i.jsxs("div",{className:"text-center text-bambu-gray",children:[i.jsx(db,{className:"w-12 h-12 mx-auto mb-3 opacity-30"}),i.jsx("p",{className:"text-sm font-medium text-white mb-2",children:a("settings.noProvidersTitle")}),i.jsx("p",{className:"text-xs mb-3",children:a("settings.noProvidersDescription")}),i.jsxs(Oe,{size:"sm",onClick:()=>{ie(null),O(!0)},children:[i.jsx(rr,{className:"w-4 h-4"}),a("settings.addProvider")]})]})})})]}),i.jsxs("div",{children:[i.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2 mb-4",children:[i.jsx(Ds,{className:"w-5 h-5 text-bambu-green"}),a("settings.messageTemplates")]}),i.jsx("p",{className:"text-sm text-bambu-gray mb-4",children:a("settings.messageTemplatesDescription")}),In?i.jsx("div",{className:"flex justify-center py-8",children:i.jsx(lt,{className:"w-6 h-6 text-bambu-green animate-spin"})}):Pn&&Pn.length>0?i.jsx("div",{className:"space-y-2",children:[...Pn].sort((Se,Dt)=>Se.name.localeCompare(Dt.name)).map(Se=>i.jsx(Tt,{className:"cursor-pointer hover:border-bambu-green/50 transition-colors",onClick:()=>ae(Se),children:i.jsx(Pt,{className:"py-2.5 px-3",children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"min-w-0 flex-1",children:[i.jsx("p",{className:"text-white font-medium text-sm truncate",children:Se.name}),i.jsx("p",{className:"text-bambu-gray text-xs truncate mt-0.5",children:Se.title_template})]}),i.jsx("button",{className:"p-1.5 hover:bg-bambu-dark-tertiary rounded transition-colors shrink-0 ml-2",onClick:Dt=>{Dt.stopPropagation(),ae(Se)},children:i.jsx(Mm,{className:"w-4 h-4 text-bambu-gray"})})]})})},Se.id))}):i.jsx(Tt,{children:i.jsx(Pt,{className:"py-8",children:i.jsxs("div",{className:"text-center text-bambu-gray",children:[i.jsx(Ds,{className:"w-12 h-12 mx-auto mb-3 opacity-30"}),i.jsx("p",{className:"text-sm",children:a("settings.noTemplatesAvailable")})]})})})]})]}),q==="apikeys"&&i.jsxs("div",{className:"grid grid-cols-1 xl:grid-cols-2 gap-8",children:[i.jsxs("div",{children:[i.jsxs("div",{className:"flex items-start justify-between gap-4 mb-6",children:[i.jsxs("div",{className:"flex-1",children:[i.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(sl,{className:"w-5 h-5 text-bambu-green"}),a("settings.apiKeys")]}),i.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:a("settings.apiKeysDescription")})]}),i.jsxs(Oe,{size:"sm",onClick:()=>B(!0),className:"flex-shrink-0",children:[i.jsx(rr,{className:"w-4 h-4"}),a("settings.createKey")]})]}),J&&i.jsx(Tt,{className:"mb-6 border-bambu-green",children:i.jsx(Pt,{className:"py-4",children:i.jsxs("div",{className:"flex items-start gap-3",children:[i.jsx(pr,{className:"w-5 h-5 text-bambu-green flex-shrink-0 mt-0.5"}),i.jsxs("div",{className:"flex-1",children:[i.jsx("p",{className:"text-white font-medium mb-1",children:a("settings.apiKeyCreated")}),i.jsx("p",{className:"text-sm text-bambu-gray mb-2",children:a("settings.apiKeyCopyWarning")}),i.jsxs("div",{className:"flex items-center gap-2 bg-bambu-dark rounded-lg p-2",children:[i.jsx("code",{className:"flex-1 text-sm text-bambu-green font-mono break-all",children:J}),i.jsx(Oe,{variant:"secondary",size:"sm",onClick:async()=>{try{if(navigator.clipboard&&navigator.clipboard.writeText)await navigator.clipboard.writeText(J);else{const Se=document.createElement("textarea");Se.value=J,Se.style.position="fixed",Se.style.left="-999999px",document.body.appendChild(Se),Se.select(),document.execCommand("copy"),document.body.removeChild(Se)}o(a("settings.toast.keyCopied"))}catch{o(a("settings.toast.copyFailed"),"error")}},children:i.jsx(_l,{className:"w-4 h-4"})})]}),i.jsxs("div",{className:"flex gap-2 mt-3",children:[i.jsx(Oe,{variant:"secondary",size:"sm",onClick:()=>{le(J),o(a("settings.toast.keyAddedToBrowser"))},children:a("settings.useInApiBrowser")}),i.jsx(Oe,{variant:"secondary",size:"sm",onClick:()=>ne(null),children:a("common.dismiss")})]})]})]})})}),G&&i.jsxs(Tt,{className:"mb-6",children:[i.jsx(qn,{children:i.jsx("h3",{className:"text-base font-semibold text-white",children:a("settings.createNewApiKey")})}),i.jsxs(Pt,{className:"space-y-4",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:a("settings.keyName")}),i.jsx("input",{type:"text",value:re,onChange:Se=>z(Se.target.value),placeholder:a("settings.keyNamePlaceholder"),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-2",children:a("common.permissions")}),i.jsxs("div",{className:"space-y-2",children:[i.jsxs("label",{className:"flex items-center gap-3 cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:V.can_read_status,onChange:Se=>ee(Dt=>({...Dt,can_read_status:Se.target.checked})),className:"w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green"}),i.jsxs("div",{children:[i.jsx("span",{className:"text-white",children:a("settings.readStatus")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:a("settings.readStatusDescription")})]})]}),i.jsxs("label",{className:"flex items-center gap-3 cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:V.can_queue,onChange:Se=>ee(Dt=>({...Dt,can_queue:Se.target.checked})),className:"w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green"}),i.jsxs("div",{children:[i.jsx("span",{className:"text-white",children:a("settings.manageQueue")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:a("settings.manageQueueDescription")})]})]}),i.jsxs("label",{className:"flex items-center gap-3 cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:V.can_control_printer,onChange:Se=>ee(Dt=>({...Dt,can_control_printer:Se.target.checked})),className:"w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green"}),i.jsxs("div",{children:[i.jsx("span",{className:"text-white",children:a("settings.controlPrinter")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:a("settings.controlPrinterDescription")})]})]})]})]}),i.jsxs("div",{className:"flex items-center gap-2 pt-2",children:[i.jsxs(Oe,{onClick:()=>cn.mutate({name:re||a("settings.unnamedKey"),...V}),disabled:cn.isPending,children:[cn.isPending?i.jsx(lt,{className:"w-4 h-4 animate-spin"}):i.jsx(rr,{className:"w-4 h-4"}),a("settings.createKey")]}),i.jsx(Oe,{variant:"secondary",onClick:()=>B(!1),children:a("common.cancel")})]})]})]}),Ft?i.jsx("div",{className:"flex justify-center py-12",children:i.jsx(lt,{className:"w-8 h-8 text-bambu-green animate-spin"})}):jt&&jt.length>0?i.jsx("div",{className:"space-y-3",children:jt.map(Se=>i.jsx(Tt,{children:i.jsx(Pt,{className:"py-3",children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx(sl,{className:`w-5 h-5 ${Se.enabled?"text-bambu-green":"text-bambu-gray"}`}),i.jsxs("div",{children:[i.jsx("p",{className:"text-white font-medium",children:Se.name}),i.jsxs("p",{className:"text-xs text-bambu-gray",children:[Se.key_prefix,"••••••••",Se.last_used&&` · ${a("settings.lastUsed")}: ${Wp(Se.last_used)}`]})]})]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsxs("div",{className:"flex gap-1 text-xs",children:[Se.can_read_status&&i.jsx("span",{className:"px-1.5 py-0.5 bg-blue-500/20 text-blue-400 rounded",children:a("settings.read")}),Se.can_queue&&i.jsx("span",{className:"px-1.5 py-0.5 bg-green-500/20 text-green-400 rounded",children:a("queue.title")}),Se.can_control_printer&&i.jsx("span",{className:"px-1.5 py-0.5 bg-orange-500/20 text-orange-400 rounded",children:a("settings.control")})]}),i.jsx(Oe,{variant:"secondary",size:"sm",onClick:()=>ue(Se.id),children:i.jsx(Qt,{className:"w-4 h-4 text-red-400"})})]})]})})},Se.id))}):i.jsx(Tt,{children:i.jsx(Pt,{className:"py-12",children:i.jsxs("div",{className:"text-center text-bambu-gray",children:[i.jsx(sl,{className:"w-16 h-16 mx-auto mb-4 opacity-30"}),i.jsx("p",{className:"text-lg font-medium text-white mb-2",children:a("settings.apiKeysEmptyTitle")}),i.jsx("p",{className:"text-sm mb-4",children:a("settings.apiKeysEmptyDescription")}),i.jsxs(Oe,{onClick:()=>B(!0),children:[i.jsx(rr,{className:"w-4 h-4"}),a("settings.createFirstKey")]})]})})}),i.jsxs(Tt,{className:"mt-6",children:[i.jsx(qn,{children:i.jsx("h3",{className:"text-base font-semibold text-white",children:a("settings.webhookEndpoints")})}),i.jsxs(Pt,{className:"space-y-3 text-sm",children:[i.jsx("p",{className:"text-bambu-gray",children:a("settings.webhookApiKeyHint")}),i.jsxs("div",{className:"space-y-2 font-mono text-xs",children:[i.jsxs("div",{className:"p-2 bg-bambu-dark rounded",children:[i.jsx("span",{className:"text-blue-400",children:"GET"})," ",i.jsx("span",{className:"text-white",children:"/api/v1/webhook/status"}),i.jsxs("span",{className:"text-bambu-gray",children:[" - ",a("settings.webhook.getAllStatus")]})]}),i.jsxs("div",{className:"p-2 bg-bambu-dark rounded",children:[i.jsx("span",{className:"text-blue-400",children:"GET"})," ",i.jsx("span",{className:"text-white",children:"/api/v1/webhook/status/:id"}),i.jsxs("span",{className:"text-bambu-gray",children:[" - ",a("settings.webhook.getSpecificStatus")]})]}),i.jsxs("div",{className:"p-2 bg-bambu-dark rounded",children:[i.jsx("span",{className:"text-green-400",children:"POST"})," ",i.jsx("span",{className:"text-white",children:"/api/v1/webhook/queue"}),i.jsxs("span",{className:"text-bambu-gray",children:[" - ",a("settings.webhook.addToQueue")]})]}),i.jsxs("div",{className:"p-2 bg-bambu-dark rounded",children:[i.jsx("span",{className:"text-orange-400",children:"POST"})," ",i.jsx("span",{className:"text-white",children:"/api/v1/webhook/printer/:id/pause"}),i.jsxs("span",{className:"text-bambu-gray",children:[" - ",a("settings.webhook.pausePrint")]})]}),i.jsxs("div",{className:"p-2 bg-bambu-dark rounded",children:[i.jsx("span",{className:"text-orange-400",children:"POST"})," ",i.jsx("span",{className:"text-white",children:"/api/v1/webhook/printer/:id/resume"}),i.jsxs("span",{className:"text-bambu-gray",children:[" - ",a("settings.webhook.resumePrint")]})]}),i.jsxs("div",{className:"p-2 bg-bambu-dark rounded",children:[i.jsx("span",{className:"text-red-400",children:"POST"})," ",i.jsx("span",{className:"text-white",children:"/api/v1/webhook/printer/:id/stop"}),i.jsxs("span",{className:"text-bambu-gray",children:[" - ",a("settings.webhook.stopPrint")]})]})]})]})]})]}),i.jsxs("div",{children:[i.jsxs("div",{className:"mb-6",children:[i.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx($m,{className:"w-5 h-5 text-bambu-green"}),a("settings.apiBrowser")]}),i.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:a("settings.apiBrowserDescription")})]}),i.jsx(Tt,{className:"mb-4",children:i.jsxs(Pt,{className:"py-3",children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-2",children:a("settings.apiKeyForTesting")}),i.jsx("input",{type:"text",value:ge,onChange:Se=>le(Se.target.value),placeholder:a("settings.apiKeyPlaceholder"),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white font-mono text-sm focus:border-bambu-green focus:outline-none"}),i.jsx("p",{className:"text-xs text-bambu-gray mt-2",children:a("settings.apiKeyHint")})]})}),i.jsx(vJe,{apiKey:ge})]})]}),q==="virtual-printer"&&i.jsx(uJe,{}),q==="filament"&&k&&i.jsx(i.Fragment,{children:i.jsxs("div",{className:"flex flex-col lg:flex-row gap-6 lg:gap-8",children:[i.jsxs("div",{className:"lg:w-1/3 space-y-6",children:[i.jsx(iJe,{}),i.jsxs(Tt,{children:[i.jsx(qn,{children:i.jsx("h2",{className:"text-lg font-semibold text-white",children:a("settings.amsDisplayThresholds")})}),i.jsxs(Pt,{className:"space-y-4",children:[i.jsx("p",{className:"text-sm text-bambu-gray",children:a("settings.amsThresholdsDescription")}),i.jsxs("div",{className:"space-y-3",children:[i.jsxs("div",{className:"flex items-center gap-2 text-white",children:[i.jsx(WF,{className:"w-4 h-4 text-blue-400"}),i.jsx("span",{className:"font-medium",children:a("settings.humidity")})]}),i.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[a("settings.goodGreen")," ≤"]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("input",{type:"number",min:"0",max:"100",value:k.ams_humidity_good??40,onChange:Se=>$t("ams_humidity_good",parseInt(Se.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"}),i.jsx("span",{className:"text-bambu-gray",children:"%"})]})]}),i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[a("settings.fairOrange")," ≤"]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("input",{type:"number",min:"0",max:"100",value:k.ams_humidity_fair??60,onChange:Se=>$t("ams_humidity_fair",parseInt(Se.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"}),i.jsx("span",{className:"text-bambu-gray",children:"%"})]})]})]}),i.jsx("p",{className:"text-xs text-bambu-gray",children:a("settings.aboveFairBad")})]}),i.jsxs("div",{className:"space-y-3 pt-2 border-t border-bambu-dark-tertiary",children:[i.jsxs("div",{className:"flex items-center gap-2 text-white",children:[i.jsx(bC,{className:"w-4 h-4 text-orange-400"}),i.jsx("span",{className:"font-medium",children:a("settings.temperature")})]}),i.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[a("settings.goodBlue")," ≤"]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("input",{type:"number",step:"0.5",min:"0",max:"60",value:k.ams_temp_good??28,onChange:Se=>$t("ams_temp_good",parseFloat(Se.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"}),i.jsx("span",{className:"text-bambu-gray",children:"°C"})]})]}),i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[a("settings.fairOrange")," ≤"]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("input",{type:"number",step:"0.5",min:"0",max:"60",value:k.ams_temp_fair??35,onChange:Se=>$t("ams_temp_fair",parseFloat(Se.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"}),i.jsx("span",{className:"text-bambu-gray",children:"°C"})]})]})]}),i.jsx("p",{className:"text-xs text-bambu-gray",children:a("settings.aboveFairHot")})]}),i.jsxs("div",{className:"space-y-3 pt-4 border-t border-bambu-dark-tertiary",children:[i.jsxs("div",{className:"flex items-center gap-2 text-white",children:[i.jsx(Uc,{className:"w-4 h-4 text-purple-400"}),i.jsx("span",{className:"font-medium",children:a("settings.historyRetention")})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:a("settings.keepSensorHistory")}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("input",{type:"number",min:"1",max:"365",value:k.ams_history_retention_days??30,onChange:Se=>$t("ams_history_retention_days",parseInt(Se.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"}),i.jsx("span",{className:"text-bambu-gray",children:a("common.days")})]})]}),i.jsx("p",{className:"text-xs text-bambu-gray",children:a("settings.historyRetentionDescription")})]}),i.jsxs("div",{className:"space-y-3 pt-4 border-t border-bambu-dark-tertiary",children:[i.jsxs("div",{className:"flex items-center gap-2 text-white",children:[i.jsx(_r,{className:"w-4 h-4 text-bambu-green"}),i.jsx("span",{className:"font-medium",children:a("settings.printModal")})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-white",children:a("settings.expandCustomMapping")}),i.jsx("p",{className:"text-xs text-bambu-gray mt-0.5",children:a("settings.expandCustomMappingDescription")})]}),i.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:k.per_printer_mapping_expanded??!1,onChange:Se=>$t("per_printer_mapping_expanded",Se.target.checked),className:"sr-only peer"}),i.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]})]})]})]})]}),i.jsxs("div",{className:"lg:w-2/3 space-y-6",children:[i.jsx(aJe,{}),i.jsx(sJe,{})]})]})}),se!==null&&i.jsx(_n,{title:a("settings.deleteApiKeyTitle"),message:a("settings.deleteApiKeyMessage"),confirmText:a("settings.deleteKey"),variant:"danger",onConfirm:()=>{Jt.mutate(se),ue(null)},onCancel:()=>ue(null)}),A&&i.jsx(YZe,{plug:$,onClose:()=>{R(!1),U(null)}}),W&&i.jsx(ZZe,{provider:te,onClose:()=>{O(!1),ie(null)}}),Y&&i.jsx(JZe,{template:Y,onClose:()=>ae(null)}),de&&i.jsx(tJe,{onClose:()=>pe(!1)}),I&&i.jsx(_n,{title:a("settings.clearNotificationLogs"),message:a("settings.clearLogsMessage"),confirmText:a("settings.clearLogs"),variant:"warning",onConfirm:async()=>{F(!1);try{const Se=await fe.clearNotificationLogs(30);o(Se.message,"success")}catch{o(a("settings.toast.clearLogsFailed"),"error")}},onCancel:()=>F(!1)}),Z&&i.jsx(_n,{title:a("settings.resetUiPreferences"),message:a("settings.resetUiPreferencesMessage"),confirmText:a("settings.resetPreferences"),variant:"default",onConfirm:()=>{xe(!1),localStorage.clear(),o(a("settings.toast.uiPreferencesReset"),"success"),setTimeout(()=>window.location.reload(),1e3)},onCancel:()=>xe(!1)}),he&&i.jsx(_n,{title:`Turn All Plugs ${he==="on"?"On":"Off"}`,message:`This will turn ${he==="on"?"ON":"OFF"} all ${Ie?.filter(Se=>Se.enabled).length||0} enabled smart plugs. ${he==="off"?"Any running printers may be affected!":""}`,confirmText:`Turn All ${he==="on"?"On":"Off"}`,variant:he==="off"?"danger":"warning",onConfirm:()=>{const Se=he;ce(null),bt.mutate(Se)},onCancel:()=>ce(null)}),Ae&&gn?.release_notes&&i.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",onClick:()=>_e(!1),children:i.jsxs(Tt,{className:"w-full max-w-2xl max-h-[80vh] flex flex-col",onClick:Se=>Se.stopPropagation(),children:[i.jsxs(qn,{className:"flex flex-row items-center justify-between shrink-0",children:[i.jsxs("div",{children:[i.jsxs("h2",{className:"text-lg font-semibold text-white",children:["Release Notes - v",gn.latest_version]}),gn.release_name&&gn.release_name!==gn.latest_version&&i.jsx("p",{className:"text-sm text-bambu-gray",children:gn.release_name})]}),i.jsx("button",{onClick:()=>_e(!1),className:"p-1 rounded hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white",children:i.jsx(zt,{className:"w-5 h-5"})})]}),i.jsx(Pt,{className:"overflow-y-auto flex-1",children:i.jsx("pre",{className:"text-sm text-bambu-gray whitespace-pre-wrap font-sans",children:gn.release_notes})}),i.jsxs("div",{className:"p-4 border-t border-bambu-dark-tertiary shrink-0 flex gap-2",children:[gn.release_url&&i.jsx("a",{href:gn.release_url,target:"_blank",rel:"noopener noreferrer",className:"flex-1",children:i.jsxs(Oe,{variant:"secondary",className:"w-full",children:[i.jsx(ei,{className:"w-4 h-4"}),"View on GitHub"]})}),i.jsx(Oe,{onClick:()=>_e(!1),className:"flex-1",children:"Close"})]})]})}),q==="users"&&i.jsxs("div",{className:"space-y-6",children:[i.jsxs("div",{className:"flex gap-1 border-b border-bambu-dark-tertiary",children:[i.jsxs("button",{onClick:()=>j("users"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${E==="users"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[i.jsx(Sm,{className:"w-4 h-4"}),a("settings.tabs.users")]}),i.jsxs("button",{onClick:()=>j("email"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${E==="email"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[i.jsx(Lv,{className:"w-4 h-4"}),a("settings.tabs.emailAuth")||"Email Authentication",Rr?.advanced_auth_enabled&&i.jsx("span",{className:"w-2 h-2 rounded-full bg-green-400"})]})]}),E==="users"&&i.jsxs(i.Fragment,{children:[i.jsx(Tt,{children:i.jsx(Pt,{className:"py-4",children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx("div",{className:`w-10 h-10 rounded-full flex items-center justify-center ${l?"bg-green-500/20":"bg-gray-500/20"}`,children:l?i.jsx(Jh,{className:"w-5 h-5 text-green-400"}):i.jsx(o1,{className:"w-5 h-5 text-gray-400"})}),i.jsxs("div",{children:[i.jsx("h3",{className:"text-white font-medium",children:a("settings.authentication")}),i.jsx("p",{className:"text-sm text-bambu-gray",children:a(l?"settings.authEnabledDescription":"settings.authDisabledDescription")})]})]}),l?c?.is_admin&&i.jsxs(Oe,{variant:"secondary",onClick:()=>$e(!0),children:[i.jsx(o1,{className:"w-4 h-4"}),a("common.disable")]}):i.jsxs(Oe,{onClick:()=>e("/setup"),children:[i.jsx(Jh,{className:"w-4 h-4"}),a("common.enable")]})]})})}),Rr?.advanced_auth_enabled&&i.jsx(Tt,{className:"border-blue-500/30 bg-blue-500/5",children:i.jsx(Pt,{className:"py-4",children:i.jsxs("div",{className:"flex items-start gap-3",children:[i.jsx("div",{className:"w-10 h-10 rounded-full flex items-center justify-center bg-blue-500/20 flex-shrink-0",children:i.jsx(Lv,{className:"w-5 h-5 text-blue-400"})}),i.jsxs("div",{children:[i.jsx("h3",{className:"text-white font-medium",children:a("settings.email.advancedAuthEnabled")}),i.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:a("settings.email.advancedAuthEnabledDesc")})]})]})})}),l&&i.jsxs("div",{className:"grid grid-cols-1 xl:grid-cols-2 gap-6",children:[i.jsxs("div",{className:"space-y-6",children:[c&&i.jsxs(Tt,{children:[i.jsx(qn,{children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("h3",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(Sm,{className:"w-5 h-5 text-bambu-green"}),a("settings.currentUser")]}),i.jsxs(Oe,{size:"sm",variant:"ghost",onClick:()=>ke(!0),children:[i.jsx(sl,{className:"w-4 h-4"}),a("settings.changePassword")]})]})}),i.jsx(Pt,{children:i.jsx("div",{className:"flex items-center justify-between",children:i.jsxs("div",{children:[i.jsx("p",{className:"text-white font-medium text-lg",children:c.username}),i.jsxs("div",{className:"flex flex-wrap gap-1 mt-2",children:[c.is_admin&&i.jsx("span",{className:"px-2 py-0.5 rounded-full text-xs font-medium bg-purple-500/20 text-purple-300",children:a("settings.admin")}),c.groups?.map(Se=>i.jsx("span",{className:`px-2 py-0.5 rounded-full text-xs font-medium ${Se.name==="Administrators"?"bg-purple-500/20 text-purple-300":Se.name==="Operators"?"bg-blue-500/20 text-blue-300":Se.name==="Viewers"?"bg-green-500/20 text-green-300":"bg-gray-500/20 text-gray-300"}`,children:Se.name},Se.id))]})]})})})]}),i.jsxs(Tt,{children:[i.jsx(qn,{children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("h3",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(Sm,{className:"w-5 h-5 text-bambu-green"}),a("settings.users")]}),bi("users:create")&&i.jsxs(Oe,{size:"sm",onClick:()=>{Ve(!0),Bt({username:"",password:"",email:"",confirmPassword:"",role:"user",group_ids:[]})},children:[i.jsx(rr,{className:"w-4 h-4"}),a("settings.addUser")]})]})}),i.jsx(Pt,{children:Nf?i.jsx("div",{className:"flex items-center justify-center py-8",children:i.jsx(lt,{className:"w-6 h-6 text-bambu-green animate-spin"})}):_h.length===0?i.jsx("p",{className:"text-center text-bambu-gray py-8",children:a("settings.noUsersFound")}):i.jsx("div",{className:"divide-y divide-bambu-dark-tertiary",children:_h.map(Se=>i.jsxs("div",{className:"py-3 flex items-center justify-between",children:[i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsx("p",{className:"text-white font-medium truncate",children:Se.username}),i.jsxs("div",{className:"flex flex-wrap gap-1 mt-1",children:[Se.is_admin&&i.jsx("span",{className:"px-2 py-0.5 rounded-full text-xs font-medium bg-purple-500/20 text-purple-300",children:a("settings.admin")}),Se.groups?.map(Dt=>i.jsx("span",{className:`px-2 py-0.5 rounded-full text-xs font-medium ${Dt.name==="Administrators"?"bg-purple-500/20 text-purple-300":Dt.name==="Operators"?"bg-blue-500/20 text-blue-300":Dt.name==="Viewers"?"bg-green-500/20 text-green-300":"bg-gray-500/20 text-gray-300"}`,children:Dt.name},Dt.id))]})]}),i.jsxs("div",{className:"flex items-center gap-1 ml-4",children:[bi("users:update")&&i.jsx(Oe,{size:"sm",variant:"ghost",onClick:()=>Nh(Se),children:i.jsx(Mm,{className:"w-4 h-4"})}),bi("users:delete")&&Se.id!==c?.id&&i.jsx(Oe,{size:"sm",variant:"ghost",onClick:()=>ks(Se.id),children:i.jsx(Qt,{className:"w-4 h-4"})})]})]},Se.id))})})]})]}),i.jsx("div",{children:i.jsxs(Tt,{children:[i.jsx(qn,{children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("h3",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(AD,{className:"w-5 h-5 text-bambu-green"}),a("settings.groups")]}),bi("groups:create")&&i.jsxs(Oe,{size:"sm",onClick:()=>e("/groups/new"),children:[i.jsx(rr,{className:"w-4 h-4"}),a("settings.addGroup")]})]})}),i.jsx(Pt,{children:kf?i.jsx("div",{className:"flex items-center justify-center py-8",children:i.jsx(lt,{className:"w-6 h-6 text-bambu-green animate-spin"})}):za.length===0?i.jsx("p",{className:"text-center text-bambu-gray py-8",children:a("settings.noGroupsFound")}):i.jsx("div",{className:"divide-y divide-bambu-dark-tertiary",children:za.map(Se=>i.jsxs("div",{className:"py-3",children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(AD,{className:`w-4 h-4 ${Se.name==="Administrators"?"text-purple-400":Se.name==="Operators"?"text-blue-400":Se.name==="Viewers"?"text-green-400":"text-bambu-gray"}`}),i.jsx("span",{className:"text-white font-medium",children:Se.name}),Se.is_system&&i.jsx("span",{className:"px-2 py-0.5 rounded text-xs bg-yellow-500/20 text-yellow-400",children:a("settings.system")})]}),i.jsxs("div",{className:"flex items-center gap-1",children:[bi("groups:update")&&i.jsx(Oe,{size:"sm",variant:"ghost",onClick:()=>e(`/groups/${Se.id}/edit`),children:i.jsx(Mm,{className:"w-4 h-4"})}),bi("groups:delete")&&!Se.is_system&&i.jsx(Oe,{size:"sm",variant:"ghost",onClick:()=>sn(Se.id),children:i.jsx(Qt,{className:"w-4 h-4"})})]})]}),i.jsx("p",{className:"text-sm text-bambu-gray mt-1 ml-6",children:Se.description||a("settings.noDescription")}),i.jsxs("div",{className:"flex items-center gap-4 mt-2 ml-6 text-xs text-bambu-gray",children:[i.jsx("span",{children:a("settings.userCount",{count:Se.user_count})}),i.jsx("span",{children:a("settings.permissionCount",{count:Se.permissions.length})})]})]},Se.id))})})]})})]}),!l&&i.jsx(Tt,{children:i.jsx(Pt,{className:"py-6",children:i.jsxs("div",{className:"text-center",children:[i.jsx(o1,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),i.jsx("h3",{className:"text-lg font-medium text-white mb-2",children:a("settings.authDisabledTitle")}),i.jsx("p",{className:"text-sm text-bambu-gray mb-4 max-w-md mx-auto",children:a("settings.authDisabledMessage")}),i.jsxs("ul",{className:"space-y-2 text-sm text-bambu-gray mb-6 text-left max-w-xs mx-auto",children:[i.jsxs("li",{className:"flex items-start gap-2",children:[i.jsx(pr,{className:"w-4 h-4 text-bambu-green mt-0.5 flex-shrink-0"}),i.jsx("span",{children:a("settings.authDisabledFeature1")})]}),i.jsxs("li",{className:"flex items-start gap-2",children:[i.jsx(pr,{className:"w-4 h-4 text-bambu-green mt-0.5 flex-shrink-0"}),i.jsx("span",{children:a("settings.authDisabledFeature2")})]}),i.jsxs("li",{className:"flex items-start gap-2",children:[i.jsx(pr,{className:"w-4 h-4 text-bambu-green mt-0.5 flex-shrink-0"}),i.jsx("span",{children:a("settings.authDisabledFeature3")})]})]}),i.jsxs(Oe,{onClick:()=>e("/setup"),children:[i.jsx(Jh,{className:"w-4 h-4"}),a("settings.enableAuthentication")]})]})})})]}),E==="email"&&i.jsx("div",{className:"max-w-2xl",children:i.jsx(gJe,{})})]}),Ce&&!Rr?.advanced_auth_enabled&&i.jsx("div",{className:"fixed inset-0 bg-black flex items-center justify-center z-50 p-4",onClick:()=>{Ve(!1),Bt({username:"",password:"",email:"",confirmPassword:"",role:"user",group_ids:[]})},children:i.jsxs(Tt,{className:"w-full max-w-md",onClick:Se=>Se.stopPropagation(),children:[i.jsx(qn,{children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(Sm,{className:"w-5 h-5 text-bambu-green"}),i.jsx("h2",{className:"text-lg font-semibold text-white",children:a("settings.createUser")})]}),i.jsx(Oe,{variant:"ghost",size:"sm",onClick:()=>{Ve(!1),Bt({username:"",password:"",email:"",confirmPassword:"",role:"user",group_ids:[]})},children:i.jsx(zt,{className:"w-5 h-5"})})]})}),i.jsxs(Pt,{children:[i.jsxs("div",{className:"space-y-4",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:a("settings.username")}),i.jsx("input",{type:"text",value:ft.username,onChange:Se=>Bt({...ft,username:Se.target.value}),className:"w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors",placeholder:a("settings.enterUsername"),autoComplete:"username"})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:a("settings.password")}),i.jsx("input",{type:"password",value:ft.password,onChange:Se=>Bt({...ft,password:Se.target.value}),className:"w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors",placeholder:a("settings.enterPassword"),autoComplete:"new-password",minLength:6})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:a("settings.confirmPassword")}),i.jsx("input",{type:"password",value:ft.confirmPassword,onChange:Se=>Bt({...ft,confirmPassword:Se.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors ${ft.confirmPassword&&ft.password!==ft.confirmPassword?"border-red-500":"border-bambu-dark-tertiary"}`,placeholder:a("settings.confirmPasswordPlaceholder"),autoComplete:"new-password",minLength:6}),ft.confirmPassword&&ft.password!==ft.confirmPassword&&i.jsx("p",{className:"text-red-400 text-xs mt-1",children:a("settings.passwordsDoNotMatch")})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:a("settings.groups")}),i.jsxs("div",{className:"space-y-2 max-h-40 overflow-y-auto p-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg",children:[za.map(Se=>i.jsxs("label",{className:"flex items-center gap-3 px-2 py-1.5 rounded hover:bg-bambu-dark-tertiary cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:ft.group_ids.includes(Se.id),onChange:()=>pc(Se.id),className:"w-4 h-4 rounded border-bambu-gray text-bambu-green focus:ring-bambu-green focus:ring-offset-0 bg-bambu-dark"}),i.jsx("span",{className:"text-sm text-white",children:Se.name}),Se.is_system&&i.jsx("span",{className:"text-xs text-yellow-400",children:a("settings.systemBadge")})]},Se.id)),za.length===0&&i.jsx("p",{className:"text-sm text-bambu-gray",children:a("settings.noGroupsAvailable")})]})]})]}),i.jsxs("div",{className:"mt-6 flex justify-end gap-3",children:[i.jsx(Oe,{variant:"secondary",onClick:()=>{Ve(!1),Bt({username:"",password:"",email:"",confirmPassword:"",role:"user",group_ids:[]})},children:a("common.cancel")}),i.jsx(Oe,{onClick:Rl,disabled:mc.isPending||!ft.username||!ft.password||ft.password!==ft.confirmPassword||ft.password.length<6,children:mc.isPending?i.jsxs(i.Fragment,{children:[i.jsx(lt,{className:"w-4 h-4 animate-spin"}),a("settings.creating")]}):i.jsxs(i.Fragment,{children:[i.jsx(rr,{className:"w-4 h-4"}),a("settings.createUser")]})})]})]})]})}),Ce&&Rr?.advanced_auth_enabled&&i.jsx(rJe,{formData:ft,setFormData:Bt,groups:za,onClose:()=>{Ve(!1),Bt({username:"",password:"",email:"",confirmPassword:"",role:"user",group_ids:[]})},onCreate:Rl,isCreating:mc.isPending,isCreateButtonDisabled:mc.isPending||!ft.username||!ft.email}),je&&ve!==null&&i.jsx("div",{className:"fixed inset-0 bg-black flex items-center justify-center z-50 p-4",onClick:()=>{Re(!1),Ge(null),Bt({username:"",password:"",email:"",confirmPassword:"",role:"user",group_ids:[]})},children:i.jsxs(Tt,{className:"w-full max-w-md",onClick:Se=>Se.stopPropagation(),children:[i.jsx(qn,{children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(Mm,{className:"w-5 h-5 text-bambu-green"}),i.jsx("h2",{className:"text-lg font-semibold text-white",children:a("settings.editUser")})]}),i.jsx(Oe,{variant:"ghost",size:"sm",onClick:()=>{Re(!1),Ge(null),Bt({username:"",password:"",email:"",confirmPassword:"",role:"user",group_ids:[]})},children:i.jsx(zt,{className:"w-5 h-5"})})]})}),i.jsxs(Pt,{children:[i.jsxs("div",{className:"space-y-4",children:[i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm font-medium text-white mb-2",children:[a("settings.username")," ",Rr?.advanced_auth_enabled&&i.jsx("span",{className:"text-red-400",children:"*"})]}),i.jsx("input",{type:"text",value:ft.username,onChange:Se=>Bt({...ft,username:Se.target.value}),className:"w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors",placeholder:a("settings.enterUsername"),autoComplete:"username"})]}),i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm font-medium text-white mb-2",children:[a("users.form.email")||"Email"," ",Rr?.advanced_auth_enabled?i.jsx("span",{className:"text-red-400",children:"*"}):i.jsxs("span",{className:"text-bambu-gray font-normal",children:["(",a("users.form.optional")||"optional",")"]})]}),i.jsx("input",{type:"email",value:ft.email,onChange:Se=>Bt({...ft,email:Se.target.value}),className:"w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors",placeholder:a("users.form.emailPlaceholder")||"user@example.com",required:Rr?.advanced_auth_enabled})]}),!Rr?.advanced_auth_enabled&&i.jsxs(i.Fragment,{children:[i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm font-medium text-white mb-2",children:[a("users.form.password")||"Password"," ",i.jsxs("span",{className:"text-bambu-gray font-normal",children:["(",a("users.form.leaveBlankToKeep")||"leave blank to keep current",")"]})]}),i.jsx("input",{type:"password",value:ft.password,onChange:Se=>Bt({...ft,password:Se.target.value,confirmPassword:""}),className:"w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors",placeholder:a("settings.enterNewPassword"),autoComplete:"new-password",minLength:6})]}),ft.password&&i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:a("settings.confirmPassword")}),i.jsx("input",{type:"password",value:ft.confirmPassword,onChange:Se=>Bt({...ft,confirmPassword:Se.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors ${ft.confirmPassword&&ft.password!==ft.confirmPassword?"border-red-500":"border-bambu-dark-tertiary"}`,placeholder:a("settings.confirmNewPassword"),autoComplete:"new-password",minLength:6}),ft.confirmPassword&&ft.password!==ft.confirmPassword&&i.jsx("p",{className:"text-red-400 text-xs mt-1",children:a("settings.passwordsDoNotMatch")})]})]}),Rr?.advanced_auth_enabled&&i.jsxs("div",{className:"bg-bambu-dark-secondary/50 border border-bambu-green/20 rounded-lg p-3 space-y-3",children:[i.jsx("p",{className:"text-sm text-bambu-gray",children:a("users.form.passwordManagedByAdvancedAuth")||'Password is managed by Advanced Authentication. Use "Reset Password" to send a new password to the user via email.'}),i.jsx(Oe,{variant:"secondary",size:"sm",onClick:()=>ve&&Ns.mutate(ve),disabled:Ns.isPending||!ft.email,className:"w-full",children:Ns.isPending?i.jsxs(i.Fragment,{children:[i.jsx(lt,{className:"w-4 h-4 animate-spin"}),a("users.form.resettingPassword")||"Resetting Password..."]}):i.jsxs(i.Fragment,{children:[i.jsx(mo,{className:"w-4 h-4"}),a("users.form.resetPassword")||"Reset Password"]})})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:a("users.form.groups")||"Groups"}),i.jsx("div",{className:"space-y-2 max-h-40 overflow-y-auto p-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg",children:za.map(Se=>i.jsxs("label",{className:"flex items-center gap-3 px-2 py-1.5 rounded hover:bg-bambu-dark-tertiary cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:ft.group_ids.includes(Se.id),onChange:()=>pc(Se.id),className:"w-4 h-4 rounded border-bambu-gray text-bambu-green focus:ring-bambu-green focus:ring-offset-0 bg-bambu-dark"}),i.jsx("span",{className:"text-sm text-white",children:Se.name}),Se.is_system&&i.jsxs("span",{className:"text-xs text-yellow-400",children:["(",a("users.system")||"System",")"]})]},Se.id))})]})]}),i.jsxs("div",{className:"mt-6 flex justify-end gap-3",children:[i.jsx(Oe,{variant:"secondary",onClick:()=>{Re(!1),Ge(null),Bt({username:"",password:"",email:"",confirmPassword:"",role:"user",group_ids:[]})},children:a("users.modal.cancel")||"Cancel"}),i.jsx(Oe,{onClick:()=>Cf(ve),disabled:hc.isPending||!ft.username||Rr?.advanced_auth_enabled&&!ft.email||!!(!Rr?.advanced_auth_enabled&&ft.password&&(ft.password!==ft.confirmPassword||ft.password.length<6)),children:hc.isPending?i.jsxs(i.Fragment,{children:[i.jsx(lt,{className:"w-4 h-4 animate-spin"}),a("users.modal.saving")||"Saving..."]}):i.jsxs(i.Fragment,{children:[i.jsx(gs,{className:"w-4 h-4"}),a("users.modal.saveChanges")||"Save Changes"]})})]})]})]})}),rt!==null&&i.jsx("div",{className:"fixed inset-0 bg-black/80 flex items-center justify-center z-50 p-4",onClick:()=>{vt(null),kt(null)},children:i.jsxs(Tt,{className:"w-full max-w-md",onClick:Se=>Se.stopPropagation(),children:[i.jsx(qn,{children:i.jsxs("div",{className:"flex items-center gap-2 text-red-400",children:[i.jsx(Qt,{className:"w-5 h-5"}),i.jsx("h3",{className:"text-lg font-semibold",children:a("settings.deleteUserTitle")})]})}),i.jsx(Pt,{className:"space-y-4",children:qe?i.jsx("div",{className:"flex items-center justify-center py-4",children:i.jsx("div",{className:"animate-spin rounded-full h-6 w-6 border-2 border-bambu-green border-t-transparent"})}):_t&&_t.archives+_t.queue_items+_t.library_files>0?i.jsxs(i.Fragment,{children:[i.jsx("p",{className:"text-white",children:a("settings.userHasCreated")}),i.jsxs("ul",{className:"list-disc list-inside text-bambu-gray space-y-1",children:[_t.archives>0&&i.jsxs("li",{children:[_t.archives," archive",_t.archives!==1?"s":""]}),_t.queue_items>0&&i.jsxs("li",{children:[_t.queue_items," queue item",_t.queue_items!==1?"s":""]}),_t.library_files>0&&i.jsxs("li",{children:[_t.library_files," library file",_t.library_files!==1?"s":""]})]}),i.jsx("p",{className:"text-bambu-gray text-sm",children:a("settings.userItemsQuestion")}),i.jsxs("div",{className:"flex flex-col gap-2",children:[i.jsx(Oe,{variant:"danger",onClick:()=>Yi.mutate({id:rt,deleteItems:!0}),disabled:Yi.isPending,className:"justify-center",children:a("settings.deleteUserAndItems")}),i.jsx(Oe,{variant:"secondary",onClick:()=>Yi.mutate({id:rt,deleteItems:!1}),disabled:Yi.isPending,className:"justify-center",children:a("settings.deleteUserKeepItems")}),i.jsx(Oe,{variant:"ghost",onClick:()=>{vt(null),kt(null)},disabled:Yi.isPending,className:"justify-center",children:a("common.cancel")})]})]}):i.jsxs(i.Fragment,{children:[i.jsx("p",{className:"text-white",children:a("settings.deleteUserConfirm")}),i.jsx("p",{className:"text-bambu-gray text-sm",children:a("settings.actionCannotBeUndone")}),i.jsxs("div",{className:"flex gap-2 justify-end",children:[i.jsx(Oe,{variant:"ghost",onClick:()=>{vt(null),kt(null)},disabled:Yi.isPending,children:a("common.cancel")}),i.jsx(Oe,{variant:"danger",onClick:()=>Yi.mutate({id:rt,deleteItems:!1}),disabled:Yi.isPending,children:a("settings.deleteUserTitle")})]})]})})]})}),tn!==null&&i.jsx(_n,{title:a("settings.deleteGroupTitle"),message:a("settings.deleteGroupMessage"),confirmText:a("settings.deleteGroup"),variant:"danger",onConfirm:()=>{Vs.mutate(tn),sn(null)},onCancel:()=>sn(null)}),q==="backup"&&i.jsx(hJe,{}),Ue&&i.jsx(_n,{title:a("settings.disableAuthenticationTitle"),message:a("settings.disableAuthenticationMessage"),confirmText:a("settings.disableAuthentication"),variant:"danger",onConfirm:async()=>{try{await fe.disableAuth(),o(a("settings.toast.authDisabled"),"success"),await d(),$e(!1),window.location.href="/"}catch(Se){const Dt=Se instanceof Error?Se.message:a("settings.toast.authDisableFailed");o(Dt,"error")}},onCancel:()=>$e(!1)}),Fe&&i.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",onClick:()=>{ke(!1),Ne({currentPassword:"",newPassword:"",confirmPassword:""})},children:i.jsxs(Tt,{className:"w-full max-w-md",onClick:Se=>Se.stopPropagation(),children:[i.jsx(qn,{children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(sl,{className:"w-5 h-5 text-bambu-green"}),i.jsx("h2",{className:"text-lg font-semibold text-white",children:a("settings.changePassword")})]}),i.jsx(Oe,{variant:"ghost",size:"sm",onClick:()=>{ke(!1),Ne({currentPassword:"",newPassword:"",confirmPassword:""})},children:i.jsx(zt,{className:"w-5 h-5"})})]})}),i.jsxs(Pt,{children:[i.jsxs("div",{className:"space-y-4",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:"Current Password"}),i.jsx("input",{type:"password",value:Me.currentPassword,onChange:Se=>Ne({...Me,currentPassword:Se.target.value}),className:"w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors",placeholder:a("settings.enterCurrentPassword"),autoComplete:"current-password"})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:"New Password"}),i.jsx("input",{type:"password",value:Me.newPassword,onChange:Se=>Ne({...Me,newPassword:Se.target.value}),className:"w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors",placeholder:a("settings.enterNewPasswordMin6"),autoComplete:"new-password",minLength:6})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:"Confirm New Password"}),i.jsx("input",{type:"password",value:Me.confirmPassword,onChange:Se=>Ne({...Me,confirmPassword:Se.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors ${Me.confirmPassword&&Me.newPassword!==Me.confirmPassword?"border-red-500":"border-bambu-dark-tertiary"}`,placeholder:a("settings.confirmNewPassword"),autoComplete:"new-password",minLength:6}),Me.confirmPassword&&Me.newPassword!==Me.confirmPassword&&i.jsx("p",{className:"text-red-400 text-xs mt-1",children:a("settings.passwordsDoNotMatch")})]})]}),i.jsxs("div",{className:"mt-6 flex justify-end gap-3",children:[i.jsx(Oe,{variant:"secondary",onClick:()=>{ke(!1),Ne({currentPassword:"",newPassword:"",confirmPassword:""})},children:a("common.cancel")}),i.jsx(Oe,{onClick:async()=>{if(Me.newPassword!==Me.confirmPassword){o(a("settings.toast.passwordsDoNotMatch"),"error");return}if(Me.newPassword.length<6){o(a("settings.toast.passwordTooShort"),"error");return}We(!0);try{await fe.changePassword(Me.currentPassword,Me.newPassword),o(a("settings.toast.passwordChanged"),"success"),ke(!1),Ne({currentPassword:"",newPassword:"",confirmPassword:""})}catch(Se){const Dt=Se instanceof Error?Se.message:"Failed to change password";o(Dt,"error")}finally{We(!1)}},disabled:Pe||!Me.currentPassword||!Me.newPassword||Me.newPassword!==Me.confirmPassword||Me.newPassword.length<6,children:Pe?i.jsxs(i.Fragment,{children:[i.jsx(lt,{className:"w-4 h-4 animate-spin"}),a("settings.changing")]}):i.jsxs(i.Fragment,{children:[i.jsx(sl,{className:"w-4 h-4"}),a("settings.changePassword")]})})]})]})]})})]})}const Mse=t=>{const e=parseFloat(t);return(Math.trunc(e*1e3)/1e3).toFixed(3)},NJe=t=>t.startsWith("HH")?"HF":"S",kJe=t=>{const e=t.match(/^([A-Z]{2}\d{2})/);return e?e[1]:"HH00"},Ese=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 Kj({profile:t,onEdit:e,onCopy:n,selectionMode:r,isSelected:a,onToggleSelect:s,note:o}){const l=NJe(t.nozzle_id),c=t.nozzle_diameter,d=()=>{r&&s?s():e()};return i.jsxs("div",{className:"flex items-center gap-2",children:[r&&i.jsx("button",{onClick:s,className:"text-bambu-gray hover:text-white transition-colors p-1",children:a?i.jsx(ho,{className:"w-4 h-4 text-bambu-green"}):i.jsx(Nl,{className:"w-4 h-4"})}),i.jsxs("button",{onClick:d,className:`flex-1 text-left px-3 py-2 bg-bambu-dark rounded hover:bg-bambu-dark-tertiary transition-colors ${a?"ring-1 ring-bambu-green":""}`,children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("span",{className:"text-bambu-green font-mono text-sm font-bold whitespace-nowrap",children:Mse(t.k_value)}),i.jsx("span",{className:"text-white text-sm truncate flex-1",title:t.name,children:t.name||"Unnamed"}),o&&i.jsx("span",{title:"Has note",children:i.jsx(JY,{className:"w-3 h-3 text-yellow-500"})}),i.jsxs("span",{className:"text-xs text-bambu-gray whitespace-nowrap",children:[l," ",c]})]}),o&&i.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&&i.jsx("button",{onClick:u=>{u.stopPropagation(),n()},className:"text-bambu-gray hover:text-white transition-colors p-1",title:"Copy profile",children:i.jsx(_l,{className:"w-4 h-4"})})]})}function Yj({profile:t,printerId:e,nozzleDiameter:n,existingProfiles:r=[],builtinFilaments:a=[],isDualNozzle:s=!1,initialNote:o="",initialNoteKey:l=null,onClose:c,onSave:d,onSaveNote:u,hasPermission:m}){const{t:p}=Mt(),{showToast:f}=hn(),[x,v]=w.useState(t?.name||""),[g,y]=w.useState(t?.k_value?Mse(t.k_value):"0.020"),[_,N]=w.useState(t?.filament_id||""),[C,T]=w.useState(t?.nozzle_id?kJe(t.nozzle_id):"HH00"),[P,k]=w.useState(t?.nozzle_diameter||n),[D,A]=w.useState(t?[t.extruder_id]:s?[0,1]:[0]),[R,$]=w.useState(!1),[U,W]=w.useState({current:0,total:0}),[O,te]=w.useState(o),ie=Kr.useMemo(()=>{const me=new Map;for(const Ee of a)me.set(Ee.filament_id,Ee.name);const we=new Map;for(const Ee of r)if(Ee.filament_id&&!we.has(Ee.filament_id)){const K=me.get(Ee.filament_id)||Ese(Ee.name||"");we.set(Ee.filament_id,{id:Ee.filament_id,name:K||Ee.filament_id})}return Array.from(we.values()).sort((Ee,q)=>Ee.name.localeCompare(q.name))},[r,a]),Y=dt({mutationFn:me=>(console.log("[KProfile] Calling API..."),fe.setKProfile(e,me)),onSuccess:me=>{if(console.log("[KProfile] Save success:",me),f(p("kProfiles.toast.profileSaved")),u&&O!==o){let we;O===""&&l?we=l:t&&t.slot_id>0?we=t.setting_id||`slot_${t.slot_id}_${t.filament_id}_${t.extruder_id}`:we=`name_${x}_${_}`,u(we,O)}$(!0),setTimeout(()=>{$(!1),d()},2500)},onError:me=>{console.error("[KProfile] Save error:",me),f(me.message,"error"),$(!1)}}),ae=dt({mutationFn:me=>(console.log("[KProfile] Deleting profile..."),fe.deleteKProfile(e,me)),onSuccess:me=>{console.log("[KProfile] Delete success:",me),f(p("kProfiles.toast.profileDeleted")),$(!0),setTimeout(()=>{$(!1),c()},4e3)},onError:me=>{console.error("[KProfile] Delete error:",me),f(me.message,"error"),$(!1)}}),[de,pe]=w.useState(!1),Q=()=>{t&&ae.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})},oe=async me=>{if(me.preventDefault(),s&&!t&&D.length===0){f(p("kProfiles.toast.selectAtLeastOneExtruder"),"error");return}const we=parseFloat(g).toFixed(6),Ee=`${C}-${P}`;if(t||D.length===1){const K={name:x,k_value:we,filament_id:_,nozzle_id:Ee,nozzle_diameter:P,extruder_id:t?t.extruder_id:D[0],setting_id:t?.setting_id,slot_id:t?.slot_id??0};console.log("[KProfile] Saving profile:",K),Y.mutate(K);return}$(!0),W({current:1,total:D.length});const q=D.map(K=>({name:x,k_value:we,filament_id:_,nozzle_id:Ee,nozzle_diameter:P,extruder_id:K,setting_id:void 0,slot_id:0}));console.log(`[KProfile] Saving ${q.length} profiles in batch:`,q);try{if(await fe.setKProfilesBatch(e,q),f(p("kProfiles.toast.profilesSaved",{count:D.length})),u&&O){const K=`name_${x}_${_}`;u(K,O)}}catch(K){console.error("[KProfile] Failed to save batch:",K),f(p("kProfiles.toast.failedToSaveBatch"),"error"),$(!1),W({current:0,total:0});return}W({current:D.length,total:D.length}),setTimeout(()=>{$(!1),W({current:0,total:0}),d()},3e3)};return i.jsxs("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",children:[i.jsxs(Tt,{className:"w-full max-w-md relative",children:[R&&i.jsxs("div",{className:"absolute inset-0 bg-bambu-dark-secondary/90 flex flex-col items-center justify-center z-10 rounded-lg",children:[i.jsx(lt,{className:"w-8 h-8 text-bambu-green animate-spin mb-3"}),i.jsx("p",{className:"text-white font-medium",children:U.total>1?p("kProfiles.modal.savingExtruder",{current:U.current,total:U.total}):p("kProfiles.modal.syncing")}),i.jsx("p",{className:"text-bambu-gray text-sm mt-1",children:p("kProfiles.modal.pleaseWait")})]}),i.jsxs(Pt,{className:"p-0",children:[i.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[i.jsx("h2",{className:"text-xl font-semibold text-white",children:p(t?"kProfiles.modal.editTitle":"kProfiles.modal.addTitle")}),i.jsx("button",{onClick:c,className:"text-bambu-gray hover:text-white transition-colors",disabled:R,children:i.jsx(zt,{className:"w-5 h-5"})})]}),i.jsxs("form",{onSubmit:oe,className:"p-4 space-y-4",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:p("kProfiles.modal.profileName")}),i.jsx("input",{type:"text",value:x,onChange:me=>v(me.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:p("kProfiles.modal.profileNamePlaceholder"),required:!t})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:p("kProfiles.modal.kValue")}),i.jsx("input",{type:"text",inputMode:"decimal",value:g,onChange:me=>{const we=me.target.value;(we===""||/^\d*\.?\d*$/.test(we))&&y(we)},onBlur:me=>{const we=parseFloat(me.target.value);isNaN(we)||y((Math.trunc(we*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:p("kProfiles.modal.kValuePlaceholder"),required:!0}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:p("kProfiles.modal.kValueHelp")})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:p("kProfiles.modal.filament")}),i.jsxs("select",{value:_,onChange:me=>{const we=me.target.value;if(N(we),!t&&we&&!x){const Ee=ie.find(q=>q.id===we);Ee&&v(`${C==="HH00"?"HF":"S"} ${Ee.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:[i.jsx("option",{value:"",children:p("kProfiles.modal.selectFilament")}),t?.filament_id&&i.jsx("option",{value:t.filament_id,children:ie.find(me=>me.id===t.filament_id)?.name||t.filament_id},t.filament_id),!t&&ie.map(me=>i.jsx("option",{value:me.id,children:me.name},me.id))]}),!t&&ie.length===0&&i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:p("kProfiles.modal.noFilamentsHelp")})]}),i.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:p("kProfiles.modal.flowType")}),i.jsxs("select",{value:C,onChange:me=>{const we=me.target.value;if(T(we),!t&&_&&!x){const Ee=ie.find(q=>q.id===_);Ee&&v(`${we==="HS00"?"HF":"S"} ${Ee.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:[i.jsx("option",{value:"HH00",children:p("kProfiles.modal.highFlow")}),i.jsx("option",{value:"HS00",children:p("kProfiles.modal.standard")})]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:p("kProfiles.modal.nozzleSize")}),i.jsxs("select",{value:P,onChange:me=>k(me.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:[i.jsx("option",{value:"0.2",children:"0.2mm"}),i.jsx("option",{value:"0.4",children:"0.4mm"}),i.jsx("option",{value:"0.6",children:"0.6mm"}),i.jsx("option",{value:"0.8",children:"0.8mm"})]})]})]}),s&&i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:p(t?"kProfiles.modal.extruder":"kProfiles.modal.extruders")}),t?i.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?p("kProfiles.modal.left"):p("kProfiles.modal.right")}):i.jsxs("div",{className:"flex gap-4",children:[i.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:D.includes(1),onChange:me=>{me.target.checked?A([...D,1]):A(D.filter(we=>we!==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"}),i.jsx("span",{className:"text-white",children:p("kProfiles.modal.left")})]}),i.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:D.includes(0),onChange:me=>{me.target.checked?A([...D,0]):A(D.filter(we=>we!==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"}),i.jsx("span",{className:"text-white",children:p("kProfiles.modal.right")})]})]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:p("kProfiles.modal.notes")}),i.jsx("textarea",{value:O,onChange:me=>te(me.target.value),placeholder:p("kProfiles.modal.notesPlaceholder"),rows:2,className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none resize-none"}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:p("kProfiles.modal.notesHelp")})]}),i.jsxs("div",{className:"flex gap-2 pt-4",children:[t&&i.jsx(Oe,{type:"button",variant:"secondary",onClick:()=>pe(!0),disabled:ae.isPending||R||!m("kprofiles:delete"),title:m("kprofiles:delete")?void 0:p("kProfiles.permission.noDelete"),className:"text-red-500 hover:bg-red-500/10",children:ae.isPending?i.jsx(lt,{className:"w-4 h-4 animate-spin"}):i.jsx(Qt,{className:"w-4 h-4"})}),i.jsx(Oe,{type:"button",variant:"secondary",onClick:c,disabled:R,className:"flex-1",children:p("common.cancel")}),i.jsxs(Oe,{type:"submit",disabled:Y.isPending||R||!m(t?"kprofiles:update":"kprofiles:create"),title:m(t?"kprofiles:update":"kprofiles:create")?void 0:p(t?"kProfiles.permission.noUpdate":"kProfiles.permission.noCreate"),className:"flex-1",children:[Y.isPending?i.jsx(lt,{className:"w-4 h-4 animate-spin"}):i.jsx(cC,{className:"w-4 h-4"}),p("common.save")]})]})]})]})]}),de&&i.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-[60]",children:i.jsx(Tt,{className:"w-full max-w-sm",children:i.jsxs(Pt,{className:"p-6",children:[i.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[i.jsx("div",{className:"w-10 h-10 rounded-full bg-red-500/20 flex items-center justify-center",children:i.jsx(Qt,{className:"w-5 h-5 text-red-500"})}),i.jsxs("div",{children:[i.jsx("h3",{className:"text-lg font-semibold text-white",children:p("kProfiles.deleteConfirm.title")}),i.jsx("p",{className:"text-sm text-bambu-gray",children:p("kProfiles.deleteConfirm.cannotUndo")})]})]}),i.jsx("p",{className:"text-bambu-gray mb-6",children:p("kProfiles.deleteConfirm.message",{name:t?.name})}),i.jsxs("div",{className:"flex gap-3",children:[i.jsx(Oe,{variant:"secondary",onClick:()=>pe(!1),className:"flex-1",children:p("common.cancel")}),i.jsxs(Oe,{onClick:()=>{pe(!1),Q()},disabled:ae.isPending,className:"flex-1 bg-red-500 hover:bg-red-600 text-white",children:[ae.isPending?i.jsx(lt,{className:"w-4 h-4 animate-spin"}):i.jsx(Qt,{className:"w-4 h-4"}),p("common.delete")]})]})]})})})]})}const i1={NOZZLE_DIAMETER:"bambusy_kprofiles_nozzle",SORT_OPTION:"bambusy_kprofiles_sort"};function CJe(){const{t}=Mt(),{showToast:e}=hn(),{hasPermission:n}=Dr(),[r,a]=w.useState(null),[s,o]=w.useState(()=>localStorage.getItem(i1.NOZZLE_DIAMETER)||"0.4"),[l,c]=w.useState(null),[d,u]=w.useState(!1),[m,p]=w.useState(null),[f,x]=w.useState(""),[v,g]=w.useState("all"),[y,_]=w.useState("all"),[N,C]=w.useState(()=>localStorage.getItem(i1.SORT_OPTION)||"name"),[T,P]=w.useState(!1),[k,D]=w.useState(new Set),[A,R]=w.useState(!1),[$,U]=w.useState(!1),W=w.useCallback(F=>`${F.slot_id}_${F.extruder_id}`,[]);w.useEffect(()=>{localStorage.setItem(i1.NOZZLE_DIAMETER,s)},[s]),w.useEffect(()=>{localStorage.setItem(i1.SORT_OPTION,N)},[N]);const{data:O,isLoading:te}=Ze({queryKey:["printers"],queryFn:fe.getPrinters}),{data:ie,isLoading:Y,isFetching:ae,error:de,refetch:pe}=Ze({queryKey:["kprofiles",r,s],queryFn:async()=>{console.log("[KProfiles] Fetching profiles for printer",r,"nozzle",s);const F=await fe.getKProfiles(r,s);return console.log("[KProfiles] Received profiles:",F?.profiles?.length||0,"profiles"),F},enabled:!!r,retry:!1,staleTime:0,gcTime:0,refetchOnMount:"always"}),{data:Q}=Ze({queryKey:["kprofiles",r,"0.4"],queryFn:()=>fe.getKProfiles(r,"0.4"),enabled:!!r,staleTime:6e4}),{data:oe}=Ze({queryKey:["builtinFilaments"],queryFn:()=>fe.getBuiltinFilaments(),staleTime:3e5}),{data:me}=Ze({queryKey:["filamentIdMap"],queryFn:()=>fe.getFilamentIdMap(),staleTime:3e5}),{data:we,refetch:Ee}=Ze({queryKey:["kprofile-notes",r],queryFn:()=>fe.getKProfileNotes(r),enabled:!!r,staleTime:3e4}),q=de?.message?.includes("not connected");w.useEffect(()=>{if(!r&&O&&O.length>0){const F=O.find(Z=>Z.is_active);F&&a(F.id)}},[r,O]),w.useEffect(()=>{if(r){const F=setTimeout(()=>{pe()},150);return()=>clearTimeout(F)}},[r,s]);const K=O?.filter(F=>F.is_active)||[],E=Kr.useMemo(()=>{const F=new Map;if(oe)for(const Z of oe)F.set(Z.filament_id,Z.name);if(me)for(const[Z,xe]of Object.entries(me))F.has(Z)||F.set(Z,xe);return F},[oe,me]),j=Kr.useMemo(()=>Array.from(E.entries()).map(([F,Z])=>({filament_id:F,name:Z})),[E]),L=Kr.useCallback(F=>E.get(F.filament_id)||Ese(F.name),[E]),G=Kr.useMemo(()=>ie?.profiles?ie.profiles.filter(Z=>{const xe=f.toLowerCase(),he=!xe||Z.name.toLowerCase().includes(xe)||Z.filament_id.toLowerCase().includes(xe),ce=v==="all"||v==="left"&&Z.extruder_id===1||v==="right"&&Z.extruder_id===0,Ae=y==="all"||y==="hf"&&Z.nozzle_id.startsWith("HH")||y==="s"&&Z.nozzle_id.startsWith("HS");return he&&ce&&Ae}).sort((Z,xe)=>{switch(N){case"k_value":return parseFloat(Z.k_value)-parseFloat(xe.k_value);case"filament":return L(Z).localeCompare(L(xe));default:return Z.name.localeCompare(xe.name)}}):[],[ie?.profiles,f,v,y,N,L]),B=O?.find(F=>F.id===r),re=B?.nozzle_count===2;w.useEffect(()=>{const F=Z=>{Z.target instanceof HTMLInputElement||Z.target instanceof HTMLTextAreaElement||Z.target instanceof HTMLSelectElement||l||d||m||(Z.key==="r"||Z.key==="R"?(Z.preventDefault(),pe()):Z.key==="n"||Z.key==="N"?(Z.preventDefault(),u(!0)):Z.key==="Escape"&&T&&(Z.preventDefault(),P(!1),D(new Set)))};return window.addEventListener("keydown",F),()=>window.removeEventListener("keydown",F)},[l,d,m,T,pe]);const z=w.useCallback(()=>{if(!ie?.profiles||ie.profiles.length===0){e(t("kProfiles.toast.noProfilesToExport"),"error");return}const F={version:1,exported_at:new Date().toISOString(),printer:B?.name||"Unknown",nozzle_diameter:s,profiles:ie.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}))},Z=new Blob([JSON.stringify(F,null,2)],{type:"application/json"}),xe=URL.createObjectURL(Z),he=document.createElement("a");he.href=xe,he.download=`kprofiles_${B?.name||"printer"}_${s}mm_${new Date().toISOString().split("T")[0]}.json`,document.body.appendChild(he),he.click(),document.body.removeChild(he),URL.revokeObjectURL(xe),e(t("kProfiles.toast.exportedProfiles",{count:ie.profiles.length}))},[ie?.profiles,B,s,e,t]),V=w.useCallback(()=>{const F=document.createElement("input");F.type="file",F.accept=".json",F.onchange=async Z=>{const xe=Z.target.files?.[0];if(xe)try{const he=await xe.text(),ce=JSON.parse(he);if(!ce.profiles||!Array.isArray(ce.profiles)){e(t("kProfiles.toast.invalidFileFormat"),"error");return}let Ae=0;for(const _e of ce.profiles)if(!(!_e.name||!_e.k_value||!_e.filament_id))try{await fe.setKProfile(r,{name:_e.name,k_value:parseFloat(_e.k_value).toFixed(6),filament_id:_e.filament_id,nozzle_id:_e.nozzle_id||`HH00-${s}`,nozzle_diameter:_e.nozzle_diameter||s,extruder_id:_e.extruder_id??0,slot_id:0}),Ae++,await new Promise(Ue=>setTimeout(Ue,500))}catch(Ue){console.error("Failed to import profile:",_e.name,Ue)}e(t("kProfiles.toast.importedProfiles",{count:Ae,total:ce.profiles.length})),pe()}catch(he){console.error("Import error:",he),e(t("kProfiles.toast.failedToParseImport"),"error")}},F.click()},[r,s,e,pe,t]),ee=w.useCallback(F=>{D(Z=>{const xe=new Set(Z);return xe.has(F)?xe.delete(F):xe.add(F),xe})},[]),J=w.useCallback(()=>{D(new Set(G.map(F=>W(F))))},[G,W]),ne=w.useCallback(()=>{k.size!==0&&R(!0)},[k.size]),se=w.useCallback(async()=>{const F=G.filter(xe=>k.has(W(xe)));U(!0);let Z=0;for(const xe of F)try{await fe.deleteKProfile(r,{slot_id:xe.slot_id,extruder_id:xe.extruder_id,nozzle_id:xe.nozzle_id,nozzle_diameter:xe.nozzle_diameter,filament_id:xe.filament_id,setting_id:xe.setting_id}),Z++,await new Promise(he=>setTimeout(he,300))}catch(he){console.error("Failed to delete profile:",xe.name,he)}e(t("kProfiles.toast.profilesDeleted",{count:Z})),U(!1),R(!1),P(!1),D(new Set),pe()},[r,k,G,e,pe,W,t]),ue=w.useCallback(F=>{const Z=[];return F.setting_id&&Z.push(F.setting_id),Z.push(`slot_${F.slot_id}_${F.filament_id}_${F.extruder_id}`),Z.push(`name_${F.name}_${F.filament_id}`),Z},[]),ge=w.useCallback(async(F,Z)=>{if(r)try{await fe.setKProfileNote(r,F,Z),Ee()}catch(xe){console.error("Failed to save note:",xe),e(t("kProfiles.toast.failedToSaveNote"),"error")}},[r,Ee,e,t]),le=w.useCallback(F=>{if(!we?.notes)return{note:"",key:null};const Z=ue(F);for(const xe of Z)if(we.notes[xe])return{note:we.notes[xe],key:xe};return{note:"",key:null}},[we,ue]),I=w.useCallback(F=>le(F).note,[le]);return te?i.jsx("div",{className:"flex justify-center py-12",children:i.jsx(lt,{className:"w-8 h-8 text-bambu-green animate-spin"})}):!O||O.length===0?i.jsx(Tt,{children:i.jsxs(Pt,{className:"py-12 text-center",children:[i.jsx(zi,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),i.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:t("kProfiles.noPrintersConfigured")}),i.jsx("p",{className:"text-bambu-gray",children:t("kProfiles.addPrinterInSettings")})]})}):K.length===0?i.jsx(Tt,{children:i.jsxs(Pt,{className:"py-12 text-center",children:[i.jsx(_r,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),i.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:t("kProfiles.noActivePrinters")}),i.jsx("p",{className:"text-bambu-gray",children:t("kProfiles.enablePrinterConnection")})]})}):i.jsxs(i.Fragment,{children:[ae&&!Y&&i.jsxs("div",{className:"fixed inset-0 bg-black/50 flex flex-col items-center justify-center z-40",children:[i.jsx(lt,{className:"w-10 h-10 text-bambu-green animate-spin mb-3"}),i.jsx("p",{className:"text-white font-medium",children:t("kProfiles.loadingProfiles")})]}),i.jsxs("div",{className:"flex flex-wrap gap-4 mb-6",children:[i.jsxs("div",{className:"flex-1 min-w-48",children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:t("kProfiles.printer")}),i.jsx("select",{value:r||"",onChange:F=>a(parseInt(F.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:K.map(F=>i.jsx("option",{value:F.id,children:F.name},F.id))})]}),i.jsxs("div",{className:"w-32",children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:t("kProfiles.nozzle")}),i.jsxs("select",{value:s,onChange:F=>o(F.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:[i.jsx("option",{value:"0.2",children:"0.2mm"}),i.jsx("option",{value:"0.4",children:"0.4mm"}),i.jsx("option",{value:"0.6",children:"0.6mm"}),i.jsx("option",{value:"0.8",children:"0.8mm"})]})]}),i.jsxs("div",{className:"flex items-end gap-2",children:[i.jsxs(Oe,{variant:"secondary",onClick:()=>pe(),disabled:ae||!n("kprofiles:read"),title:n("kprofiles:read")?void 0:t("kProfiles.permission.noRead"),children:[i.jsx(Sr,{className:`w-4 h-4 ${ae?"animate-spin":""}`}),t("kProfiles.refresh")]}),i.jsxs(Oe,{onClick:()=>u(!0),disabled:!n("kprofiles:create"),title:n("kprofiles:create")?void 0:t("kProfiles.permission.noCreate"),children:[i.jsx(rr,{className:"w-4 h-4"}),t("kProfiles.addProfile")]})]})]}),i.jsxs("div",{className:"flex flex-wrap gap-4 mb-4",children:[i.jsxs("div",{className:"flex-1 min-w-48 relative",children:[i.jsx(jr,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray"}),i.jsx("input",{type:"text",value:f,onChange:F=>x(F.target.value),placeholder:t("kProfiles.searchPlaceholder"),className:"w-full pl-10 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none"})]}),re&&i.jsx("div",{className:"w-36",children:i.jsxs("select",{value:v,onChange:F=>g(F.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:[i.jsx("option",{value:"all",children:t("kProfiles.allExtruders")}),i.jsx("option",{value:"left",children:t("kProfiles.leftOnly")}),i.jsx("option",{value:"right",children:t("kProfiles.rightOnly")})]})}),i.jsx("div",{className:"w-32",children:i.jsxs("select",{value:y,onChange:F=>_(F.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:[i.jsx("option",{value:"all",children:t("kProfiles.allFlow")}),i.jsx("option",{value:"hf",children:t("kProfiles.hfOnly")}),i.jsx("option",{value:"s",children:t("kProfiles.sOnly")})]})}),i.jsx("div",{className:"w-32",children:i.jsxs("select",{value:N,onChange:F=>C(F.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:[i.jsx("option",{value:"name",children:t("kProfiles.sortName")}),i.jsx("option",{value:"k_value",children:t("kProfiles.sortKValue")}),i.jsx("option",{value:"filament",children:t("kProfiles.sortFilament")})]})})]}),i.jsxs("div",{className:"flex flex-wrap gap-2 mb-6",children:[i.jsxs(Oe,{variant:"secondary",onClick:z,disabled:!ie?.profiles?.length||!n("kprofiles:read"),title:n("kprofiles:read")?void 0:t("kProfiles.permission.noExport"),children:[i.jsx(hi,{className:"w-4 h-4"}),t("kProfiles.export")]}),i.jsxs(Oe,{variant:"secondary",onClick:V,disabled:!n("kprofiles:create"),title:n("kprofiles:create")?void 0:t("kProfiles.permission.noImport"),children:[i.jsx(Si,{className:"w-4 h-4"}),t("kProfiles.import")]}),i.jsx("div",{className:"flex-1"}),T?i.jsxs(i.Fragment,{children:[i.jsxs(Oe,{variant:"secondary",onClick:J,children:[i.jsx(ho,{className:"w-4 h-4"}),t("kProfiles.selectAll")]}),i.jsxs(Oe,{variant:"secondary",onClick:ne,disabled:k.size===0||!n("kprofiles:delete"),className:"text-red-500 hover:bg-red-500/10",title:n("kprofiles:delete")?void 0:t("kProfiles.permission.noDelete"),children:[i.jsx(Qt,{className:"w-4 h-4"}),t("kProfiles.delete")," (",k.size,")"]}),i.jsxs(Oe,{variant:"secondary",onClick:()=>{P(!1),D(new Set)},children:[i.jsx(zt,{className:"w-4 h-4"}),t("common.cancel")]})]}):i.jsxs(Oe,{variant:"secondary",onClick:()=>P(!0),disabled:!G.length||!n("kprofiles:delete"),title:n("kprofiles:delete")?void 0:t("kProfiles.permission.noDelete"),children:[i.jsx(ho,{className:"w-4 h-4"}),t("kProfiles.select")]})]}),Y?i.jsx("div",{className:"flex justify-center py-12",children:i.jsx(lt,{className:"w-8 h-8 text-bambu-green animate-spin"})}):q?i.jsx(Tt,{children:i.jsxs(Pt,{className:"py-12 text-center",children:[i.jsx(rh,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),i.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:t("kProfiles.printerOffline")}),i.jsx("p",{className:"text-bambu-gray mb-4",children:t("kProfiles.printerOfflineDesc")}),i.jsxs(Oe,{variant:"secondary",onClick:()=>pe(),children:[i.jsx(Sr,{className:"w-4 h-4"}),t("common.refresh")]})]})}):G.length>0?re?i.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[i.jsxs("div",{children:[i.jsx("h3",{className:"text-sm font-medium text-bambu-gray mb-2 px-1",children:t("kProfiles.leftExtruder")}),i.jsx("div",{className:"space-y-1",children:G.filter(F=>F.extruder_id===1).map(F=>i.jsx(Kj,{profile:F,onEdit:()=>c(F),onCopy:()=>p(F),selectionMode:T,isSelected:k.has(W(F)),onToggleSelect:()=>ee(W(F)),note:I(F)},W(F)))})]}),i.jsxs("div",{children:[i.jsx("h3",{className:"text-sm font-medium text-bambu-gray mb-2 px-1",children:t("kProfiles.rightExtruder")}),i.jsx("div",{className:"space-y-1",children:G.filter(F=>F.extruder_id===0).map(F=>i.jsx(Kj,{profile:F,onEdit:()=>c(F),onCopy:()=>p(F),selectionMode:T,isSelected:k.has(W(F)),onToggleSelect:()=>ee(W(F)),note:I(F)},W(F)))})]})]}):i.jsx("div",{className:"space-y-1",children:G.map(F=>i.jsx(Kj,{profile:F,onEdit:()=>c(F),onCopy:()=>p(F),selectionMode:T,isSelected:k.has(W(F)),onToggleSelect:()=>ee(W(F)),note:I(F)},W(F)))}):f||v!=="all"||y!=="all"?i.jsx(Tt,{children:i.jsxs(Pt,{className:"py-12 text-center",children:[i.jsx(jr,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),i.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:t("kProfiles.noMatchingProfiles")}),i.jsx("p",{className:"text-bambu-gray",children:t("kProfiles.noMatchingProfilesDesc")})]})}):i.jsx(Tt,{children:i.jsxs(Pt,{className:"py-12 text-center",children:[i.jsx(cC,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),i.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:t("kProfiles.noKProfiles")}),i.jsx("p",{className:"text-bambu-gray mb-4",children:t("kProfiles.noKProfilesDesc",{diameter:s})}),i.jsxs(Oe,{onClick:()=>u(!0),children:[i.jsx(rr,{className:"w-4 h-4"}),t("kProfiles.createFirstProfile")]})]})}),l&&r&&(()=>{const{note:F,key:Z}=le(l);return i.jsx(Yj,{profile:l,printerId:r,nozzleDiameter:s,existingProfiles:Q?.profiles||ie?.profiles,builtinFilaments:j,isDualNozzle:re,initialNote:F,initialNoteKey:Z,onSaveNote:ge,hasPermission:n,onClose:()=>{console.log("[KProfiles] Edit modal onClose - refetching profiles..."),c(null),pe()},onSave:()=>{c(null),pe()}})})(),d&&r&&i.jsx(Yj,{printerId:r,nozzleDiameter:s,existingProfiles:Q?.profiles||ie?.profiles,builtinFilaments:j,isDualNozzle:re,onSaveNote:ge,hasPermission:n,onClose:()=>{u(!1),pe()},onSave:()=>{u(!1),pe()}}),m&&r&&i.jsx(Yj,{printerId:r,nozzleDiameter:s,existingProfiles:Q?.profiles||ie?.profiles,builtinFilaments:j,isDualNozzle:re,onSaveNote:ge,hasPermission:n,profile:{...m,slot_id:0,name:`${m.name} (Copy)`},onClose:()=>{p(null),pe()},onSave:()=>{p(null),pe()}}),A&&i.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",children:i.jsx(Tt,{className:"w-full max-w-sm",children:i.jsxs(Pt,{className:"p-6",children:[i.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[i.jsx("div",{className:"w-10 h-10 rounded-full bg-red-500/20 flex items-center justify-center",children:i.jsx(Qt,{className:"w-5 h-5 text-red-500"})}),i.jsxs("div",{children:[i.jsx("h3",{className:"text-lg font-semibold text-white",children:t("kProfiles.bulkDelete.title")}),i.jsx("p",{className:"text-sm text-bambu-gray",children:t("kProfiles.bulkDelete.cannotUndo")})]})]}),i.jsx("p",{className:"text-bambu-gray mb-6",children:t("kProfiles.bulkDelete.message",{count:k.size})}),i.jsxs("div",{className:"flex gap-3",children:[i.jsx(Oe,{variant:"secondary",onClick:()=>R(!1),disabled:$,className:"flex-1",children:t("common.cancel")}),i.jsxs(Oe,{onClick:se,disabled:$,className:"flex-1 bg-red-500 hover:bg-red-600 text-white",children:[$?i.jsx(lt,{className:"w-4 h-4 animate-spin"}):i.jsx(Qt,{className:"w-4 h-4"}),t("common.delete")]})]})]})})})]})}const jse=["PLA","PETG","PCTG","ABS","ASA","TPU","PC","PA","PVA","HIPS","PP","PET","NYLON"],TJe={PLA:"E8E8E8",PETG:"4A90D9",ABS:"E67E22",ASA:"D35400",TPU:"9B59B6",PC:"BDC3C7",PA:"2ECC71",NYLON:"2ECC71",PVA:"F1C40F",HIPS:"95A5A6",PP:"ECF0F1",PET:"3498DB"};function PJe(t){const e=t.toUpperCase();for(const n of jse)if(new RegExp(`\\b${n}\\b`).test(e))return n;return null}function AJe(t){const e=t.replace(/@.+$/,"").trim(),n=e.toUpperCase();for(const r of jse){const a=n.indexOf(r);if(a>0){const s=e.slice(0,a).trim();if(s&&s.length>1)return s}}return null}function Xj({preset:t,onDelete:e,onExpand:n,isExpanded:r}){const{t:a}=Mt(),{hasPermission:s}=Dr(),o=t.filament_type||PJe(t.name),l=t.filament_vendor||AJe(t.name);let c=null,d=!1;if(t.default_filament_colour)try{const u=JSON.parse(t.default_filament_colour),m=Array.isArray(u)?u[0]:u;typeof m=="string"&&/^#?[0-9a-fA-F]{6,8}$/.test(m.replace("#",""))&&(c=m.replace("#","").slice(0,6),d=!0)}catch{const u=t.default_filament_colour;/^#?[0-9a-fA-F]{6,8}$/.test(u.replace("#",""))&&(c=u.replace("#","").slice(0,6),d=!0)}return!c&&o&&(c=TJe[o.toUpperCase()]||null),i.jsx(Tt,{className:"bg-bambu-dark border-bambu-dark-tertiary hover:border-bambu-dark-tertiary/80 transition-colors",children:i.jsxs(Pt,{className:"p-3",children:[i.jsxs("div",{className:"flex items-start justify-between gap-2",children:[i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[t.preset_type==="filament"&&i.jsx("div",{className:`w-4 h-4 rounded-full border border-white/20 flex-shrink-0 ${!d&&!c?"opacity-25":d?"":"opacity-50"}`,style:{backgroundColor:c?`#${c}`:"#666"}}),i.jsx("span",{className:"text-sm font-medium text-white truncate",children:t.name})]}),i.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[o&&i.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-bambu-green/20 text-bambu-green",children:o}),l&&i.jsx("span",{className:"text-xs text-bambu-gray",children:l}),i.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-blue-500/20 text-blue-400",children:a("profiles.localProfiles.badge")})]})]}),i.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[s("settings:update")&&i.jsx("button",{onClick:()=>e(t.id),className:"p-1 text-bambu-gray hover:text-red-400 transition-colors",title:a("profiles.localProfiles.delete"),children:i.jsx(Qt,{className:"w-3.5 h-3.5"})}),i.jsx("button",{onClick:()=>n(r?null:t.id),className:"p-1 text-bambu-gray hover:text-white transition-colors",children:r?i.jsx(Sl,{className:"w-3.5 h-3.5"}):i.jsx(jn,{className:"w-3.5 h-3.5"})})]})]}),r&&i.jsxs("div",{className:"mt-3 pt-3 border-t border-bambu-dark-tertiary text-xs space-y-1.5",children:[o&&i.jsxs("div",{className:"flex justify-between",children:[i.jsx("span",{className:"text-bambu-gray",children:a("profiles.localProfiles.filamentType")}),i.jsx("span",{className:"text-white",children:o})]}),l&&i.jsxs("div",{className:"flex justify-between",children:[i.jsx("span",{className:"text-bambu-gray",children:a("profiles.localProfiles.vendor")}),i.jsx("span",{className:"text-white",children:l})]}),t.nozzle_temp_min!=null&&t.nozzle_temp_max!=null&&i.jsxs("div",{className:"flex justify-between",children:[i.jsx("span",{className:"text-bambu-gray",children:a("profiles.localProfiles.nozzleTemp")}),i.jsxs("span",{className:"text-white",children:[t.nozzle_temp_min,"–",t.nozzle_temp_max,"°C"]})]}),t.filament_cost&&i.jsxs("div",{className:"flex justify-between",children:[i.jsx("span",{className:"text-bambu-gray",children:a("profiles.localProfiles.cost")}),i.jsx("span",{className:"text-white",children:t.filament_cost})]}),t.filament_density&&i.jsxs("div",{className:"flex justify-between",children:[i.jsx("span",{className:"text-bambu-gray",children:a("profiles.localProfiles.density")}),i.jsxs("span",{className:"text-white",children:[t.filament_density," g/cm³"]})]}),t.pressure_advance&&i.jsxs("div",{className:"flex justify-between",children:[i.jsx("span",{className:"text-bambu-gray",children:a("profiles.localProfiles.pressureAdvance")}),i.jsx("span",{className:"text-white",children:t.pressure_advance})]}),t.compatible_printers&&i.jsxs("div",{className:"flex justify-between",children:[i.jsx("span",{className:"text-bambu-gray",children:a("profiles.localProfiles.compatiblePrinters")}),i.jsx("span",{className:"text-white truncate ml-2",children:(()=>{try{return JSON.parse(t.compatible_printers).join(", ")}catch{return t.compatible_printers}})()})]}),t.inherits&&t.inherits!==t.name&&i.jsxs("div",{className:"flex justify-between",children:[i.jsx("span",{className:"text-bambu-gray",children:a("profiles.localProfiles.inheritsFrom")}),i.jsx("span",{className:"text-white truncate ml-2",children:t.inherits})]}),i.jsxs("div",{className:"flex justify-between",children:[i.jsx("span",{className:"text-bambu-gray",children:a("profiles.localProfiles.source")}),i.jsx("span",{className:"text-white capitalize",children:t.source})]})]})]})})}function MJe(){const{t}=Mt(),{hasPermission:e}=Dr(),n=Zt(),{showToast:r}=hn(),[a,s]=w.useState(""),[o,l]=w.useState(null),[c,d]=w.useState(!1),[u,m]=w.useState(null),{data:p,isLoading:f}=Ze({queryKey:["localPresets"],queryFn:()=>fe.getLocalPresets()}),x=dt({mutationFn:async k=>{const D=[];for(const A of Array.from(k)){const R=new FormData;R.append("file",A),D.push(await fe.importLocalPresets(R))}return D},onSuccess:k=>{n.invalidateQueries({queryKey:["localPresets"]});let D=0,A=0,R=0;for(const $ of k)D+=$.imported,A+=$.skipped,R+=$.errors.length;D>0&&r(t("profiles.localProfiles.toast.importSuccess",{count:D})),A>0&&r(t("profiles.localProfiles.toast.importSkipped",{count:A}),"warning"),R>0&&r(t("profiles.localProfiles.toast.importError",{count:R}),"error")},onError:k=>{r(k.message,"error")}}),v=dt({mutationFn:k=>fe.deleteLocalPreset(k),onSuccess:()=>{n.invalidateQueries({queryKey:["localPresets"]}),m(null),r(t("profiles.localProfiles.toast.deleted"))}}),g=w.useCallback(k=>{!k||k.length===0||x.mutate(k)},[x]),y=w.useCallback(k=>{k.preventDefault(),d(!1),g(k.dataTransfer.files)},[g]),_=w.useCallback(k=>{if(!a)return k;const D=a.toLowerCase();return k.filter(A=>A.name.toLowerCase().includes(D)||A.filament_type?.toLowerCase().includes(D)||A.filament_vendor?.toLowerCase().includes(D))},[a]),N=w.useMemo(()=>_(p?.filament||[]),[p?.filament,_]),C=w.useMemo(()=>_(p?.printer||[]),[p?.printer,_]),T=w.useMemo(()=>_(p?.process||[]),[p?.process,_]),P=N.length+C.length+T.length;return f?i.jsx("div",{className:"flex items-center justify-center py-16",children:i.jsx(lt,{className:"w-8 h-8 text-bambu-green animate-spin"})}):i.jsxs("div",{className:"space-y-6",children:[e("settings:update")&&i.jsxs("div",{onDragOver:k=>{k.preventDefault(),d(!0)},onDragLeave:()=>d(!1),onDrop:y,className:`relative border-2 border-dashed rounded-lg p-6 text-center transition-colors ${c?"border-bambu-green bg-bambu-green/10":"border-bambu-dark-tertiary hover:border-bambu-gray"}`,children:[i.jsx("input",{type:"file",accept:".json,.zip,.orca_filament,.bbscfg,.bbsflmt",multiple:!0,className:"absolute inset-0 w-full h-full opacity-0 cursor-pointer",onChange:k=>g(k.target.files)}),x.isPending?i.jsxs("div",{className:"flex items-center justify-center gap-2",children:[i.jsx(lt,{className:"w-5 h-5 text-bambu-green animate-spin"}),i.jsx("span",{className:"text-bambu-gray",children:t("profiles.localProfiles.importing")})]}):i.jsxs(i.Fragment,{children:[i.jsx(Si,{className:"w-8 h-8 text-bambu-gray mx-auto mb-2"}),i.jsx("p",{className:"text-sm text-white font-medium",children:t("profiles.localProfiles.import")}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:t("profiles.localProfiles.importDesc")})]})]}),P>0&&i.jsxs("div",{className:"relative",children:[i.jsx(jr,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray"}),i.jsx("input",{type:"text",value:a,onChange:k=>s(k.target.value),placeholder:t("profiles.localProfiles.search"),className:"w-full pl-9 pr-4 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green"})]}),P===0&&!f&&i.jsxs("div",{className:"text-center py-12",children:[i.jsx(cx,{className:"w-12 h-12 text-bambu-gray mx-auto mb-3 opacity-50"}),i.jsx("p",{className:"text-bambu-gray",children:t("profiles.localProfiles.noPresets")}),i.jsx("p",{className:"text-xs text-bambu-gray/60 mt-1",children:t("profiles.localProfiles.importDesc")})]}),P>0&&i.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6",children:[N.length>0&&i.jsxs("div",{children:[i.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[i.jsx(sC,{className:"w-4 h-4 text-bambu-green"}),i.jsx("h3",{className:"text-sm font-medium text-white",children:t("profiles.localProfiles.filament")}),i.jsxs("span",{className:"text-xs text-bambu-gray",children:["(",N.length,")"]})]}),i.jsx("div",{className:"space-y-2",children:N.map(k=>i.jsx(Xj,{preset:k,onDelete:D=>m(D),onExpand:l,isExpanded:o===k.id},k.id))})]}),T.length>0&&i.jsxs("div",{children:[i.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[i.jsx(Gi,{className:"w-4 h-4 text-blue-400"}),i.jsx("h3",{className:"text-sm font-medium text-white",children:t("profiles.localProfiles.process")}),i.jsxs("span",{className:"text-xs text-bambu-gray",children:["(",T.length,")"]})]}),i.jsx("div",{className:"space-y-2",children:T.map(k=>i.jsx(Xj,{preset:k,onDelete:D=>m(D),onExpand:l,isExpanded:o===k.id},k.id))})]}),C.length>0&&i.jsxs("div",{children:[i.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[i.jsx(cu,{className:"w-4 h-4 text-orange-400"}),i.jsx("h3",{className:"text-sm font-medium text-white",children:t("profiles.localProfiles.printer")}),i.jsxs("span",{className:"text-xs text-bambu-gray",children:["(",C.length,")"]})]}),i.jsx("div",{className:"space-y-2",children:C.map(k=>i.jsx(Xj,{preset:k,onDelete:D=>m(D),onExpand:l,isExpanded:o===k.id},k.id))})]})]}),u!==null&&i.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50",children:i.jsxs("div",{className:"bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg p-6 max-w-sm mx-4",children:[i.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[i.jsx(zi,{className:"w-5 h-5 text-red-400"}),i.jsx("h3",{className:"text-white font-medium",children:t("profiles.localProfiles.deleteConfirmTitle")})]}),i.jsx("p",{className:"text-sm text-bambu-gray mb-4",children:t("profiles.localProfiles.deleteConfirm")}),i.jsxs("div",{className:"flex justify-end gap-2",children:[i.jsx(Oe,{variant:"secondary",size:"sm",onClick:()=>m(null),children:t("profiles.localProfiles.cancel")}),i.jsxs(Oe,{variant:"danger",size:"sm",onClick:()=>v.mutate(u),disabled:v.isPending,children:[v.isPending?i.jsx(lt,{className:"w-4 h-4 animate-spin"}):i.jsx(Qt,{className:"w-4 h-4"}),t("profiles.localProfiles.delete")]})]})]})})]})}function EI(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),a=r?r[1].trim():null,s=n.match(/(\d+\.?\d*)\s*(?:mm\s*)?nozzle|nozzle\s*(\d+\.?\d*)/i),o=s?(s[1]||s[2])+"mm":null,l=n.match(/(\d+\.?\d*)mm\s*(?:Standard|Fine|Extra Fine|Draft|Quality)?/i),c=l?l[1]+"mm":null,d=n.match(/\b(PLA|PETG|ABS|ASA|TPU|PC|PA|PVA|HIPS|PP|PET(?:-?CF)?|PA(?:-?CF)?|PLA(?:-?CF)?)\b/i),u=d?d[1].toUpperCase():null;return{printer:a,nozzle:o,layerHeight:c,filamentType:u}}function C0(t){return/^(P[FPM]US|PF\d|PP\d)/.test(t)}function EJe({onSuccess:t,t:e}){const{showToast:n}=hn(),[r,a]=w.useState("email"),[s,o]=w.useState(""),[l,c]=w.useState(""),[d,u]=w.useState(""),[m,p]=w.useState(""),[f,x]=w.useState("global"),[v,g]=w.useState(null),[y,_]=w.useState(null),N=dt({mutationFn:()=>fe.cloudLogin(s,l,f),onSuccess:D=>{D.success?(n(e("profiles.login.toast.loggedIn")),t()):D.needs_verification?(g(D.verification_type||"email"),_(D.tfa_key||null),D.verification_type==="totp"?n(e("profiles.login.toast.enterTotp")):n(e("profiles.login.toast.codeSent")),a("code")):n(D.message,"error")},onError:D=>n(D.message,"error")}),C=dt({mutationFn:()=>fe.cloudVerify(s,d,y||void 0),onSuccess:D=>{D.success?(n(e("profiles.login.toast.loggedIn")),t()):n(D.message,"error")},onError:D=>n(D.message,"error")}),T=dt({mutationFn:()=>fe.cloudSetToken(m),onSuccess:()=>{n(e("profiles.login.toast.tokenSet")),t()},onError:D=>n(D.message,"error")}),P=D=>{D.preventDefault(),r==="email"?N.mutate():r==="code"?C.mutate():r==="token"&&T.mutate()},k=N.isPending||C.isPending||T.isPending;return i.jsx(Tt,{className:"max-w-md mx-auto",children:i.jsxs(Pt,{children:[i.jsxs("div",{className:"text-center mb-6",children:[i.jsx("div",{className:"inline-flex items-center justify-center w-12 h-12 rounded-xl bg-bambu-green/20 mb-3",children:i.jsx(lx,{className:"w-6 h-6 text-bambu-green"})}),i.jsx("h2",{className:"text-xl font-semibold text-white",children:e("profiles.login.title")}),i.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:e("profiles.login.subtitle")})]}),i.jsxs("form",{onSubmit:P,className:"space-y-4",children:[r==="email"&&i.jsxs(i.Fragment,{children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:e("profiles.login.email")}),i.jsx("input",{type:"email",value:s,onChange:D=>o(D.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})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:e("profiles.login.password")}),i.jsx("input",{type:"password",value:l,onChange:D=>c(D.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})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:e("profiles.login.region")}),i.jsxs("select",{value:f,onChange:D=>x(D.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:[i.jsx("option",{value:"global",children:e("profiles.login.regionGlobal")}),i.jsx("option",{value:"china",children:e("profiles.login.regionChina")})]})]})]}),r==="code"&&i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:e(v==="totp"?"profiles.login.totpCode":"profiles.login.verificationCode")}),i.jsx("p",{className:"text-xs text-bambu-gray mb-2",children:v==="totp"?e("profiles.login.enterTotpHint"):e("profiles.login.checkEmail",{email:s})}),i.jsx("input",{type:"text",value:d,onChange:D=>u(D.target.value.replace(/\D/g,"").slice(0,6)),className:"w-full px-3 py-3 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-center text-2xl tracking-widest font-mono focus:border-bambu-green focus:outline-none",placeholder:"000000",maxLength:6,required:!0})]}),r==="token"&&i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:e("profiles.login.accessToken")}),i.jsx("p",{className:"text-xs text-bambu-gray mb-2",children:e("profiles.login.accessTokenHint")}),i.jsx("textarea",{value:m,onChange:D=>p(D.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})]}),i.jsxs("div",{className:"flex gap-2 max-[550px]:flex-wrap max-[550px]:items-center",children:[r==="code"&&i.jsx(Oe,{type:"button",variant:"secondary",onClick:()=>a("email"),className:"flex-1",children:e("profiles.login.back")}),i.jsxs(Oe,{type:"submit",disabled:k,className:"flex-1",children:[k?i.jsx(lt,{className:"w-4 h-4 animate-spin"}):i.jsx(n8,{className:"w-4 h-4"}),e(r==="email"?"profiles.login.loginButton":r==="code"?"profiles.login.verifyButton":"profiles.login.setTokenButton")]})]}),r==="email"&&i.jsx("div",{className:"pt-4 border-t border-bambu-dark-tertiary",children:i.jsxs("button",{type:"button",onClick:()=>a("token"),className:"text-sm text-bambu-gray hover:text-white flex items-center gap-2 transition-colors",children:[i.jsx(sl,{className:"w-4 h-4"}),e("profiles.login.useToken")]})}),r==="token"&&i.jsx("div",{className:"pt-4 border-t border-bambu-dark-tertiary",children:i.jsxs("button",{type:"button",onClick:()=>a("email"),className:"text-sm text-bambu-gray hover:text-white flex items-center gap-2 transition-colors",children:[i.jsx(n8,{className:"w-4 h-4"}),e("profiles.login.useEmail")]})})]})]})})}function Gg({label:t,value:e,options:n,onChange:r}){const[a,s]=w.useState(!1),o=n.find(l=>l.value===e);return i.jsxs("div",{className:"relative",children:[i.jsxs("button",{onClick:()=>s(!a),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:[i.jsxs("span",{className:"text-bambu-gray",children:[t,":"]}),i.jsx("span",{children:o?.label||"All"}),i.jsx(jn,{className:`w-4 h-4 text-bambu-gray transition-transform ${a?"rotate-180":""}`})]}),a&&i.jsxs(i.Fragment,{children:[i.jsx("div",{className:"fixed inset-0 z-10",onClick:()=>s(!1)}),i.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=>i.jsxs("button",{onClick:()=>{r(l.value),s(!1)},className:`w-full px-3 py-2 text-left text-sm flex items-center justify-between hover:bg-bambu-dark-tertiary transition-colors ${e===l.value?"text-bambu-green":"text-white"}`,children:[i.jsx("span",{children:l.label}),l.count!==void 0&&i.jsx("span",{className:"text-bambu-gray text-xs",children:l.count})]},l.value))})]})]})}function jJe(){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?i.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:i.jsx($p,{className:"w-5 h-5"})}):null}function Qj({setting:t,onClick:e,onDuplicate:n,compareMode:r,isCompareSelected:a,compareIndex:s,compareDisabled:o,t:l}){const c=EI(t.name),d=C0(t.setting_id);return i.jsxs("div",{className:"flex items-center gap-2 group",children:[i.jsx("button",{onClick:e,disabled:o,className:`flex-1 text-left px-3 py-2 rounded transition-colors ${a?"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:i.jsxs("div",{className:"flex items-center gap-2",children:[a&&s!==void 0&&i.jsx("span",{className:"flex-shrink-0 w-5 h-5 rounded-full bg-blue-500 text-white text-xs flex items-center justify-center font-medium",children:s+1}),!a&&d&&i.jsx("span",{className:"flex-shrink-0 w-1.5 h-1.5 rounded-full bg-bambu-green",title:l("profiles.presets.myPreset")}),i.jsx("span",{className:"text-white text-sm truncate flex-1",title:t.name,children:t.name}),c.filamentType&&t.type==="filament"&&i.jsx("span",{className:"text-xs text-bambu-gray whitespace-nowrap",children:c.filamentType}),c.layerHeight&&t.type==="process"&&i.jsx("span",{className:"text-xs text-bambu-gray whitespace-nowrap",children:c.layerHeight}),c.printer&&i.jsx("span",{className:"text-xs text-bambu-gray whitespace-nowrap",children:c.printer})]})}),i.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:l("profiles.presets.duplicate"),children:i.jsx(_l,{className:"w-4 h-4"})})]})}function kF(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(` +`);V=ne.pop()||"";for(const se of ne)if(se.startsWith("data: "))try{const ue=JSON.parse(se.slice(6));ue.type==="progress"?U({fetched:ue.total_fetched,total:ue.total_available}):ue.type==="complete"?ue.added===0?e(t("settings.colorCatalog.syncUpToDate",{count:ue.total_fetched}),"success"):e(t("settings.colorCatalog.syncComplete",{added:ue.added,skipped:ue.skipped}),"success"):ue.type==="error"&&e(`${t("settings.colorCatalog.syncError")}: ${ue.error}`,"error")}catch{}}await Y()}catch{e(t("settings.colorCatalog.syncFailed"),"error")}finally{R(!1),U(null)}},E=()=>{const L=n.map(({manufacturer:z,color_name:V,hex_color:ee,material:J})=>({manufacturer:z,color_name:V,hex_color:ee,material:J})),G=new Blob([JSON.stringify(L,null,2)],{type:"application/json"}),B=URL.createObjectURL(G),re=document.createElement("a");re.href=B,re.download="color-catalog.json",document.body.appendChild(re),re.click(),document.body.removeChild(re),URL.revokeObjectURL(B),e(t("settings.colorCatalog.exported",{count:n.length}),"success")},j=async L=>{const G=L.target.files?.[0];if(G){try{const B=await G.text(),re=JSON.parse(B);if(!Array.isArray(re))throw new Error("Invalid format");let z=0,V=0;for(const ee of re){if(!ee.manufacturer||!ee.color_name||!ee.hex_color){V++;continue}if(n.some(ne=>ne.manufacturer.toLowerCase()===ee.manufacturer.toLowerCase()&&ne.color_name.toLowerCase()===ee.color_name.toLowerCase()&&(ne.material||"").toLowerCase()===(ee.material||"").toLowerCase())){V++;continue}try{const ne=await fe.addColorEntry({manufacturer:ee.manufacturer,color_name:ee.color_name,hex_color:ee.hex_color,material:ee.material||null});r(se=>[...se,ne].sort((ue,ge)=>ue.manufacturer.localeCompare(ge.manufacturer)||(ue.material||"").localeCompare(ge.material||"")||ue.color_name.localeCompare(ge.color_name))),z++}catch{V++}}e(t("settings.colorCatalog.imported",{added:z,skipped:V}),"success")}catch{e(t("settings.colorCatalog.importFailed"),"error")}u.current&&(u.current.value="")}};return i.jsxs(Tt,{children:[i.jsxs(qn,{children:[i.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[i.jsx(mC,{className:"w-5 h-5 text-bambu-gray"}),i.jsx("h2",{className:"text-lg font-semibold text-white",children:t("settings.colorCatalog.title")}),i.jsxs("span",{className:"text-sm text-bambu-gray",children:["(",n.length,")"]})]}),i.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[i.jsxs("button",{onClick:E,className:"px-3 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray hover:text-white transition-colors flex items-center gap-1.5",children:[i.jsx(hi,{className:"w-4 h-4"}),i.jsx("span",{className:"hidden sm:inline",children:t("common.export")})]}),i.jsxs("button",{onClick:()=>u.current?.click(),className:"px-3 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray hover:text-white transition-colors flex items-center gap-1.5",children:[i.jsx(Si,{className:"w-4 h-4"}),i.jsx("span",{className:"hidden sm:inline",children:t("common.import")})]}),i.jsx("input",{ref:u,type:"file",accept:".json",className:"hidden",onChange:j}),i.jsxs("button",{onClick:K,disabled:A,className:"px-3 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray hover:text-white transition-colors flex items-center gap-1.5",title:t("settings.colorCatalog.syncTooltip"),children:[A?i.jsx(lt,{className:"w-4 h-4 animate-spin"}):i.jsx(lx,{className:"w-4 h-4"}),i.jsx("span",{className:"hidden sm:inline",children:A?$?`${Math.min($.fetched,$.total)} / ${$.total}`:t("settings.colorCatalog.starting"):t("settings.colorCatalog.sync")})]}),i.jsxs("button",{onClick:()=>ie(!0),className:"px-3 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray hover:text-white transition-colors flex items-center gap-1.5",children:[i.jsx(mo,{className:"w-4 h-4"}),i.jsx("span",{className:"hidden sm:inline",children:t("common.reset")})]}),i.jsxs("button",{onClick:()=>p(!0),className:"px-3 py-1.5 text-sm bg-bambu-green text-white rounded-lg hover:bg-bambu-green/80 transition-colors flex items-center gap-1.5",children:[i.jsx(rr,{className:"w-4 h-4"}),i.jsx("span",{className:"hidden sm:inline",children:t("common.add")})]})]})]}),i.jsxs(Pt,{className:"space-y-4",children:[i.jsx("p",{className:"text-sm text-bambu-gray",children:t("settings.colorCatalog.description")}),i.jsxs("div",{className:"flex gap-2 flex-wrap",children:[i.jsxs("div",{className:"relative flex-1 min-w-[200px]",children:[i.jsx(jr,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray"}),i.jsx("input",{type:"text",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",placeholder:t("settings.colorCatalog.searchColors"),value:o,onChange:L=>l(L.target.value)})]}),i.jsxs("select",{className:"px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",value:c,onChange:L=>d(L.target.value),children:[i.jsx("option",{value:"",children:t("settings.colorCatalog.allManufacturers")}),ae.map(L=>i.jsx("option",{value:L,children:L},L))]})]}),m&&i.jsxs("div",{className:"p-4 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary",children:[i.jsx("h3",{className:"text-sm font-medium text-white mb-3",children:t("settings.colorCatalog.addNewColor")}),i.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-5 gap-2 items-end",children:[i.jsx("input",{type:"text",className:"px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none",placeholder:t("settings.colorCatalog.manufacturer"),value:v,onChange:L=>g(L.target.value)}),i.jsx("input",{type:"text",className:"px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none",placeholder:t("settings.colorCatalog.colorName"),value:y,onChange:L=>_(L.target.value)}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("input",{type:"color",className:"w-20 h-10 rounded cursor-pointer border border-bambu-dark-tertiary",value:N,onChange:L=>C(L.target.value)}),i.jsx("input",{type:"text",className:"w-32 px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none",placeholder:"#FFFFFF",value:N,onChange:L=>C(L.target.value)})]}),i.jsxs("div",{className:"flex items-center gap-1",children:[i.jsx("input",{type:"text",className:"flex-1 max-w-lg min-w-[200px] px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none",placeholder:t("settings.colorCatalog.materialOptional"),value:T,onChange:L=>P(L.target.value)}),i.jsxs("button",{onClick:Q,disabled:k,className:"w-24 px-3 py-2 bg-bambu-green text-white rounded-lg hover:bg-bambu-green/80 flex items-center justify-center gap-3",children:[k?i.jsx(lt,{className:"w-4 h-4 animate-spin"}):i.jsx(Vr,{className:"w-4 h-4"}),t("common.add")]}),i.jsx("button",{onClick:()=>{p(!1),pe()},className:"p-2 ml-2 rounded-lg text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary",children:i.jsx(zt,{className:"w-4 h-4"})})]})]})]}),(o||c)&&i.jsx("div",{className:"text-xs text-bambu-gray",children:t("settings.colorCatalog.showing",{filtered:de.length,total:n.length})}),a?i.jsxs("div",{className:"flex items-center justify-center py-8 text-bambu-gray",children:[i.jsx(lt,{className:"w-5 h-5 animate-spin mr-2"}),t("common.loading")]}):i.jsx("div",{className:"max-h-[600px] overflow-auto border border-bambu-dark-tertiary rounded-lg",children:i.jsxs("table",{className:"w-full text-sm",children:[i.jsx("thead",{className:"bg-bambu-dark sticky top-0",children:i.jsxs("tr",{children:[i.jsx("th",{className:"px-3 py-2 text-left text-bambu-gray font-medium w-12"}),i.jsx("th",{className:"px-3 py-2 text-left text-bambu-gray font-medium",children:t("settings.colorCatalog.manufacturer")}),i.jsx("th",{className:"px-3 py-2 text-left text-bambu-gray font-medium",children:t("inventory.material")}),i.jsx("th",{className:"px-3 py-2 text-left text-bambu-gray font-medium",children:t("settings.colorCatalog.colorName")}),i.jsx("th",{className:"px-3 py-2 text-left text-bambu-gray font-medium w-24",children:t("settings.colorCatalog.hex")}),i.jsx("th",{className:"px-3 py-2 w-16"})]})}),i.jsx("tbody",{children:de.length===0?i.jsx("tr",{children:i.jsx("td",{colSpan:6,className:"px-3 py-8 text-center text-bambu-gray",children:t(o||c?"settings.colorCatalog.noMatch":"settings.colorCatalog.empty")})}):de.map(L=>i.jsx("tr",{className:"border-t border-bambu-dark-tertiary hover:bg-bambu-dark",children:f===L.id?i.jsxs(i.Fragment,{children:[i.jsx("td",{className:"px-3 py-2",children:i.jsx("input",{type:"color",className:"w-8 h-8 rounded cursor-pointer border border-bambu-dark-tertiary",value:N,onChange:G=>C(G.target.value)})}),i.jsx("td",{className:"px-3 py-2",children:i.jsx("input",{type:"text",className:"w-full px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none",value:v,onChange:G=>g(G.target.value)})}),i.jsx("td",{className:"px-3 py-2",children:i.jsx("input",{type:"text",className:"w-full px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none",value:T,onChange:G=>P(G.target.value)})}),i.jsx("td",{className:"px-3 py-2",children:i.jsx("input",{type:"text",className:"w-full px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none",value:y,onChange:G=>_(G.target.value)})}),i.jsx("td",{className:"px-3 py-2",children:i.jsx("input",{type:"text",className:"w-full px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none",value:N,onChange:G=>C(G.target.value)})}),i.jsx("td",{className:"px-3 py-2",children:i.jsxs("div",{className:"flex justify-end gap-1",children:[i.jsx("button",{onClick:()=>we(L.id),disabled:k,className:"p-1.5 rounded hover:bg-green-500/20 text-green-500",children:k?i.jsx(lt,{className:"w-4 h-4 animate-spin"}):i.jsx(Vr,{className:"w-4 h-4"})}),i.jsx("button",{onClick:me,className:"p-1.5 rounded hover:bg-bambu-dark-tertiary text-bambu-gray",children:i.jsx(zt,{className:"w-4 h-4"})})]})})]}):i.jsxs(i.Fragment,{children:[i.jsx("td",{className:"px-3 py-2",children:i.jsx("div",{className:"w-8 h-8 rounded border border-bambu-dark-tertiary",style:{backgroundColor:L.hex_color},title:L.hex_color})}),i.jsx("td",{className:"px-3 py-2 text-white",children:L.manufacturer}),i.jsx("td",{className:"px-3 py-2 text-bambu-gray",children:L.material||"-"}),i.jsx("td",{className:"px-3 py-2 text-white",children:L.color_name}),i.jsx("td",{className:"px-3 py-2 font-mono text-xs text-bambu-gray",children:L.hex_color}),i.jsx("td",{className:"px-3 py-2",children:i.jsxs("div",{className:"flex justify-end gap-1",children:[i.jsx("button",{onClick:()=>oe(L),className:"p-1.5 rounded hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white",children:i.jsx(Ki,{className:"w-4 h-4"})}),i.jsx("button",{onClick:()=>O(L),className:"p-1.5 rounded bg-red-500/10 hover:bg-red-500/20 text-red-500",children:i.jsx(Qt,{className:"w-4 h-4"})})]})})]})},L.id))})]})})]}),W&&i.jsx(_n,{title:t("settings.colorCatalog.deleteColor"),message:t("settings.colorCatalog.deleteConfirm",{name:`${W.manufacturer} - ${W.color_name}`}),confirmText:t("common.delete"),variant:"danger",onConfirm:Ee,onCancel:()=>O(null)}),te&&i.jsx(_n,{title:t("settings.colorCatalog.resetCatalog"),message:t("settings.colorCatalog.resetConfirm"),confirmText:t("common.reset"),variant:"danger",onConfirm:q,onCancel:()=>ie(!1)})]})}function oJe({link:t,onClose:e}){const{t:n}=Mt(),r=Zt(),a=!!t,s=w.useRef(null),[o,l]=w.useState(t?.name||""),[c,d]=w.useState(t?.url||""),[u,m]=w.useState(t?.icon||"link"),[p,f]=w.useState(t?.open_in_new_tab||!1),[x,v]=w.useState(!!t?.custom_icon),[g,y]=w.useState(t?.custom_icon?fe.getExternalLinkIconUrl(t.id):null),[_,N]=w.useState(null),[C,T]=w.useState(null);w.useEffect(()=>{const W=O=>{O.key==="Escape"&&e()};return window.addEventListener("keydown",W),()=>window.removeEventListener("keydown",W)},[e]);const P=dt({mutationFn:async W=>{const O=await fe.createExternalLink(W);return _?await fe.uploadExternalLinkIcon(O.id,_):O},onSuccess:()=>{r.invalidateQueries({queryKey:["external-links"]}),e()},onError:W=>{T(W.message)}}),k=dt({mutationFn:async W=>{let O=await fe.updateExternalLink(t.id,W);return _?O=await fe.uploadExternalLinkIcon(t.id,_):!x&&t?.custom_icon&&(O=await fe.deleteExternalLinkIcon(t.id)),O},onSuccess:()=>{r.invalidateQueries({queryKey:["external-links"]}),e()},onError:W=>{T(W.message)}}),D=W=>{const O=W.target.files?.[0];if(O){if(!["image/png","image/jpeg","image/gif","image/svg+xml","image/webp","image/x-icon"].includes(O.type)){T("Please select a valid image file (PNG, JPG, GIF, SVG, WebP, or ICO)");return}if(O.size>1024*1024){T("Image file must be less than 1MB");return}N(O),v(!0);const ie=new FileReader;ie.onload=Y=>{y(Y.target?.result)},ie.readAsDataURL(O)}},A=()=>{N(null),y(null),v(!1),s.current&&(s.current.value="")},R=W=>{if(W.preventDefault(),T(null),!o.trim()){T("Name is required");return}if(!c.trim()){T("URL is required");return}if(!c.startsWith("http://")&&!c.startsWith("https://")){T("URL must start with http:// or https://");return}const O={name:o.trim(),url:c.trim(),icon:u,open_in_new_tab:p};a?k.mutate(O):P.mutate(O)},$=P.isPending||k.isPending,U=yC(u);return i.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",onClick:e,children:i.jsxs("div",{className:"bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-md",onClick:W=>W.stopPropagation(),children:[i.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary",children:[i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx("div",{className:"p-2 rounded-full bg-bambu-green/20 text-bambu-green",children:x&&g?i.jsx("img",{src:g,alt:"",className:"w-5 h-5 rounded"}):i.jsx(U,{className:"w-5 h-5"})}),i.jsx("h2",{className:"text-lg font-semibold text-white",children:a?"Edit Link":"Add External Link"})]}),i.jsx("button",{onClick:e,className:"text-bambu-gray hover:text-white transition-colors",children:i.jsx(zt,{className:"w-5 h-5"})})]}),i.jsxs("form",{onSubmit:R,className:"p-6 space-y-4",children:[C&&i.jsx("div",{className:"p-3 bg-red-500/20 border border-red-500/50 rounded-lg text-sm text-red-400",children:C}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Name *"}),i.jsx("input",{type:"text",value:o,onChange:W=>l(W.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"})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"URL *"}),i.jsx("input",{type:"text",value:c,onChange:W=>d(W.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"})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("label",{className:"text-sm text-bambu-gray",children:n("externalLinks.openInNewTab")}),i.jsx("button",{type:"button",onClick:()=>f(!p),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors ${p?"bg-bambu-green":"bg-bambu-dark-tertiary"}`,children:i.jsx("span",{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${p?"translate-x-6":"translate-x-1"}`})})]}),i.jsxs("div",{className:"space-y-3",children:[i.jsx("label",{className:"block text-sm text-bambu-gray",children:"Icon"}),i.jsxs("div",{className:"p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary",children:[i.jsxs("div",{className:"flex items-center justify-between mb-2",children:[i.jsx("span",{className:"text-sm text-white",children:"Custom Icon"}),i.jsx("input",{ref:s,type:"file",accept:"image/png,image/jpeg,image/gif,image/svg+xml,image/webp,image/x-icon",className:"hidden",onChange:D}),x&&g?i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("img",{src:g,alt:"Custom icon",className:"w-8 h-8 rounded border border-bambu-dark-tertiary"}),i.jsx("button",{type:"button",onClick:A,className:"p-1 text-red-400 hover:text-red-300 transition-colors",title:"Remove custom icon",children:i.jsx(Qt,{className:"w-4 h-4"})})]}):i.jsxs(Oe,{type:"button",variant:"secondary",size:"sm",onClick:()=>s.current?.click(),children:[i.jsx(Si,{className:"w-4 h-4"}),"Upload"]})]}),i.jsx("p",{className:"text-xs text-bambu-gray",children:"PNG, JPG, GIF, SVG, WebP, or ICO. Max 1MB."})]}),!x&&i.jsxs("div",{children:[i.jsx("span",{className:"text-sm text-bambu-gray block mb-2",children:"Or choose a preset icon"}),i.jsx(nbe,{value:u,onChange:m})]})]}),i.jsxs("div",{className:"flex gap-3 pt-2",children:[i.jsx(Oe,{type:"button",variant:"secondary",onClick:e,className:"flex-1",children:"Cancel"}),i.jsxs(Oe,{type:"submit",disabled:$,className:"flex-1",children:[$?i.jsx(lt,{className:"w-4 h-4 animate-spin"}):i.jsx(gs,{className:"w-4 h-4"}),a?"Save":"Add"]})]})]})]})})}function lJe(){const{t}=Mt(),e=Zt(),[n,r]=w.useState(!1),[a,s]=w.useState(null),[o,l]=w.useState(null),[c,d]=w.useState(null),{data:u,isLoading:m}=Ze({queryKey:["external-links"],queryFn:fe.getExternalLinks}),p=dt({mutationFn:N=>fe.deleteExternalLink(N),onSuccess:()=>{e.invalidateQueries({queryKey:["external-links"]})}}),f=dt({mutationFn:N=>fe.reorderExternalLinks(N),onSuccess:()=>{e.invalidateQueries({queryKey:["external-links"]})}}),x=(N,C)=>{d(C),N.dataTransfer.effectAllowed="move"},v=N=>{N.preventDefault(),N.dataTransfer.dropEffect="move"},g=(N,C)=>{if(N.preventDefault(),c===null||c===C||!u)return;const T=u.map(A=>A.id),P=T.indexOf(c),k=T.indexOf(C);if(P===-1||k===-1)return;const D=[...T];D.splice(P,1),D.splice(k,0,c),f.mutate(D),d(null)},y=N=>{l(N)},_=()=>{o&&(p.mutate(o.id),l(null))};return i.jsxs(i.Fragment,{children:[i.jsxs(Tt,{children:[i.jsx(qn,{children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(Vm,{className:"w-5 h-5 text-bambu-green"}),i.jsx("h2",{className:"text-lg font-semibold text-white",children:"Sidebar Links"})]}),i.jsxs(Oe,{size:"sm",onClick:()=>r(!0),children:[i.jsx(rr,{className:"w-4 h-4"}),"Add Link"]})]})}),i.jsxs(Pt,{children:[i.jsx("p",{className:"text-sm text-bambu-gray mb-4",children:"Add external links to the sidebar navigation. Drag to reorder."}),m?i.jsx("div",{className:"flex justify-center py-8",children:i.jsx(lt,{className:"w-6 h-6 text-bambu-green animate-spin"})}):u&&u.length>0?i.jsx("div",{className:"space-y-2",children:u.map(N=>{const C=yC(N.icon);return i.jsxs("div",{draggable:!0,onDragStart:T=>x(T,N.id),onDragOver:v,onDrop:T=>g(T,N.id),className:`flex items-center gap-3 p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary transition-colors ${c===N.id?"opacity-50":""}`,children:[i.jsx(qm,{className:"w-6 h-6 md:w-4 md:h-4 text-bambu-gray cursor-grab flex-shrink-0"}),i.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark-tertiary text-bambu-gray",children:i.jsx(C,{className:"w-4 h-4"})}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("span",{className:"text-white font-medium truncate",children:N.name}),i.jsx(ei,{className:"w-3 h-3 text-bambu-gray flex-shrink-0"})]}),i.jsx("span",{className:"text-sm text-bambu-gray truncate block",children:N.url})]}),i.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[i.jsx("button",{onClick:()=>s(N),className:"p-2 rounded-lg hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white transition-colors",title:t("common.edit"),children:i.jsx(Ki,{className:"w-4 h-4"})}),i.jsx("button",{onClick:()=>y(N),disabled:p.isPending,className:"p-2 rounded-lg hover:bg-red-500/20 text-bambu-gray hover:text-red-400 transition-colors disabled:opacity-50",title:t("externalLinks.deleteLink"),children:i.jsx(Qt,{className:"w-4 h-4"})})]})]},N.id)})}):i.jsxs("div",{className:"text-center py-8 text-bambu-gray",children:[i.jsx(Vm,{className:"w-8 h-8 mx-auto mb-2 opacity-50"}),i.jsx("p",{children:t("externalLinks.noLinksConfigured")}),i.jsx("p",{className:"text-sm",children:'Click "Add Link" to add one'})]})]})]}),(n||a)&&i.jsx(oJe,{link:a,onClose:()=>{r(!1),s(null)}}),o&&i.jsx(_n,{title:"Delete Link",message:`Are you sure you want to delete "${o.name}"? This action cannot be undone.`,confirmText:"Delete",cancelText:"Cancel",variant:"danger",onConfirm:_,onCancel:()=>l(null)})]})}const Wj={immediate:"archive",review:"review",print_queue:"queue",proxy:"proxy"};function cJe({printer:t,models:e}){const{t:n}=Mt(),r=Zt(),{showToast:a}=hn(),[s,o]=w.useState(!0),[l,c]=w.useState(t.enabled),[d,u]=w.useState(t.name),[m,p]=w.useState(""),[f,x]=w.useState(t.mode==="queue"?"review":t.mode),[v,g]=w.useState(t.target_printer_id),[y,_]=w.useState(t.bind_ip||""),[N,C]=w.useState(t.remote_interface_ip||""),[T,P]=w.useState(t.model||""),[k,D]=w.useState(!1),[A,R]=w.useState(null),[$,U]=w.useState(!1);w.useEffect(()=>{A||(c(t.enabled),x(t.mode==="queue"?"review":t.mode),u(t.name),g(t.target_printer_id),_(t.bind_ip||""),C(t.remote_interface_ip||""),P(t.model||""))},[t,A]);const{data:W}=Ze({queryKey:["printers"],queryFn:fe.getPrinters}),{data:O}=Ze({queryKey:["network-interfaces"],queryFn:()=>fe.getNetworkInterfaces().then(K=>K.interfaces)}),te=dt({mutationFn:K=>G1.update(t.id,K),onSuccess:()=>{r.invalidateQueries({queryKey:["virtual-printers"]}),a(n("virtualPrinter.toast.updated")),R(null)},onError:K=>{a(K.message||n("virtualPrinter.toast.failedToUpdate"),"error"),c(t.enabled),x(t.mode==="queue"?"review":t.mode),g(t.target_printer_id),_(t.bind_ip||""),R(null)}}),ie=dt({mutationFn:()=>G1.remove(t.id),onSuccess:()=>{r.invalidateQueries({queryKey:["virtual-printers"]}),a(n("virtualPrinter.toast.deleted")),U(!1)},onError:K=>{a(K.message||n("virtualPrinter.toast.failedToDelete"),"error"),U(!1)}}),Y=K=>{K.stopPropagation();const E=!l;if(E){if(!y){a(n("virtualPrinter.toast.bindIpRequired"),"error");return}if(f==="proxy"){if(!v){a(n("virtualPrinter.toast.targetPrinterRequired"),"error");return}}else if(!m&&!t.access_code_set){a(n("virtualPrinter.toast.accessCodeRequired"),"error");return}}c(E),R("toggle"),te.mutate({enabled:E})},ae=()=>{d.trim()&&(R("name"),te.mutate({name:d.trim()}))},de=()=>{if(!m){a(n("virtualPrinter.toast.accessCodeEmpty"),"error");return}if(m.length!==8){a(n("virtualPrinter.toast.accessCodeLength"),"error");return}R("accessCode"),te.mutate({access_code:m}),p("")},pe=K=>{x(K),R("mode"),te.mutate({mode:K})},Q=K=>{P(K),R("model"),te.mutate({model:K})},oe=K=>{g(K),R("targetPrinter"),te.mutate({target_printer_id:K})},me=K=>{C(K),R("remoteInterface"),te.mutate({remote_interface_ip:K})},we=t.status?.running||!1,Ee=n(`virtualPrinter.mode.${Wj[f]||"archive"}`),q=W?.find(K=>K.id===v)?.name;return i.jsxs(i.Fragment,{children:[i.jsxs(Tt,{children:[i.jsxs("div",{className:"px-4 py-3 flex items-center gap-3 cursor-pointer select-none",onClick:()=>o(!s),children:[i.jsx("button",{className:"text-bambu-gray flex-shrink-0",children:s?i.jsx(jn,{className:"w-4 h-4"}):i.jsx(fa,{className:"w-4 h-4"})}),i.jsx("span",{className:`w-2 h-2 rounded-full flex-shrink-0 ${we?"bg-green-400 animate-pulse":"bg-gray-500"}`}),i.jsx("span",{className:"text-white font-medium truncate",children:t.name}),i.jsx("span",{className:"text-xs text-bambu-gray flex-shrink-0",children:Ee}),t.model_name&&i.jsx("span",{className:"text-xs text-bambu-gray flex-shrink-0",children:t.model_name}),q&&i.jsxs("span",{className:"text-xs text-bambu-gray flex-shrink-0 truncate",children:[f==="proxy"&&i.jsx(SD,{className:"w-3 h-3 inline mr-1"}),q]}),y&&i.jsx("span",{className:"text-[10px] text-bambu-gray flex-shrink-0 font-mono",children:y}),N&&i.jsx("span",{className:"text-[10px] text-bambu-gray flex-shrink-0 font-mono",children:N}),i.jsx("div",{className:"ml-auto flex items-center gap-2 flex-shrink-0",onClick:K=>K.stopPropagation(),children:i.jsx("button",{onClick:Y,disabled:A==="toggle",className:`relative w-10 h-5 rounded-full transition-colors ${l?"bg-bambu-green":"bg-bambu-dark-tertiary"} ${A==="toggle"?"opacity-50":""}`,children:i.jsx("span",{className:`absolute top-0.5 left-0.5 w-4 h-4 bg-white rounded-full transition-transform ${l?"translate-x-5":""}`})})})]}),s&&i.jsxs(Pt,{className:"pt-0 space-y-4",children:[i.jsx("div",{className:"border-t border-bambu-dark-tertiary"}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("input",{type:"text",value:d,onChange:K=>u(K.target.value),onBlur:ae,onKeyDown:K=>K.key==="Enter"&&ae(),className:"flex-1 text-sm text-white bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-1.5 focus:border-bambu-green focus:outline-none"}),i.jsx("span",{className:"text-xs text-bambu-gray font-mono",children:t.serial}),i.jsx("button",{onClick:()=>U(!0),className:"p-1.5 text-bambu-gray hover:text-red-400 transition-colors",title:n("common.delete"),children:i.jsx(Qt,{className:"w-4 h-4"})})]}),i.jsxs("div",{children:[i.jsx("div",{className:"text-white text-sm font-medium mb-2",children:n("virtualPrinter.mode.title")}),i.jsx("div",{className:"grid grid-cols-2 gap-2",children:["immediate","review","print_queue","proxy"].map(K=>i.jsxs("button",{onClick:()=>pe(K),disabled:A==="mode",className:`p-2 rounded-lg border text-left transition-colors ${f===K?K==="proxy"?"border-blue-500 bg-blue-500/10":"border-bambu-green bg-bambu-green/10":"border-bambu-dark-tertiary hover:border-bambu-gray"}`,children:[i.jsxs("div",{className:"flex items-center gap-1.5 text-white text-xs font-medium",children:[K==="proxy"&&i.jsx(SD,{className:"w-3 h-3"}),n(`virtualPrinter.mode.${Wj[K]}`)]}),i.jsx("div",{className:"text-[10px] text-bambu-gray",children:n(`virtualPrinter.mode.${Wj[K]}Desc`)})]},K))})]}),f!=="proxy"&&i.jsxs("div",{className:"pt-2 border-t border-bambu-dark-tertiary",children:[i.jsx("div",{className:"text-white text-sm font-medium mb-1",children:n("virtualPrinter.model.title")}),i.jsx("p",{className:"text-xs text-bambu-gray mb-2",children:n("virtualPrinter.model.description")}),i.jsxs("div",{className:"relative",children:[i.jsx("select",{value:T,onChange:K=>Q(K.target.value),disabled:A==="model",className:"w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-1.5 text-white text-sm appearance-none cursor-pointer disabled:opacity-50 pr-10",children:Object.entries(e).map(([K,E])=>i.jsxs("option",{value:K,children:[E," (",K,")"]},K))}),i.jsx(jn,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]})]}),f==="proxy"&&i.jsx("div",{className:"pt-2 border-t border-bambu-dark-tertiary",children:i.jsxs("div",{className:"flex items-start gap-2 p-2 rounded bg-blue-500/10 border border-blue-500/30",children:[i.jsx(Rs,{className:"w-4 h-4 text-blue-400 flex-shrink-0 mt-0.5"}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("virtualPrinter.proxy.accessCodeHint")})]})}),f!=="proxy"&&i.jsxs("div",{className:"pt-2 border-t border-bambu-dark-tertiary",children:[i.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[i.jsx("div",{className:"text-white text-sm font-medium",children:n("virtualPrinter.accessCode.title")}),t.access_code_set?i.jsxs("span",{className:"flex items-center gap-1 text-xs text-green-400",children:[i.jsx(Vr,{className:"w-3 h-3"}),n("virtualPrinter.accessCode.isSet")]}):i.jsxs("span",{className:"flex items-center gap-1 text-xs text-yellow-400",children:[i.jsx(Cn,{className:"w-3 h-3"}),n("virtualPrinter.accessCode.notSet")]})]}),i.jsxs("div",{className:"flex gap-2",children:[i.jsxs("div",{className:"relative flex-1",children:[i.jsx("input",{type:k?"text":"password",value:m,onChange:K=>p(K.target.value),placeholder:t.access_code_set?n("virtualPrinter.accessCode.placeholderChange"):n("virtualPrinter.accessCode.placeholder"),maxLength:8,className:"w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-1.5 text-white text-sm placeholder-bambu-gray pr-10 font-mono"}),i.jsx("button",{onClick:()=>D(!k),className:"absolute right-2 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white",children:k?i.jsx(E0,{className:"w-4 h-4"}):i.jsx(rc,{className:"w-4 h-4"})})]}),i.jsx(Oe,{onClick:de,disabled:!m||A==="accessCode",variant:"primary",children:A==="accessCode"?i.jsx(lt,{className:"w-4 h-4 animate-spin"}):n("common.save")})]}),m&&i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:i.jsx("span",{className:m.length===8?"text-green-400":"text-yellow-400",children:n("virtualPrinter.accessCode.charCount",{count:m.length})})})]}),i.jsxs("div",{className:"pt-2 border-t border-bambu-dark-tertiary",children:[i.jsx("div",{className:"text-white text-sm font-medium mb-2",children:n("virtualPrinter.targetPrinter.title")}),i.jsxs("div",{className:"relative",children:[i.jsxs("select",{value:v??"",onChange:K=>{const E=parseInt(K.target.value,10);isNaN(E)||oe(E)},disabled:A==="targetPrinter",className:"w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-1.5 text-white text-sm appearance-none cursor-pointer disabled:opacity-50 pr-10",children:[i.jsx("option",{value:"",children:n("virtualPrinter.targetPrinter.placeholder")}),W?.map(K=>i.jsxs("option",{value:K.id,children:[K.name," (",K.ip_address,")"]},K.id))]}),i.jsx(jn,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]})]}),i.jsxs("div",{className:"pt-2 border-t border-bambu-dark-tertiary",children:[i.jsx("div",{className:"text-white text-sm font-medium mb-1",children:n("virtualPrinter.bindIp.title")}),i.jsxs("div",{className:"relative",children:[i.jsxs("select",{value:y,onChange:K=>{_(K.target.value),R("bindIp"),te.mutate({bind_ip:K.target.value})},disabled:A==="bindIp",className:"w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-1.5 text-white text-sm appearance-none cursor-pointer disabled:opacity-50 pr-10",children:[i.jsx("option",{value:"",children:n("virtualPrinter.bindIp.placeholder")}),O?.map(K=>i.jsxs("option",{value:K.ip,children:[K.name," (",K.ip,")",K.is_alias?" [alias]":""," - ",K.subnet]},K.ip))]}),i.jsx(jn,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:n("virtualPrinter.bindIp.hint")})]}),i.jsxs("div",{className:"pt-2 border-t border-bambu-dark-tertiary",children:[i.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[i.jsx("div",{className:"text-white text-sm font-medium",children:n("virtualPrinter.remoteInterface.title")}),N?i.jsx("span",{className:"flex items-center gap-1 text-xs text-green-400",children:i.jsx(Vr,{className:"w-3 h-3"})}):i.jsx("span",{className:"flex items-center gap-1 text-xs text-bambu-gray",title:n("virtualPrinter.remoteInterface.optional"),children:i.jsx(Rs,{className:"w-3 h-3"})})]}),i.jsxs("div",{className:"relative",children:[i.jsxs("select",{value:N,onChange:K=>me(K.target.value),disabled:A==="remoteInterface",className:"w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-1.5 text-white text-sm appearance-none cursor-pointer disabled:opacity-50 pr-10",children:[i.jsx("option",{value:"",children:n("virtualPrinter.remoteInterface.placeholder")}),O?.map(K=>i.jsxs("option",{value:K.ip,children:[K.name," (",K.ip,") - ",K.subnet]},K.ip))]}),i.jsx(jn,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]})]})]})]}),$&&i.jsx(_n,{title:n("virtualPrinter.deleteConfirm.title"),message:n("virtualPrinter.deleteConfirm.message",{name:t.name}),variant:"danger",confirmText:n("common.delete"),isLoading:ie.isPending,onConfirm:()=>ie.mutate(),onCancel:()=>U(!1)})]})}const TK={immediate:"archive",review:"review",print_queue:"queue",proxy:"proxy"};function dJe({onClose:t}){const{t:e}=Mt(),n=Zt(),{showToast:r}=hn(),[a,s]=w.useState(""),[o,l]=w.useState("immediate"),[c,d]=w.useState(null),{data:u}=Ze({queryKey:["printers"],queryFn:fe.getPrinters}),m=dt({mutationFn:()=>G1.create({name:a.trim()||"Bambuddy",mode:o,target_printer_id:o==="proxy"?c??void 0:void 0}),onSuccess:()=>{n.invalidateQueries({queryKey:["virtual-printers"]}),r(e("virtualPrinter.toast.created")),t()},onError:p=>{r(p.message||e("virtualPrinter.toast.failedToCreate"),"error")}});return i.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",onClick:t,children:i.jsx(Tt,{className:"w-full max-w-md",onClick:p=>p.stopPropagation(),children:i.jsxs(Pt,{className:"p-6 space-y-4",children:[i.jsx("h3",{className:"text-lg font-semibold text-white",children:e("virtualPrinter.addDialog.title")}),i.jsxs("div",{children:[i.jsx("label",{className:"text-sm text-white font-medium block mb-1",children:e("virtualPrinter.addDialog.name")}),i.jsx("input",{type:"text",value:a,onChange:p=>s(p.target.value),placeholder:"Bambuddy",className:"w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-2 text-white text-sm placeholder-bambu-gray",autoFocus:!0})]}),i.jsxs("div",{children:[i.jsx("label",{className:"text-sm text-white font-medium block mb-1",children:e("virtualPrinter.mode.title")}),i.jsx("div",{className:"grid grid-cols-2 gap-2",children:["immediate","review","print_queue","proxy"].map(p=>i.jsxs("button",{onClick:()=>l(p),className:`p-2 rounded-lg border text-left transition-colors ${o===p?p==="proxy"?"border-blue-500 bg-blue-500/10":"border-bambu-green bg-bambu-green/10":"border-bambu-dark-tertiary hover:border-bambu-gray"}`,children:[i.jsxs("div",{className:"flex items-center gap-1.5 text-white text-xs font-medium",children:[p==="proxy"&&i.jsx(SD,{className:"w-3 h-3"}),e(`virtualPrinter.mode.${TK[p]}`)]}),i.jsx("div",{className:"text-[10px] text-bambu-gray",children:e(`virtualPrinter.mode.${TK[p]}Desc`)})]},p))})]}),o==="proxy"&&i.jsxs("div",{children:[i.jsx("label",{className:"text-sm text-white font-medium block mb-1",children:e("virtualPrinter.targetPrinter.title")}),i.jsxs("div",{className:"relative",children:[i.jsxs("select",{value:c??"",onChange:p=>{const f=parseInt(p.target.value,10);d(isNaN(f)?null:f)},className:"w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-2 text-white text-sm appearance-none cursor-pointer pr-10",children:[i.jsx("option",{value:"",children:e("virtualPrinter.targetPrinter.placeholder")}),u?.map(p=>i.jsxs("option",{value:p.id,children:[p.name," (",p.ip_address,")"]},p.id))]}),i.jsx(jn,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]})]}),i.jsx("p",{className:"text-xs text-bambu-gray",children:e("virtualPrinter.addDialog.hint")}),i.jsxs("div",{className:"flex gap-3 pt-2",children:[i.jsx(Oe,{variant:"secondary",onClick:t,className:"flex-1",disabled:m.isPending,children:e("common.cancel")}),i.jsx(Oe,{variant:"primary",onClick:()=>m.mutate(),className:"flex-1",disabled:m.isPending,children:m.isPending?i.jsx(lt,{className:"w-4 h-4 animate-spin"}):e("virtualPrinter.addDialog.create")})]})]})})})}function uJe(){const{t}=Mt(),[e,n]=w.useState(!1),{data:r,isLoading:a}=Ze({queryKey:["virtual-printers"],queryFn:G1.list,refetchInterval:1e4});if(a)return i.jsx(Tt,{children:i.jsx(Pt,{className:"py-8 flex justify-center",children:i.jsx(lt,{className:"w-6 h-6 animate-spin text-bambu-green"})})});const s=r?.printers||[],o=r?.models||{};return i.jsxs("div",{className:"space-y-4",children:[i.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-4 gap-4 items-stretch",children:[i.jsx(Tt,{className:"border-l-4 border-l-yellow-500",children:i.jsx(Pt,{className:"py-3 px-4",children:i.jsxs("div",{className:"flex items-start gap-2",children:[i.jsx(Cn,{className:"w-4 h-4 text-yellow-500 flex-shrink-0 mt-0.5"}),i.jsxs("div",{className:"text-xs",children:[i.jsx("p",{className:"text-white font-medium",children:t("virtualPrinter.setupRequired.title")}),i.jsx("p",{className:"text-bambu-gray mt-1",children:t("virtualPrinter.setupRequired.description")}),i.jsxs("a",{href:"https://wiki.bambuddy.cool/features/virtual-printer/",target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1.5 mt-2 px-3 py-1.5 bg-yellow-500/20 border border-yellow-500/50 rounded text-yellow-400 hover:bg-yellow-500/30 transition-colors text-xs",children:[i.jsx(ei,{className:"w-3 h-3"}),t("virtualPrinter.setupRequired.readGuide")]})]})]})})}),i.jsx(Tt,{className:"lg:col-span-3",children:i.jsx(Pt,{className:"py-3 px-4",children:i.jsxs("div",{className:"flex items-start gap-2",children:[i.jsx(Rs,{className:"w-4 h-4 text-blue-400 flex-shrink-0 mt-0.5"}),i.jsxs("div",{className:"text-xs text-bambu-gray",children:[i.jsx("p",{className:"text-white font-medium mb-1",children:t("virtualPrinter.howItWorks.title")}),i.jsxs("ul",{className:"space-y-1 list-disc list-inside",children:[i.jsx("li",{children:t("virtualPrinter.howItWorks.step1")}),i.jsx("li",{children:t("virtualPrinter.howItWorks.step2")}),i.jsx("li",{children:t("virtualPrinter.howItWorks.step3")})]})]})]})})})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(_r,{className:"w-5 h-5 text-bambu-green"}),i.jsx("h2",{className:"text-lg font-semibold text-white",children:t("virtualPrinter.list.title")}),i.jsxs("span",{className:"text-sm text-bambu-gray",children:["(",s.length,")"]})]}),i.jsxs(Oe,{variant:"primary",onClick:()=>n(!0),children:[i.jsx(rr,{className:"w-4 h-4 mr-1"}),t("virtualPrinter.list.add")]})]}),s.length===0?i.jsx(Tt,{children:i.jsxs(Pt,{className:"py-8 text-center",children:[i.jsx(_r,{className:"w-12 h-12 text-bambu-gray mx-auto mb-3"}),i.jsx("p",{className:"text-bambu-gray mb-4",children:t("virtualPrinter.list.empty")}),i.jsxs(Oe,{variant:"primary",onClick:()=>n(!0),children:[i.jsx(rr,{className:"w-4 h-4 mr-1"}),t("virtualPrinter.list.addFirst")]})]})}):i.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-4 items-start",children:s.map(l=>i.jsx(cJe,{printer:l,models:o},l.id))}),e&&i.jsx(dJe,{onClose:()=>n(!1)})]})}function mJe(t){return t?new Date(t).toLocaleString():"-"}function PK({status:t}){if(!t)return null;const e={success:"bg-green-500/20 text-green-400",failed:"bg-red-500/20 text-red-400",skipped:"bg-yellow-500/20 text-yellow-400",running:"bg-blue-500/20 text-blue-400"},n={success:i.jsx(pr,{className:"w-3 h-3"}),failed:i.jsx(Vi,{className:"w-3 h-3"}),skipped:i.jsx(XF,{className:"w-3 h-3"}),running:i.jsx(lt,{className:"w-3 h-3 animate-spin"})};return i.jsxs("span",{className:`inline-flex items-center gap-1 px-2 py-0.5 rounded text-xs font-medium ${e[t]||"bg-gray-500/20 text-gray-400"}`,children:[n[t],t.charAt(0).toUpperCase()+t.slice(1)]})}function hJe(){const t=Zt(),{showToast:e}=hn(),{t:n}=Mt(),[r,a]=w.useState(""),[s,o]=w.useState(""),[l,c]=w.useState("main"),[d,u]=w.useState(!1),[m,p]=w.useState("daily"),[f,x]=w.useState(!0),[v,g]=w.useState(!0),[y,_]=w.useState(!1),[N,C]=w.useState(!0),[T,P]=w.useState(!1),[k,D]=w.useState(!1),[A,R]=w.useState(""),[$,U]=w.useState(!1),[W,O]=w.useState(null),[te,ie]=w.useState(null),Y=w.useRef(null);w.useEffect(()=>{if(T||k){const I=F=>(F.preventDefault(),F.returnValue="A backup operation is in progress. Are you sure you want to leave?",F.returnValue);return window.addEventListener("beforeunload",I),()=>window.removeEventListener("beforeunload",I)}},[T,k]);const[ae,de]=w.useState(!1),[pe,Q]=w.useState(null),oe=w.useRef(null),me=w.useRef(!1),{data:we,isLoading:Ee}=Ze({queryKey:["github-backup-config"],queryFn:fe.getGitHubBackupConfig}),{data:q}=Ze({queryKey:["github-backup-status"],queryFn:fe.getGitHubBackupStatus,refetchInterval:le=>le.state.data?.is_running?500:1e4}),{data:K}=Ze({queryKey:["github-backup-logs"],queryFn:()=>fe.getGitHubBackupLogs(20)}),{data:E}=Ze({queryKey:["cloud-status"],queryFn:fe.getCloudStatus}),{data:j}=Ze({queryKey:["printers"],queryFn:fe.getPrinters}),L=ox({queries:(j??[]).map(le=>({queryKey:["printerStatus",le.id],queryFn:()=>fe.getPrinterStatus(le.id),staleTime:1e4,refetchInterval:3e4}))}),G=(j??[]).map((le,I)=>({printer:le,connected:L[I]?.data?.connected??!1})),B=G.length,re=G.filter(le=>le.connected).length,z=B>0&&re===0,V=re>0&&re{we&&(a(we.repository_url),c(we.branch),u(we.schedule_enabled),p(we.schedule_type),x(we.backup_kprofiles),g(we.backup_cloud_profiles),_(we.backup_settings),C(we.enabled),o(""),setTimeout(()=>{me.current=!0},100))},[we]);const ee=w.useCallback(async(le=!1)=>{if(we?.has_token)try{le&&s?(await fe.saveGitHubBackupConfig({repository_url:r,access_token:s,branch:l,schedule_enabled:d,schedule_type:m,backup_kprofiles:f,backup_cloud_profiles:v,backup_settings:y,enabled:N}),o(""),e(n("backup.tokenUpdated"))):(await fe.updateGitHubBackupConfig({repository_url:r,branch:l,schedule_enabled:d,schedule_type:m,backup_kprofiles:f,backup_cloud_profiles:v,backup_settings:y,enabled:N}),e(n("backup.settingsSaved"))),t.invalidateQueries({queryKey:["github-backup-config"]}),t.invalidateQueries({queryKey:["github-backup-status"]})}catch(I){e(n("backup.failedToSave",{message:I.message}),"error")}},[we?.has_token,r,s,l,d,m,f,v,y,N,t,e,n]);w.useEffect(()=>{if(!(!me.current||!we?.has_token))return oe.current&&clearTimeout(oe.current),oe.current=setTimeout(()=>{ee(!1)},500),()=>{oe.current&&clearTimeout(oe.current)}},[r,l,d,m,f,v,y,N,ee,we?.has_token]),w.useEffect(()=>{if(!(!me.current||!we?.has_token||!s))return oe.current&&clearTimeout(oe.current),oe.current=setTimeout(()=>{ee(!0)},1e3),()=>{oe.current&&clearTimeout(oe.current)}},[s,ee,we?.has_token]);const J=dt({mutationFn:le=>fe.saveGitHubBackupConfig(le),onSuccess:()=>{t.invalidateQueries({queryKey:["github-backup-config"]}),t.invalidateQueries({queryKey:["github-backup-status"]}),e(n("backup.githubBackupEnabled")),o(""),me.current=!0},onError:le=>{e(n("backup.failedToSave",{message:le.message}),"error")}}),ne=dt({mutationFn:fe.triggerGitHubBackup,onSuccess:le=>{t.invalidateQueries({queryKey:["github-backup-status"]}),t.invalidateQueries({queryKey:["github-backup-logs"]}),le.success?le.files_changed>0?e(n("backup.backupCompleteFiles",{count:le.files_changed})):e(n("backup.backupSkippedNoChanges")):e(n("backup.backupFailed2",{message:le.message}),"error")},onError:le=>{e(n("backup.backupFailed2",{message:le.message}),"error")}}),se=dt({mutationFn:()=>fe.clearGitHubBackupLogs(0),onSuccess:le=>{t.invalidateQueries({queryKey:["github-backup-logs"]}),e(n("backup.clearedLogs",{count:le.deleted}))},onError:le=>{e(n("backup.failedToClearLogs",{message:le.message}),"error")}}),ue=async()=>{de(!0),Q(null);try{let le;if(s){if(!r){e(n("backup.enterRepoUrl"),"error"),de(!1);return}le=await fe.testGitHubConnection(r,s)}else if(we?.has_token)le=await fe.testGitHubStoredConnection();else{e(n("backup.enterRepoAndToken"),"error"),de(!1);return}Q({success:le.success,message:le.message})}catch(le){Q({success:!1,message:le.message})}finally{de(!1)}},ge=()=>{if(!r){e(n("backup.repoRequired"),"error");return}if(!s){e(n("backup.tokenRequired"),"error");return}J.mutate({repository_url:r,access_token:s,branch:l,schedule_enabled:d,schedule_type:m,backup_kprofiles:f,backup_cloud_profiles:v,backup_settings:y,enabled:N})};return Ee?i.jsx("div",{className:"flex items-center justify-center py-12",children:i.jsx(lt,{className:"w-8 h-8 animate-spin text-bambu-green"})}):i.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[i.jsxs("div",{className:"space-y-6",children:[i.jsxs(Tt,{children:[i.jsx(qn,{children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(ND,{className:"w-5 h-5 text-gray-400"}),i.jsx("h2",{className:"text-lg font-semibold text-white",children:n("backup.githubBackup")})]}),we&&E?.is_authenticated&&i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("span",{className:"text-sm text-bambu-gray",children:n("backup.enabled")}),i.jsx($n,{checked:N,onChange:C})]})]})}),i.jsx(Pt,{className:"space-y-4",children:E?.is_authenticated?i.jsxs(i.Fragment,{children:[i.jsx("p",{className:"text-sm text-bambu-gray",children:n("backup.githubDescription")}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("backup.repositoryUrl")}),i.jsx("input",{type:"text",value:r,onChange:le=>{a(le.target.value),Q(null)},placeholder:"https://github.com/username/bambuddy-backup",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]}),i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[n("backup.personalAccessToken")," ",we?.has_token&&i.jsx("span",{className:"text-green-400",children:n("backup.tokenSaved")})]}),i.jsx("input",{type:"password",value:s,onChange:le=>{o(le.target.value),Q(null)},placeholder:we?.has_token?n("backup.enterNewToken"):"ghp_xxxxxxxxxxxx",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:n("backup.tokenHint")})]}),i.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("backup.branch")}),i.jsx("input",{type:"text",value:l,onChange:le=>c(le.target.value),placeholder:"main",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("backup.autoBackup")}),i.jsxs("select",{value:d?m:"disabled",onChange:le=>{le.target.value==="disabled"?u(!1):(u(!0),p(le.target.value))},className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[i.jsx("option",{value:"disabled",children:n("backup.manualOnly")}),i.jsx("option",{value:"hourly",children:n("backup.hourly")}),i.jsx("option",{value:"daily",children:n("backup.daily")}),i.jsx("option",{value:"weekly",children:n("backup.weekly")})]})]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-2",children:n("backup.includeInBackup")}),i.jsxs("div",{className:"space-y-2",children:[i.jsxs("label",{className:`flex items-start gap-2 ${z?"cursor-not-allowed opacity-60":"cursor-pointer"}`,children:[i.jsx("input",{type:"checkbox",checked:f,onChange:le=>x(le.target.checked),className:"w-4 h-4 mt-0.5 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green",disabled:z}),i.jsxs("div",{className:"flex-1",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("span",{className:`text-sm ${z?"text-bambu-gray":"text-white"}`,children:n("backup.kProfiles")}),z&&i.jsxs("span",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-xs bg-yellow-500/20 text-yellow-400",children:[i.jsx(Cn,{className:"w-3 h-3"}),n("backup.noPrintersConnected")]}),V&&i.jsxs("span",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-xs bg-yellow-500/20 text-yellow-400",children:[i.jsx(Cn,{className:"w-3 h-3"}),n("backup.printersConnected",{connected:re,total:B})]})]}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("backup.kProfilesDescription")})]})]}),i.jsxs("label",{className:"flex items-start gap-2 cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:v,onChange:le=>g(le.target.checked),className:"w-4 h-4 mt-0.5 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green",disabled:!E?.is_authenticated}),i.jsxs("div",{children:[i.jsx("span",{className:`text-sm ${E?.is_authenticated?"text-white":"text-bambu-gray"}`,children:n("backup.cloudProfiles")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("backup.cloudProfilesDescription")})]})]}),i.jsxs("label",{className:"flex items-start gap-2 cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:y,onChange:le=>_(le.target.checked),className:"w-4 h-4 mt-0.5 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),i.jsxs("div",{children:[i.jsx("span",{className:"text-white text-sm",children:n("backup.appSettings")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:n("backup.appSettingsDescription")})]})]})]})]}),i.jsxs("div",{className:"border-t border-bambu-dark-tertiary pt-4 space-y-3",children:[q?.configured&&i.jsxs("div",{className:"flex items-center justify-between text-sm",children:[i.jsx("div",{className:"flex items-center gap-2 text-bambu-gray",children:q.last_backup_at?i.jsxs(i.Fragment,{children:[i.jsxs("span",{children:[n("backup.lastBackupAt")," ",Iv(q.last_backup_at,"system",n)]}),i.jsx(PK,{status:q.last_backup_status})]}):i.jsx("span",{children:n("backup.noBackupsYet")})}),q.next_scheduled_run&&i.jsxs("span",{className:"text-bambu-gray",children:[i.jsx(Xn,{className:"w-3 h-3 inline mr-1"}),n("backup.next")," ",Iv(q.next_scheduled_run,"system",n)]})]}),pe&&i.jsxs("div",{className:`text-sm flex items-center gap-1 ${pe.success?"text-green-400":"text-red-400"}`,children:[pe.success?i.jsx(pr,{className:"w-4 h-4"}):i.jsx(Vi,{className:"w-4 h-4"}),pe.message]}),i.jsx("div",{className:"flex flex-wrap items-center gap-2",children:q?.configured?i.jsx(i.Fragment,{children:ne.isPending||q.is_running?i.jsxs("div",{className:"flex items-center gap-2 text-bambu-green",children:[i.jsx(lt,{className:"w-4 h-4 animate-spin"}),i.jsx("span",{className:"text-sm",children:q.progress||n("backup.startingBackup")})]}):i.jsxs(i.Fragment,{children:[i.jsxs(Oe,{variant:"primary",size:"sm",onClick:()=>ne.mutate(),disabled:!we?.enabled,children:[i.jsx(uo,{className:"w-4 h-4"}),n("backup.backupNow")]}),i.jsxs(Oe,{variant:"secondary",size:"sm",onClick:ue,disabled:ae,children:[ae?i.jsx(lt,{className:"w-4 h-4 animate-spin"}):i.jsx(Sr,{className:"w-4 h-4"}),n("backup.test")]})]})}):i.jsxs(i.Fragment,{children:[i.jsxs(Oe,{variant:"primary",size:"sm",onClick:ge,disabled:J.isPending||!r||!s,children:[J.isPending?i.jsx(lt,{className:"w-4 h-4 animate-spin"}):i.jsx(pr,{className:"w-4 h-4"}),n("backup.enableBackup")]}),i.jsxs(Oe,{variant:"secondary",size:"sm",onClick:ue,disabled:ae||!r||!s,children:[ae?i.jsx(lt,{className:"w-4 h-4 animate-spin"}):i.jsx(Sr,{className:"w-4 h-4"}),n("backup.testConnection")]})]})})]})]}):i.jsxs("div",{className:"flex items-start gap-2 p-3 bg-yellow-500/10 border border-yellow-500/30 rounded-lg",children:[i.jsx(Cn,{className:"w-4 h-4 text-yellow-400 mt-0.5 flex-shrink-0"}),i.jsx("p",{className:"text-sm text-yellow-400",children:n("backup.cloudLoginRequired")})]})})]}),K&&K.length>0&&i.jsxs(Tt,{children:[i.jsx(qn,{children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(Fv,{className:"w-5 h-5 text-gray-400"}),i.jsx("h2",{className:"text-lg font-semibold text-white",children:n("backup.history")})]}),i.jsxs(Oe,{variant:"ghost",size:"sm",onClick:()=>se.mutate(),disabled:se.isPending,children:[i.jsx(Qt,{className:"w-4 h-4"}),n("backup.clear")]})]})}),i.jsx(Pt,{children:i.jsx("div",{className:"overflow-x-auto",children:i.jsxs("table",{className:"w-full text-sm",children:[i.jsx("thead",{children:i.jsxs("tr",{className:"text-bambu-gray border-b border-bambu-dark-tertiary",children:[i.jsx("th",{className:"text-left py-2 px-2",children:n("backup.date")}),i.jsx("th",{className:"text-left py-2 px-2",children:n("backup.status")}),i.jsx("th",{className:"text-left py-2 px-2",children:n("backup.commit")})]})}),i.jsx("tbody",{children:K.slice(0,10).map(le=>i.jsxs("tr",{className:"border-b border-bambu-dark-tertiary/50 hover:bg-bambu-dark-secondary",children:[i.jsx("td",{className:"py-2 px-2 text-white",children:mJe(le.started_at)}),i.jsx("td",{className:"py-2 px-2",children:i.jsx(PK,{status:le.status})}),i.jsx("td",{className:"py-2 px-2",children:le.commit_sha?i.jsxs("a",{href:`${we?.repository_url}/commit/${le.commit_sha}`,target:"_blank",rel:"noopener noreferrer",className:"text-bambu-green hover:underline inline-flex items-center gap-1",children:[le.commit_sha.substring(0,7),i.jsx(ei,{className:"w-3 h-3"})]}):i.jsx("span",{className:"text-bambu-gray",children:"-"})})]},le.id))})]})})})]})]}),i.jsx("div",{className:"space-y-6",children:i.jsxs(Tt,{children:[i.jsx(qn,{children:i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(Uc,{className:"w-5 h-5 text-gray-400"}),i.jsx("h2",{className:"text-lg font-semibold text-white",children:n("backup.localBackup")})]})}),i.jsxs(Pt,{className:"space-y-4",children:[i.jsx("p",{className:"text-sm text-bambu-gray",children:n("backup.localBackupDescription")}),i.jsxs("div",{className:"flex items-center justify-between py-3 border-b border-bambu-dark-tertiary",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-white",children:n("backup.downloadBackupLabel")}),i.jsx("p",{className:"text-sm text-bambu-gray",children:n("backup.completeBackupZip")})]}),i.jsxs(Oe,{variant:"secondary",size:"sm",disabled:T||k,onClick:async()=>{P(!0),R(n("backup.preparingBackup"));try{R(n("backup.creatingArchive"));const{blob:le,filename:I}=await fe.exportBackup();R(n("backup.downloadingFile"));const F=URL.createObjectURL(le),Z=document.createElement("a");Z.href=F,Z.download=I,Z.click(),URL.revokeObjectURL(F),e(n("backup.backupDownloaded"))}catch(le){e(n("backup.failedToCreateBackup",{message:le instanceof Error?le.message:"Unknown error"}),"error")}finally{P(!1),R("")}},children:[i.jsx(hi,{className:"w-4 h-4"}),n("backup.download")]})]}),i.jsxs("div",{className:"flex items-center justify-between py-3 border-b border-bambu-dark-tertiary",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-white",children:n("backup.restoreBackup")}),i.jsx("p",{className:"text-sm text-bambu-gray",children:n("backup.restoreDescription")}),i.jsx("p",{className:"text-xs text-bambu-gray-light mt-1",children:n("backup.restoreNote")})]}),i.jsx("input",{ref:Y,type:"file",accept:".zip",className:"hidden",onChange:le=>{const I=le.target.files?.[0];I&&(O(I),U(!0)),le.target.value=""}}),i.jsxs(Oe,{variant:"secondary",size:"sm",disabled:k||T,onClick:()=>Y.current?.click(),children:[i.jsx(Si,{className:"w-4 h-4"}),n("backup.restore")]})]}),te&&i.jsx("div",{className:`p-3 rounded-lg ${te.success?"bg-green-500/10 border border-green-500/30":"bg-red-500/10 border border-red-500/30"}`,children:i.jsxs("div",{className:"flex items-start gap-2 text-sm",children:[te.success?i.jsx(pr,{className:"w-4 h-4 text-green-400 mt-0.5 flex-shrink-0"}):i.jsx(Vi,{className:"w-4 h-4 text-red-400 mt-0.5 flex-shrink-0"}),i.jsxs("div",{className:te.success?"text-green-200":"text-red-200",children:[te.message,te.success&&i.jsx("div",{className:"mt-2",children:i.jsxs(Oe,{size:"sm",onClick:()=>window.location.reload(),children:[i.jsx(mo,{className:"w-3 h-3"}),n("backup.reloadNow")]})})]})]})}),i.jsx("div",{className:"p-3 rounded-lg bg-yellow-500/10 border border-yellow-500/30",children:i.jsxs("div",{className:"flex items-start gap-2 text-sm",children:[i.jsx(Cn,{className:"w-4 h-4 text-yellow-400 mt-0.5 flex-shrink-0"}),i.jsxs("div",{className:"text-yellow-200",children:[i.jsx("span",{className:"font-medium",children:n("backup.restoreReplacesAll")})," ",i.jsx("span",{className:"text-yellow-200/70",children:n("backup.restoreReplacesAllDetail")})]})]})})]})]})}),$&&W&&i.jsx(_n,{title:n("backup.restoreConfirmTitle"),message:n("backup.restoreConfirmMessage",{filename:W.name}),confirmText:n("backup.restoreConfirmButton"),variant:"danger",onConfirm:async()=>{U(!1),D(!0),ie(null);try{R(n("backup.uploadingFile"));const le=await fe.importBackup(W);ie(le),le.success?e(n("backup.backupRestoredRestart"),"success"):e(le.message,"error")}catch(le){const I=le instanceof Error?le.message:n("backup.failedToRestore");ie({success:!1,message:I}),e(I,"error")}finally{D(!1),R(""),O(null)}},onCancel:()=>{U(!1),O(null)}}),(T||k)&&i.jsx("div",{className:"fixed inset-0 bg-black/80 flex items-center justify-center z-[100]",children:i.jsxs("div",{className:"bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl p-8 max-w-md w-full mx-4 text-center",children:[i.jsx("div",{className:"flex justify-center mb-4",children:i.jsxs("div",{className:"relative",children:[i.jsx("div",{className:"w-16 h-16 border-4 border-bambu-dark-tertiary rounded-full"}),i.jsx("div",{className:"w-16 h-16 border-4 border-bambu-green border-t-transparent rounded-full absolute inset-0 animate-spin"})]})}),i.jsx("h3",{className:"text-xl font-semibold text-white mb-2",children:n(T?"backup.creatingBackup":"backup.restoringBackup")}),i.jsx("p",{className:"text-bambu-gray mb-4",children:A||n(T?"backup.preparing":"backup.processing")}),i.jsx("div",{className:"p-3 rounded-lg bg-yellow-500/10 border border-yellow-500/30",children:i.jsxs("div",{className:"flex items-start gap-2 text-sm",children:[i.jsx(Cn,{className:"w-4 h-4 text-yellow-400 mt-0.5 flex-shrink-0"}),i.jsx("p",{className:"text-yellow-200 text-left",children:n("backup.doNotClosePage")})]})})]})})]})}const pJe={starttls:587,ssl:465,none:25},fJe={587:"starttls",465:"ssl",25:"none"};function gJe(){const{t}=Mt(),{showToast:e}=hn(),n=Zt(),[r,a]=w.useState({smtp_host:"",smtp_port:587,smtp_username:"",smtp_password:"",smtp_security:"starttls",smtp_auth_enabled:!0,smtp_from_email:"",smtp_from_name:"BamBuddy"}),[s,o]=w.useState(""),{data:l,isLoading:c}=Ze({queryKey:["smtpSettings"],queryFn:()=>fe.getSMTPSettings()}),{data:d}=Ze({queryKey:["advancedAuthStatus"],queryFn:()=>fe.getAdvancedAuthStatus()});w.useEffect(()=>{l&&a({...l,smtp_password:""})},[l]);const u=P=>{a({...r,smtp_security:P,smtp_port:pJe[P]})},m=P=>{const k=fJe[P];a({...r,smtp_port:P,...k?{smtp_security:k}:{}})},p=P=>{a({...r,smtp_auth_enabled:P,...P?{}:{smtp_username:"",smtp_password:""}})},f=dt({mutationFn:P=>fe.saveSMTPSettings(P),onSuccess:()=>{n.invalidateQueries({queryKey:["smtpSettings"]}),n.invalidateQueries({queryKey:["advancedAuthStatus"]}),e(t("settings.email.success.settingsSaved"),"success")},onError:P=>{e(P.message,"error")}}),x=dt({mutationFn:P=>fe.testSMTP(P),onSuccess:P=>{e(P.message,P.success?"success":"error")},onError:P=>{e(P.message,"error")}}),v=dt({mutationFn:P=>P?fe.enableAdvancedAuth():fe.disableAdvancedAuth(),onSuccess:P=>{n.invalidateQueries({queryKey:["advancedAuthStatus"]}),e(P.message,"success")},onError:P=>{e(P.message,"error")}}),g=()=>{if(!r.smtp_host||!r.smtp_from_email){e(t("settings.email.errors.requiredFields"),"error");return}if(r.smtp_auth_enabled&&!r.smtp_username){e(t("settings.email.errors.usernameRequired"),"error");return}f.mutate(r)},y=()=>{if(!s){e(t("settings.email.errors.enterTestEmail"),"error");return}if(!r.smtp_host||!r.smtp_from_email){e(t("settings.email.errors.smtpServerAndEmail"),"error");return}if(r.smtp_auth_enabled&&(!r.smtp_username||!r.smtp_password)){e(t("settings.email.errors.usernamePasswordRequired"),"error");return}x.mutate({smtp_host:r.smtp_host,smtp_port:r.smtp_port,smtp_username:r.smtp_username,smtp_password:r.smtp_password,smtp_security:r.smtp_security,smtp_auth_enabled:r.smtp_auth_enabled,smtp_from_email:r.smtp_from_email,test_recipient:s})},_=()=>{if(!d?.advanced_auth_enabled&&!d?.smtp_configured){e(t("settings.email.errors.configureSmtpFirst"),"error");return}v.mutate(!d?.advanced_auth_enabled)};if(c)return i.jsx("div",{className:"flex items-center justify-center p-12",children:i.jsx(lt,{className:"w-8 h-8 animate-spin text-bambu-green"})});const N=d?.advanced_auth_enabled??!1,C="w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors",T="w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white/40 placeholder-bambu-gray/40 cursor-not-allowed";return i.jsxs("div",{className:"space-y-6",children:[i.jsxs(Tt,{children:[i.jsx(qn,{children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(Lv,{className:"w-5 h-5 text-bambu-green"}),i.jsx("h2",{className:"text-lg font-semibold text-white",children:t("settings.email.advancedAuth")||"Advanced Authentication"})]}),i.jsx(Oe,{onClick:_,disabled:v.isPending,variant:N?"danger":"primary",children:N?i.jsxs(i.Fragment,{children:[i.jsx(o1,{className:"w-4 h-4"}),t("settings.email.disable")||"Disable"]}):i.jsxs(i.Fragment,{children:[i.jsx(Jh,{className:"w-4 h-4"}),t("settings.email.enable")||"Enable"]})})]})}),i.jsx(Pt,{children:i.jsx("div",{className:"space-y-4",children:N?i.jsx("div",{className:"bg-green-500/10 border border-green-500/30 rounded-lg p-4",children:i.jsxs("div",{className:"flex items-start gap-3",children:[i.jsx(pr,{className:"w-5 h-5 text-green-400 mt-0.5 flex-shrink-0"}),i.jsxs("div",{className:"space-y-2",children:[i.jsx("p",{className:"text-white font-medium",children:t("settings.email.advancedAuthEnabled")||"Advanced Authentication is enabled"}),i.jsxs("ul",{className:"text-sm text-green-300 space-y-1 list-disc list-inside",children:[i.jsx("li",{children:t("settings.email.feature1")||"Passwords are auto-generated and emailed to new users"}),i.jsx("li",{children:t("settings.email.feature2")||"Users can login with username or email"}),i.jsx("li",{children:t("settings.email.feature3")||"Forgot password feature is available"}),i.jsx("li",{children:t("settings.email.feature4")||"Admins can reset user passwords via email"})]})]})]})}):i.jsx("div",{className:"bg-yellow-500/10 border border-yellow-500/30 rounded-lg p-4",children:i.jsxs("div",{className:"flex items-start gap-3",children:[i.jsx(Cn,{className:"w-5 h-5 text-yellow-400 mt-0.5 flex-shrink-0"}),i.jsxs("div",{className:"space-y-2",children:[i.jsx("p",{className:"text-white font-medium",children:t("settings.email.advancedAuthDisabled")||"Advanced Authentication is disabled"}),i.jsx("p",{className:"text-sm text-yellow-300",children:t("settings.email.advancedAuthDisabledDesc")||"Enable advanced authentication to activate email-based features for user management."})]})]})})})})]}),i.jsx("div",{className:N?"":"opacity-50 pointer-events-none",children:i.jsxs(Tt,{children:[i.jsx(qn,{children:i.jsx("h2",{className:"text-lg font-semibold text-white",children:t("settings.email.smtpSettings")||"SMTP Configuration"})}),i.jsx(Pt,{children:i.jsxs("div",{className:"space-y-4",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:t("settings.email.authentication")||"Authentication"}),i.jsxs("select",{value:r.smtp_auth_enabled?"true":"false",onChange:P=>p(P.target.value==="true"),className:C,children:[i.jsx("option",{value:"true",children:t("settings.email.authOptions.enabled")}),i.jsx("option",{value:"false",children:t("settings.email.authOptions.disabled")})]})]}),i.jsxs("div",{className:`grid grid-cols-1 md:grid-cols-2 gap-4 transition-opacity ${r.smtp_auth_enabled?"":"opacity-40 pointer-events-none"}`,children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:t("settings.email.username")||"Username"}),i.jsx("input",{type:"text",value:r.smtp_username||"",onChange:P=>a({...r,smtp_username:P.target.value}),placeholder:"your.email@gmail.com",disabled:!r.smtp_auth_enabled,className:r.smtp_auth_enabled?C:T})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:t("settings.email.password")||"Password"}),i.jsx("input",{type:"password",value:r.smtp_password||"",onChange:P=>a({...r,smtp_password:P.target.value}),placeholder:l?"••••••••":"App password",disabled:!r.smtp_auth_enabled,className:r.smtp_auth_enabled?C:T})]})]}),i.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm font-medium text-white mb-2",children:[t("settings.email.smtpHost")||"SMTP Server"," *"]}),i.jsx("input",{type:"text",value:r.smtp_host,onChange:P=>a({...r,smtp_host:P.target.value}),placeholder:"smtp.gmail.com",className:C})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:t("settings.email.smtpPort")||"SMTP Port"}),i.jsx("input",{type:"number",value:r.smtp_port,onChange:P=>m(parseInt(P.target.value)||587),placeholder:"587",className:C})]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:t("settings.email.security")||"Security"}),i.jsxs("select",{value:r.smtp_security,onChange:P=>u(P.target.value),className:C,children:[i.jsx("option",{value:"starttls",children:t("settings.email.securityOptions.starttls")}),i.jsx("option",{value:"ssl",children:t("settings.email.securityOptions.ssl")}),i.jsx("option",{value:"none",children:t("settings.email.securityOptions.none")})]})]}),i.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm font-medium text-white mb-2",children:[t("settings.email.fromEmail")||"From Email"," *"]}),i.jsx("input",{type:"email",value:r.smtp_from_email,onChange:P=>a({...r,smtp_from_email:P.target.value}),placeholder:"your@email.com",className:C})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:t("settings.email.fromName")||"From Name"}),i.jsx("input",{type:"text",value:r.smtp_from_name,onChange:P=>a({...r,smtp_from_name:P.target.value}),placeholder:"BamBuddy",className:C})]})]}),i.jsx("div",{className:"flex gap-2",children:i.jsx(Oe,{onClick:g,disabled:f.isPending,className:"flex-1",children:f.isPending?i.jsxs(i.Fragment,{children:[i.jsx(lt,{className:"w-4 h-4 animate-spin"}),t("settings.email.saving")||"Saving..."]}):t("settings.email.save")||"Save Settings"})})]})})]})}),i.jsx("div",{className:N?"":"opacity-50 pointer-events-none",children:i.jsxs(Tt,{children:[i.jsx(qn,{children:i.jsx("h2",{className:"text-lg font-semibold text-white",children:t("settings.email.testConnection")||"Test SMTP Connection"})}),i.jsx(Pt,{children:i.jsxs("div",{className:"space-y-4",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:t("settings.email.testRecipient")||"Test Recipient Email"}),i.jsx("input",{type:"email",value:s,onChange:P=>o(P.target.value),placeholder:"test@example.com",className:C})]}),i.jsx(Oe,{onClick:y,disabled:x.isPending,variant:"secondary",children:x.isPending?i.jsxs(i.Fragment,{children:[i.jsx(lt,{className:"w-4 h-4 animate-spin"}),t("settings.email.sending")||"Sending..."]}):i.jsxs(i.Fragment,{children:[i.jsx(fC,{className:"w-4 h-4"}),t("settings.email.sendTest")||"Send Test Email"]})})]})})]})})]})}const bJe={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 xJe(t,e){const n=e.replace("#/","").split("/");let r=t;for(const a of n)r=r[a];return r}function rv(t,e,n=0){if(n>5)return"...";if(e.$ref)return rv(t,xJe(t,e.$ref),n+1);if(e.allOf){const r={};for(const a of e.allOf){const s=rv(t,a,n+1);typeof s=="object"&&s!==null&&Object.assign(r,s)}return r}if(e.example!==void 0)return e.example;if(e.default!==void 0)return e.default;switch(e.type){case"string":return e.enum?e.enum[0]:"string";case"integer":case"number":return 0;case"boolean":return!1;case"array":return e.items?[rv(t,e.items,n+1)]:[];case"object":if(e.properties){const r={};for(const[a,s]of Object.entries(e.properties))r[a]=rv(t,s,n+1);return r}return{};default:return null}}function yJe({path:t,method:e,spec:n,schema:r,apiKey:a}){const[s,o]=w.useState(!1),[l,c]=w.useState({}),[d,u]=w.useState(""),[m,p]=w.useState(null),[f,x]=w.useState(!1),[v,g]=w.useState(!1);w.useEffect(()=>{if(s&&n.parameters){const D={};for(const A of n.parameters)A.schema?.default!==void 0&&(D[A.name]=String(A.schema.default));c(A=>({...D,...A}))}},[s,n.parameters]),w.useEffect(()=>{if(s&&n.requestBody?.content?.["application/json"]?.schema&&!d){const D=n.requestBody.content["application/json"].schema,A=rv(r,D);u(JSON.stringify(A,null,2))}},[s,n.requestBody,r,d]);const _=(()=>{const D=[];for(const A of n.parameters||[])if(A.in==="path"||A.required){const R=l[A.name];(R===void 0||R==="")&&D.push(A.name)}return D})(),N=async()=>{if(_.length>0){p({status:0,statusText:"Validation Error",headers:{},body:`Missing required parameters: ${_.join(", ")}`,duration:0});return}x(!0),p(null);try{let D=t;const A=new URLSearchParams;for(const pe of n.parameters||[]){const Q=l[pe.name];Q!==void 0&&Q!==""&&(pe.in==="path"?D=D.replace(`{${pe.name}}`,encodeURIComponent(Q)):pe.in==="query"&&A.append(pe.name,Q))}const R=A.toString(),$=`${D}${R?`?${R}`:""}`,U={"Content-Type":"application/json"};a&&(U["X-API-Key"]=a);const W={method:e.toUpperCase(),headers:U};["post","put","patch"].includes(e)&&d&&(W.body=d);const O=performance.now(),te=await fetch($,W),ie=Math.round(performance.now()-O),Y={};te.headers.forEach((pe,Q)=>{Y[Q]=pe});let ae;te.headers.get("content-type")?.includes("application/json")?ae=await te.json():ae=await te.text(),p({status:te.status,statusText:te.statusText,headers:Y,body:ae,duration:ie})}catch(D){p({status:0,statusText:"Network Error",headers:{},body:D instanceof Error?D.message:"Unknown error",duration:0})}finally{x(!1)}},C=async()=>{if(m){const D=typeof m.body=="string"?m.body:JSON.stringify(m.body,null,2);try{await navigator.clipboard.writeText(D),g(!0),setTimeout(()=>g(!1),2e3)}catch{const A=document.createElement("textarea");A.value=D,A.style.position="fixed",A.style.left="-999999px",document.body.appendChild(A),A.select(),document.execCommand("copy"),document.body.removeChild(A),g(!0),setTimeout(()=>g(!1),2e3)}}},T=(n.parameters||[]).filter(D=>D.in==="path"),P=(n.parameters||[]).filter(D=>D.in==="query"),k=["post","put","patch"].includes(e)&&n.requestBody;return i.jsxs("div",{className:"border border-bambu-dark-tertiary rounded-lg overflow-hidden",children:[i.jsxs("button",{onClick:()=>o(!s),className:"w-full flex items-center gap-3 p-3 hover:bg-bambu-dark-tertiary/50 transition-colors text-left",children:[s?i.jsx(jn,{className:"w-4 h-4 text-bambu-gray flex-shrink-0"}):i.jsx(fa,{className:"w-4 h-4 text-bambu-gray flex-shrink-0"}),i.jsx("span",{className:`px-2 py-0.5 text-xs font-mono font-semibold uppercase rounded border ${bJe[e]||"bg-gray-500/20 text-gray-400"}`,children:e}),i.jsx("code",{className:"text-sm text-white font-mono flex-1 truncate",children:t}),n.summary&&i.jsx("span",{className:"text-sm text-bambu-gray truncate max-w-[40%]",children:n.summary})]}),s&&i.jsxs("div",{className:"border-t border-bambu-dark-tertiary p-4 space-y-4 bg-bambu-dark/50",children:[n.description&&i.jsx("p",{className:"text-sm text-bambu-gray",children:n.description}),T.length>0&&i.jsxs("div",{className:"space-y-2",children:[i.jsx("h4",{className:"text-sm font-medium text-white",children:"Path Parameters"}),i.jsx("div",{className:"space-y-2",children:T.map(D=>i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsxs("label",{className:"text-sm text-bambu-gray w-32 flex-shrink-0",children:[D.name,D.required&&i.jsx("span",{className:"text-red-400 ml-1",children:"*"})]}),i.jsx("input",{type:"text",value:l[D.name]||"",onChange:A=>c(R=>({...R,[D.name]:A.target.value})),placeholder:D.description||D.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"})]},D.name))})]}),P.length>0&&i.jsxs("div",{className:"space-y-2",children:[i.jsx("h4",{className:"text-sm font-medium text-white",children:"Query Parameters"}),i.jsx("div",{className:"space-y-2",children:P.map(D=>i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsxs("label",{className:"text-sm text-bambu-gray w-32 flex-shrink-0",children:[D.name,D.required&&i.jsx("span",{className:"text-red-400 ml-1",children:"*"})]}),D.schema?.enum?i.jsxs("select",{value:l[D.name]||"",onChange:A=>c(R=>({...R,[D.name]:A.target.value})),className:"flex-1 px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none",children:[i.jsx("option",{value:"",children:"-- Select --"}),D.schema.enum.map(A=>i.jsx("option",{value:A,children:A},A))]}):i.jsx("input",{type:"text",value:l[D.name]||"",onChange:A=>c(R=>({...R,[D.name]:A.target.value})),placeholder:D.description||D.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"})]},D.name))})]}),k&&i.jsxs("div",{className:"space-y-2",children:[i.jsx("h4",{className:"text-sm font-medium text-white",children:"Request Body"}),i.jsx("textarea",{value:d,onChange:D=>u(D.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..."})]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsxs(Oe,{onClick:N,disabled:f,children:[f?i.jsx(lt,{className:"w-4 h-4 animate-spin"}):i.jsx(uo,{className:"w-4 h-4"}),"Execute"]}),_.length>0&&i.jsxs("span",{className:"text-xs text-yellow-400 flex items-center gap-1",children:[i.jsx(zi,{className:"w-3 h-3"}),"Fill in: ",_.join(", ")]})]}),m&&i.jsxs("div",{className:"space-y-2",children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("h4",{className:"text-sm font-medium text-white flex items-center gap-2",children:["Response",i.jsxs("span",{className:`px-2 py-0.5 text-xs rounded ${m.status>=200&&m.status<300?"bg-green-500/20 text-green-400":m.status>=400?"bg-red-500/20 text-red-400":"bg-yellow-500/20 text-yellow-400"}`,children:[m.status," ",m.statusText]}),i.jsxs("span",{className:"text-xs text-bambu-gray",children:[m.duration,"ms"]})]}),i.jsx(Oe,{variant:"secondary",size:"sm",onClick:C,children:v?i.jsx(pr,{className:"w-3 h-3 text-green-400"}):i.jsx(_l,{className:"w-3 h-3"})})]}),i.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 m.body=="string"?m.body:JSON.stringify(m.body,null,2)})]})]})]})}function vJe({apiKey:t=""}){const[e,n]=w.useState(null),[r,a]=w.useState(!0),[s,o]=w.useState(null),[l,c]=w.useState(new Set),[d,u]=w.useState("");if(w.useEffect(()=>{async function g(){try{const y=await fetch("/openapi.json");if(!y.ok)throw new Error("Failed to fetch OpenAPI schema");const _=await y.json();n(_)}catch(y){o(y instanceof Error?y.message:"Unknown error")}finally{a(!1)}}g()},[]),r)return i.jsx("div",{className:"flex justify-center py-12",children:i.jsx(lt,{className:"w-8 h-8 text-bambu-green animate-spin"})});if(s||!e)return i.jsx(Tt,{children:i.jsx(Pt,{className:"py-8",children:i.jsxs("div",{className:"text-center text-red-400",children:[i.jsx(zi,{className:"w-12 h-12 mx-auto mb-3 opacity-50"}),i.jsx("p",{children:"Failed to load API schema"}),i.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:s})]})})});const m={};for(const[g,y]of Object.entries(e.paths))for(const[_,N]of Object.entries(y)){if(_==="parameters")continue;const C=N.tags||["Other"];for(const T of C)m[T]||(m[T]=[]),m[T].push({path:g,method:_,spec:N})}const p=Object.entries(m).map(([g,y])=>{if(!d)return{tag:g,endpoints:y};const _=y.filter(({path:N,method:C,spec:T})=>{const P=d.toLowerCase();return N.toLowerCase().includes(P)||C.toLowerCase().includes(P)||(T.summary?.toLowerCase()||"").includes(P)||(T.description?.toLowerCase()||"").includes(P)});return{tag:g,endpoints:_}}).filter(({endpoints:g})=>g.length>0).sort((g,y)=>g.tag.localeCompare(y.tag)),f=g=>{c(y=>{const _=new Set(y);return _.has(g)?_.delete(g):_.add(g),_})},x=()=>{c(new Set(p.map(g=>g.tag)))},v=()=>{c(new Set)};return i.jsxs("div",{className:"space-y-4",children:[i.jsxs("div",{className:"flex items-center justify-between gap-4",children:[i.jsx("div",{className:"flex-1",children:i.jsx("input",{type:"text",value:d,onChange:g=>u(g.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"})}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(Oe,{variant:"secondary",size:"sm",onClick:x,children:"Expand All"}),i.jsx(Oe,{variant:"secondary",size:"sm",onClick:v,children:"Collapse All"}),i.jsxs("a",{href:"/docs",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1 text-sm text-bambu-green hover:underline",children:[i.jsx(ei,{className:"w-4 h-4"}),"Swagger UI"]})]})]}),i.jsxs("p",{className:"text-sm text-bambu-gray",children:[p.reduce((g,y)=>g+y.endpoints.length,0)," endpoints in ",p.length," categories"]}),i.jsx("div",{className:"space-y-3",children:p.map(({tag:g,endpoints:y})=>i.jsxs(Tt,{children:[i.jsx("button",{onClick:()=>f(g),className:"w-full flex items-center justify-between p-4 hover:bg-bambu-dark-tertiary/30 transition-colors text-left",children:i.jsxs("div",{className:"flex items-center gap-2",children:[l.has(g)?i.jsx(jn,{className:"w-5 h-5 text-bambu-gray"}):i.jsx(fa,{className:"w-5 h-5 text-bambu-gray"}),i.jsx("h3",{className:"text-base font-semibold text-white capitalize",children:g.replace(/-/g," ")}),i.jsx("span",{className:"text-xs bg-bambu-dark-tertiary px-2 py-0.5 rounded-full text-bambu-gray",children:y.length})]})}),l.has(g)&&i.jsx(Pt,{className:"pt-0 space-y-2",children:y.map(({path:_,method:N,spec:C})=>i.jsx(yJe,{path:_,method:N,spec:C,schema:e,apiKey:t},`${N}-${_}`))})]},g))})]})}const wJe=["general","network","plugs","notifications","filament","apikeys","virtual-printer","users","backup"],SJe={database:"bg-blue-600",library_files:"bg-green-500",library_thumbnails:"bg-teal-500",library_other:"bg-emerald-700",archive_timelapses:"bg-red-500",archive_thumbnails:"bg-amber-500",archive_files:"bg-sky-500",virtual_printer_uploads:"bg-purple-500",virtual_printer_upload_cache:"bg-fuchsia-500",virtual_printer_certs:"bg-violet-500",virtual_printer_other:"bg-purple-700",downloads:"bg-cyan-500",plate_calibration:"bg-lime-500",logs:"bg-orange-500",other_data:"bg-yellow-500"},AK=["bg-blue-500","bg-green-500","bg-yellow-500","bg-red-500","bg-orange-500","bg-teal-500","bg-cyan-500","bg-purple-500"],MK=(t,e)=>SJe[t]||AK[e%AK.length];function _Je(){const t=Zt(),e=jl(),[n,r]=OF(),{t:a,i18n:s}=Mt(),{showToast:o}=hn(),{authEnabled:l,user:c,refreshAuth:d}=Dr(),{mode:u,darkStyle:m,darkBackground:p,darkAccent:f,lightStyle:x,lightBackground:v,lightAccent:g,setDarkStyle:y,setDarkBackground:_,setDarkAccent:N,setLightStyle:C,setLightBackground:T,setLightAccent:P}=bf(),[k,D]=w.useState(null),[A,R]=w.useState(!1),[$,U]=w.useState(null),[W,O]=w.useState(!1),[te,ie]=w.useState(null),[Y,ae]=w.useState(null),[de,pe]=w.useState(!1),[Q,oe]=w.useState(dX()),me=n.get("tab"),we=me==="email",Ee=we?"users":me&&wJe.includes(me)?me:"general",[q,K]=w.useState(Ee),[E,j]=w.useState(we?"email":"users"),L=Se=>{K(Se),Se==="users"&&j("users"),Se==="general"?n.delete("tab"):n.set("tab",Se),r(n,{replace:!0})},[G,B]=w.useState(!1),[re,z]=w.useState(""),[V,ee]=w.useState({can_queue:!0,can_control_printer:!1,can_read_status:!0}),[J,ne]=w.useState(null),[se,ue]=w.useState(null),[ge,le]=w.useState(""),[I,F]=w.useState(!1),[Z,xe]=w.useState(!1),[he,ce]=w.useState(null),[Ae,_e]=w.useState(!1),[Ue,$e]=w.useState(!1),[Fe,ke]=w.useState(!1),[Me,Ne]=w.useState({currentPassword:"",newPassword:"",confirmPassword:""}),[Pe,We]=w.useState(!1),[be,He]=w.useState(!1),[Ce,Ve]=w.useState(!1),[je,Re]=w.useState(!1),[ve,Ge]=w.useState(null),[rt,vt]=w.useState(null),[_t,kt]=w.useState(null),[qe,ht]=w.useState(!1),[ft,Bt]=w.useState({username:"",password:"",email:"",confirmPassword:"",role:"user",group_ids:[]}),[tn,sn]=w.useState(null),[Sn,on]=w.useState(null),[xn,Rn]=w.useState(!1),[Qn,Fn]=w.useState({}),[Be,De]=w.useState({}),Je=Se=>{oe(Se),ybe(Se),o(a("settings.toast.settingsSaved"),"success")},tt=()=>{localStorage.removeItem("sidebarOrder"),window.location.reload()},{data:Ye,isLoading:Rt}=Ze({queryKey:["settings"],queryFn:fe.getSettings}),{data:Te,isLoading:Ke,isFetching:et}=Ze({queryKey:["storage-usage"],queryFn:()=>fe.getStorageUsage(),enabled:q==="general",staleTime:1/0,refetchInterval:!1,refetchOnWindowFocus:!1,refetchOnReconnect:!1}),Qe=async()=>{He(!0);try{const Se=await fe.getStorageUsage({refresh:!0});t.setQueryData(["storage-usage"],Se)}catch(Se){const Dt=Se instanceof Error?Se.message:"Failed to refresh storage usage";o(Dt,"error")}finally{He(!1)}},{data:Ie,isLoading:ut}=Ze({queryKey:["smart-plugs"],queryFn:fe.getSmartPlugs}),{data:ot,isLoading:nt}=Ze({queryKey:["smart-plugs-energy",Ie?.map(Se=>Se.id)],queryFn:async()=>{if(!Ie||Ie.length===0)return null;const Se=await Promise.all(Ie.filter(Xi=>Xi.enabled).map(async Xi=>{try{const Wn=await fe.getSmartPlugStatus(Xi.id);return{plug:Xi,status:Wn}}catch{return{plug:Xi,status:null}}}));let Dt=0,sr=0,hr=0,Ti=0,Ua=0;for(const{plug:Xi,status:Wn}of Se){const Cs=Xi.plug_type==="mqtt"&&Wn?.energy?.power!=null;(Wn?.reachable||Cs)&&Wn?.energy&&(Ua++,Wn.energy?.power!=null&&(Dt+=Wn.energy.power),Wn.energy?.today!=null&&(sr+=Wn.energy.today),Wn.energy?.yesterday!=null&&(hr+=Wn.energy.yesterday),Wn.energy?.total!=null&&(Ti+=Wn.energy.total))}return{totalPower:Dt,totalToday:sr,totalYesterday:hr,totalLifetime:Ti,reachableCount:Ua,totalPlugs:Ie.filter(Xi=>Xi.enabled).length}},enabled:q==="plugs"&&!!Ie&&Ie.length>0,refetchInterval:q==="plugs"?1e4:!1}),{data:St,isLoading:Lt}=Ze({queryKey:["notification-providers"],queryFn:fe.getNotificationProviders}),{data:jt,isLoading:Ft}=Ze({queryKey:["api-keys"],queryFn:fe.getAPIKeys}),cn=dt({mutationFn:Se=>fe.createAPIKey(Se),onSuccess:Se=>{ne(Se.key||null),B(!1),z(""),t.invalidateQueries({queryKey:["api-keys"]}),o(a("settings.toast.apiKeyCreated"))},onError:Se=>{o(`Failed to create API key: ${Se.message}`,"error")}}),Jt=dt({mutationFn:Se=>fe.deleteAPIKey(Se),onSuccess:()=>{t.invalidateQueries({queryKey:["api-keys"]}),o(a("settings.toast.apiKeyDeleted"))},onError:Se=>{o(`Failed to delete API key: ${Se.message}`,"error")}}),{data:fn}=Ze({queryKey:["printers"],queryFn:fe.getPrinters}),{data:Pn,isLoading:In}=Ze({queryKey:["notification-templates"],queryFn:fe.getNotificationTemplates}),{data:Xt}=Ze({queryKey:["virtual-printer-settings"],queryFn:Xge.getSettings,refetchInterval:1e4}),vn=Xt?.status?.running??!1,{data:yn}=Ze({queryKey:["ffmpeg-status"],queryFn:fe.checkFfmpeg}),{data:yr}=Ze({queryKey:["version"],queryFn:fe.getVersion}),{data:gn,refetch:ar,isRefetching:li}=Ze({queryKey:["updateCheck"],queryFn:fe.checkForUpdates,enabled:Ye?.check_updates!==!1,staleTime:300*1e3}),{data:Dn,refetch:fi}=Ze({queryKey:["updateStatus"],queryFn:fe.getUpdateStatus,refetchInterval:Se=>{const Dt=Se.state.data;return Dt?.status==="downloading"||Dt?.status==="installing"?1e3:!1}}),{data:Zn}=Ze({queryKey:["mqtt-status"],queryFn:fe.getMQTTStatus,refetchInterval:q==="network"?5e3:!1}),{data:gi}=Ze({queryKey:["github-backup-status"],queryFn:fe.getGitHubBackupStatus}),{data:ni}=Ze({queryKey:["cloud-status"],queryFn:fe.getCloudStatus}),{data:Rr={advanced_auth_enabled:!1,smtp_configured:!1}}=Ze({queryKey:["advancedAuthStatus"],queryFn:()=>fe.getAdvancedAuthStatus()}),{hasPermission:bi}=Dr(),{data:_h=[],isLoading:Nf}=Ze({queryKey:["users"],queryFn:()=>fe.getUsers(),enabled:l&&bi("users:read")}),{data:za=[],isLoading:kf}=Ze({queryKey:["groups"],queryFn:()=>fe.getGroups(),enabled:l&&bi("groups:read")}),mc=dt({mutationFn:Se=>fe.createUser(Se),onSuccess:()=>{t.invalidateQueries({queryKey:["users"]}),t.invalidateQueries({queryKey:["groups"]}),Ve(!1),Bt({username:"",password:"",email:"",confirmPassword:"",role:"user",group_ids:[]}),o(a("settings.toast.userCreated"))},onError:Se=>{o(Se.message,"error")}}),hc=dt({mutationFn:({id:Se,data:Dt})=>fe.updateUser(Se,Dt),onSuccess:()=>{t.invalidateQueries({queryKey:["users"]}),t.invalidateQueries({queryKey:["groups"]}),Re(!1),Ge(null),Bt({username:"",password:"",email:"",confirmPassword:"",role:"user",group_ids:[]}),o(a("settings.toast.userUpdated"))},onError:Se=>{o(Se.message,"error")}}),Yi=dt({mutationFn:({id:Se,deleteItems:Dt})=>fe.deleteUser(Se,Dt),onSuccess:()=>{t.invalidateQueries({queryKey:["users"]}),o(a("settings.toast.userDeleted")),vt(null),kt(null)},onError:Se=>{o(Se.message,"error")}}),Ns=dt({mutationFn:Se=>fe.resetUserPassword({user_id:Se}),onSuccess:Se=>{o(Se.message,"success")},onError:Se=>{o(Se.message,"error")}}),ks=async Se=>{vt(Se),ht(!0);try{const Dt=await fe.getUserItemsCount(Se);kt(Dt)}catch{kt({archives:0,queue_items:0,library_files:0})}finally{ht(!1)}},Vs=dt({mutationFn:Se=>fe.deleteGroup(Se),onSuccess:()=>{t.invalidateQueries({queryKey:["groups"]}),o(a("settings.toast.groupDeleted"))},onError:Se=>{o(Se.message,"error")}}),Rl=()=>{const Se=Rr?.advanced_auth_enabled||!1;if(!ft.username){o(a("settings.toast.fillRequiredFields"),"error");return}if(Se&&!ft.email){o("Email is required when advanced authentication is enabled","error");return}if(!Se){if(!ft.password){o(a("settings.toast.fillRequiredFields"),"error");return}if(ft.password!==ft.confirmPassword){o(a("settings.toast.passwordsDoNotMatch"),"error");return}if(ft.password.length<6){o(a("settings.toast.passwordTooShort"),"error");return}}mc.mutate({username:ft.username,password:Se?void 0:ft.password,email:ft.email||void 0,role:ft.role,group_ids:ft.group_ids.length>0?ft.group_ids:void 0})},Cf=Se=>{if(ft.password){if(ft.password!==ft.confirmPassword){o(a("settings.toast.passwordsDoNotMatch"),"error");return}if(ft.password.length<6){o(a("settings.toast.passwordTooShort"),"error");return}}const Dt={username:ft.username||void 0,password:ft.password||void 0,role:ft.role,group_ids:ft.group_ids};Dt.password||delete Dt.password,hc.mutate({id:Se,data:Dt})},Nh=Se=>{Ge(Se.id),Bt({username:Se.username,password:"",email:Se.email||"",confirmPassword:"",role:Se.role,group_ids:Se.groups?.map(Dt=>Dt.id)||[]}),Re(!0)},pc=Se=>{Bt(Dt=>({...Dt,group_ids:Dt.group_ids.includes(Se)?Dt.group_ids.filter(sr=>sr!==Se):[...Dt.group_ids,Se]}))},Fl=dt({mutationFn:fe.applyUpdate,onSuccess:Se=>{Se.is_docker?o(Se.message,"error"):fi()}}),[ka,ad]=w.useState(null),Ll=dt({mutationFn:fe.testAllNotificationProviders,onSuccess:Se=>{ad(Se),t.invalidateQueries({queryKey:["notification-providers"]}),Se.failed===0?o(`All ${Se.tested} providers tested successfully!`,"success"):o(`${Se.success}/${Se.tested} providers succeeded`,Se.failed>0?"error":"success")},onError:Se=>{o(`Failed to test providers: ${Se.message}`,"error")}}),bt=dt({mutationFn:async Se=>{if(!Ie)return{success:0,failed:0};const Dt=Ie.filter(hr=>hr.enabled),sr=await Promise.all(Dt.map(async hr=>{try{return await fe.controlSmartPlug(hr.id,Se),{success:!0}}catch{return{success:!1}}}));return{success:sr.filter(hr=>hr.success).length,failed:sr.filter(hr=>!hr.success).length}},onSuccess:(Se,Dt)=>{t.invalidateQueries({queryKey:["smart-plugs"]}),t.invalidateQueries({queryKey:["smart-plugs-energy"]}),Se.failed===0?o(`All ${Se.success} plugs turned ${Dt}`,"success"):o(`${Se.success} plugs turned ${Dt}, ${Se.failed} failed`,"error")},onError:Se=>{o(`Failed: ${Se.message}`,"error")}}),It=w.useRef(null),nn=w.useRef(!1),Nt=w.useRef(!0);w.useEffect(()=>{if(Ye&&!k){const Se={...Ye,external_url:Ye.external_url||window.location.origin};D(Se),setTimeout(()=>{Nt.current=!1},100)}},[Ye,k]);const wn=dt({mutationFn:fe.updateSettings,onSuccess:Se=>{t.setQueryData(["settings"],Se),t.invalidateQueries({queryKey:["archiveStats"]}),o(a("settings.toast.settingsSaved"),"success")},onError:Se=>{o(`Failed to save: ${Se.message}`,"error")},onSettled:()=>{nn.current=!1}}),Nr=dt({mutationFn:({id:Se,data:Dt})=>fe.updatePrinter(Se,Dt),onSuccess:()=>{t.invalidateQueries({queryKey:["printers"]}),o(a("settings.toast.cameraSettingsSaved"),"success")},onError:Se=>{o(`Failed to update printer: ${Se.message}`,"error")}});w.useEffect(()=>{if(!(Nt.current||!k||!Ye||!(Ye.auto_archive!==k.auto_archive||Ye.save_thumbnails!==k.save_thumbnails||Ye.capture_finish_photo!==k.capture_finish_photo||Ye.default_filament_cost!==k.default_filament_cost||Ye.currency!==k.currency||Ye.energy_cost_per_kwh!==k.energy_cost_per_kwh||Ye.energy_tracking_mode!==k.energy_tracking_mode||Ye.check_updates!==k.check_updates||(Ye.check_printer_firmware??!0)!==(k.check_printer_firmware??!0)||(Ye.include_beta_updates??!1)!==(k.include_beta_updates??!1)||Ye.notification_language!==k.notification_language||(Ye.bed_cooled_threshold??35)!==(k.bed_cooled_threshold??35)||Ye.ams_humidity_good!==k.ams_humidity_good||Ye.ams_humidity_fair!==k.ams_humidity_fair||Ye.ams_temp_good!==k.ams_temp_good||Ye.ams_temp_fair!==k.ams_temp_fair||Ye.ams_history_retention_days!==k.ams_history_retention_days||Ye.per_printer_mapping_expanded!==k.per_printer_mapping_expanded||Ye.date_format!==k.date_format||Ye.time_format!==k.time_format||Ye.default_printer_id!==k.default_printer_id||Ye.ftp_retry_enabled!==k.ftp_retry_enabled||Ye.ftp_retry_count!==k.ftp_retry_count||Ye.ftp_retry_delay!==k.ftp_retry_delay||Ye.ftp_timeout!==k.ftp_timeout||Ye.mqtt_enabled!==k.mqtt_enabled||Ye.mqtt_broker!==k.mqtt_broker||Ye.mqtt_port!==k.mqtt_port||Ye.mqtt_username!==k.mqtt_username||Ye.mqtt_password!==k.mqtt_password||Ye.mqtt_topic_prefix!==k.mqtt_topic_prefix||Ye.mqtt_use_tls!==k.mqtt_use_tls||Ye.external_url!==k.external_url||Ye.ha_enabled!==k.ha_enabled||Ye.ha_url!==k.ha_url||Ye.ha_token!==k.ha_token||(Ye.library_archive_mode??"ask")!==(k.library_archive_mode??"ask")||Number(Ye.library_disk_warning_gb??5)!==Number(k.library_disk_warning_gb??5)||(Ye.camera_view_mode??"window")!==(k.camera_view_mode??"window")||(Ye.preferred_slicer??"bambu_studio")!==(k.preferred_slicer??"bambu_studio")||Ye.prometheus_enabled!==k.prometheus_enabled||Ye.prometheus_token!==k.prometheus_token))&&!nn.current)return It.current&&clearTimeout(It.current),It.current=setTimeout(()=>{if(nn.current)return;nn.current=!0;const Dt={auto_archive:k.auto_archive,save_thumbnails:k.save_thumbnails,capture_finish_photo:k.capture_finish_photo,default_filament_cost:k.default_filament_cost,currency:k.currency,energy_cost_per_kwh:k.energy_cost_per_kwh,energy_tracking_mode:k.energy_tracking_mode,check_updates:k.check_updates,check_printer_firmware:k.check_printer_firmware,include_beta_updates:k.include_beta_updates,notification_language:k.notification_language,bed_cooled_threshold:k.bed_cooled_threshold,ams_humidity_good:k.ams_humidity_good,ams_humidity_fair:k.ams_humidity_fair,ams_temp_good:k.ams_temp_good,ams_temp_fair:k.ams_temp_fair,ams_history_retention_days:k.ams_history_retention_days,per_printer_mapping_expanded:k.per_printer_mapping_expanded,date_format:k.date_format,time_format:k.time_format,default_printer_id:k.default_printer_id,ftp_retry_enabled:k.ftp_retry_enabled,ftp_retry_count:k.ftp_retry_count,ftp_retry_delay:k.ftp_retry_delay,ftp_timeout:k.ftp_timeout,mqtt_enabled:k.mqtt_enabled,mqtt_broker:k.mqtt_broker,mqtt_port:k.mqtt_port,mqtt_username:k.mqtt_username,mqtt_password:k.mqtt_password,mqtt_topic_prefix:k.mqtt_topic_prefix,mqtt_use_tls:k.mqtt_use_tls,external_url:k.external_url,ha_enabled:k.ha_enabled,ha_url:k.ha_url,ha_token:k.ha_token,library_archive_mode:k.library_archive_mode,library_disk_warning_gb:k.library_disk_warning_gb,camera_view_mode:k.camera_view_mode,preferred_slicer:k.preferred_slicer,prometheus_enabled:k.prometheus_enabled,prometheus_token:k.prometheus_token};wn.mutate(Dt)},500),()=>{It.current&&clearTimeout(It.current)}},[k,Ye,wn]);const $t=w.useCallback((Se,Dt)=>{D(sr=>sr?{...sr,[Se]:Dt}:null)},[]),vr=async(Se,Dt,sr)=>{if(!Dt){o(a("settings.toast.enterCameraUrl"),"error");return}De(hr=>({...hr,[Se]:!0})),Fn(hr=>({...hr,[Se]:null}));try{const hr=await fe.testExternalCamera(Se,Dt,sr);Fn(Ti=>({...Ti,[Se]:hr})),hr.success?o(a("settings.toast.cameraConnected",{resolution:hr.resolution||""}),"success"):o(hr.error||a("settings.toast.connectionFailed"),"error")}catch(hr){const Ti=hr instanceof Error?hr.message:a("settings.toast.testFailed");Fn(Ua=>({...Ua,[Se]:{success:!1,error:Ti}})),o(Ti,"error")}finally{De(hr=>({...hr,[Se]:!1}))}},[xi,rn]=w.useState({}),Ln=w.useRef({}),Ho=w.useRef(new Set);w.useEffect(()=>{if(fn){const Se={};fn.forEach(Dt=>{Dt.external_camera_url&&!Ho.current.has(Dt.id)&&(Se[Dt.id]=Dt.external_camera_url,Ho.current.add(Dt.id))}),Object.keys(Se).length>0&&rn(Dt=>({...Dt,...Se}))}},[fn]);const Gs=(Se,Dt)=>{rn(sr=>({...sr,[Se]:Dt})),Ln.current[Se]&&clearTimeout(Ln.current[Se]),Ln.current[Se]=setTimeout(()=>{Nr.mutate({id:Se,data:{external_camera_url:Dt||null}})},800)},bo=(Se,Dt)=>{const sr={};Dt.type!==void 0&&(sr.external_camera_type=Dt.type||null),Dt.enabled!==void 0&&(sr.external_camera_enabled=Dt.enabled),Nr.mutate({id:Se,data:sr})};return Rt||!k?i.jsx("div",{className:"p-4 md:p-8 flex justify-center",children:i.jsx(lt,{className:"w-8 h-8 text-bambu-green animate-spin"})}):i.jsxs("div",{className:"p-4 md:p-8",children:[i.jsxs("div",{className:"mb-8",children:[i.jsx("h1",{className:"text-2xl font-bold text-white",children:a("settings.title")}),i.jsx("p",{className:"text-bambu-gray",children:a("settings.configureBambuddy")})]}),i.jsxs("div",{className:"flex flex-wrap gap-1 mb-6 border-b border-bambu-dark-tertiary",children:[i.jsx("button",{onClick:()=>L("general"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px ${q==="general"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:a("settings.tabs.general")}),i.jsxs("button",{onClick:()=>L("plugs"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${q==="plugs"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[i.jsx(bl,{className:"w-4 h-4"}),a("settings.tabs.smartPlugs"),Ie&&Ie.length>0&&i.jsx("span",{className:"text-xs bg-bambu-dark-tertiary px-1.5 py-0.5 rounded-full",children:Ie.length})]}),i.jsxs("button",{onClick:()=>L("notifications"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${q==="notifications"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[i.jsx(db,{className:"w-4 h-4"}),a("settings.tabs.notifications"),St&&St.length>0&&i.jsx("span",{className:"text-xs bg-bambu-dark-tertiary px-1.5 py-0.5 rounded-full",children:St.length})]}),i.jsxs("button",{onClick:()=>L("filament"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${q==="filament"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[i.jsx(Dhe,{className:"w-4 h-4"}),a("settings.tabs.filament")]}),i.jsxs("button",{onClick:()=>L("network"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${q==="network"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[i.jsx(mb,{className:"w-4 h-4"}),a("settings.tabs.network"),i.jsx("span",{className:`w-2 h-2 rounded-full ${Zn?.enabled?"bg-green-400":"bg-gray-500"}`})]}),i.jsxs("button",{onClick:()=>L("apikeys"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${q==="apikeys"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[i.jsx(sl,{className:"w-4 h-4"}),a("settings.tabs.apiKeys"),jt&&jt.length>0&&i.jsx("span",{className:"text-xs bg-bambu-dark-tertiary px-1.5 py-0.5 rounded-full",children:jt.length})]}),i.jsxs("button",{onClick:()=>L("virtual-printer"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${q==="virtual-printer"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[i.jsx(_r,{className:"w-4 h-4"}),a("settings.tabs.virtualPrinter"),i.jsx("span",{className:`w-2 h-2 rounded-full ${vn?"bg-green-400":"bg-gray-500"}`})]}),i.jsxs("button",{onClick:()=>L("users"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${q==="users"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[i.jsx(Sm,{className:"w-4 h-4"}),a("settings.tabs.users"),l&&i.jsx("span",{className:"w-2 h-2 rounded-full bg-green-400"})]}),i.jsxs("button",{onClick:()=>L("backup"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${q==="backup"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[i.jsx(Uc,{className:"w-4 h-4"}),a("settings.tabs.backup"),i.jsx("span",{className:`w-2 h-2 rounded-full ${ni?.is_authenticated&&gi?.configured&&gi?.enabled?"bg-green-400":"bg-gray-500"}`})]})]}),q==="general"&&i.jsxs("div",{className:"flex flex-col lg:flex-row gap-6 lg:gap-8",children:[i.jsxs("div",{className:"space-y-6 flex-1 lg:max-w-xl",children:[i.jsxs(Tt,{children:[i.jsx(qn,{children:i.jsx("h2",{className:"text-lg font-semibold text-white",children:a("settings.general")})}),i.jsxs(Pt,{className:"space-y-4",children:[i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[i.jsx($m,{className:"w-4 h-4 inline mr-1"}),a("settings.language")]}),i.jsxs("div",{className:"relative",children:[i.jsx("select",{value:s.language,onChange:Se=>{s.changeLanguage(Se.target.value),fe.updateSettings({language:Se.target.value}),o(a("settings.toast.settingsSaved"),"success")},className:"w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer",children:OB.map(Se=>i.jsxs("option",{value:Se.code,children:[Se.nativeName," (",Se.name,")"]},Se.code))}),i.jsx(jn,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:a("settings.languageDescription")})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:a("settings.defaultView")}),i.jsxs("div",{className:"relative",children:[i.jsx("select",{value:Q,onChange:Se=>Je(Se.target.value),className:"w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer",children:zv.map(Se=>i.jsx("option",{value:Se.to,children:a(Se.labelKey)},Se.id))}),i.jsx(jn,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:a("settings.defaultViewDescription")})]}),i.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:a("settings.dateFormat")}),i.jsxs("div",{className:"relative",children:[i.jsxs("select",{value:k.date_format||"system",onChange:Se=>$t("date_format",Se.target.value),className:"w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer",children:[i.jsx("option",{value:"system",children:a("settings.systemDefault")}),i.jsx("option",{value:"us",children:a("settings.dateFormatUs")}),i.jsx("option",{value:"eu",children:a("settings.dateFormatEu")}),i.jsx("option",{value:"iso",children:a("settings.dateFormatIso")})]}),i.jsx(jn,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:a("settings.timeFormat")}),i.jsxs("div",{className:"relative",children:[i.jsxs("select",{value:k.time_format||"system",onChange:Se=>$t("time_format",Se.target.value),className:"w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer",children:[i.jsx("option",{value:"system",children:a("settings.systemDefault")}),i.jsx("option",{value:"12h",children:a("settings.timeFormat12")}),i.jsx("option",{value:"24h",children:a("settings.timeFormat24")})]}),i.jsx(jn,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]})]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:a("settings.defaultPrinter")}),i.jsxs("div",{className:"relative",children:[i.jsxs("select",{value:k.default_printer_id??"",onChange:Se=>$t("default_printer_id",Se.target.value?Number(Se.target.value):null),className:"w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer",children:[i.jsx("option",{value:"",children:a("settings.noDefaultPrinter")}),fn?.map(Se=>i.jsx("option",{value:Se.id,children:Se.name},Se.id))]}),i.jsx(jn,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:a("settings.defaultPrinterDescription")})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:a("settings.preferredSlicer")}),i.jsxs("div",{className:"relative",children:[i.jsxs("select",{value:k.preferred_slicer??"bambu_studio",onChange:Se=>$t("preferred_slicer",Se.target.value),className:"w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer",children:[i.jsx("option",{value:"bambu_studio",children:a("settings.slicerBambuStudio")}),i.jsx("option",{value:"orcaslicer",children:a("settings.slicerOrcaSlicer")})]}),i.jsx(jn,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:a("settings.preferredSlicerDescription")})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-white",children:a("settings.sidebarOrder")}),i.jsx("p",{className:"text-sm text-bambu-gray",children:a("settings.sidebarOrderDescription")})]}),i.jsxs(Oe,{variant:"secondary",size:"sm",onClick:tt,children:[i.jsx(mo,{className:"w-4 h-4"}),a("settings.reset")]})]})]})]}),i.jsxs(Tt,{children:[i.jsx(qn,{children:i.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(mC,{className:"w-5 h-5"}),a("settings.appearance")]})}),i.jsxs(Pt,{className:"space-y-6",children:[i.jsxs("div",{className:`space-y-3 p-4 rounded-lg border ${u==="dark"?"border-bambu-green bg-bambu-green/5":"border-bambu-dark-tertiary"}`,children:[i.jsxs("h3",{className:"text-sm font-medium text-white flex items-center gap-2",children:[a("settings.darkMode"),u==="dark"&&i.jsx("span",{className:"text-xs text-bambu-green",children:a("settings.active")})]}),i.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:a("settings.background")}),i.jsxs("select",{value:p,onChange:Se=>{_(Se.target.value),o(a("settings.toast.settingsSaved"),"success")},className:"w-full px-2 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[i.jsx("option",{value:"neutral",children:a("settings.bgNeutral")}),i.jsx("option",{value:"warm",children:a("settings.bgWarm")}),i.jsx("option",{value:"cool",children:a("settings.bgCool")}),i.jsx("option",{value:"oled",children:a("settings.bgOled")}),i.jsx("option",{value:"slate",children:a("settings.bgSlate")}),i.jsx("option",{value:"forest",children:a("settings.bgForest")})]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:a("settings.accent")}),i.jsxs("select",{value:f,onChange:Se=>{N(Se.target.value),o(a("settings.toast.settingsSaved"),"success")},className:"w-full px-2 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[i.jsx("option",{value:"green",children:a("settings.accentGreen")}),i.jsx("option",{value:"teal",children:a("settings.accentTeal")}),i.jsx("option",{value:"blue",children:a("settings.accentBlue")}),i.jsx("option",{value:"orange",children:a("settings.accentOrange")}),i.jsx("option",{value:"purple",children:a("settings.accentPurple")}),i.jsx("option",{value:"red",children:a("settings.accentRed")})]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:a("settings.style")}),i.jsxs("select",{value:m,onChange:Se=>{y(Se.target.value),o(a("settings.toast.settingsSaved"),"success")},className:"w-full px-2 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[i.jsx("option",{value:"classic",children:a("settings.styleClassic")}),i.jsx("option",{value:"glow",children:a("settings.styleGlow")}),i.jsx("option",{value:"vibrant",children:a("settings.styleVibrant")})]})]})]})]}),i.jsxs("div",{className:`space-y-3 p-4 rounded-lg border ${u==="light"?"border-bambu-green bg-bambu-green/5":"border-bambu-dark-tertiary"}`,children:[i.jsxs("h3",{className:"text-sm font-medium text-white flex items-center gap-2",children:[a("settings.lightMode"),u==="light"&&i.jsx("span",{className:"text-xs text-bambu-green",children:a("settings.active")})]}),i.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:a("settings.background")}),i.jsxs("select",{value:v,onChange:Se=>{T(Se.target.value),o(a("settings.toast.settingsSaved"),"success")},className:"w-full px-2 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[i.jsx("option",{value:"neutral",children:a("settings.bgNeutral")}),i.jsx("option",{value:"warm",children:a("settings.bgWarm")}),i.jsx("option",{value:"cool",children:a("settings.bgCool")})]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:a("settings.accent")}),i.jsxs("select",{value:g,onChange:Se=>{P(Se.target.value),o(a("settings.toast.settingsSaved"),"success")},className:"w-full px-2 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[i.jsx("option",{value:"green",children:a("settings.accentGreen")}),i.jsx("option",{value:"teal",children:a("settings.accentTeal")}),i.jsx("option",{value:"blue",children:a("settings.accentBlue")}),i.jsx("option",{value:"orange",children:a("settings.accentOrange")}),i.jsx("option",{value:"purple",children:a("settings.accentPurple")}),i.jsx("option",{value:"red",children:a("settings.accentRed")})]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:a("settings.style")}),i.jsxs("select",{value:x,onChange:Se=>{C(Se.target.value),o(a("settings.toast.settingsSaved"),"success")},className:"w-full px-2 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[i.jsx("option",{value:"classic",children:a("settings.styleClassic")}),i.jsx("option",{value:"glow",children:a("settings.styleGlow")}),i.jsx("option",{value:"vibrant",children:a("settings.styleVibrant")})]})]})]})]}),i.jsx("p",{className:"text-xs text-bambu-gray",children:a("settings.themeToggleHint")})]})]}),i.jsxs(Tt,{children:[i.jsx(qn,{children:i.jsx("h2",{className:"text-lg font-semibold text-white",children:a("settings.archiveSettings")})}),i.jsxs(Pt,{className:"space-y-4",children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-white",children:a("settings.autoArchivePrints")}),i.jsx("p",{className:"text-sm text-bambu-gray",children:a("settings.autoArchiveDescription")})]}),i.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:k.auto_archive,onChange:Se=>$t("auto_archive",Se.target.checked),className:"sr-only peer"}),i.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-white",children:a("settings.saveThumbnails")}),i.jsx("p",{className:"text-sm text-bambu-gray",children:a("settings.saveThumbnailsDescription")})]}),i.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:k.save_thumbnails,onChange:Se=>$t("save_thumbnails",Se.target.checked),className:"sr-only peer"}),i.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-white",children:a("settings.captureFinishPhoto")}),i.jsx("p",{className:"text-sm text-bambu-gray",children:a("settings.captureFinishPhotoDescription")})]}),i.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:k.capture_finish_photo,onChange:Se=>$t("capture_finish_photo",Se.target.checked),className:"sr-only peer"}),i.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"})]})]}),k.capture_finish_photo&&yn&&!yn.installed&&i.jsxs("div",{className:"flex items-start gap-2 p-3 bg-yellow-500/10 border border-yellow-500/30 rounded-lg",children:[i.jsx(Cn,{className:"w-5 h-5 text-yellow-500 flex-shrink-0 mt-0.5"}),i.jsxs("div",{className:"text-sm",children:[i.jsx("p",{className:"text-yellow-500 font-medium",children:a("settings.ffmpegNotInstalled")}),i.jsx("p",{className:"text-bambu-gray mt-1",children:a("settings.ffmpegRequired")})]})]})]})]})]}),i.jsxs("div",{className:"space-y-6 flex-1 lg:max-w-md",children:[i.jsxs(Tt,{children:[i.jsx(qn,{children:i.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(ZF,{className:"w-5 h-5 text-bambu-green"}),a("settings.camera")]})}),i.jsxs(Pt,{className:"space-y-4",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:a("settings.cameraViewMode")}),i.jsxs("select",{value:k.camera_view_mode??"window",onChange:Se=>$t("camera_view_mode",Se.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:[i.jsx("option",{value:"window",children:a("settings.newWindow")}),i.jsx("option",{value:"embedded",children:a("settings.embeddedOverlay")})]}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:k.camera_view_mode==="embedded"?a("settings.cameraOverlayDescription"):a("settings.cameraWindowDescription")})]}),i.jsxs("div",{className:"border-t border-bambu-dark-tertiary pt-4 mt-4",children:[i.jsx("h3",{className:"text-sm font-medium text-white mb-2",children:a("settings.externalCameras")}),i.jsx("p",{className:"text-xs text-bambu-gray mb-3",children:a("settings.externalCamerasDescription")}),fn&&fn.length>0?i.jsx("div",{className:"space-y-3",children:fn.map(Se=>i.jsxs("div",{className:"p-3 bg-bambu-dark rounded-lg",children:[i.jsxs("div",{className:"flex items-center justify-between mb-2",children:[i.jsx("span",{className:"text-white font-medium text-sm",children:Se.name}),i.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:Se.external_camera_enabled,onChange:Dt=>bo(Se.id,{enabled:Dt.target.checked}),className:"sr-only peer"}),i.jsx("div",{className:"w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green"})]})]}),Se.external_camera_enabled&&i.jsxs("div",{className:"space-y-2 mt-2",children:[i.jsx("input",{type:"text",placeholder:Se.external_camera_type==="usb"?a("settings.cameraPlaceholderUsb"):a("settings.cameraPlaceholderUrl"),value:xi[Se.id]??Se.external_camera_url??"",onChange:Dt=>Gs(Se.id,Dt.target.value),className:"w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none"}),i.jsxs("div",{className:"flex gap-2",children:[i.jsxs("select",{value:Se.external_camera_type||"mjpeg",onChange:Dt=>bo(Se.id,{type:Dt.target.value}),className:"flex-1 px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none",children:[i.jsx("option",{value:"mjpeg",children:a("settings.cameraTypeMjpeg")}),i.jsx("option",{value:"rtsp",children:a("settings.cameraTypeRtsp")}),i.jsx("option",{value:"snapshot",children:a("settings.cameraTypeSnapshot")}),i.jsx("option",{value:"usb",children:a("settings.cameraTypeUsb")})]}),i.jsx(Oe,{size:"sm",variant:"secondary",onClick:()=>vr(Se.id,xi[Se.id]??Se.external_camera_url??"",Se.external_camera_type||"mjpeg"),disabled:Be[Se.id]||!(xi[Se.id]??Se.external_camera_url),children:Be[Se.id]?i.jsx(lt,{className:"w-4 h-4 animate-spin"}):a("settings.test")})]}),Qn[Se.id]&&i.jsx("div",{className:`text-xs flex items-center gap-1 ${Qn[Se.id]?.success?"text-green-500":"text-red-500"}`,children:Qn[Se.id]?.success?i.jsxs(i.Fragment,{children:[i.jsx(pr,{className:"w-3 h-3"}),a("settings.connected"),Qn[Se.id]?.resolution&&` (${Qn[Se.id]?.resolution})`]}):i.jsxs(i.Fragment,{children:[i.jsx(Vi,{className:"w-3 h-3"}),Qn[Se.id]?.error||a("settings.toast.connectionFailed")]})})]})]},Se.id))}):i.jsx("p",{className:"text-xs text-bambu-gray italic",children:a("settings.noPrintersConfigured")})]})]})]}),i.jsxs(Tt,{children:[i.jsx(qn,{children:i.jsx("h2",{className:"text-lg font-semibold text-white",children:a("settings.costTracking")})}),i.jsxs(Pt,{className:"space-y-4",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:a("settings.currency")}),i.jsx("select",{value:k.currency,onChange:Se=>$t("currency",Se.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:W$e.map(Se=>i.jsx("option",{value:Se.code,children:Se.label},Se.code))})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:a("settings.defaultFilamentCost")}),i.jsxs("div",{className:"relative",children:[i.jsx("span",{className:"absolute left-3 top-1/2 -translate-y-1/2 text-bambu-gray text-sm pointer-events-none",children:ol(k.currency)}),i.jsx("input",{type:"number",step:"0.01",min:"0",value:k.default_filament_cost,onChange:Se=>$t("default_filament_cost",parseFloat(Se.target.value)||0),style:{paddingLeft:`${Math.max(2,ol(k.currency).length*.6+1)}rem`},className:"w-full pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:a("settings.electricityCost")}),i.jsxs("div",{className:"relative",children:[i.jsx("span",{className:"absolute left-3 top-1/2 -translate-y-1/2 text-bambu-gray text-sm pointer-events-none",children:ol(k.currency)}),i.jsx("input",{type:"number",step:"0.001",min:"0",value:k.energy_cost_per_kwh,onChange:Se=>$t("energy_cost_per_kwh",parseFloat(Se.target.value)||0),style:{paddingLeft:`${Math.max(2,ol(k.currency).length*.6+1)}rem`},className:"w-full pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:a("settings.energyDisplayMode")}),i.jsxs("select",{value:k.energy_tracking_mode||"total",onChange:Se=>$t("energy_tracking_mode",Se.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:[i.jsx("option",{value:"print",children:a("settings.printsOnly")}),i.jsx("option",{value:"total",children:a("settings.totalConsumption")})]}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:k.energy_tracking_mode==="print"?a("settings.energyModePrintDescription"):a("settings.energyModeTotalDescription")})]})]})]}),i.jsxs(Tt,{children:[i.jsx(qn,{children:i.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(Ds,{className:"w-5 h-5 text-bambu-green"}),a("settings.fileManager")]})}),i.jsxs(Pt,{className:"space-y-4",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:a("settings.createArchiveEntry")}),i.jsxs("select",{value:k.library_archive_mode??"ask",onChange:Se=>$t("library_archive_mode",Se.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:[i.jsx("option",{value:"always",children:a("settings.archiveMode.always")}),i.jsx("option",{value:"never",children:a("settings.archiveMode.never")}),i.jsx("option",{value:"ask",children:a("settings.archiveMode.ask")})]}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:a("settings.createArchiveEntryDescription")})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:a("settings.lowDiskSpaceWarning")}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("input",{type:"number",min:"0.5",max:"100",step:"0.5",value:k.library_disk_warning_gb??5,onChange:Se=>$t("library_disk_warning_gb",parseFloat(Se.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"}),i.jsx("span",{className:"text-bambu-gray",children:"GB"})]}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:a("settings.lowDiskSpaceDescription")})]})]})]})]}),i.jsxs("div",{className:"space-y-6 flex-1 lg:max-w-sm",children:[i.jsx(lJe,{}),i.jsxs(Tt,{children:[i.jsx(qn,{children:i.jsx("h2",{className:"text-lg font-semibold text-white",children:a("settings.updates")})}),i.jsxs(Pt,{className:"space-y-4",children:[i.jsx("p",{className:"text-xs font-medium text-bambu-gray uppercase tracking-wider",children:a("settings.printerFirmware")}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-white",children:a("settings.checkPrinterFirmware")}),i.jsx("p",{className:"text-sm text-bambu-gray",children:a("settings.checkFirmwareDescription")})]}),i.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:k.check_printer_firmware??!0,onChange:Se=>$t("check_printer_firmware",Se.target.checked),className:"sr-only peer"}),i.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]}),i.jsx("div",{className:"border-t border-bambu-dark-tertiary pt-4",children:i.jsx("p",{className:"text-xs font-medium text-bambu-gray uppercase tracking-wider mb-4",children:a("settings.bambuddySoftware")})}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-white",children:a("settings.checkForUpdatesLabel")}),i.jsx("p",{className:"text-sm text-bambu-gray",children:a("settings.autoCheckDescription")})]}),i.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:k.check_updates,onChange:Se=>$t("check_updates",Se.target.checked),className:"sr-only peer"}),i.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]}),i.jsxs("div",{className:`flex items-center justify-between ${k.check_updates?"":"opacity-50"}`,children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-white",children:a("settings.includeBetaUpdates")}),i.jsx("p",{className:"text-sm text-bambu-gray",children:a("settings.includeBetaUpdatesDesc")})]}),i.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:k.include_beta_updates??!1,onChange:Se=>$t("include_beta_updates",Se.target.checked),disabled:!k.check_updates,className:"sr-only peer"}),i.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]}),i.jsxs("div",{children:[i.jsxs("div",{className:"flex items-center justify-between mb-2",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-white",children:a("settings.currentVersion")}),i.jsxs("p",{className:"text-sm text-bambu-gray",children:["v",yr?.version||"..."]})]}),i.jsxs(Oe,{variant:"secondary",size:"sm",onClick:()=>ar(),disabled:li,children:[li?i.jsx(lt,{className:"w-4 h-4 animate-spin"}):i.jsx(Sr,{className:"w-4 h-4"}),a("settings.checkNow")]})]}),gn?.update_available?i.jsxs("div",{className:"mt-4 p-3 bg-bambu-green/10 border border-bambu-green/30 rounded-lg",children:[i.jsxs("div",{className:"flex items-start justify-between",children:[i.jsxs("div",{children:[i.jsxs("p",{className:"text-bambu-green font-medium",children:["Update available: v",gn.latest_version]}),gn.release_name&&gn.release_name!==gn.latest_version&&i.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:gn.release_name})]}),i.jsxs("div",{className:"flex items-center gap-2",children:[gn.release_notes&&i.jsx("button",{onClick:()=>_e(!0),className:"text-bambu-gray hover:text-white transition-colors text-sm underline",children:a("settings.releaseNotes")}),gn.release_url&&i.jsx("a",{href:gn.release_url,target:"_blank",rel:"noopener noreferrer",className:"text-bambu-gray hover:text-white transition-colors",title:a("settings.viewReleaseOnGitHub"),children:i.jsx(ei,{className:"w-4 h-4"})})]})]}),Dn?.status==="downloading"||Dn?.status==="installing"?i.jsxs("div",{className:"mt-3",children:[i.jsxs("div",{className:"flex items-center gap-2 text-sm text-bambu-gray",children:[i.jsx(lt,{className:"w-4 h-4 animate-spin"}),i.jsx("span",{children:Dn.message})]}),i.jsx("div",{className:"mt-2 w-full bg-bambu-dark-tertiary rounded-full h-2",children:i.jsx("div",{className:"bg-bambu-green h-2 rounded-full transition-all duration-300",style:{width:`${Dn.progress}%`}})})]}):Dn?.status==="complete"?i.jsx("div",{className:"mt-3 p-2 bg-bambu-green/20 rounded text-sm text-bambu-green",children:Dn.message}):Dn?.status==="error"?i.jsx("div",{className:"mt-3 p-2 bg-red-500/20 rounded text-sm text-red-400",children:Dn.error||Dn.message}):gn?.is_docker?i.jsxs("div",{className:"mt-3 p-3 bg-bambu-dark-tertiary rounded-lg",children:[i.jsx("p",{className:"text-sm text-bambu-gray mb-2",children:a("settings.updateViaDocker")}),i.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"})]}):i.jsxs(Oe,{className:"mt-3",onClick:()=>Fl.mutate(),disabled:Fl.isPending,children:[Fl.isPending?i.jsx(lt,{className:"w-4 h-4 animate-spin"}):i.jsx(hi,{className:"w-4 h-4"}),a("settings.installUpdate")]})]}):gn?.error?i.jsx("div",{className:"mt-2 p-2 bg-red-500/10 border border-red-500/30 rounded text-sm text-red-400",children:a("settings.failedToCheckUpdates",{error:gn.error})}):gn&&!gn.update_available?i.jsx("p",{className:"mt-2 text-sm text-bambu-gray",children:a("settings.latestVersionRunning")}):null]})]})]}),i.jsxs(Tt,{children:[i.jsx(qn,{children:i.jsx("h2",{className:"text-lg font-semibold text-white",children:a("settings.dataManagement")})}),i.jsxs(Pt,{className:"space-y-4",children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-white",children:a("settings.clearNotificationLogs")}),i.jsx("p",{className:"text-sm text-bambu-gray",children:a("settings.clearNotificationLogsDescription")})]}),i.jsxs(Oe,{variant:"secondary",size:"sm",onClick:()=>F(!0),children:[i.jsx(Qt,{className:"w-4 h-4"}),a("common.clear")]})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-white",children:a("settings.resetUiPreferences")}),i.jsx("p",{className:"text-sm text-bambu-gray",children:a("settings.resetUiPreferencesDescription")})]}),i.jsxs(Oe,{variant:"secondary",size:"sm",onClick:()=>xe(!0),children:[i.jsx(Qt,{className:"w-4 h-4"}),a("settings.reset")]})]}),i.jsxs("div",{className:"pt-4 border-t border-bambu-dark-tertiary",children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-white",children:a("settings.storageUsage","Storage Usage")}),i.jsx("p",{className:"text-sm text-bambu-gray",children:a("settings.storageUsageDescription","Breakdown of data usage by category")})]}),i.jsxs(Oe,{variant:"secondary",size:"sm",onClick:Qe,disabled:et||be,children:[i.jsx(Sr,{className:`w-4 h-4 ${et||be?"animate-spin":""}`}),a("common.refresh","Refresh")]})]}),i.jsx("div",{className:"mt-3",children:Ke?i.jsxs("div",{className:"flex items-center gap-2 text-sm text-bambu-gray",children:[i.jsx(lt,{className:"w-4 h-4 animate-spin"}),a("common.loading","Loading")]}):Te?i.jsxs(i.Fragment,{children:[i.jsx("div",{className:"w-full h-3 bg-bambu-dark rounded-full overflow-hidden flex",children:Te.categories.filter(Se=>Se.bytes>0).map((Se,Dt)=>i.jsx("div",{className:`${MK(Se.key,Dt)} h-full`,style:{width:`${Se.percent_of_total}%`},title:`${Se.label}: ${Se.formatted}`},Se.key))}),i.jsx("div",{className:"mt-3 flex flex-wrap gap-3",children:Te.categories.filter(Se=>Se.bytes>0).map((Se,Dt)=>i.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[i.jsx("span",{className:`w-3 h-3 rounded-full ${MK(Se.key,Dt)}`}),i.jsx("span",{className:"text-bambu-gray",children:Se.label}),i.jsx("span",{className:"text-white",children:Se.formatted}),i.jsxs("span",{className:"text-bambu-gray",children:["(",Se.percent_of_total.toFixed(1),"%)"]})]},Se.key))}),i.jsxs("div",{className:"mt-2 text-xs text-bambu-gray",children:[a("settings.storageUsageTotal","Total"),": ",i.jsx("span",{className:"text-white",children:Te.total_formatted}),Te.scan_errors>0&&i.jsxs("span",{className:"ml-2 text-amber-400",children:[a("settings.storageUsageErrors","Scan errors"),": ",Te.scan_errors]})]}),Te.other_breakdown?.length>0&&i.jsxs("div",{className:"mt-4",children:[i.jsx("p",{className:"text-xs text-bambu-gray mb-2",children:a("settings.storageUsageOtherBreakdown","Other breakdown")}),i.jsx("div",{className:"space-y-2",children:Te.other_breakdown.map(Se=>i.jsxs("div",{className:"flex items-center justify-between text-xs",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("span",{className:"text-white",children:Se.label}),i.jsx("span",{className:`px-2 py-0.5 rounded-full border ${Se.kind==="system"?"border-slate-500 text-slate-300":"border-bambu-green text-bambu-green"}`,children:Se.kind==="system"?a("settings.storageUsageSystem","System"):a("settings.storageUsageData","Data")})]}),i.jsxs("div",{className:"flex items-center gap-2 text-bambu-gray",children:[i.jsx("span",{className:"text-white",children:Se.formatted}),i.jsxs("span",{children:["(",Se.percent_of_total.toFixed(1),"%)"]})]})]},`${Se.bucket}-${Se.kind}`))})]})]}):i.jsx("p",{className:"text-sm text-bambu-gray",children:a("settings.storageUsageUnavailable","Storage usage data is unavailable")})})]}),i.jsxs("div",{className:"flex items-center justify-between pt-4 border-t border-bambu-dark-tertiary",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-white",children:a("settings.backupRestore")}),i.jsx("p",{className:"text-sm text-bambu-gray",children:a("settings.backupRestoreDescription")})]}),i.jsxs(Oe,{variant:"secondary",size:"sm",onClick:()=>L("backup"),children:[i.jsx(Uc,{className:"w-4 h-4"}),a("settings.goToBackup")]})]})]})]})]})]}),q==="network"&&k&&i.jsxs("div",{className:"flex flex-col lg:flex-row gap-6",children:[i.jsxs("div",{className:"flex-1 lg:max-w-xl space-y-4",children:[i.jsxs(Tt,{children:[i.jsx(qn,{children:i.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx($m,{className:"w-5 h-5 text-blue-400"}),a("settings.externalUrl")]})}),i.jsxs(Pt,{className:"space-y-4",children:[i.jsx("p",{className:"text-sm text-bambu-gray",children:a("settings.externalUrlDescription")}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:a("settings.bambuddyUrl")}),i.jsx("input",{type:"text",value:k.external_url??"",onChange:Se=>$t("external_url",Se.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"}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:a("settings.externalUrlHint")})]})]})]}),i.jsxs(Tt,{children:[i.jsx(qn,{children:i.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(Sr,{className:"w-5 h-5 text-blue-400"}),a("settings.ftpRetry")]})}),i.jsxs(Pt,{className:"space-y-4",children:[i.jsx("p",{className:"text-sm text-bambu-gray",children:a("settings.ftpRetryDescription")}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-white",children:a("settings.enableRetry")}),i.jsx("p",{className:"text-sm text-bambu-gray",children:a("settings.autoRetryDescription")})]}),i.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:k.ftp_retry_enabled??!0,onChange:Se=>$t("ftp_retry_enabled",Se.target.checked),className:"sr-only peer"}),i.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"})]})]}),k.ftp_retry_enabled&&i.jsxs("div",{className:"space-y-4 pt-2 border-t border-bambu-dark-tertiary",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:a("settings.retryAttempts")}),i.jsxs("div",{className:"relative w-44",children:[i.jsx("select",{value:k.ftp_retry_count??3,onChange:Se=>$t("ftp_retry_count",parseInt(Se.target.value)),className:"w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer",children:[1,2,3,4,5,6,7,8,9,10].map(Se=>i.jsx("option",{value:Se,children:a("settings.time",{count:Se})},Se))}),i.jsx(jn,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:a("settings.retryDelay")}),i.jsxs("div",{className:"relative w-44",children:[i.jsx("select",{value:k.ftp_retry_delay??2,onChange:Se=>$t("ftp_retry_delay",parseInt(Se.target.value)),className:"w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer",children:[1,2,3,5,10,15,20,30].map(Se=>i.jsx("option",{value:Se,children:a("settings.second",{count:Se})},Se))}),i.jsx(jn,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:a("settings.connectionTimeout")}),i.jsxs("div",{className:"relative w-44",children:[i.jsx("select",{value:k.ftp_timeout??30,onChange:Se=>$t("ftp_timeout",parseInt(Se.target.value)),className:"w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer",children:[10,15,20,30,45,60,90,120].map(Se=>i.jsx("option",{value:Se,children:a("settings.nSeconds",{count:Se})},Se))}),i.jsx(jn,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:a("settings.increaseForWeakWifi")})]})]})]})]})]}),i.jsxs("div",{className:"flex-1 lg:max-w-xl space-y-4",children:[i.jsxs(Tt,{children:[i.jsx(qn,{children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(j0,{className:"w-5 h-5 text-bambu-green"}),a("settings.homeAssistant")]}),k.ha_enabled&&Sn&&i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("span",{className:`w-2.5 h-2.5 rounded-full ${Sn.success?"bg-green-400":"bg-red-400"}`}),i.jsx("span",{className:`text-sm ${Sn.success?"text-green-400":"text-red-400"}`,children:Sn.success?a("settings.connected"):a("settings.disconnected")})]})]})}),i.jsxs(Pt,{className:"space-y-4",children:[i.jsx("p",{className:"text-sm text-bambu-gray",children:a("settings.homeAssistantFullDescription")}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex-1",children:[i.jsx("p",{className:"text-white",children:a("settings.enableHomeAssistant")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:a("settings.homeAssistantDescription")}),k.ha_env_managed&&i.jsxs("div",{className:"flex items-center gap-1 mt-1",children:[i.jsx(Jh,{className:"w-3 h-3 text-bambu-green"}),i.jsx("span",{className:"text-xs text-bambu-green",children:a("settings.autoEnabledViaEnv")})]})]}),i.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:k.ha_enabled??!1,onChange:Se=>$t("ha_enabled",Se.target.checked),disabled:k.ha_env_managed,className:"sr-only peer"}),i.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 ${k.ha_env_managed?"opacity-60 cursor-not-allowed":""}`})]})]}),k.ha_enabled&&i.jsxs(i.Fragment,{children:[i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[a("settings.homeAssistantUrl"),k.ha_url_from_env&&i.jsx("span",{className:"ml-2 text-xs text-bambu-green",children:a("settings.environmentManagedLabel")})]}),i.jsxs("div",{className:"relative",children:[i.jsx("input",{type:"text",value:k.ha_url??"",onChange:Se=>$t("ha_url",Se.target.value),placeholder:"http://192.168.1.100:8123",disabled:k.ha_url_from_env,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 ${k.ha_url_from_env?"opacity-60 cursor-not-allowed":""}`}),k.ha_url_from_env&&i.jsx(Jh,{className:"absolute right-3 top-2.5 w-4 h-4 text-bambu-gray"})]}),k.ha_url_from_env&&i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:a("settings.urlFromEnvReadOnly")})]}),i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[a("settings.longLivedAccessToken"),k.ha_token_from_env&&i.jsx("span",{className:"ml-2 text-xs text-bambu-green",children:a("settings.environmentManagedLabel")})]}),i.jsxs("div",{className:"relative",children:[i.jsx("input",{type:"password",value:k.ha_token??"",onChange:Se=>$t("ha_token",Se.target.value),placeholder:"eyJ0eXAiOiJKV1QiLC...",disabled:k.ha_token_from_env,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 ${k.ha_token_from_env?"opacity-60 cursor-not-allowed":""}`}),k.ha_token_from_env&&i.jsx(Jh,{className:"absolute right-3 top-2.5 w-4 h-4 text-bambu-gray"})]}),k.ha_token_from_env?i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:a("settings.tokenFromEnvReadOnly")}):i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:a("settings.haTokenHint")})]}),k.ha_url&&k.ha_token&&i.jsx("div",{className:"pt-2 border-t border-bambu-dark-tertiary",children:i.jsxs(Oe,{variant:"secondary",size:"sm",disabled:xn,onClick:async()=>{Rn(!0),on(null);try{const Se=await fe.testHAConnection(k.ha_url,k.ha_token);on(Se)}catch(Se){on({success:!1,message:null,error:Se instanceof Error?Se.message:a("common.unknownError")})}finally{Rn(!1)}},children:[xn?i.jsx(lt,{className:"w-4 h-4 animate-spin"}):i.jsx(mb,{className:"w-4 h-4"}),a("settings.testConnection")]})})]})]})]}),i.jsxs(Tt,{children:[i.jsx(qn,{children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(mb,{className:"w-5 h-5 text-blue-400"}),a("settings.mqttPublishing")]}),Zn?.enabled&&i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("span",{className:`w-2.5 h-2.5 rounded-full ${Zn.connected?"bg-green-400":"bg-red-400"}`}),i.jsx("span",{className:`text-sm ${Zn.connected?"text-green-400":"text-red-400"}`,children:Zn.connected?a("settings.connected"):a("settings.disconnected")})]})]})}),i.jsxs(Pt,{className:"space-y-4",children:[i.jsx("p",{className:"text-sm text-bambu-gray",children:a("settings.mqttDescription")}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-white",children:a("settings.enableMqtt")}),i.jsx("p",{className:"text-sm text-bambu-gray",children:a("settings.mqttEnableDescription")})]}),i.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:k.mqtt_enabled??!1,onChange:Se=>$t("mqtt_enabled",Se.target.checked),className:"sr-only peer"}),i.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"})]})]}),k.mqtt_enabled&&i.jsxs("div",{className:"space-y-4 pt-2 border-t border-bambu-dark-tertiary",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:a("settings.brokerHostname")}),i.jsx("input",{type:"text",value:k.mqtt_broker??"",onChange:Se=>$t("mqtt_broker",Se.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"})]}),i.jsxs("div",{className:"flex items-end gap-4",children:[i.jsxs("div",{className:"flex-1",children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:a("settings.port")}),i.jsx("input",{type:"number",min:"1",max:"65535",value:k.mqtt_port??1883,onChange:Se=>$t("mqtt_port",Math.min(65535,Math.max(1,parseInt(Se.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"})]}),i.jsxs("div",{className:"flex items-center gap-3 pb-2",children:[i.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:k.mqtt_use_tls??!1,onChange:Se=>{const Dt=Se.target.checked;$t("mqtt_use_tls",Dt);const sr=k.mqtt_port??1883;Dt&&sr===1883?$t("mqtt_port",8883):!Dt&&sr===8883&&$t("mqtt_port",1883)},className:"sr-only peer"}),i.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]}),i.jsx("span",{className:"text-white text-sm",children:a("settings.useTls")})]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:a("settings.usernameOptional")}),i.jsx("input",{type:"text",value:k.mqtt_username??"",onChange:Se=>$t("mqtt_username",Se.target.value),placeholder:a("settings.leaveEmptyForAnonymous"),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:a("settings.passwordOptional")}),i.jsx("input",{type:"password",value:k.mqtt_password??"",onChange:Se=>$t("mqtt_password",Se.target.value),placeholder:a("settings.leaveEmptyForAnonymous"),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:a("settings.topicPrefix")}),i.jsx("input",{type:"text",value:k.mqtt_topic_prefix??"bambuddy",onChange:Se=>$t("mqtt_topic_prefix",Se.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"}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:a("settings.topicPrefixHint",{prefix:k.mqtt_topic_prefix||"bambuddy"})})]}),Zn&&i.jsx("div",{className:"pt-3 mt-3 border-t border-bambu-dark-tertiary",children:i.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[i.jsx("span",{className:`w-2 h-2 rounded-full ${Zn.connected?"bg-green-400":"bg-red-400"}`}),i.jsx("span",{className:"text-bambu-gray",children:Zn.connected?i.jsxs(i.Fragment,{children:[a("settings.mqttConnectedTo")," ",i.jsxs("span",{className:"text-white",children:[Zn.broker,":",Zn.port]})]}):a("settings.spoolmanDisconnected")})]})})]})]})]})]}),i.jsx("div",{className:"flex-1 lg:max-w-md space-y-4",children:i.jsxs(Tt,{children:[i.jsx(qn,{children:i.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(MD,{className:"w-5 h-5 text-orange-400"}),a("settings.prometheusMetrics")]})}),i.jsxs(Pt,{className:"space-y-4",children:[i.jsx("p",{className:"text-sm text-bambu-gray",children:a("settings.prometheusEndpointDescription")}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-white",children:a("settings.enableMetricsEndpoint")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:a("settings.prometheusDescription")})]}),i.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:k.prometheus_enabled??!1,onChange:Se=>$t("prometheus_enabled",Se.target.checked),className:"sr-only peer"}),i.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"})]})]}),k.prometheus_enabled&&i.jsxs("div",{className:"space-y-4 pt-2 border-t border-bambu-dark-tertiary",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:a("settings.bearerTokenOptional")}),i.jsx("input",{type:"password",value:k.prometheus_token??"",onChange:Se=>$t("prometheus_token",Se.target.value),placeholder:a("settings.leaveEmptyForNoAuth"),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:a("settings.bearerTokenHint")})]}),i.jsxs("div",{className:"pt-2 border-t border-bambu-dark-tertiary",children:[i.jsx("p",{className:"text-sm text-white mb-2",children:a("settings.availableMetrics")}),i.jsxs("div",{className:"text-xs text-bambu-gray space-y-1",children:[i.jsxs("p",{children:[i.jsx("code",{className:"text-orange-400",children:"bambuddy_printer_connected"})," - ",a("settings.metricsConnectionStatus")]}),i.jsxs("p",{children:[i.jsx("code",{className:"text-orange-400",children:"bambuddy_printer_state"})," - ",a("settings.metricsPrinterState")]}),i.jsxs("p",{children:[i.jsx("code",{className:"text-orange-400",children:"bambuddy_print_progress"})," - ",a("settings.metricsPrintProgress")]}),i.jsxs("p",{children:[i.jsx("code",{className:"text-orange-400",children:"bambuddy_bed_temp_celsius"})," - ",a("settings.metricsBedTemp")]}),i.jsxs("p",{children:[i.jsx("code",{className:"text-orange-400",children:"bambuddy_nozzle_temp_celsius"})," - ",a("settings.metricsNozzleTemp")]}),i.jsxs("p",{children:[i.jsx("code",{className:"text-orange-400",children:"bambuddy_prints_total"})," - ",a("settings.metricsPrintsTotal")]}),i.jsx("p",{className:"text-bambu-gray/70 italic",children:a("settings.metricsMore")})]})]})]})]})]})})]}),Sn&&i.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50",children:i.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg p-6 max-w-md w-full mx-4",children:[i.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[Sn.success?i.jsx(pr,{className:"w-8 h-8 text-green-400"}):i.jsx(Vi,{className:"w-8 h-8 text-red-400"}),i.jsx("h3",{className:"text-lg font-medium text-white",children:Sn.success?a("settings.connectionSuccessful"):a("settings.connectionFailed")})]}),i.jsx("p",{className:"text-bambu-gray mb-6",children:Sn.success?Sn.message||a("settings.haConnectionSuccess"):Sn.error||a("settings.haConnectionFailed")}),i.jsx("div",{className:"flex justify-end",children:i.jsx(Oe,{variant:"primary",onClick:()=>on(null),children:a("settings.ok")})})]})}),q==="plugs"&&i.jsxs("div",{className:"max-w-4xl",children:[i.jsxs("div",{className:"flex items-start justify-between mb-6",children:[i.jsxs("div",{children:[i.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(bl,{className:"w-5 h-5 text-bambu-green"}),a("settings.smartPlugs")]}),i.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:a("settings.smartPlugsDescription")})]}),i.jsxs("div",{className:"flex items-center gap-2 pt-1 shrink-0",children:[Ie&&Ie.filter(Se=>Se.enabled).length>1&&i.jsxs(i.Fragment,{children:[i.jsxs(Oe,{variant:"secondary",size:"sm",className:"whitespace-nowrap",onClick:()=>ce("on"),disabled:bt.isPending,title:a("settings.turnAllPlugsOn"),children:[bt.isPending?i.jsx(lt,{className:"w-4 h-4 animate-spin"}):i.jsx(Su,{className:"w-4 h-4 text-bambu-green"}),a("settings.allOn")]}),i.jsxs(Oe,{variant:"secondary",size:"sm",className:"whitespace-nowrap",onClick:()=>ce("off"),disabled:bt.isPending,title:a("settings.turnAllPlugsOff"),children:[bt.isPending?i.jsx(lt,{className:"w-4 h-4 animate-spin"}):i.jsx(pC,{className:"w-4 h-4 text-red-400"}),a("settings.allOff")]})]}),i.jsxs(Oe,{className:"whitespace-nowrap",onClick:()=>{U(null),R(!0)},children:[i.jsx(rr,{className:"w-4 h-4"}),a("settings.addSmartPlug")]})]})]}),Ie&&Ie.length>0&&i.jsxs(Tt,{className:"mb-6",children:[i.jsx(qn,{children:i.jsxs("h3",{className:"text-base font-semibold text-white flex items-center gap-2",children:[i.jsx(ac,{className:"w-4 h-4 text-yellow-400"}),a("settings.energySummary"),nt&&i.jsx(lt,{className:"w-4 h-4 animate-spin text-bambu-gray ml-2"})]})}),i.jsx(Pt,{children:ot?i.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[i.jsxs("div",{className:"bg-bambu-dark rounded-lg p-3",children:[i.jsxs("div",{className:"flex items-center gap-2 text-bambu-gray text-xs mb-1",children:[i.jsx(ac,{className:"w-3 h-3"}),a("settings.currentPower")]}),i.jsxs("div",{className:"text-xl font-bold text-white",children:[ot.totalPower.toFixed(1),i.jsx("span",{className:"text-sm font-normal text-bambu-gray ml-1",children:"W"})]}),i.jsx("div",{className:"text-xs text-bambu-gray mt-1",children:a("settings.plugsOnline",{reachable:ot.reachableCount,total:ot.totalPlugs})})]}),i.jsxs("div",{className:"bg-bambu-dark rounded-lg p-3",children:[i.jsxs("div",{className:"flex items-center gap-2 text-bambu-gray text-xs mb-1",children:[i.jsx(Xr,{className:"w-3 h-3"}),a("settings.today")]}),i.jsxs("div",{className:"text-xl font-bold text-white",children:[ot.totalToday.toFixed(3),i.jsx("span",{className:"text-sm font-normal text-bambu-gray ml-1",children:"kWh"})]}),(k?.energy_cost_per_kwh??0)>0&&i.jsxs("div",{className:"text-xs text-bambu-gray mt-1",children:["~",(ot.totalToday*(k?.energy_cost_per_kwh??0)).toFixed(2)," ",ol(k?.currency||"USD")]})]}),i.jsxs("div",{className:"bg-bambu-dark rounded-lg p-3",children:[i.jsxs("div",{className:"flex items-center gap-2 text-bambu-gray text-xs mb-1",children:[i.jsx(MD,{className:"w-3 h-3"}),a("settings.yesterday")]}),i.jsxs("div",{className:"text-xl font-bold text-white",children:[ot.totalYesterday.toFixed(3),i.jsx("span",{className:"text-sm font-normal text-bambu-gray ml-1",children:"kWh"})]}),(k?.energy_cost_per_kwh??0)>0&&i.jsxs("div",{className:"text-xs text-bambu-gray mt-1",children:["~",(ot.totalYesterday*(k?.energy_cost_per_kwh??0)).toFixed(2)," ",ol(k?.currency||"USD")]})]}),i.jsxs("div",{className:"bg-bambu-dark rounded-lg p-3",children:[i.jsxs("div",{className:"flex items-center gap-2 text-bambu-gray text-xs mb-1",children:[i.jsx(U1,{className:"w-3 h-3"}),a("settings.total")]}),i.jsxs("div",{className:"text-xl font-bold text-white",children:[ot.totalLifetime.toFixed(1),i.jsx("span",{className:"text-sm font-normal text-bambu-gray ml-1",children:"kWh"})]}),(k?.energy_cost_per_kwh??0)>0&&i.jsxs("div",{className:"text-xs text-bambu-gray mt-1",children:["~",(ot.totalLifetime*(k?.energy_cost_per_kwh??0)).toFixed(2)," ",ol(k?.currency||"USD")]})]})]}):nt?null:i.jsx("p",{className:"text-sm text-bambu-gray",children:a("settings.enablePlugsForSummary")})})]}),ut?i.jsx("div",{className:"flex justify-center py-12",children:i.jsx(lt,{className:"w-8 h-8 text-bambu-green animate-spin"})}):Ie&&Ie.length>0?i.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:Ie.map(Se=>i.jsx(KZe,{plug:Se,onEdit:Dt=>{U(Dt),R(!0)}},Se.id))}):i.jsx(Tt,{children:i.jsx(Pt,{className:"py-12",children:i.jsxs("div",{className:"text-center text-bambu-gray",children:[i.jsx(bl,{className:"w-16 h-16 mx-auto mb-4 opacity-30"}),i.jsx("p",{className:"text-lg font-medium text-white mb-2",children:a("settings.noSmartPlugsTitle")}),i.jsx("p",{className:"text-sm mb-4",children:a("settings.noSmartPlugsDescription")}),i.jsxs(Oe,{onClick:()=>{U(null),R(!0)},children:[i.jsx(rr,{className:"w-4 h-4"}),a("settings.addFirstSmartPlug")]})]})})})]}),q==="notifications"&&i.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-8",children:[i.jsxs("div",{children:[i.jsxs("div",{className:"flex items-center justify-between mb-4",children:[i.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(db,{className:"w-5 h-5 text-bambu-green"}),a("settings.providers")]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsxs(Oe,{size:"sm",variant:"secondary",onClick:()=>pe(!0),children:[i.jsx(Fv,{className:"w-4 h-4"}),a("settings.log")]}),St&&St.length>0&&i.jsxs(Oe,{size:"sm",variant:"secondary",onClick:()=>{ad(null),Ll.mutate()},disabled:Ll.isPending,children:[Ll.isPending?i.jsx(lt,{className:"w-4 h-4 animate-spin"}):i.jsx(fC,{className:"w-4 h-4"}),a("settings.testAll")]}),i.jsxs(Oe,{size:"sm",onClick:()=>{ie(null),O(!0)},children:[i.jsx(rr,{className:"w-4 h-4"}),a("settings.addNotificationProvider")]})]})]}),i.jsx(Tt,{className:"mb-4",children:i.jsx(Pt,{className:"py-3",children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-white text-sm font-medium",children:a("settings.notificationLanguage")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:a("settings.notificationLanguageDescription")})]}),i.jsx("select",{value:k.notification_language||"en",onChange:Se=>$t("notification_language",Se.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:OB.map(Se=>i.jsx("option",{value:Se.code,children:Se.nativeName},Se.code))})]})})}),i.jsx(Tt,{className:"mb-4",children:i.jsx(Pt,{className:"py-3",children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-white text-sm font-medium",children:a("settings.bedCooledThreshold")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:a("settings.bedCooledThresholdDescription")})]}),i.jsxs("div",{className:"flex items-center gap-1",children:[i.jsx("input",{type:"number",min:20,max:80,step:1,value:k.bed_cooled_threshold??35,onChange:Se=>$t("bed_cooled_threshold",Number(Se.target.value)),className:"w-16 px-2 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm text-center focus:outline-none focus:ring-1 focus:ring-bambu-green"}),i.jsx("span",{className:"text-sm text-bambu-gray",children:"°C"})]})]})})}),ka&&i.jsx(Tt,{className:"mb-4",children:i.jsxs(Pt,{className:"py-3",children:[i.jsxs("div",{className:"flex items-center justify-between mb-2",children:[i.jsx("span",{className:"text-sm font-medium text-white",children:a("settings.testResults")}),i.jsx("button",{onClick:()=>ad(null),className:"text-bambu-gray hover:text-white text-xs",children:a("common.dismiss")})]}),i.jsxs("div",{className:"flex items-center gap-4 text-sm mb-2",children:[i.jsxs("span",{className:"flex items-center gap-1 text-bambu-green",children:[i.jsx(pr,{className:"w-4 h-4"}),a("settings.testPassedCount",{count:ka.success})]}),ka.failed>0&&i.jsxs("span",{className:"flex items-center gap-1 text-red-400",children:[i.jsx(Vi,{className:"w-4 h-4"}),a("settings.testFailedCount",{count:ka.failed})]})]}),ka.results.filter(Se=>!Se.success).length>0&&i.jsx("div",{className:"space-y-1 mt-2 pt-2 border-t border-bambu-dark-tertiary",children:ka.results.filter(Se=>!Se.success).map(Se=>i.jsxs("div",{className:"text-xs text-red-400",children:[i.jsxs("span",{className:"font-medium",children:[Se.provider_name,":"]})," ",Se.message]},Se.provider_id))})]})}),Lt?i.jsx("div",{className:"flex justify-center py-12",children:i.jsx(lt,{className:"w-6 h-6 text-bambu-green animate-spin"})}):St&&St.length>0?i.jsx("div",{className:"space-y-3",children:St.map(Se=>i.jsx(XZe,{provider:Se,onEdit:Dt=>{ie(Dt),O(!0)}},Se.id))}):i.jsx(Tt,{children:i.jsx(Pt,{className:"py-8",children:i.jsxs("div",{className:"text-center text-bambu-gray",children:[i.jsx(db,{className:"w-12 h-12 mx-auto mb-3 opacity-30"}),i.jsx("p",{className:"text-sm font-medium text-white mb-2",children:a("settings.noProvidersTitle")}),i.jsx("p",{className:"text-xs mb-3",children:a("settings.noProvidersDescription")}),i.jsxs(Oe,{size:"sm",onClick:()=>{ie(null),O(!0)},children:[i.jsx(rr,{className:"w-4 h-4"}),a("settings.addProvider")]})]})})})]}),i.jsxs("div",{children:[i.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2 mb-4",children:[i.jsx(Ds,{className:"w-5 h-5 text-bambu-green"}),a("settings.messageTemplates")]}),i.jsx("p",{className:"text-sm text-bambu-gray mb-4",children:a("settings.messageTemplatesDescription")}),In?i.jsx("div",{className:"flex justify-center py-8",children:i.jsx(lt,{className:"w-6 h-6 text-bambu-green animate-spin"})}):Pn&&Pn.length>0?i.jsx("div",{className:"space-y-2",children:[...Pn].sort((Se,Dt)=>Se.name.localeCompare(Dt.name)).map(Se=>i.jsx(Tt,{className:"cursor-pointer hover:border-bambu-green/50 transition-colors",onClick:()=>ae(Se),children:i.jsx(Pt,{className:"py-2.5 px-3",children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"min-w-0 flex-1",children:[i.jsx("p",{className:"text-white font-medium text-sm truncate",children:Se.name}),i.jsx("p",{className:"text-bambu-gray text-xs truncate mt-0.5",children:Se.title_template})]}),i.jsx("button",{className:"p-1.5 hover:bg-bambu-dark-tertiary rounded transition-colors shrink-0 ml-2",onClick:Dt=>{Dt.stopPropagation(),ae(Se)},children:i.jsx(Mm,{className:"w-4 h-4 text-bambu-gray"})})]})})},Se.id))}):i.jsx(Tt,{children:i.jsx(Pt,{className:"py-8",children:i.jsxs("div",{className:"text-center text-bambu-gray",children:[i.jsx(Ds,{className:"w-12 h-12 mx-auto mb-3 opacity-30"}),i.jsx("p",{className:"text-sm",children:a("settings.noTemplatesAvailable")})]})})})]})]}),q==="apikeys"&&i.jsxs("div",{className:"grid grid-cols-1 xl:grid-cols-2 gap-8",children:[i.jsxs("div",{children:[i.jsxs("div",{className:"flex items-start justify-between gap-4 mb-6",children:[i.jsxs("div",{className:"flex-1",children:[i.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(sl,{className:"w-5 h-5 text-bambu-green"}),a("settings.apiKeys")]}),i.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:a("settings.apiKeysDescription")})]}),i.jsxs(Oe,{size:"sm",onClick:()=>B(!0),className:"flex-shrink-0",children:[i.jsx(rr,{className:"w-4 h-4"}),a("settings.createKey")]})]}),J&&i.jsx(Tt,{className:"mb-6 border-bambu-green",children:i.jsx(Pt,{className:"py-4",children:i.jsxs("div",{className:"flex items-start gap-3",children:[i.jsx(pr,{className:"w-5 h-5 text-bambu-green flex-shrink-0 mt-0.5"}),i.jsxs("div",{className:"flex-1",children:[i.jsx("p",{className:"text-white font-medium mb-1",children:a("settings.apiKeyCreated")}),i.jsx("p",{className:"text-sm text-bambu-gray mb-2",children:a("settings.apiKeyCopyWarning")}),i.jsxs("div",{className:"flex items-center gap-2 bg-bambu-dark rounded-lg p-2",children:[i.jsx("code",{className:"flex-1 text-sm text-bambu-green font-mono break-all",children:J}),i.jsx(Oe,{variant:"secondary",size:"sm",onClick:async()=>{try{if(navigator.clipboard&&navigator.clipboard.writeText)await navigator.clipboard.writeText(J);else{const Se=document.createElement("textarea");Se.value=J,Se.style.position="fixed",Se.style.left="-999999px",document.body.appendChild(Se),Se.select(),document.execCommand("copy"),document.body.removeChild(Se)}o(a("settings.toast.keyCopied"))}catch{o(a("settings.toast.copyFailed"),"error")}},children:i.jsx(_l,{className:"w-4 h-4"})})]}),i.jsxs("div",{className:"flex gap-2 mt-3",children:[i.jsx(Oe,{variant:"secondary",size:"sm",onClick:()=>{le(J),o(a("settings.toast.keyAddedToBrowser"))},children:a("settings.useInApiBrowser")}),i.jsx(Oe,{variant:"secondary",size:"sm",onClick:()=>ne(null),children:a("common.dismiss")})]})]})]})})}),G&&i.jsxs(Tt,{className:"mb-6",children:[i.jsx(qn,{children:i.jsx("h3",{className:"text-base font-semibold text-white",children:a("settings.createNewApiKey")})}),i.jsxs(Pt,{className:"space-y-4",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:a("settings.keyName")}),i.jsx("input",{type:"text",value:re,onChange:Se=>z(Se.target.value),placeholder:a("settings.keyNamePlaceholder"),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-2",children:a("common.permissions")}),i.jsxs("div",{className:"space-y-2",children:[i.jsxs("label",{className:"flex items-center gap-3 cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:V.can_read_status,onChange:Se=>ee(Dt=>({...Dt,can_read_status:Se.target.checked})),className:"w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green"}),i.jsxs("div",{children:[i.jsx("span",{className:"text-white",children:a("settings.readStatus")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:a("settings.readStatusDescription")})]})]}),i.jsxs("label",{className:"flex items-center gap-3 cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:V.can_queue,onChange:Se=>ee(Dt=>({...Dt,can_queue:Se.target.checked})),className:"w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green"}),i.jsxs("div",{children:[i.jsx("span",{className:"text-white",children:a("settings.manageQueue")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:a("settings.manageQueueDescription")})]})]}),i.jsxs("label",{className:"flex items-center gap-3 cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:V.can_control_printer,onChange:Se=>ee(Dt=>({...Dt,can_control_printer:Se.target.checked})),className:"w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green"}),i.jsxs("div",{children:[i.jsx("span",{className:"text-white",children:a("settings.controlPrinter")}),i.jsx("p",{className:"text-xs text-bambu-gray",children:a("settings.controlPrinterDescription")})]})]})]})]}),i.jsxs("div",{className:"flex items-center gap-2 pt-2",children:[i.jsxs(Oe,{onClick:()=>cn.mutate({name:re||a("settings.unnamedKey"),...V}),disabled:cn.isPending,children:[cn.isPending?i.jsx(lt,{className:"w-4 h-4 animate-spin"}):i.jsx(rr,{className:"w-4 h-4"}),a("settings.createKey")]}),i.jsx(Oe,{variant:"secondary",onClick:()=>B(!1),children:a("common.cancel")})]})]})]}),Ft?i.jsx("div",{className:"flex justify-center py-12",children:i.jsx(lt,{className:"w-8 h-8 text-bambu-green animate-spin"})}):jt&&jt.length>0?i.jsx("div",{className:"space-y-3",children:jt.map(Se=>i.jsx(Tt,{children:i.jsx(Pt,{className:"py-3",children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx(sl,{className:`w-5 h-5 ${Se.enabled?"text-bambu-green":"text-bambu-gray"}`}),i.jsxs("div",{children:[i.jsx("p",{className:"text-white font-medium",children:Se.name}),i.jsxs("p",{className:"text-xs text-bambu-gray",children:[Se.key_prefix,"••••••••",Se.last_used&&` · ${a("settings.lastUsed")}: ${Wp(Se.last_used)}`]})]})]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsxs("div",{className:"flex gap-1 text-xs",children:[Se.can_read_status&&i.jsx("span",{className:"px-1.5 py-0.5 bg-blue-500/20 text-blue-400 rounded",children:a("settings.read")}),Se.can_queue&&i.jsx("span",{className:"px-1.5 py-0.5 bg-green-500/20 text-green-400 rounded",children:a("queue.title")}),Se.can_control_printer&&i.jsx("span",{className:"px-1.5 py-0.5 bg-orange-500/20 text-orange-400 rounded",children:a("settings.control")})]}),i.jsx(Oe,{variant:"secondary",size:"sm",onClick:()=>ue(Se.id),children:i.jsx(Qt,{className:"w-4 h-4 text-red-400"})})]})]})})},Se.id))}):i.jsx(Tt,{children:i.jsx(Pt,{className:"py-12",children:i.jsxs("div",{className:"text-center text-bambu-gray",children:[i.jsx(sl,{className:"w-16 h-16 mx-auto mb-4 opacity-30"}),i.jsx("p",{className:"text-lg font-medium text-white mb-2",children:a("settings.apiKeysEmptyTitle")}),i.jsx("p",{className:"text-sm mb-4",children:a("settings.apiKeysEmptyDescription")}),i.jsxs(Oe,{onClick:()=>B(!0),children:[i.jsx(rr,{className:"w-4 h-4"}),a("settings.createFirstKey")]})]})})}),i.jsxs(Tt,{className:"mt-6",children:[i.jsx(qn,{children:i.jsx("h3",{className:"text-base font-semibold text-white",children:a("settings.webhookEndpoints")})}),i.jsxs(Pt,{className:"space-y-3 text-sm",children:[i.jsx("p",{className:"text-bambu-gray",children:a("settings.webhookApiKeyHint")}),i.jsxs("div",{className:"space-y-2 font-mono text-xs",children:[i.jsxs("div",{className:"p-2 bg-bambu-dark rounded",children:[i.jsx("span",{className:"text-blue-400",children:"GET"})," ",i.jsx("span",{className:"text-white",children:"/api/v1/webhook/status"}),i.jsxs("span",{className:"text-bambu-gray",children:[" - ",a("settings.webhook.getAllStatus")]})]}),i.jsxs("div",{className:"p-2 bg-bambu-dark rounded",children:[i.jsx("span",{className:"text-blue-400",children:"GET"})," ",i.jsx("span",{className:"text-white",children:"/api/v1/webhook/status/:id"}),i.jsxs("span",{className:"text-bambu-gray",children:[" - ",a("settings.webhook.getSpecificStatus")]})]}),i.jsxs("div",{className:"p-2 bg-bambu-dark rounded",children:[i.jsx("span",{className:"text-green-400",children:"POST"})," ",i.jsx("span",{className:"text-white",children:"/api/v1/webhook/queue"}),i.jsxs("span",{className:"text-bambu-gray",children:[" - ",a("settings.webhook.addToQueue")]})]}),i.jsxs("div",{className:"p-2 bg-bambu-dark rounded",children:[i.jsx("span",{className:"text-orange-400",children:"POST"})," ",i.jsx("span",{className:"text-white",children:"/api/v1/webhook/printer/:id/pause"}),i.jsxs("span",{className:"text-bambu-gray",children:[" - ",a("settings.webhook.pausePrint")]})]}),i.jsxs("div",{className:"p-2 bg-bambu-dark rounded",children:[i.jsx("span",{className:"text-orange-400",children:"POST"})," ",i.jsx("span",{className:"text-white",children:"/api/v1/webhook/printer/:id/resume"}),i.jsxs("span",{className:"text-bambu-gray",children:[" - ",a("settings.webhook.resumePrint")]})]}),i.jsxs("div",{className:"p-2 bg-bambu-dark rounded",children:[i.jsx("span",{className:"text-red-400",children:"POST"})," ",i.jsx("span",{className:"text-white",children:"/api/v1/webhook/printer/:id/stop"}),i.jsxs("span",{className:"text-bambu-gray",children:[" - ",a("settings.webhook.stopPrint")]})]})]})]})]})]}),i.jsxs("div",{children:[i.jsxs("div",{className:"mb-6",children:[i.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx($m,{className:"w-5 h-5 text-bambu-green"}),a("settings.apiBrowser")]}),i.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:a("settings.apiBrowserDescription")})]}),i.jsx(Tt,{className:"mb-4",children:i.jsxs(Pt,{className:"py-3",children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-2",children:a("settings.apiKeyForTesting")}),i.jsx("input",{type:"text",value:ge,onChange:Se=>le(Se.target.value),placeholder:a("settings.apiKeyPlaceholder"),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white font-mono text-sm focus:border-bambu-green focus:outline-none"}),i.jsx("p",{className:"text-xs text-bambu-gray mt-2",children:a("settings.apiKeyHint")})]})}),i.jsx(vJe,{apiKey:ge})]})]}),q==="virtual-printer"&&i.jsx(uJe,{}),q==="filament"&&k&&i.jsx(i.Fragment,{children:i.jsxs("div",{className:"flex flex-col lg:flex-row gap-6 lg:gap-8",children:[i.jsxs("div",{className:"lg:w-1/3 space-y-6",children:[i.jsx(iJe,{}),i.jsxs(Tt,{children:[i.jsx(qn,{children:i.jsx("h2",{className:"text-lg font-semibold text-white",children:a("settings.amsDisplayThresholds")})}),i.jsxs(Pt,{className:"space-y-4",children:[i.jsx("p",{className:"text-sm text-bambu-gray",children:a("settings.amsThresholdsDescription")}),i.jsxs("div",{className:"space-y-3",children:[i.jsxs("div",{className:"flex items-center gap-2 text-white",children:[i.jsx(WF,{className:"w-4 h-4 text-blue-400"}),i.jsx("span",{className:"font-medium",children:a("settings.humidity")})]}),i.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[a("settings.goodGreen")," ≤"]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("input",{type:"number",min:"0",max:"100",value:k.ams_humidity_good??40,onChange:Se=>$t("ams_humidity_good",parseInt(Se.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"}),i.jsx("span",{className:"text-bambu-gray",children:"%"})]})]}),i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[a("settings.fairOrange")," ≤"]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("input",{type:"number",min:"0",max:"100",value:k.ams_humidity_fair??60,onChange:Se=>$t("ams_humidity_fair",parseInt(Se.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"}),i.jsx("span",{className:"text-bambu-gray",children:"%"})]})]})]}),i.jsx("p",{className:"text-xs text-bambu-gray",children:a("settings.aboveFairBad")})]}),i.jsxs("div",{className:"space-y-3 pt-2 border-t border-bambu-dark-tertiary",children:[i.jsxs("div",{className:"flex items-center gap-2 text-white",children:[i.jsx(bC,{className:"w-4 h-4 text-orange-400"}),i.jsx("span",{className:"font-medium",children:a("settings.temperature")})]}),i.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[a("settings.goodBlue")," ≤"]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("input",{type:"number",step:"0.5",min:"0",max:"60",value:k.ams_temp_good??28,onChange:Se=>$t("ams_temp_good",parseFloat(Se.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"}),i.jsx("span",{className:"text-bambu-gray",children:"°C"})]})]}),i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[a("settings.fairOrange")," ≤"]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("input",{type:"number",step:"0.5",min:"0",max:"60",value:k.ams_temp_fair??35,onChange:Se=>$t("ams_temp_fair",parseFloat(Se.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"}),i.jsx("span",{className:"text-bambu-gray",children:"°C"})]})]})]}),i.jsx("p",{className:"text-xs text-bambu-gray",children:a("settings.aboveFairHot")})]}),i.jsxs("div",{className:"space-y-3 pt-4 border-t border-bambu-dark-tertiary",children:[i.jsxs("div",{className:"flex items-center gap-2 text-white",children:[i.jsx(Uc,{className:"w-4 h-4 text-purple-400"}),i.jsx("span",{className:"font-medium",children:a("settings.historyRetention")})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:a("settings.keepSensorHistory")}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("input",{type:"number",min:"1",max:"365",value:k.ams_history_retention_days??30,onChange:Se=>$t("ams_history_retention_days",parseInt(Se.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"}),i.jsx("span",{className:"text-bambu-gray",children:a("common.days")})]})]}),i.jsx("p",{className:"text-xs text-bambu-gray",children:a("settings.historyRetentionDescription")})]}),i.jsxs("div",{className:"space-y-3 pt-4 border-t border-bambu-dark-tertiary",children:[i.jsxs("div",{className:"flex items-center gap-2 text-white",children:[i.jsx(_r,{className:"w-4 h-4 text-bambu-green"}),i.jsx("span",{className:"font-medium",children:a("settings.printModal")})]}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-white",children:a("settings.expandCustomMapping")}),i.jsx("p",{className:"text-xs text-bambu-gray mt-0.5",children:a("settings.expandCustomMappingDescription")})]}),i.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:k.per_printer_mapping_expanded??!1,onChange:Se=>$t("per_printer_mapping_expanded",Se.target.checked),className:"sr-only peer"}),i.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]})]})]})]})]}),i.jsxs("div",{className:"lg:w-2/3 space-y-6",children:[i.jsx(aJe,{}),i.jsx(sJe,{})]})]})}),se!==null&&i.jsx(_n,{title:a("settings.deleteApiKeyTitle"),message:a("settings.deleteApiKeyMessage"),confirmText:a("settings.deleteKey"),variant:"danger",onConfirm:()=>{Jt.mutate(se),ue(null)},onCancel:()=>ue(null)}),A&&i.jsx(YZe,{plug:$,onClose:()=>{R(!1),U(null)}}),W&&i.jsx(ZZe,{provider:te,onClose:()=>{O(!1),ie(null)}}),Y&&i.jsx(JZe,{template:Y,onClose:()=>ae(null)}),de&&i.jsx(tJe,{onClose:()=>pe(!1)}),I&&i.jsx(_n,{title:a("settings.clearNotificationLogs"),message:a("settings.clearLogsMessage"),confirmText:a("settings.clearLogs"),variant:"warning",onConfirm:async()=>{F(!1);try{const Se=await fe.clearNotificationLogs(30);o(Se.message,"success")}catch{o(a("settings.toast.clearLogsFailed"),"error")}},onCancel:()=>F(!1)}),Z&&i.jsx(_n,{title:a("settings.resetUiPreferences"),message:a("settings.resetUiPreferencesMessage"),confirmText:a("settings.resetPreferences"),variant:"default",onConfirm:()=>{xe(!1),localStorage.clear(),o(a("settings.toast.uiPreferencesReset"),"success"),setTimeout(()=>window.location.reload(),1e3)},onCancel:()=>xe(!1)}),he&&i.jsx(_n,{title:`Turn All Plugs ${he==="on"?"On":"Off"}`,message:`This will turn ${he==="on"?"ON":"OFF"} all ${Ie?.filter(Se=>Se.enabled).length||0} enabled smart plugs. ${he==="off"?"Any running printers may be affected!":""}`,confirmText:`Turn All ${he==="on"?"On":"Off"}`,variant:he==="off"?"danger":"warning",onConfirm:()=>{const Se=he;ce(null),bt.mutate(Se)},onCancel:()=>ce(null)}),Ae&&gn?.release_notes&&i.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",onClick:()=>_e(!1),children:i.jsxs(Tt,{className:"w-full max-w-2xl max-h-[80vh] flex flex-col",onClick:Se=>Se.stopPropagation(),children:[i.jsxs(qn,{className:"flex flex-row items-center justify-between shrink-0",children:[i.jsxs("div",{children:[i.jsxs("h2",{className:"text-lg font-semibold text-white",children:["Release Notes - v",gn.latest_version]}),gn.release_name&&gn.release_name!==gn.latest_version&&i.jsx("p",{className:"text-sm text-bambu-gray",children:gn.release_name})]}),i.jsx("button",{onClick:()=>_e(!1),className:"p-1 rounded hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white",children:i.jsx(zt,{className:"w-5 h-5"})})]}),i.jsx(Pt,{className:"overflow-y-auto flex-1",children:i.jsx("pre",{className:"text-sm text-bambu-gray whitespace-pre-wrap font-sans",children:gn.release_notes})}),i.jsxs("div",{className:"p-4 border-t border-bambu-dark-tertiary shrink-0 flex gap-2",children:[gn.release_url&&i.jsx("a",{href:gn.release_url,target:"_blank",rel:"noopener noreferrer",className:"flex-1",children:i.jsxs(Oe,{variant:"secondary",className:"w-full",children:[i.jsx(ei,{className:"w-4 h-4"}),"View on GitHub"]})}),i.jsx(Oe,{onClick:()=>_e(!1),className:"flex-1",children:"Close"})]})]})}),q==="users"&&i.jsxs("div",{className:"space-y-6",children:[i.jsxs("div",{className:"flex gap-1 border-b border-bambu-dark-tertiary",children:[i.jsxs("button",{onClick:()=>j("users"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${E==="users"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[i.jsx(Sm,{className:"w-4 h-4"}),a("settings.tabs.users")]}),i.jsxs("button",{onClick:()=>j("email"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${E==="email"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[i.jsx(Lv,{className:"w-4 h-4"}),a("settings.tabs.emailAuth")||"Email Authentication",Rr?.advanced_auth_enabled&&i.jsx("span",{className:"w-2 h-2 rounded-full bg-green-400"})]})]}),E==="users"&&i.jsxs(i.Fragment,{children:[i.jsx(Tt,{children:i.jsx(Pt,{className:"py-4",children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx("div",{className:`w-10 h-10 rounded-full flex items-center justify-center ${l?"bg-green-500/20":"bg-gray-500/20"}`,children:l?i.jsx(Jh,{className:"w-5 h-5 text-green-400"}):i.jsx(o1,{className:"w-5 h-5 text-gray-400"})}),i.jsxs("div",{children:[i.jsx("h3",{className:"text-white font-medium",children:a("settings.authentication")}),i.jsx("p",{className:"text-sm text-bambu-gray",children:a(l?"settings.authEnabledDescription":"settings.authDisabledDescription")})]})]}),l?c?.is_admin&&i.jsxs(Oe,{variant:"secondary",onClick:()=>$e(!0),children:[i.jsx(o1,{className:"w-4 h-4"}),a("common.disable")]}):i.jsxs(Oe,{onClick:()=>e("/setup"),children:[i.jsx(Jh,{className:"w-4 h-4"}),a("common.enable")]})]})})}),Rr?.advanced_auth_enabled&&i.jsx(Tt,{className:"border-blue-500/30 bg-blue-500/5",children:i.jsx(Pt,{className:"py-4",children:i.jsxs("div",{className:"flex items-start gap-3",children:[i.jsx("div",{className:"w-10 h-10 rounded-full flex items-center justify-center bg-blue-500/20 flex-shrink-0",children:i.jsx(Lv,{className:"w-5 h-5 text-blue-400"})}),i.jsxs("div",{children:[i.jsx("h3",{className:"text-white font-medium",children:a("settings.email.advancedAuthEnabled")}),i.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:a("settings.email.advancedAuthEnabledDesc")})]})]})})}),l&&i.jsxs("div",{className:"grid grid-cols-1 xl:grid-cols-2 gap-6",children:[i.jsxs("div",{className:"space-y-6",children:[c&&i.jsxs(Tt,{children:[i.jsx(qn,{children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("h3",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(Sm,{className:"w-5 h-5 text-bambu-green"}),a("settings.currentUser")]}),i.jsxs(Oe,{size:"sm",variant:"ghost",onClick:()=>ke(!0),children:[i.jsx(sl,{className:"w-4 h-4"}),a("settings.changePassword")]})]})}),i.jsx(Pt,{children:i.jsx("div",{className:"flex items-center justify-between",children:i.jsxs("div",{children:[i.jsx("p",{className:"text-white font-medium text-lg",children:c.username}),i.jsxs("div",{className:"flex flex-wrap gap-1 mt-2",children:[c.is_admin&&i.jsx("span",{className:"px-2 py-0.5 rounded-full text-xs font-medium bg-purple-500/20 text-purple-300",children:a("settings.admin")}),c.groups?.map(Se=>i.jsx("span",{className:`px-2 py-0.5 rounded-full text-xs font-medium ${Se.name==="Administrators"?"bg-purple-500/20 text-purple-300":Se.name==="Operators"?"bg-blue-500/20 text-blue-300":Se.name==="Viewers"?"bg-green-500/20 text-green-300":"bg-gray-500/20 text-gray-300"}`,children:Se.name},Se.id))]})]})})})]}),i.jsxs(Tt,{children:[i.jsx(qn,{children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("h3",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(Sm,{className:"w-5 h-5 text-bambu-green"}),a("settings.users")]}),bi("users:create")&&i.jsxs(Oe,{size:"sm",onClick:()=>{Ve(!0),Bt({username:"",password:"",email:"",confirmPassword:"",role:"user",group_ids:[]})},children:[i.jsx(rr,{className:"w-4 h-4"}),a("settings.addUser")]})]})}),i.jsx(Pt,{children:Nf?i.jsx("div",{className:"flex items-center justify-center py-8",children:i.jsx(lt,{className:"w-6 h-6 text-bambu-green animate-spin"})}):_h.length===0?i.jsx("p",{className:"text-center text-bambu-gray py-8",children:a("settings.noUsersFound")}):i.jsx("div",{className:"divide-y divide-bambu-dark-tertiary",children:_h.map(Se=>i.jsxs("div",{className:"py-3 flex items-center justify-between",children:[i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsx("p",{className:"text-white font-medium truncate",children:Se.username}),i.jsxs("div",{className:"flex flex-wrap gap-1 mt-1",children:[Se.is_admin&&i.jsx("span",{className:"px-2 py-0.5 rounded-full text-xs font-medium bg-purple-500/20 text-purple-300",children:a("settings.admin")}),Se.groups?.map(Dt=>i.jsx("span",{className:`px-2 py-0.5 rounded-full text-xs font-medium ${Dt.name==="Administrators"?"bg-purple-500/20 text-purple-300":Dt.name==="Operators"?"bg-blue-500/20 text-blue-300":Dt.name==="Viewers"?"bg-green-500/20 text-green-300":"bg-gray-500/20 text-gray-300"}`,children:Dt.name},Dt.id))]})]}),i.jsxs("div",{className:"flex items-center gap-1 ml-4",children:[bi("users:update")&&i.jsx(Oe,{size:"sm",variant:"ghost",onClick:()=>Nh(Se),children:i.jsx(Mm,{className:"w-4 h-4"})}),bi("users:delete")&&Se.id!==c?.id&&i.jsx(Oe,{size:"sm",variant:"ghost",onClick:()=>ks(Se.id),children:i.jsx(Qt,{className:"w-4 h-4"})})]})]},Se.id))})})]})]}),i.jsx("div",{children:i.jsxs(Tt,{children:[i.jsx(qn,{children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("h3",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[i.jsx(AD,{className:"w-5 h-5 text-bambu-green"}),a("settings.groups")]}),bi("groups:create")&&i.jsxs(Oe,{size:"sm",onClick:()=>e("/groups/new"),children:[i.jsx(rr,{className:"w-4 h-4"}),a("settings.addGroup")]})]})}),i.jsx(Pt,{children:kf?i.jsx("div",{className:"flex items-center justify-center py-8",children:i.jsx(lt,{className:"w-6 h-6 text-bambu-green animate-spin"})}):za.length===0?i.jsx("p",{className:"text-center text-bambu-gray py-8",children:a("settings.noGroupsFound")}):i.jsx("div",{className:"divide-y divide-bambu-dark-tertiary",children:za.map(Se=>i.jsxs("div",{className:"py-3",children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(AD,{className:`w-4 h-4 ${Se.name==="Administrators"?"text-purple-400":Se.name==="Operators"?"text-blue-400":Se.name==="Viewers"?"text-green-400":"text-bambu-gray"}`}),i.jsx("span",{className:"text-white font-medium",children:Se.name}),Se.is_system&&i.jsx("span",{className:"px-2 py-0.5 rounded text-xs bg-yellow-500/20 text-yellow-400",children:a("settings.system")})]}),i.jsxs("div",{className:"flex items-center gap-1",children:[bi("groups:update")&&i.jsx(Oe,{size:"sm",variant:"ghost",onClick:()=>e(`/groups/${Se.id}/edit`),children:i.jsx(Mm,{className:"w-4 h-4"})}),bi("groups:delete")&&!Se.is_system&&i.jsx(Oe,{size:"sm",variant:"ghost",onClick:()=>sn(Se.id),children:i.jsx(Qt,{className:"w-4 h-4"})})]})]}),i.jsx("p",{className:"text-sm text-bambu-gray mt-1 ml-6",children:Se.description||a("settings.noDescription")}),i.jsxs("div",{className:"flex items-center gap-4 mt-2 ml-6 text-xs text-bambu-gray",children:[i.jsx("span",{children:a("settings.userCount",{count:Se.user_count})}),i.jsx("span",{children:a("settings.permissionCount",{count:Se.permissions.length})})]})]},Se.id))})})]})})]}),!l&&i.jsx(Tt,{children:i.jsx(Pt,{className:"py-6",children:i.jsxs("div",{className:"text-center",children:[i.jsx(o1,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),i.jsx("h3",{className:"text-lg font-medium text-white mb-2",children:a("settings.authDisabledTitle")}),i.jsx("p",{className:"text-sm text-bambu-gray mb-4 max-w-md mx-auto",children:a("settings.authDisabledMessage")}),i.jsxs("ul",{className:"space-y-2 text-sm text-bambu-gray mb-6 text-left max-w-xs mx-auto",children:[i.jsxs("li",{className:"flex items-start gap-2",children:[i.jsx(pr,{className:"w-4 h-4 text-bambu-green mt-0.5 flex-shrink-0"}),i.jsx("span",{children:a("settings.authDisabledFeature1")})]}),i.jsxs("li",{className:"flex items-start gap-2",children:[i.jsx(pr,{className:"w-4 h-4 text-bambu-green mt-0.5 flex-shrink-0"}),i.jsx("span",{children:a("settings.authDisabledFeature2")})]}),i.jsxs("li",{className:"flex items-start gap-2",children:[i.jsx(pr,{className:"w-4 h-4 text-bambu-green mt-0.5 flex-shrink-0"}),i.jsx("span",{children:a("settings.authDisabledFeature3")})]})]}),i.jsxs(Oe,{onClick:()=>e("/setup"),children:[i.jsx(Jh,{className:"w-4 h-4"}),a("settings.enableAuthentication")]})]})})})]}),E==="email"&&i.jsx("div",{className:"max-w-2xl",children:i.jsx(gJe,{})})]}),Ce&&!Rr?.advanced_auth_enabled&&i.jsx("div",{className:"fixed inset-0 bg-black flex items-center justify-center z-50 p-4",onClick:()=>{Ve(!1),Bt({username:"",password:"",email:"",confirmPassword:"",role:"user",group_ids:[]})},children:i.jsxs(Tt,{className:"w-full max-w-md",onClick:Se=>Se.stopPropagation(),children:[i.jsx(qn,{children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(Sm,{className:"w-5 h-5 text-bambu-green"}),i.jsx("h2",{className:"text-lg font-semibold text-white",children:a("settings.createUser")})]}),i.jsx(Oe,{variant:"ghost",size:"sm",onClick:()=>{Ve(!1),Bt({username:"",password:"",email:"",confirmPassword:"",role:"user",group_ids:[]})},children:i.jsx(zt,{className:"w-5 h-5"})})]})}),i.jsxs(Pt,{children:[i.jsxs("div",{className:"space-y-4",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:a("settings.username")}),i.jsx("input",{type:"text",value:ft.username,onChange:Se=>Bt({...ft,username:Se.target.value}),className:"w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors",placeholder:a("settings.enterUsername"),autoComplete:"username"})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:a("settings.password")}),i.jsx("input",{type:"password",value:ft.password,onChange:Se=>Bt({...ft,password:Se.target.value}),className:"w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors",placeholder:a("settings.enterPassword"),autoComplete:"new-password",minLength:6})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:a("settings.confirmPassword")}),i.jsx("input",{type:"password",value:ft.confirmPassword,onChange:Se=>Bt({...ft,confirmPassword:Se.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors ${ft.confirmPassword&&ft.password!==ft.confirmPassword?"border-red-500":"border-bambu-dark-tertiary"}`,placeholder:a("settings.confirmPasswordPlaceholder"),autoComplete:"new-password",minLength:6}),ft.confirmPassword&&ft.password!==ft.confirmPassword&&i.jsx("p",{className:"text-red-400 text-xs mt-1",children:a("settings.passwordsDoNotMatch")})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:a("settings.groups")}),i.jsxs("div",{className:"space-y-2 max-h-40 overflow-y-auto p-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg",children:[za.map(Se=>i.jsxs("label",{className:"flex items-center gap-3 px-2 py-1.5 rounded hover:bg-bambu-dark-tertiary cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:ft.group_ids.includes(Se.id),onChange:()=>pc(Se.id),className:"w-4 h-4 rounded border-bambu-gray text-bambu-green focus:ring-bambu-green focus:ring-offset-0 bg-bambu-dark"}),i.jsx("span",{className:"text-sm text-white",children:Se.name}),Se.is_system&&i.jsx("span",{className:"text-xs text-yellow-400",children:a("settings.systemBadge")})]},Se.id)),za.length===0&&i.jsx("p",{className:"text-sm text-bambu-gray",children:a("settings.noGroupsAvailable")})]})]})]}),i.jsxs("div",{className:"mt-6 flex justify-end gap-3",children:[i.jsx(Oe,{variant:"secondary",onClick:()=>{Ve(!1),Bt({username:"",password:"",email:"",confirmPassword:"",role:"user",group_ids:[]})},children:a("common.cancel")}),i.jsx(Oe,{onClick:Rl,disabled:mc.isPending||!ft.username||!ft.password||ft.password!==ft.confirmPassword||ft.password.length<6,children:mc.isPending?i.jsxs(i.Fragment,{children:[i.jsx(lt,{className:"w-4 h-4 animate-spin"}),a("settings.creating")]}):i.jsxs(i.Fragment,{children:[i.jsx(rr,{className:"w-4 h-4"}),a("settings.createUser")]})})]})]})]})}),Ce&&Rr?.advanced_auth_enabled&&i.jsx(rJe,{formData:ft,setFormData:Bt,groups:za,onClose:()=>{Ve(!1),Bt({username:"",password:"",email:"",confirmPassword:"",role:"user",group_ids:[]})},onCreate:Rl,isCreating:mc.isPending,isCreateButtonDisabled:mc.isPending||!ft.username||!ft.email}),je&&ve!==null&&i.jsx("div",{className:"fixed inset-0 bg-black flex items-center justify-center z-50 p-4",onClick:()=>{Re(!1),Ge(null),Bt({username:"",password:"",email:"",confirmPassword:"",role:"user",group_ids:[]})},children:i.jsxs(Tt,{className:"w-full max-w-md",onClick:Se=>Se.stopPropagation(),children:[i.jsx(qn,{children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(Mm,{className:"w-5 h-5 text-bambu-green"}),i.jsx("h2",{className:"text-lg font-semibold text-white",children:a("settings.editUser")})]}),i.jsx(Oe,{variant:"ghost",size:"sm",onClick:()=>{Re(!1),Ge(null),Bt({username:"",password:"",email:"",confirmPassword:"",role:"user",group_ids:[]})},children:i.jsx(zt,{className:"w-5 h-5"})})]})}),i.jsxs(Pt,{children:[i.jsxs("div",{className:"space-y-4",children:[i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm font-medium text-white mb-2",children:[a("settings.username")," ",Rr?.advanced_auth_enabled&&i.jsx("span",{className:"text-red-400",children:"*"})]}),i.jsx("input",{type:"text",value:ft.username,onChange:Se=>Bt({...ft,username:Se.target.value}),className:"w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors",placeholder:a("settings.enterUsername"),autoComplete:"username"})]}),i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm font-medium text-white mb-2",children:[a("users.form.email")||"Email"," ",Rr?.advanced_auth_enabled?i.jsx("span",{className:"text-red-400",children:"*"}):i.jsxs("span",{className:"text-bambu-gray font-normal",children:["(",a("users.form.optional")||"optional",")"]})]}),i.jsx("input",{type:"email",value:ft.email,onChange:Se=>Bt({...ft,email:Se.target.value}),className:"w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors",placeholder:a("users.form.emailPlaceholder")||"user@example.com",required:Rr?.advanced_auth_enabled})]}),!Rr?.advanced_auth_enabled&&i.jsxs(i.Fragment,{children:[i.jsxs("div",{children:[i.jsxs("label",{className:"block text-sm font-medium text-white mb-2",children:[a("users.form.password")||"Password"," ",i.jsxs("span",{className:"text-bambu-gray font-normal",children:["(",a("users.form.leaveBlankToKeep")||"leave blank to keep current",")"]})]}),i.jsx("input",{type:"password",value:ft.password,onChange:Se=>Bt({...ft,password:Se.target.value,confirmPassword:""}),className:"w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors",placeholder:a("settings.enterNewPassword"),autoComplete:"new-password",minLength:6})]}),ft.password&&i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:a("settings.confirmPassword")}),i.jsx("input",{type:"password",value:ft.confirmPassword,onChange:Se=>Bt({...ft,confirmPassword:Se.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors ${ft.confirmPassword&&ft.password!==ft.confirmPassword?"border-red-500":"border-bambu-dark-tertiary"}`,placeholder:a("settings.confirmNewPassword"),autoComplete:"new-password",minLength:6}),ft.confirmPassword&&ft.password!==ft.confirmPassword&&i.jsx("p",{className:"text-red-400 text-xs mt-1",children:a("settings.passwordsDoNotMatch")})]})]}),Rr?.advanced_auth_enabled&&i.jsxs("div",{className:"bg-bambu-dark-secondary/50 border border-bambu-green/20 rounded-lg p-3 space-y-3",children:[i.jsx("p",{className:"text-sm text-bambu-gray",children:a("users.form.passwordManagedByAdvancedAuth")||'Password is managed by Advanced Authentication. Use "Reset Password" to send a new password to the user via email.'}),i.jsx(Oe,{variant:"secondary",size:"sm",onClick:()=>ve&&Ns.mutate(ve),disabled:Ns.isPending||!ft.email,className:"w-full",children:Ns.isPending?i.jsxs(i.Fragment,{children:[i.jsx(lt,{className:"w-4 h-4 animate-spin"}),a("users.form.resettingPassword")||"Resetting Password..."]}):i.jsxs(i.Fragment,{children:[i.jsx(mo,{className:"w-4 h-4"}),a("users.form.resetPassword")||"Reset Password"]})})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:a("users.form.groups")||"Groups"}),i.jsx("div",{className:"space-y-2 max-h-40 overflow-y-auto p-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg",children:za.map(Se=>i.jsxs("label",{className:"flex items-center gap-3 px-2 py-1.5 rounded hover:bg-bambu-dark-tertiary cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:ft.group_ids.includes(Se.id),onChange:()=>pc(Se.id),className:"w-4 h-4 rounded border-bambu-gray text-bambu-green focus:ring-bambu-green focus:ring-offset-0 bg-bambu-dark"}),i.jsx("span",{className:"text-sm text-white",children:Se.name}),Se.is_system&&i.jsxs("span",{className:"text-xs text-yellow-400",children:["(",a("users.system")||"System",")"]})]},Se.id))})]})]}),i.jsxs("div",{className:"mt-6 flex justify-end gap-3",children:[i.jsx(Oe,{variant:"secondary",onClick:()=>{Re(!1),Ge(null),Bt({username:"",password:"",email:"",confirmPassword:"",role:"user",group_ids:[]})},children:a("users.modal.cancel")||"Cancel"}),i.jsx(Oe,{onClick:()=>Cf(ve),disabled:hc.isPending||!ft.username||Rr?.advanced_auth_enabled&&!ft.email||!!(!Rr?.advanced_auth_enabled&&ft.password&&(ft.password!==ft.confirmPassword||ft.password.length<6)),children:hc.isPending?i.jsxs(i.Fragment,{children:[i.jsx(lt,{className:"w-4 h-4 animate-spin"}),a("users.modal.saving")||"Saving..."]}):i.jsxs(i.Fragment,{children:[i.jsx(gs,{className:"w-4 h-4"}),a("users.modal.saveChanges")||"Save Changes"]})})]})]})]})}),rt!==null&&i.jsx("div",{className:"fixed inset-0 bg-black/80 flex items-center justify-center z-50 p-4",onClick:()=>{vt(null),kt(null)},children:i.jsxs(Tt,{className:"w-full max-w-md",onClick:Se=>Se.stopPropagation(),children:[i.jsx(qn,{children:i.jsxs("div",{className:"flex items-center gap-2 text-red-400",children:[i.jsx(Qt,{className:"w-5 h-5"}),i.jsx("h3",{className:"text-lg font-semibold",children:a("settings.deleteUserTitle")})]})}),i.jsx(Pt,{className:"space-y-4",children:qe?i.jsx("div",{className:"flex items-center justify-center py-4",children:i.jsx("div",{className:"animate-spin rounded-full h-6 w-6 border-2 border-bambu-green border-t-transparent"})}):_t&&_t.archives+_t.queue_items+_t.library_files>0?i.jsxs(i.Fragment,{children:[i.jsx("p",{className:"text-white",children:a("settings.userHasCreated")}),i.jsxs("ul",{className:"list-disc list-inside text-bambu-gray space-y-1",children:[_t.archives>0&&i.jsxs("li",{children:[_t.archives," archive",_t.archives!==1?"s":""]}),_t.queue_items>0&&i.jsxs("li",{children:[_t.queue_items," queue item",_t.queue_items!==1?"s":""]}),_t.library_files>0&&i.jsxs("li",{children:[_t.library_files," library file",_t.library_files!==1?"s":""]})]}),i.jsx("p",{className:"text-bambu-gray text-sm",children:a("settings.userItemsQuestion")}),i.jsxs("div",{className:"flex flex-col gap-2",children:[i.jsx(Oe,{variant:"danger",onClick:()=>Yi.mutate({id:rt,deleteItems:!0}),disabled:Yi.isPending,className:"justify-center",children:a("settings.deleteUserAndItems")}),i.jsx(Oe,{variant:"secondary",onClick:()=>Yi.mutate({id:rt,deleteItems:!1}),disabled:Yi.isPending,className:"justify-center",children:a("settings.deleteUserKeepItems")}),i.jsx(Oe,{variant:"ghost",onClick:()=>{vt(null),kt(null)},disabled:Yi.isPending,className:"justify-center",children:a("common.cancel")})]})]}):i.jsxs(i.Fragment,{children:[i.jsx("p",{className:"text-white",children:a("settings.deleteUserConfirm")}),i.jsx("p",{className:"text-bambu-gray text-sm",children:a("settings.actionCannotBeUndone")}),i.jsxs("div",{className:"flex gap-2 justify-end",children:[i.jsx(Oe,{variant:"ghost",onClick:()=>{vt(null),kt(null)},disabled:Yi.isPending,children:a("common.cancel")}),i.jsx(Oe,{variant:"danger",onClick:()=>Yi.mutate({id:rt,deleteItems:!1}),disabled:Yi.isPending,children:a("settings.deleteUserTitle")})]})]})})]})}),tn!==null&&i.jsx(_n,{title:a("settings.deleteGroupTitle"),message:a("settings.deleteGroupMessage"),confirmText:a("settings.deleteGroup"),variant:"danger",onConfirm:()=>{Vs.mutate(tn),sn(null)},onCancel:()=>sn(null)}),q==="backup"&&i.jsx(hJe,{}),Ue&&i.jsx(_n,{title:a("settings.disableAuthenticationTitle"),message:a("settings.disableAuthenticationMessage"),confirmText:a("settings.disableAuthentication"),variant:"danger",onConfirm:async()=>{try{await fe.disableAuth(),o(a("settings.toast.authDisabled"),"success"),await d(),$e(!1),window.location.href="/"}catch(Se){const Dt=Se instanceof Error?Se.message:a("settings.toast.authDisableFailed");o(Dt,"error")}},onCancel:()=>$e(!1)}),Fe&&i.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",onClick:()=>{ke(!1),Ne({currentPassword:"",newPassword:"",confirmPassword:""})},children:i.jsxs(Tt,{className:"w-full max-w-md",onClick:Se=>Se.stopPropagation(),children:[i.jsx(qn,{children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(sl,{className:"w-5 h-5 text-bambu-green"}),i.jsx("h2",{className:"text-lg font-semibold text-white",children:a("settings.changePassword")})]}),i.jsx(Oe,{variant:"ghost",size:"sm",onClick:()=>{ke(!1),Ne({currentPassword:"",newPassword:"",confirmPassword:""})},children:i.jsx(zt,{className:"w-5 h-5"})})]})}),i.jsxs(Pt,{children:[i.jsxs("div",{className:"space-y-4",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:"Current Password"}),i.jsx("input",{type:"password",value:Me.currentPassword,onChange:Se=>Ne({...Me,currentPassword:Se.target.value}),className:"w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors",placeholder:a("settings.enterCurrentPassword"),autoComplete:"current-password"})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:"New Password"}),i.jsx("input",{type:"password",value:Me.newPassword,onChange:Se=>Ne({...Me,newPassword:Se.target.value}),className:"w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors",placeholder:a("settings.enterNewPasswordMin6"),autoComplete:"new-password",minLength:6})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:"Confirm New Password"}),i.jsx("input",{type:"password",value:Me.confirmPassword,onChange:Se=>Ne({...Me,confirmPassword:Se.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors ${Me.confirmPassword&&Me.newPassword!==Me.confirmPassword?"border-red-500":"border-bambu-dark-tertiary"}`,placeholder:a("settings.confirmNewPassword"),autoComplete:"new-password",minLength:6}),Me.confirmPassword&&Me.newPassword!==Me.confirmPassword&&i.jsx("p",{className:"text-red-400 text-xs mt-1",children:a("settings.passwordsDoNotMatch")})]})]}),i.jsxs("div",{className:"mt-6 flex justify-end gap-3",children:[i.jsx(Oe,{variant:"secondary",onClick:()=>{ke(!1),Ne({currentPassword:"",newPassword:"",confirmPassword:""})},children:a("common.cancel")}),i.jsx(Oe,{onClick:async()=>{if(Me.newPassword!==Me.confirmPassword){o(a("settings.toast.passwordsDoNotMatch"),"error");return}if(Me.newPassword.length<6){o(a("settings.toast.passwordTooShort"),"error");return}We(!0);try{await fe.changePassword(Me.currentPassword,Me.newPassword),o(a("settings.toast.passwordChanged"),"success"),ke(!1),Ne({currentPassword:"",newPassword:"",confirmPassword:""})}catch(Se){const Dt=Se instanceof Error?Se.message:"Failed to change password";o(Dt,"error")}finally{We(!1)}},disabled:Pe||!Me.currentPassword||!Me.newPassword||Me.newPassword!==Me.confirmPassword||Me.newPassword.length<6,children:Pe?i.jsxs(i.Fragment,{children:[i.jsx(lt,{className:"w-4 h-4 animate-spin"}),a("settings.changing")]}):i.jsxs(i.Fragment,{children:[i.jsx(sl,{className:"w-4 h-4"}),a("settings.changePassword")]})})]})]})]})})]})}const Mse=t=>{const e=parseFloat(t);return(Math.trunc(e*1e3)/1e3).toFixed(3)},NJe=t=>t.startsWith("HH")?"HF":"S",kJe=t=>{const e=t.match(/^([A-Z]{2}\d{2})/);return e?e[1]:"HH00"},Ese=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 Kj({profile:t,onEdit:e,onCopy:n,selectionMode:r,isSelected:a,onToggleSelect:s,note:o}){const l=NJe(t.nozzle_id),c=t.nozzle_diameter,d=()=>{r&&s?s():e()};return i.jsxs("div",{className:"flex items-center gap-2",children:[r&&i.jsx("button",{onClick:s,className:"text-bambu-gray hover:text-white transition-colors p-1",children:a?i.jsx(ho,{className:"w-4 h-4 text-bambu-green"}):i.jsx(Nl,{className:"w-4 h-4"})}),i.jsxs("button",{onClick:d,className:`flex-1 text-left px-3 py-2 bg-bambu-dark rounded hover:bg-bambu-dark-tertiary transition-colors ${a?"ring-1 ring-bambu-green":""}`,children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("span",{className:"text-bambu-green font-mono text-sm font-bold whitespace-nowrap",children:Mse(t.k_value)}),i.jsx("span",{className:"text-white text-sm truncate flex-1",title:t.name,children:t.name||"Unnamed"}),o&&i.jsx("span",{title:"Has note",children:i.jsx(JY,{className:"w-3 h-3 text-yellow-500"})}),i.jsxs("span",{className:"text-xs text-bambu-gray whitespace-nowrap",children:[l," ",c]})]}),o&&i.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&&i.jsx("button",{onClick:u=>{u.stopPropagation(),n()},className:"text-bambu-gray hover:text-white transition-colors p-1",title:"Copy profile",children:i.jsx(_l,{className:"w-4 h-4"})})]})}function Yj({profile:t,printerId:e,nozzleDiameter:n,existingProfiles:r=[],builtinFilaments:a=[],isDualNozzle:s=!1,initialNote:o="",initialNoteKey:l=null,onClose:c,onSave:d,onSaveNote:u,hasPermission:m}){const{t:p}=Mt(),{showToast:f}=hn(),[x,v]=w.useState(t?.name||""),[g,y]=w.useState(t?.k_value?Mse(t.k_value):"0.020"),[_,N]=w.useState(t?.filament_id||""),[C,T]=w.useState(t?.nozzle_id?kJe(t.nozzle_id):"HH00"),[P,k]=w.useState(t?.nozzle_diameter||n),[D,A]=w.useState(t?[t.extruder_id]:s?[0,1]:[0]),[R,$]=w.useState(!1),[U,W]=w.useState({current:0,total:0}),[O,te]=w.useState(o),ie=Kr.useMemo(()=>{const me=new Map;for(const Ee of a)me.set(Ee.filament_id,Ee.name);const we=new Map;for(const Ee of r)if(Ee.filament_id&&!we.has(Ee.filament_id)){const K=me.get(Ee.filament_id)||Ese(Ee.name||"");we.set(Ee.filament_id,{id:Ee.filament_id,name:K||Ee.filament_id})}return Array.from(we.values()).sort((Ee,q)=>Ee.name.localeCompare(q.name))},[r,a]),Y=dt({mutationFn:me=>(console.log("[KProfile] Calling API..."),fe.setKProfile(e,me)),onSuccess:me=>{if(console.log("[KProfile] Save success:",me),f(p("kProfiles.toast.profileSaved")),u&&O!==o){let we;O===""&&l?we=l:t&&t.slot_id>0?we=t.setting_id||`slot_${t.slot_id}_${t.filament_id}_${t.extruder_id}`:we=`name_${x}_${_}`,u(we,O)}$(!0),setTimeout(()=>{$(!1),d()},2500)},onError:me=>{console.error("[KProfile] Save error:",me),f(me.message,"error"),$(!1)}}),ae=dt({mutationFn:me=>(console.log("[KProfile] Deleting profile..."),fe.deleteKProfile(e,me)),onSuccess:me=>{console.log("[KProfile] Delete success:",me),f(p("kProfiles.toast.profileDeleted")),$(!0),setTimeout(()=>{$(!1),c()},4e3)},onError:me=>{console.error("[KProfile] Delete error:",me),f(me.message,"error"),$(!1)}}),[de,pe]=w.useState(!1),Q=()=>{t&&ae.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})},oe=async me=>{if(me.preventDefault(),s&&!t&&D.length===0){f(p("kProfiles.toast.selectAtLeastOneExtruder"),"error");return}const we=parseFloat(g).toFixed(6),Ee=`${C}-${P}`;if(t||D.length===1){const K={name:x,k_value:we,filament_id:_,nozzle_id:Ee,nozzle_diameter:P,extruder_id:t?t.extruder_id:D[0],setting_id:t?.setting_id,slot_id:t?.slot_id??0};console.log("[KProfile] Saving profile:",K),Y.mutate(K);return}$(!0),W({current:1,total:D.length});const q=D.map(K=>({name:x,k_value:we,filament_id:_,nozzle_id:Ee,nozzle_diameter:P,extruder_id:K,setting_id:void 0,slot_id:0}));console.log(`[KProfile] Saving ${q.length} profiles in batch:`,q);try{if(await fe.setKProfilesBatch(e,q),f(p("kProfiles.toast.profilesSaved",{count:D.length})),u&&O){const K=`name_${x}_${_}`;u(K,O)}}catch(K){console.error("[KProfile] Failed to save batch:",K),f(p("kProfiles.toast.failedToSaveBatch"),"error"),$(!1),W({current:0,total:0});return}W({current:D.length,total:D.length}),setTimeout(()=>{$(!1),W({current:0,total:0}),d()},3e3)};return i.jsxs("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",children:[i.jsxs(Tt,{className:"w-full max-w-md relative",children:[R&&i.jsxs("div",{className:"absolute inset-0 bg-bambu-dark-secondary/90 flex flex-col items-center justify-center z-10 rounded-lg",children:[i.jsx(lt,{className:"w-8 h-8 text-bambu-green animate-spin mb-3"}),i.jsx("p",{className:"text-white font-medium",children:U.total>1?p("kProfiles.modal.savingExtruder",{current:U.current,total:U.total}):p("kProfiles.modal.syncing")}),i.jsx("p",{className:"text-bambu-gray text-sm mt-1",children:p("kProfiles.modal.pleaseWait")})]}),i.jsxs(Pt,{className:"p-0",children:[i.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[i.jsx("h2",{className:"text-xl font-semibold text-white",children:p(t?"kProfiles.modal.editTitle":"kProfiles.modal.addTitle")}),i.jsx("button",{onClick:c,className:"text-bambu-gray hover:text-white transition-colors",disabled:R,children:i.jsx(zt,{className:"w-5 h-5"})})]}),i.jsxs("form",{onSubmit:oe,className:"p-4 space-y-4",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:p("kProfiles.modal.profileName")}),i.jsx("input",{type:"text",value:x,onChange:me=>v(me.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:p("kProfiles.modal.profileNamePlaceholder"),required:!t})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:p("kProfiles.modal.kValue")}),i.jsx("input",{type:"text",inputMode:"decimal",value:g,onChange:me=>{const we=me.target.value;(we===""||/^\d*\.?\d*$/.test(we))&&y(we)},onBlur:me=>{const we=parseFloat(me.target.value);isNaN(we)||y((Math.trunc(we*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:p("kProfiles.modal.kValuePlaceholder"),required:!0}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:p("kProfiles.modal.kValueHelp")})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:p("kProfiles.modal.filament")}),i.jsxs("select",{value:_,onChange:me=>{const we=me.target.value;if(N(we),!t&&we&&!x){const Ee=ie.find(q=>q.id===we);Ee&&v(`${C==="HH00"?"HF":"S"} ${Ee.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:[i.jsx("option",{value:"",children:p("kProfiles.modal.selectFilament")}),t?.filament_id&&i.jsx("option",{value:t.filament_id,children:ie.find(me=>me.id===t.filament_id)?.name||t.filament_id},t.filament_id),!t&&ie.map(me=>i.jsx("option",{value:me.id,children:me.name},me.id))]}),!t&&ie.length===0&&i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:p("kProfiles.modal.noFilamentsHelp")})]}),i.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:p("kProfiles.modal.flowType")}),i.jsxs("select",{value:C,onChange:me=>{const we=me.target.value;if(T(we),!t&&_&&!x){const Ee=ie.find(q=>q.id===_);Ee&&v(`${we==="HS00"?"HF":"S"} ${Ee.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:[i.jsx("option",{value:"HH00",children:p("kProfiles.modal.highFlow")}),i.jsx("option",{value:"HS00",children:p("kProfiles.modal.standard")})]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:p("kProfiles.modal.nozzleSize")}),i.jsxs("select",{value:P,onChange:me=>k(me.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:[i.jsx("option",{value:"0.2",children:"0.2mm"}),i.jsx("option",{value:"0.4",children:"0.4mm"}),i.jsx("option",{value:"0.6",children:"0.6mm"}),i.jsx("option",{value:"0.8",children:"0.8mm"})]})]})]}),s&&i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:p(t?"kProfiles.modal.extruder":"kProfiles.modal.extruders")}),t?i.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?p("kProfiles.modal.left"):p("kProfiles.modal.right")}):i.jsxs("div",{className:"flex gap-4",children:[i.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:D.includes(1),onChange:me=>{me.target.checked?A([...D,1]):A(D.filter(we=>we!==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"}),i.jsx("span",{className:"text-white",children:p("kProfiles.modal.left")})]}),i.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[i.jsx("input",{type:"checkbox",checked:D.includes(0),onChange:me=>{me.target.checked?A([...D,0]):A(D.filter(we=>we!==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"}),i.jsx("span",{className:"text-white",children:p("kProfiles.modal.right")})]})]})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:p("kProfiles.modal.notes")}),i.jsx("textarea",{value:O,onChange:me=>te(me.target.value),placeholder:p("kProfiles.modal.notesPlaceholder"),rows:2,className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none resize-none"}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:p("kProfiles.modal.notesHelp")})]}),i.jsxs("div",{className:"flex gap-2 pt-4",children:[t&&i.jsx(Oe,{type:"button",variant:"secondary",onClick:()=>pe(!0),disabled:ae.isPending||R||!m("kprofiles:delete"),title:m("kprofiles:delete")?void 0:p("kProfiles.permission.noDelete"),className:"text-red-500 hover:bg-red-500/10",children:ae.isPending?i.jsx(lt,{className:"w-4 h-4 animate-spin"}):i.jsx(Qt,{className:"w-4 h-4"})}),i.jsx(Oe,{type:"button",variant:"secondary",onClick:c,disabled:R,className:"flex-1",children:p("common.cancel")}),i.jsxs(Oe,{type:"submit",disabled:Y.isPending||R||!m(t?"kprofiles:update":"kprofiles:create"),title:m(t?"kprofiles:update":"kprofiles:create")?void 0:p(t?"kProfiles.permission.noUpdate":"kProfiles.permission.noCreate"),className:"flex-1",children:[Y.isPending?i.jsx(lt,{className:"w-4 h-4 animate-spin"}):i.jsx(cC,{className:"w-4 h-4"}),p("common.save")]})]})]})]})]}),de&&i.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-[60]",children:i.jsx(Tt,{className:"w-full max-w-sm",children:i.jsxs(Pt,{className:"p-6",children:[i.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[i.jsx("div",{className:"w-10 h-10 rounded-full bg-red-500/20 flex items-center justify-center",children:i.jsx(Qt,{className:"w-5 h-5 text-red-500"})}),i.jsxs("div",{children:[i.jsx("h3",{className:"text-lg font-semibold text-white",children:p("kProfiles.deleteConfirm.title")}),i.jsx("p",{className:"text-sm text-bambu-gray",children:p("kProfiles.deleteConfirm.cannotUndo")})]})]}),i.jsx("p",{className:"text-bambu-gray mb-6",children:p("kProfiles.deleteConfirm.message",{name:t?.name})}),i.jsxs("div",{className:"flex gap-3",children:[i.jsx(Oe,{variant:"secondary",onClick:()=>pe(!1),className:"flex-1",children:p("common.cancel")}),i.jsxs(Oe,{onClick:()=>{pe(!1),Q()},disabled:ae.isPending,className:"flex-1 bg-red-500 hover:bg-red-600 text-white",children:[ae.isPending?i.jsx(lt,{className:"w-4 h-4 animate-spin"}):i.jsx(Qt,{className:"w-4 h-4"}),p("common.delete")]})]})]})})})]})}const i1={NOZZLE_DIAMETER:"bambusy_kprofiles_nozzle",SORT_OPTION:"bambusy_kprofiles_sort"};function CJe(){const{t}=Mt(),{showToast:e}=hn(),{hasPermission:n}=Dr(),[r,a]=w.useState(null),[s,o]=w.useState(()=>localStorage.getItem(i1.NOZZLE_DIAMETER)||"0.4"),[l,c]=w.useState(null),[d,u]=w.useState(!1),[m,p]=w.useState(null),[f,x]=w.useState(""),[v,g]=w.useState("all"),[y,_]=w.useState("all"),[N,C]=w.useState(()=>localStorage.getItem(i1.SORT_OPTION)||"name"),[T,P]=w.useState(!1),[k,D]=w.useState(new Set),[A,R]=w.useState(!1),[$,U]=w.useState(!1),W=w.useCallback(F=>`${F.slot_id}_${F.extruder_id}`,[]);w.useEffect(()=>{localStorage.setItem(i1.NOZZLE_DIAMETER,s)},[s]),w.useEffect(()=>{localStorage.setItem(i1.SORT_OPTION,N)},[N]);const{data:O,isLoading:te}=Ze({queryKey:["printers"],queryFn:fe.getPrinters}),{data:ie,isLoading:Y,isFetching:ae,error:de,refetch:pe}=Ze({queryKey:["kprofiles",r,s],queryFn:async()=>{console.log("[KProfiles] Fetching profiles for printer",r,"nozzle",s);const F=await fe.getKProfiles(r,s);return console.log("[KProfiles] Received profiles:",F?.profiles?.length||0,"profiles"),F},enabled:!!r,retry:!1,staleTime:0,gcTime:0,refetchOnMount:"always"}),{data:Q}=Ze({queryKey:["kprofiles",r,"0.4"],queryFn:()=>fe.getKProfiles(r,"0.4"),enabled:!!r,staleTime:6e4}),{data:oe}=Ze({queryKey:["builtinFilaments"],queryFn:()=>fe.getBuiltinFilaments(),staleTime:3e5}),{data:me}=Ze({queryKey:["filamentIdMap"],queryFn:()=>fe.getFilamentIdMap(),staleTime:3e5}),{data:we,refetch:Ee}=Ze({queryKey:["kprofile-notes",r],queryFn:()=>fe.getKProfileNotes(r),enabled:!!r,staleTime:3e4}),q=de?.message?.includes("not connected");w.useEffect(()=>{if(!r&&O&&O.length>0){const F=O.find(Z=>Z.is_active);F&&a(F.id)}},[r,O]),w.useEffect(()=>{if(r){const F=setTimeout(()=>{pe()},150);return()=>clearTimeout(F)}},[r,s]);const K=O?.filter(F=>F.is_active)||[],E=Kr.useMemo(()=>{const F=new Map;if(oe)for(const Z of oe)F.set(Z.filament_id,Z.name);if(me)for(const[Z,xe]of Object.entries(me))F.has(Z)||F.set(Z,xe);return F},[oe,me]),j=Kr.useMemo(()=>Array.from(E.entries()).map(([F,Z])=>({filament_id:F,name:Z})),[E]),L=Kr.useCallback(F=>E.get(F.filament_id)||Ese(F.name),[E]),G=Kr.useMemo(()=>ie?.profiles?ie.profiles.filter(Z=>{const xe=f.toLowerCase(),he=!xe||Z.name.toLowerCase().includes(xe)||Z.filament_id.toLowerCase().includes(xe),ce=v==="all"||v==="left"&&Z.extruder_id===1||v==="right"&&Z.extruder_id===0,Ae=y==="all"||y==="hf"&&Z.nozzle_id.startsWith("HH")||y==="s"&&Z.nozzle_id.startsWith("HS");return he&&ce&&Ae}).sort((Z,xe)=>{switch(N){case"k_value":return parseFloat(Z.k_value)-parseFloat(xe.k_value);case"filament":return L(Z).localeCompare(L(xe));default:return Z.name.localeCompare(xe.name)}}):[],[ie?.profiles,f,v,y,N,L]),B=O?.find(F=>F.id===r),re=B?.nozzle_count===2;w.useEffect(()=>{const F=Z=>{Z.target instanceof HTMLInputElement||Z.target instanceof HTMLTextAreaElement||Z.target instanceof HTMLSelectElement||l||d||m||(Z.key==="r"||Z.key==="R"?(Z.preventDefault(),pe()):Z.key==="n"||Z.key==="N"?(Z.preventDefault(),u(!0)):Z.key==="Escape"&&T&&(Z.preventDefault(),P(!1),D(new Set)))};return window.addEventListener("keydown",F),()=>window.removeEventListener("keydown",F)},[l,d,m,T,pe]);const z=w.useCallback(()=>{if(!ie?.profiles||ie.profiles.length===0){e(t("kProfiles.toast.noProfilesToExport"),"error");return}const F={version:1,exported_at:new Date().toISOString(),printer:B?.name||"Unknown",nozzle_diameter:s,profiles:ie.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}))},Z=new Blob([JSON.stringify(F,null,2)],{type:"application/json"}),xe=URL.createObjectURL(Z),he=document.createElement("a");he.href=xe,he.download=`kprofiles_${B?.name||"printer"}_${s}mm_${new Date().toISOString().split("T")[0]}.json`,document.body.appendChild(he),he.click(),document.body.removeChild(he),URL.revokeObjectURL(xe),e(t("kProfiles.toast.exportedProfiles",{count:ie.profiles.length}))},[ie?.profiles,B,s,e,t]),V=w.useCallback(()=>{const F=document.createElement("input");F.type="file",F.accept=".json",F.onchange=async Z=>{const xe=Z.target.files?.[0];if(xe)try{const he=await xe.text(),ce=JSON.parse(he);if(!ce.profiles||!Array.isArray(ce.profiles)){e(t("kProfiles.toast.invalidFileFormat"),"error");return}let Ae=0;for(const _e of ce.profiles)if(!(!_e.name||!_e.k_value||!_e.filament_id))try{await fe.setKProfile(r,{name:_e.name,k_value:parseFloat(_e.k_value).toFixed(6),filament_id:_e.filament_id,nozzle_id:_e.nozzle_id||`HH00-${s}`,nozzle_diameter:_e.nozzle_diameter||s,extruder_id:_e.extruder_id??0,slot_id:0}),Ae++,await new Promise(Ue=>setTimeout(Ue,500))}catch(Ue){console.error("Failed to import profile:",_e.name,Ue)}e(t("kProfiles.toast.importedProfiles",{count:Ae,total:ce.profiles.length})),pe()}catch(he){console.error("Import error:",he),e(t("kProfiles.toast.failedToParseImport"),"error")}},F.click()},[r,s,e,pe,t]),ee=w.useCallback(F=>{D(Z=>{const xe=new Set(Z);return xe.has(F)?xe.delete(F):xe.add(F),xe})},[]),J=w.useCallback(()=>{D(new Set(G.map(F=>W(F))))},[G,W]),ne=w.useCallback(()=>{k.size!==0&&R(!0)},[k.size]),se=w.useCallback(async()=>{const F=G.filter(xe=>k.has(W(xe)));U(!0);let Z=0;for(const xe of F)try{await fe.deleteKProfile(r,{slot_id:xe.slot_id,extruder_id:xe.extruder_id,nozzle_id:xe.nozzle_id,nozzle_diameter:xe.nozzle_diameter,filament_id:xe.filament_id,setting_id:xe.setting_id}),Z++,await new Promise(he=>setTimeout(he,300))}catch(he){console.error("Failed to delete profile:",xe.name,he)}e(t("kProfiles.toast.profilesDeleted",{count:Z})),U(!1),R(!1),P(!1),D(new Set),pe()},[r,k,G,e,pe,W,t]),ue=w.useCallback(F=>{const Z=[];return F.setting_id&&Z.push(F.setting_id),Z.push(`slot_${F.slot_id}_${F.filament_id}_${F.extruder_id}`),Z.push(`name_${F.name}_${F.filament_id}`),Z},[]),ge=w.useCallback(async(F,Z)=>{if(r)try{await fe.setKProfileNote(r,F,Z),Ee()}catch(xe){console.error("Failed to save note:",xe),e(t("kProfiles.toast.failedToSaveNote"),"error")}},[r,Ee,e,t]),le=w.useCallback(F=>{if(!we?.notes)return{note:"",key:null};const Z=ue(F);for(const xe of Z)if(we.notes[xe])return{note:we.notes[xe],key:xe};return{note:"",key:null}},[we,ue]),I=w.useCallback(F=>le(F).note,[le]);return te?i.jsx("div",{className:"flex justify-center py-12",children:i.jsx(lt,{className:"w-8 h-8 text-bambu-green animate-spin"})}):!O||O.length===0?i.jsx(Tt,{children:i.jsxs(Pt,{className:"py-12 text-center",children:[i.jsx(zi,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),i.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:t("kProfiles.noPrintersConfigured")}),i.jsx("p",{className:"text-bambu-gray",children:t("kProfiles.addPrinterInSettings")})]})}):K.length===0?i.jsx(Tt,{children:i.jsxs(Pt,{className:"py-12 text-center",children:[i.jsx(_r,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),i.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:t("kProfiles.noActivePrinters")}),i.jsx("p",{className:"text-bambu-gray",children:t("kProfiles.enablePrinterConnection")})]})}):i.jsxs(i.Fragment,{children:[ae&&!Y&&i.jsxs("div",{className:"fixed inset-0 bg-black/50 flex flex-col items-center justify-center z-40",children:[i.jsx(lt,{className:"w-10 h-10 text-bambu-green animate-spin mb-3"}),i.jsx("p",{className:"text-white font-medium",children:t("kProfiles.loadingProfiles")})]}),i.jsxs("div",{className:"flex flex-wrap gap-4 mb-6",children:[i.jsxs("div",{className:"flex-1 min-w-48",children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:t("kProfiles.printer")}),i.jsx("select",{value:r||"",onChange:F=>a(parseInt(F.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:K.map(F=>i.jsx("option",{value:F.id,children:F.name},F.id))})]}),i.jsxs("div",{className:"w-32",children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:t("kProfiles.nozzle")}),i.jsxs("select",{value:s,onChange:F=>o(F.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:[i.jsx("option",{value:"0.2",children:"0.2mm"}),i.jsx("option",{value:"0.4",children:"0.4mm"}),i.jsx("option",{value:"0.6",children:"0.6mm"}),i.jsx("option",{value:"0.8",children:"0.8mm"})]})]}),i.jsxs("div",{className:"flex items-end gap-2",children:[i.jsxs(Oe,{variant:"secondary",onClick:()=>pe(),disabled:ae||!n("kprofiles:read"),title:n("kprofiles:read")?void 0:t("kProfiles.permission.noRead"),children:[i.jsx(Sr,{className:`w-4 h-4 ${ae?"animate-spin":""}`}),t("kProfiles.refresh")]}),i.jsxs(Oe,{onClick:()=>u(!0),disabled:!n("kprofiles:create"),title:n("kprofiles:create")?void 0:t("kProfiles.permission.noCreate"),children:[i.jsx(rr,{className:"w-4 h-4"}),t("kProfiles.addProfile")]})]})]}),i.jsxs("div",{className:"flex flex-wrap gap-4 mb-4",children:[i.jsxs("div",{className:"flex-1 min-w-48 relative",children:[i.jsx(jr,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray"}),i.jsx("input",{type:"text",value:f,onChange:F=>x(F.target.value),placeholder:t("kProfiles.searchPlaceholder"),className:"w-full pl-10 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none"})]}),re&&i.jsx("div",{className:"w-36",children:i.jsxs("select",{value:v,onChange:F=>g(F.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:[i.jsx("option",{value:"all",children:t("kProfiles.allExtruders")}),i.jsx("option",{value:"left",children:t("kProfiles.leftOnly")}),i.jsx("option",{value:"right",children:t("kProfiles.rightOnly")})]})}),i.jsx("div",{className:"w-32",children:i.jsxs("select",{value:y,onChange:F=>_(F.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:[i.jsx("option",{value:"all",children:t("kProfiles.allFlow")}),i.jsx("option",{value:"hf",children:t("kProfiles.hfOnly")}),i.jsx("option",{value:"s",children:t("kProfiles.sOnly")})]})}),i.jsx("div",{className:"w-32",children:i.jsxs("select",{value:N,onChange:F=>C(F.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:[i.jsx("option",{value:"name",children:t("kProfiles.sortName")}),i.jsx("option",{value:"k_value",children:t("kProfiles.sortKValue")}),i.jsx("option",{value:"filament",children:t("kProfiles.sortFilament")})]})})]}),i.jsxs("div",{className:"flex flex-wrap gap-2 mb-6",children:[i.jsxs(Oe,{variant:"secondary",onClick:z,disabled:!ie?.profiles?.length||!n("kprofiles:read"),title:n("kprofiles:read")?void 0:t("kProfiles.permission.noExport"),children:[i.jsx(hi,{className:"w-4 h-4"}),t("kProfiles.export")]}),i.jsxs(Oe,{variant:"secondary",onClick:V,disabled:!n("kprofiles:create"),title:n("kprofiles:create")?void 0:t("kProfiles.permission.noImport"),children:[i.jsx(Si,{className:"w-4 h-4"}),t("kProfiles.import")]}),i.jsx("div",{className:"flex-1"}),T?i.jsxs(i.Fragment,{children:[i.jsxs(Oe,{variant:"secondary",onClick:J,children:[i.jsx(ho,{className:"w-4 h-4"}),t("kProfiles.selectAll")]}),i.jsxs(Oe,{variant:"secondary",onClick:ne,disabled:k.size===0||!n("kprofiles:delete"),className:"text-red-500 hover:bg-red-500/10",title:n("kprofiles:delete")?void 0:t("kProfiles.permission.noDelete"),children:[i.jsx(Qt,{className:"w-4 h-4"}),t("kProfiles.delete")," (",k.size,")"]}),i.jsxs(Oe,{variant:"secondary",onClick:()=>{P(!1),D(new Set)},children:[i.jsx(zt,{className:"w-4 h-4"}),t("common.cancel")]})]}):i.jsxs(Oe,{variant:"secondary",onClick:()=>P(!0),disabled:!G.length||!n("kprofiles:delete"),title:n("kprofiles:delete")?void 0:t("kProfiles.permission.noDelete"),children:[i.jsx(ho,{className:"w-4 h-4"}),t("kProfiles.select")]})]}),Y?i.jsx("div",{className:"flex justify-center py-12",children:i.jsx(lt,{className:"w-8 h-8 text-bambu-green animate-spin"})}):q?i.jsx(Tt,{children:i.jsxs(Pt,{className:"py-12 text-center",children:[i.jsx(rh,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),i.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:t("kProfiles.printerOffline")}),i.jsx("p",{className:"text-bambu-gray mb-4",children:t("kProfiles.printerOfflineDesc")}),i.jsxs(Oe,{variant:"secondary",onClick:()=>pe(),children:[i.jsx(Sr,{className:"w-4 h-4"}),t("common.refresh")]})]})}):G.length>0?re?i.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[i.jsxs("div",{children:[i.jsx("h3",{className:"text-sm font-medium text-bambu-gray mb-2 px-1",children:t("kProfiles.leftExtruder")}),i.jsx("div",{className:"space-y-1",children:G.filter(F=>F.extruder_id===1).map(F=>i.jsx(Kj,{profile:F,onEdit:()=>c(F),onCopy:()=>p(F),selectionMode:T,isSelected:k.has(W(F)),onToggleSelect:()=>ee(W(F)),note:I(F)},W(F)))})]}),i.jsxs("div",{children:[i.jsx("h3",{className:"text-sm font-medium text-bambu-gray mb-2 px-1",children:t("kProfiles.rightExtruder")}),i.jsx("div",{className:"space-y-1",children:G.filter(F=>F.extruder_id===0).map(F=>i.jsx(Kj,{profile:F,onEdit:()=>c(F),onCopy:()=>p(F),selectionMode:T,isSelected:k.has(W(F)),onToggleSelect:()=>ee(W(F)),note:I(F)},W(F)))})]})]}):i.jsx("div",{className:"space-y-1",children:G.map(F=>i.jsx(Kj,{profile:F,onEdit:()=>c(F),onCopy:()=>p(F),selectionMode:T,isSelected:k.has(W(F)),onToggleSelect:()=>ee(W(F)),note:I(F)},W(F)))}):f||v!=="all"||y!=="all"?i.jsx(Tt,{children:i.jsxs(Pt,{className:"py-12 text-center",children:[i.jsx(jr,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),i.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:t("kProfiles.noMatchingProfiles")}),i.jsx("p",{className:"text-bambu-gray",children:t("kProfiles.noMatchingProfilesDesc")})]})}):i.jsx(Tt,{children:i.jsxs(Pt,{className:"py-12 text-center",children:[i.jsx(cC,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),i.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:t("kProfiles.noKProfiles")}),i.jsx("p",{className:"text-bambu-gray mb-4",children:t("kProfiles.noKProfilesDesc",{diameter:s})}),i.jsxs(Oe,{onClick:()=>u(!0),children:[i.jsx(rr,{className:"w-4 h-4"}),t("kProfiles.createFirstProfile")]})]})}),l&&r&&(()=>{const{note:F,key:Z}=le(l);return i.jsx(Yj,{profile:l,printerId:r,nozzleDiameter:s,existingProfiles:Q?.profiles||ie?.profiles,builtinFilaments:j,isDualNozzle:re,initialNote:F,initialNoteKey:Z,onSaveNote:ge,hasPermission:n,onClose:()=>{console.log("[KProfiles] Edit modal onClose - refetching profiles..."),c(null),pe()},onSave:()=>{c(null),pe()}})})(),d&&r&&i.jsx(Yj,{printerId:r,nozzleDiameter:s,existingProfiles:Q?.profiles||ie?.profiles,builtinFilaments:j,isDualNozzle:re,onSaveNote:ge,hasPermission:n,onClose:()=>{u(!1),pe()},onSave:()=>{u(!1),pe()}}),m&&r&&i.jsx(Yj,{printerId:r,nozzleDiameter:s,existingProfiles:Q?.profiles||ie?.profiles,builtinFilaments:j,isDualNozzle:re,onSaveNote:ge,hasPermission:n,profile:{...m,slot_id:0,name:`${m.name} (Copy)`},onClose:()=>{p(null),pe()},onSave:()=>{p(null),pe()}}),A&&i.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",children:i.jsx(Tt,{className:"w-full max-w-sm",children:i.jsxs(Pt,{className:"p-6",children:[i.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[i.jsx("div",{className:"w-10 h-10 rounded-full bg-red-500/20 flex items-center justify-center",children:i.jsx(Qt,{className:"w-5 h-5 text-red-500"})}),i.jsxs("div",{children:[i.jsx("h3",{className:"text-lg font-semibold text-white",children:t("kProfiles.bulkDelete.title")}),i.jsx("p",{className:"text-sm text-bambu-gray",children:t("kProfiles.bulkDelete.cannotUndo")})]})]}),i.jsx("p",{className:"text-bambu-gray mb-6",children:t("kProfiles.bulkDelete.message",{count:k.size})}),i.jsxs("div",{className:"flex gap-3",children:[i.jsx(Oe,{variant:"secondary",onClick:()=>R(!1),disabled:$,className:"flex-1",children:t("common.cancel")}),i.jsxs(Oe,{onClick:se,disabled:$,className:"flex-1 bg-red-500 hover:bg-red-600 text-white",children:[$?i.jsx(lt,{className:"w-4 h-4 animate-spin"}):i.jsx(Qt,{className:"w-4 h-4"}),t("common.delete")]})]})]})})})]})}const jse=["PLA","PETG","PCTG","ABS","ASA","TPU","PC","PA","PVA","HIPS","PP","PET","NYLON"],TJe={PLA:"E8E8E8",PETG:"4A90D9",ABS:"E67E22",ASA:"D35400",TPU:"9B59B6",PC:"BDC3C7",PA:"2ECC71",NYLON:"2ECC71",PVA:"F1C40F",HIPS:"95A5A6",PP:"ECF0F1",PET:"3498DB"};function PJe(t){const e=t.toUpperCase();for(const n of jse)if(new RegExp(`\\b${n}\\b`).test(e))return n;return null}function AJe(t){const e=t.replace(/@.+$/,"").trim(),n=e.toUpperCase();for(const r of jse){const a=n.indexOf(r);if(a>0){const s=e.slice(0,a).trim();if(s&&s.length>1)return s}}return null}function Xj({preset:t,onDelete:e,onExpand:n,isExpanded:r}){const{t:a}=Mt(),{hasPermission:s}=Dr(),o=t.filament_type||PJe(t.name),l=t.filament_vendor||AJe(t.name);let c=null,d=!1;if(t.default_filament_colour)try{const u=JSON.parse(t.default_filament_colour),m=Array.isArray(u)?u[0]:u;typeof m=="string"&&/^#?[0-9a-fA-F]{6,8}$/.test(m.replace("#",""))&&(c=m.replace("#","").slice(0,6),d=!0)}catch{const u=t.default_filament_colour;/^#?[0-9a-fA-F]{6,8}$/.test(u.replace("#",""))&&(c=u.replace("#","").slice(0,6),d=!0)}return!c&&o&&(c=TJe[o.toUpperCase()]||null),i.jsx(Tt,{className:"bg-bambu-dark border-bambu-dark-tertiary hover:border-bambu-dark-tertiary/80 transition-colors",children:i.jsxs(Pt,{className:"p-3",children:[i.jsxs("div",{className:"flex items-start justify-between gap-2",children:[i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[t.preset_type==="filament"&&i.jsx("div",{className:`w-4 h-4 rounded-full border border-white/20 flex-shrink-0 ${!d&&!c?"opacity-25":d?"":"opacity-50"}`,style:{backgroundColor:c?`#${c}`:"#666"}}),i.jsx("span",{className:"text-sm font-medium text-white truncate",children:t.name})]}),i.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[o&&i.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-bambu-green/20 text-bambu-green",children:o}),l&&i.jsx("span",{className:"text-xs text-bambu-gray",children:l}),i.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-blue-500/20 text-blue-400",children:a("profiles.localProfiles.badge")})]})]}),i.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[s("settings:update")&&i.jsx("button",{onClick:()=>e(t.id),className:"p-1 text-bambu-gray hover:text-red-400 transition-colors",title:a("profiles.localProfiles.delete"),children:i.jsx(Qt,{className:"w-3.5 h-3.5"})}),i.jsx("button",{onClick:()=>n(r?null:t.id),className:"p-1 text-bambu-gray hover:text-white transition-colors",children:r?i.jsx(Sl,{className:"w-3.5 h-3.5"}):i.jsx(jn,{className:"w-3.5 h-3.5"})})]})]}),r&&i.jsxs("div",{className:"mt-3 pt-3 border-t border-bambu-dark-tertiary text-xs space-y-1.5",children:[o&&i.jsxs("div",{className:"flex justify-between",children:[i.jsx("span",{className:"text-bambu-gray",children:a("profiles.localProfiles.filamentType")}),i.jsx("span",{className:"text-white",children:o})]}),l&&i.jsxs("div",{className:"flex justify-between",children:[i.jsx("span",{className:"text-bambu-gray",children:a("profiles.localProfiles.vendor")}),i.jsx("span",{className:"text-white",children:l})]}),t.nozzle_temp_min!=null&&t.nozzle_temp_max!=null&&i.jsxs("div",{className:"flex justify-between",children:[i.jsx("span",{className:"text-bambu-gray",children:a("profiles.localProfiles.nozzleTemp")}),i.jsxs("span",{className:"text-white",children:[t.nozzle_temp_min,"–",t.nozzle_temp_max,"°C"]})]}),t.filament_cost&&i.jsxs("div",{className:"flex justify-between",children:[i.jsx("span",{className:"text-bambu-gray",children:a("profiles.localProfiles.cost")}),i.jsx("span",{className:"text-white",children:t.filament_cost})]}),t.filament_density&&i.jsxs("div",{className:"flex justify-between",children:[i.jsx("span",{className:"text-bambu-gray",children:a("profiles.localProfiles.density")}),i.jsxs("span",{className:"text-white",children:[t.filament_density," g/cm³"]})]}),t.pressure_advance&&i.jsxs("div",{className:"flex justify-between",children:[i.jsx("span",{className:"text-bambu-gray",children:a("profiles.localProfiles.pressureAdvance")}),i.jsx("span",{className:"text-white",children:t.pressure_advance})]}),t.compatible_printers&&i.jsxs("div",{className:"flex justify-between",children:[i.jsx("span",{className:"text-bambu-gray",children:a("profiles.localProfiles.compatiblePrinters")}),i.jsx("span",{className:"text-white truncate ml-2",children:(()=>{try{return JSON.parse(t.compatible_printers).join(", ")}catch{return t.compatible_printers}})()})]}),t.inherits&&t.inherits!==t.name&&i.jsxs("div",{className:"flex justify-between",children:[i.jsx("span",{className:"text-bambu-gray",children:a("profiles.localProfiles.inheritsFrom")}),i.jsx("span",{className:"text-white truncate ml-2",children:t.inherits})]}),i.jsxs("div",{className:"flex justify-between",children:[i.jsx("span",{className:"text-bambu-gray",children:a("profiles.localProfiles.source")}),i.jsx("span",{className:"text-white capitalize",children:t.source})]})]})]})})}function MJe(){const{t}=Mt(),{hasPermission:e}=Dr(),n=Zt(),{showToast:r}=hn(),[a,s]=w.useState(""),[o,l]=w.useState(null),[c,d]=w.useState(!1),[u,m]=w.useState(null),{data:p,isLoading:f}=Ze({queryKey:["localPresets"],queryFn:()=>fe.getLocalPresets()}),x=dt({mutationFn:async k=>{const D=[];for(const A of Array.from(k)){const R=new FormData;R.append("file",A),D.push(await fe.importLocalPresets(R))}return D},onSuccess:k=>{n.invalidateQueries({queryKey:["localPresets"]});let D=0,A=0,R=0;for(const $ of k)D+=$.imported,A+=$.skipped,R+=$.errors.length;D>0&&r(t("profiles.localProfiles.toast.importSuccess",{count:D})),A>0&&r(t("profiles.localProfiles.toast.importSkipped",{count:A}),"warning"),R>0&&r(t("profiles.localProfiles.toast.importError",{count:R}),"error")},onError:k=>{r(k.message,"error")}}),v=dt({mutationFn:k=>fe.deleteLocalPreset(k),onSuccess:()=>{n.invalidateQueries({queryKey:["localPresets"]}),m(null),r(t("profiles.localProfiles.toast.deleted"))}}),g=w.useCallback(k=>{!k||k.length===0||x.mutate(k)},[x]),y=w.useCallback(k=>{k.preventDefault(),d(!1),g(k.dataTransfer.files)},[g]),_=w.useCallback(k=>{if(!a)return k;const D=a.toLowerCase();return k.filter(A=>A.name.toLowerCase().includes(D)||A.filament_type?.toLowerCase().includes(D)||A.filament_vendor?.toLowerCase().includes(D))},[a]),N=w.useMemo(()=>_(p?.filament||[]),[p?.filament,_]),C=w.useMemo(()=>_(p?.printer||[]),[p?.printer,_]),T=w.useMemo(()=>_(p?.process||[]),[p?.process,_]),P=N.length+C.length+T.length;return f?i.jsx("div",{className:"flex items-center justify-center py-16",children:i.jsx(lt,{className:"w-8 h-8 text-bambu-green animate-spin"})}):i.jsxs("div",{className:"space-y-6",children:[e("settings:update")&&i.jsxs("div",{onDragOver:k=>{k.preventDefault(),d(!0)},onDragLeave:()=>d(!1),onDrop:y,className:`relative border-2 border-dashed rounded-lg p-6 text-center transition-colors ${c?"border-bambu-green bg-bambu-green/10":"border-bambu-dark-tertiary hover:border-bambu-gray"}`,children:[i.jsx("input",{type:"file",accept:".json,.zip,.orca_filament,.bbscfg,.bbsflmt",multiple:!0,className:"absolute inset-0 w-full h-full opacity-0 cursor-pointer",onChange:k=>g(k.target.files)}),x.isPending?i.jsxs("div",{className:"flex items-center justify-center gap-2",children:[i.jsx(lt,{className:"w-5 h-5 text-bambu-green animate-spin"}),i.jsx("span",{className:"text-bambu-gray",children:t("profiles.localProfiles.importing")})]}):i.jsxs(i.Fragment,{children:[i.jsx(Si,{className:"w-8 h-8 text-bambu-gray mx-auto mb-2"}),i.jsx("p",{className:"text-sm text-white font-medium",children:t("profiles.localProfiles.import")}),i.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:t("profiles.localProfiles.importDesc")})]})]}),P>0&&i.jsxs("div",{className:"relative",children:[i.jsx(jr,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray"}),i.jsx("input",{type:"text",value:a,onChange:k=>s(k.target.value),placeholder:t("profiles.localProfiles.search"),className:"w-full pl-9 pr-4 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green"})]}),P===0&&!f&&i.jsxs("div",{className:"text-center py-12",children:[i.jsx(cx,{className:"w-12 h-12 text-bambu-gray mx-auto mb-3 opacity-50"}),i.jsx("p",{className:"text-bambu-gray",children:t("profiles.localProfiles.noPresets")}),i.jsx("p",{className:"text-xs text-bambu-gray/60 mt-1",children:t("profiles.localProfiles.importDesc")})]}),P>0&&i.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6",children:[N.length>0&&i.jsxs("div",{children:[i.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[i.jsx(sC,{className:"w-4 h-4 text-bambu-green"}),i.jsx("h3",{className:"text-sm font-medium text-white",children:t("profiles.localProfiles.filament")}),i.jsxs("span",{className:"text-xs text-bambu-gray",children:["(",N.length,")"]})]}),i.jsx("div",{className:"space-y-2",children:N.map(k=>i.jsx(Xj,{preset:k,onDelete:D=>m(D),onExpand:l,isExpanded:o===k.id},k.id))})]}),T.length>0&&i.jsxs("div",{children:[i.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[i.jsx(Gi,{className:"w-4 h-4 text-blue-400"}),i.jsx("h3",{className:"text-sm font-medium text-white",children:t("profiles.localProfiles.process")}),i.jsxs("span",{className:"text-xs text-bambu-gray",children:["(",T.length,")"]})]}),i.jsx("div",{className:"space-y-2",children:T.map(k=>i.jsx(Xj,{preset:k,onDelete:D=>m(D),onExpand:l,isExpanded:o===k.id},k.id))})]}),C.length>0&&i.jsxs("div",{children:[i.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[i.jsx(cu,{className:"w-4 h-4 text-orange-400"}),i.jsx("h3",{className:"text-sm font-medium text-white",children:t("profiles.localProfiles.printer")}),i.jsxs("span",{className:"text-xs text-bambu-gray",children:["(",C.length,")"]})]}),i.jsx("div",{className:"space-y-2",children:C.map(k=>i.jsx(Xj,{preset:k,onDelete:D=>m(D),onExpand:l,isExpanded:o===k.id},k.id))})]})]}),u!==null&&i.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50",children:i.jsxs("div",{className:"bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg p-6 max-w-sm mx-4",children:[i.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[i.jsx(zi,{className:"w-5 h-5 text-red-400"}),i.jsx("h3",{className:"text-white font-medium",children:t("profiles.localProfiles.deleteConfirmTitle")})]}),i.jsx("p",{className:"text-sm text-bambu-gray mb-4",children:t("profiles.localProfiles.deleteConfirm")}),i.jsxs("div",{className:"flex justify-end gap-2",children:[i.jsx(Oe,{variant:"secondary",size:"sm",onClick:()=>m(null),children:t("profiles.localProfiles.cancel")}),i.jsxs(Oe,{variant:"danger",size:"sm",onClick:()=>v.mutate(u),disabled:v.isPending,children:[v.isPending?i.jsx(lt,{className:"w-4 h-4 animate-spin"}):i.jsx(Qt,{className:"w-4 h-4"}),t("profiles.localProfiles.delete")]})]})]})})]})}function EI(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),a=r?r[1].trim():null,s=n.match(/(\d+\.?\d*)\s*(?:mm\s*)?nozzle|nozzle\s*(\d+\.?\d*)/i),o=s?(s[1]||s[2])+"mm":null,l=n.match(/(\d+\.?\d*)mm\s*(?:Standard|Fine|Extra Fine|Draft|Quality)?/i),c=l?l[1]+"mm":null,d=n.match(/\b(PLA|PETG|ABS|ASA|TPU|PC|PA|PVA|HIPS|PP|PET(?:-?CF)?|PA(?:-?CF)?|PLA(?:-?CF)?)\b/i),u=d?d[1].toUpperCase():null;return{printer:a,nozzle:o,layerHeight:c,filamentType:u}}function C0(t){return/^(P[FPM]US|PF\d|PP\d)/.test(t)}function EJe({onSuccess:t,t:e}){const{showToast:n}=hn(),[r,a]=w.useState("email"),[s,o]=w.useState(""),[l,c]=w.useState(""),[d,u]=w.useState(""),[m,p]=w.useState(""),[f,x]=w.useState("global"),[v,g]=w.useState(null),[y,_]=w.useState(null),N=dt({mutationFn:()=>fe.cloudLogin(s,l,f),onSuccess:D=>{D.success?(n(e("profiles.login.toast.loggedIn")),t()):D.needs_verification?(g(D.verification_type||"email"),_(D.tfa_key||null),D.verification_type==="totp"?n(e("profiles.login.toast.enterTotp")):n(e("profiles.login.toast.codeSent")),a("code")):n(D.message,"error")},onError:D=>n(D.message,"error")}),C=dt({mutationFn:()=>fe.cloudVerify(s,d,y||void 0),onSuccess:D=>{D.success?(n(e("profiles.login.toast.loggedIn")),t()):n(D.message,"error")},onError:D=>n(D.message,"error")}),T=dt({mutationFn:()=>fe.cloudSetToken(m),onSuccess:()=>{n(e("profiles.login.toast.tokenSet")),t()},onError:D=>n(D.message,"error")}),P=D=>{D.preventDefault(),r==="email"?N.mutate():r==="code"?C.mutate():r==="token"&&T.mutate()},k=N.isPending||C.isPending||T.isPending;return i.jsx(Tt,{className:"max-w-md mx-auto",children:i.jsxs(Pt,{children:[i.jsxs("div",{className:"text-center mb-6",children:[i.jsx("div",{className:"inline-flex items-center justify-center w-12 h-12 rounded-xl bg-bambu-green/20 mb-3",children:i.jsx(lx,{className:"w-6 h-6 text-bambu-green"})}),i.jsx("h2",{className:"text-xl font-semibold text-white",children:e("profiles.login.title")}),i.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:e("profiles.login.subtitle")})]}),i.jsxs("form",{onSubmit:P,className:"space-y-4",children:[r==="email"&&i.jsxs(i.Fragment,{children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:e("profiles.login.email")}),i.jsx("input",{type:"email",value:s,onChange:D=>o(D.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})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:e("profiles.login.password")}),i.jsx("input",{type:"password",value:l,onChange:D=>c(D.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})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:e("profiles.login.region")}),i.jsxs("select",{value:f,onChange:D=>x(D.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:[i.jsx("option",{value:"global",children:e("profiles.login.regionGlobal")}),i.jsx("option",{value:"china",children:e("profiles.login.regionChina")})]})]})]}),r==="code"&&i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:e(v==="totp"?"profiles.login.totpCode":"profiles.login.verificationCode")}),i.jsx("p",{className:"text-xs text-bambu-gray mb-2",children:v==="totp"?e("profiles.login.enterTotpHint"):e("profiles.login.checkEmail",{email:s})}),i.jsx("input",{type:"text",value:d,onChange:D=>u(D.target.value.replace(/\D/g,"").slice(0,6)),className:"w-full px-3 py-3 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-center text-2xl tracking-widest font-mono focus:border-bambu-green focus:outline-none",placeholder:"000000",maxLength:6,required:!0})]}),r==="token"&&i.jsxs("div",{children:[i.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:e("profiles.login.accessToken")}),i.jsx("p",{className:"text-xs text-bambu-gray mb-2",children:e("profiles.login.accessTokenHint")}),i.jsx("textarea",{value:m,onChange:D=>p(D.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})]}),i.jsxs("div",{className:"flex gap-2 max-[550px]:flex-wrap max-[550px]:items-center",children:[r==="code"&&i.jsx(Oe,{type:"button",variant:"secondary",onClick:()=>a("email"),className:"flex-1",children:e("profiles.login.back")}),i.jsxs(Oe,{type:"submit",disabled:k,className:"flex-1",children:[k?i.jsx(lt,{className:"w-4 h-4 animate-spin"}):i.jsx(n8,{className:"w-4 h-4"}),e(r==="email"?"profiles.login.loginButton":r==="code"?"profiles.login.verifyButton":"profiles.login.setTokenButton")]})]}),r==="email"&&i.jsx("div",{className:"pt-4 border-t border-bambu-dark-tertiary",children:i.jsxs("button",{type:"button",onClick:()=>a("token"),className:"text-sm text-bambu-gray hover:text-white flex items-center gap-2 transition-colors",children:[i.jsx(sl,{className:"w-4 h-4"}),e("profiles.login.useToken")]})}),r==="token"&&i.jsx("div",{className:"pt-4 border-t border-bambu-dark-tertiary",children:i.jsxs("button",{type:"button",onClick:()=>a("email"),className:"text-sm text-bambu-gray hover:text-white flex items-center gap-2 transition-colors",children:[i.jsx(n8,{className:"w-4 h-4"}),e("profiles.login.useEmail")]})})]})]})})}function Gg({label:t,value:e,options:n,onChange:r}){const[a,s]=w.useState(!1),o=n.find(l=>l.value===e);return i.jsxs("div",{className:"relative",children:[i.jsxs("button",{onClick:()=>s(!a),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:[i.jsxs("span",{className:"text-bambu-gray",children:[t,":"]}),i.jsx("span",{children:o?.label||"All"}),i.jsx(jn,{className:`w-4 h-4 text-bambu-gray transition-transform ${a?"rotate-180":""}`})]}),a&&i.jsxs(i.Fragment,{children:[i.jsx("div",{className:"fixed inset-0 z-10",onClick:()=>s(!1)}),i.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=>i.jsxs("button",{onClick:()=>{r(l.value),s(!1)},className:`w-full px-3 py-2 text-left text-sm flex items-center justify-between hover:bg-bambu-dark-tertiary transition-colors ${e===l.value?"text-bambu-green":"text-white"}`,children:[i.jsx("span",{children:l.label}),l.count!==void 0&&i.jsx("span",{className:"text-bambu-gray text-xs",children:l.count})]},l.value))})]})]})}function jJe(){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?i.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:i.jsx($p,{className:"w-5 h-5"})}):null}function Qj({setting:t,onClick:e,onDuplicate:n,compareMode:r,isCompareSelected:a,compareIndex:s,compareDisabled:o,t:l}){const c=EI(t.name),d=C0(t.setting_id);return i.jsxs("div",{className:"flex items-center gap-2 group",children:[i.jsx("button",{onClick:e,disabled:o,className:`flex-1 text-left px-3 py-2 rounded transition-colors ${a?"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:i.jsxs("div",{className:"flex items-center gap-2",children:[a&&s!==void 0&&i.jsx("span",{className:"flex-shrink-0 w-5 h-5 rounded-full bg-blue-500 text-white text-xs flex items-center justify-center font-medium",children:s+1}),!a&&d&&i.jsx("span",{className:"flex-shrink-0 w-1.5 h-1.5 rounded-full bg-bambu-green",title:l("profiles.presets.myPreset")}),i.jsx("span",{className:"text-white text-sm truncate flex-1",title:t.name,children:t.name}),c.filamentType&&t.type==="filament"&&i.jsx("span",{className:"text-xs text-bambu-gray whitespace-nowrap",children:c.filamentType}),c.layerHeight&&t.type==="process"&&i.jsx("span",{className:"text-xs text-bambu-gray whitespace-nowrap",children:c.layerHeight}),c.printer&&i.jsx("span",{className:"text-xs text-bambu-gray whitespace-nowrap",children:c.printer})]})}),i.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:l("profiles.presets.duplicate"),children:i.jsx(_l,{className:"w-4 h-4"})})]})}function kF(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 a=t.replace(/\\n/g,` `).replace(/\\"/g,'"').replace(/\\t/g," ").split(` `);if(a.length>1)return`""" diff --git a/static/img/android-chrome-192x192.png b/static/img/android-chrome-192x192.png index b0a45c6c0..cbd04d89d 100644 Binary files a/static/img/android-chrome-192x192.png and b/static/img/android-chrome-192x192.png differ diff --git a/static/img/android-chrome-512x512.png b/static/img/android-chrome-512x512.png index 5f871b422..19c81cc63 100644 Binary files a/static/img/android-chrome-512x512.png and b/static/img/android-chrome-512x512.png differ diff --git a/static/img/apple-touch-icon.png b/static/img/apple-touch-icon.png index 63cb2e2f6..c0502d04f 100644 Binary files a/static/img/apple-touch-icon.png and b/static/img/apple-touch-icon.png differ diff --git a/static/img/screenshot-desktop.png b/static/img/screenshot-desktop.png new file mode 100644 index 000000000..f706fee31 Binary files /dev/null and b/static/img/screenshot-desktop.png differ diff --git a/static/img/screenshot-mobile.png b/static/img/screenshot-mobile.png new file mode 100644 index 000000000..2edc73f29 Binary files /dev/null and b/static/img/screenshot-mobile.png differ diff --git a/static/index.html b/static/index.html index 28ad04225..608c5687a 100644 --- a/static/index.html +++ b/static/index.html @@ -23,7 +23,7 @@ - + diff --git a/static/manifest.json b/static/manifest.json index 48eb8eef3..7ce8fd63a 100644 --- a/static/manifest.json +++ b/static/manifest.json @@ -35,7 +35,23 @@ "src": "/img/apple-touch-icon.png", "sizes": "180x180", "type": "image/png", - "purpose": "any maskable" + "purpose": "maskable" + } + ], + "screenshots": [ + { + "src": "/img/screenshot-mobile.png", + "sizes": "1080x1920", + "type": "image/png", + "form_factor": "narrow", + "label": "Bambuddy on mobile" + }, + { + "src": "/img/screenshot-desktop.png", + "sizes": "1920x1080", + "type": "image/png", + "form_factor": "wide", + "label": "Bambuddy on desktop" } ], "categories": ["utilities", "productivity"],