From 500e99a48b9c4ff728da0b6fd867776a374492b7 Mon Sep 17 00:00:00 2001 From: maziggy Date: Thu, 14 May 2026 15:35:13 +0200 Subject: [PATCH] Post work PR #1338 --- CHANGELOG.md | 2 ++ static/assets/{index-CG1DM53r.js => index-CntkZk2s.js} | 4 ++-- static/index.html | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) rename static/assets/{index-CG1DM53r.js => index-CntkZk2s.js} (96%) diff --git a/CHANGELOG.md b/CHANGELOG.md index f00c7703c..3a7c2de15 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,8 @@ All notable changes to Bambuddy will be documented in this file. - **Slice modal: pick the build plate (#1337, reported by @digitalskies)** — Slicing a plain STL through the integrated slicer always defaulted to whatever `curr_bed_type` lived in the chosen process preset (typically `Cool Plate`), which the slicer CLI then rejected for high-temp filaments with `Plate 1: Cool Plate does not support filament 1`. The user had no way to switch plates short of cloning the process preset in BambuStudio, which defeats the point of the in-app slicer. The Slice modal now exposes a `Build plate` dropdown with the six canonical BambuStudio / OrcaSlicer plates (Cool Plate, Cool Plate SuperTack, Engineering Plate, High Temp Plate, Textured PEI Plate, Smooth PEI Plate) plus an explicit `Auto (use process preset)` option that preserves the previous behavior. The dropdown sits between Process profile and Filament rows so it stays visible regardless of how many filament slots the picked plate uses (a long filament list would otherwise push it off the modal's `max-h-[85vh]` scroll viewport) and is **always enabled** — including when the user picks a Printer Preset Bundle from the top BundlePicker. When the user picks a specific plate, the new `bed_type` field on `SliceRequest` ([`backend/app/schemas/slicer.py`](backend/app/schemas/slicer.py)) flows through the dispatcher via two paths: (1) **resolved-preset path** — the route helper `_patch_process_bed_type` in [`backend/app/api/routes/library.py`](backend/app/api/routes/library.py) overwrites `curr_bed_type` on the resolved process JSON before forwarding to the sidecar (no preset cloning required); (2) **bundle dispatch path** — `slice_with_bundle` in [`backend/app/services/slicer_api.py`](backend/app/services/slicer_api.py) adds a `bedType` form field to the sidecar multipart so the sidecar can pass `--curr_bed_type` through to the CLI, which lets the override take effect even though Bambuddy can't patch the bundle's process JSON locally (the sidecar materialises it from the stored .bbscfg). Sidecar versions that don't recognise the field silently no-op — the slice still runs, just with the bundle's default plate; the slicer-API fork at maziggy/orca-slicer-api will need the matching change for the bundle path to take full effect. **i18n parity:** 8 new keys (`slice.bedType.{label,auto,coolPlate,coolPlateSuperTack,engineering,highTemp,texturedPEI,smoothPEI}`) added to all 8 locales — full German translation, English fallbacks elsewhere per project convention. **Regression tests:** 4 in [`test_slice_request_bed_type.py`](backend/tests/unit/test_slice_request_bed_type.py) (`bed_type` defaults to None, accepts the six canonical strings, rejects overlong input via the schema's `max_length=64`; `_patch_process_bed_type` overwrites an existing value, adds the field when missing, and returns the input unchanged for malformed JSON or non-dict roots), 4 in [`test_library_slice_api.py`](backend/tests/integration/test_library_slice_api.py) (resolved-preset path: with `bed_type` set, the sidecar receives `"curr_bed_type": "Textured PEI Plate"` in the presetProfile multipart part; without it, `curr_bed_type` stays out of the body entirely. bundle dispatch path: `bedType` form field carries the override through to the sidecar; omitting `bed_type` keeps the form field out of the request so the bundle's own `curr_bed_type` is preserved), 2 in [`SliceModal.test.tsx`](frontend/src/__tests__/components/SliceModal.test.tsx) (dropdown selection puts `bed_type` on the request; leaving it on Auto omits the field). 59 backend slice tests + 34 SliceModal tests pass; build and i18n parity script clean. ### Fixed +- **Backup tab indicator dot now turns green when Scheduled (local) Backups is enabled** ([#1331](https://github.com/maziggy/bambuddy/issues/1331), [PR #1338](https://github.com/maziggy/bambuddy/pull/1338) by @chanakyan-arivumani) — Toggling **Scheduled Backups** on inside Settings → Backup left the sidebar tab indicator dot stuck on grey: the visual cue that there's an active backup configuration was lost for users who run scheduled local backups without GitHub. Two stacked layers caused it: (1) the dot condition at [`SettingsPage.tsx:1461`](frontend/src/pages/SettingsPage.tsx) only checked the GitHub chain (`cloudAuthStatus?.is_authenticated && githubBackupStatus?.configured && githubBackupStatus?.enabled`); `settings?.local_backup_enabled` was never consulted, so the scheduled-backup state had no path to the indicator. (2) The toggle handler in [`GitHubBackupSettings.tsx`](frontend/src/components/GitHubBackupSettings.tsx) called `api.updateSettings({ local_backup_enabled })` but never invalidated the `['settings']` query cache, so `SettingsPage` kept reading the stale value — the indicator would only update on a full page reload even if the condition fix were in place. Two-line fix: extend the dot's predicate to `... || settings?.local_backup_enabled` and add `queryClient.invalidateQueries({ queryKey: ['settings'] })` after a successful save (matching the existing invalidation pattern at `GitHubBackupSettings.tsx:402/463/477/497`). The GitHub-chain short-circuits first so the common case is unchanged. **Patched by @chanakyan-arivumani.** + - **Color catalog presets now apply `extra_colors` (gradient stops) and `effect_type` (sparkle / wood / marble / glow / matte) onto the spool, not just hex + name** ([#1340](https://github.com/maziggy/bambuddy/issues/1340), reported by @maugsburger) — Creating a catalog entry that pairs a base color with multi-color gradient stops and a visual effect, then clicking that swatch in the Edit Spool dialog, only copied `color_name` and `rgba` over — the `extra_colors` and `effect_type` fields were silently dropped. The data was flowing from the backend correctly (`GET /api/v1/inventory/color-catalog` returns both fields per the `ColorCatalogEntry` schema in [`frontend/src/api/client.ts`](frontend/src/api/client.ts)), but three layers above stripped them: (1) [`SpoolFormModal.tsx`](frontend/src/components/SpoolFormModal.tsx) typed its `colorCatalog` state with a narrower shape that omitted the two fields; (2) [`ColorSection.tsx`](frontend/src/components/spool-form/ColorSection.tsx) mapped catalog entries to `CatalogDisplayColor` (the typed-down shape rendered on swatches) without propagating them; (3) the `selectColor()` handler only set `rgba` + `color_name` on click. **Fix:** widened both types in [`spool-form/types.ts`](frontend/src/components/spool-form/types.ts) (`CatalogDisplayColor` + `ColorSectionProps.catalogColors`) to carry the optional `extra_colors` and `effect_type`, propagated them through the four `matchedCatalogColors` mapping callbacks (byBrand / exact full-material / normalized-trailing-`+` / base-material prefix), and extended `selectColor` to take optional `extraColors` / `effectType` parameters. **Semantic rule:** catalog swatches are complete presets — picking one writes BOTH gradient and effect from the entry (overwriting any existing values), so a gradient catalog entry applies its stops AND a solid catalog entry clears any old gradient that was on the spool. Recent-colors and the hardcoded-fallback palette are plain hex pickers — picking one keeps any existing `extra_colors` / `effect_type` untouched, since those swatches aren't presets, just color picks. **Bonus:** fixed the en-US spelling drift the reporter flagged in their nitpick — `'Extra colours'` and `'wrong colour loaded'` strings (which had been seeded into all 8 locale files as English fallbacks) standardized to `'Extra colors'` and `'wrong color loaded'`; matching comment blocks (`// Multi-colour ...`) normalized in the same pass. **Regression tests** in [`__tests__/components/spool-form/ColorSectionCatalogExtras.test.tsx`](frontend/src/__tests__/components/spool-form/ColorSectionCatalogExtras.test.tsx) (3 cases): catalog click with gradient + effect propagates all four fields to `updateField`, catalog click on a solid preset clears any pre-existing extras/effect (preset-replaces-look semantic), and fallback palette click leaves extras/effect untouched. All 23 spool-form tests + 8 i18n parity tests pass; build clean. - **Assigning a spool to an unconfigured AMS slot no longer silently skips MQTT on A1 Mini / P1S firmware — and the "PETG over a PLA-configured slot won't reconfigure" symptom is fixed in the same change** ([#1322](https://github.com/maziggy/bambuddy/issues/1322), reported by @RosdasHH) — On the user's A1 Mini BMCU (firmware 01.07.02.00) and P1S Standard AMS (firmware 00.00.06.75), pressing "Assign Spool" on any slot left the slot unconfigured: the DB row was created with `pending_config=True`, the MQTT publish was skipped, and the log line `Pre-configured assignment: ... (slot empty, will configure on insert)` fired even though the spool was physically loaded. The same code path also blocked the "swap PLA to PETG in the same slot" flow — Bambuddy would keep treating the spool as PLA because the publish never reached the printer. **Root cause:** the empty-slot detection at [`backend/app/api/routes/inventory.py:1267`](backend/app/api/routes/inventory.py) preferred `tray.state == 11` ("filament fed to extruder") over `tray_type`, falling back to `tray_type` only when `state` was missing entirely. Reporter's AMS dumps showed `state == 3` on every slot — configured and unconfigured, on both printers — and `state` was never absent. So the state-only branch always fired, the result was always "empty", and MQTT was always skipped regardless of whether the slot was actually loaded. The "fingerprint_type empty → defer until insert" pre-config replay at [`backend/app/main.py:1026`](backend/app/main.py) had the same `cur_state == 11` gate, so even when the user manually configured the slot in Bambu Studio afterward (making `tray_type` go from `""` to `"PLA"`), the deferred MQTT publish never fired because state stayed at 3. **Fix:** both call sites now use a disjunction — the slot is treated as loaded when **either** `state == 11` **or** `tray_type` is non-empty. The "Reset slot" case (state=11 + tray_type="") that the original state-only check was protecting still works through the first clause; the configured-slot case (state=3 + tray_type="PLA") on firmwares that never set state=11 now works through the second; and truly empty unconfigured slots (state≠11 + tray_type="") still fall through to the pending-config path correctly. The on_ams_change replay's disjunction also fires the deferred publish when the user later configures the slot through Bambu Studio, since that flips `tray_type` non-empty even if state stays at 3. **Caveat:** for a truly empty slot with a 3rd-party non-RFID spool that the user physically inserted, neither signal points to "loaded" on these firmwares, so we still can't auto-fire the publish until the slot gets configured (manually or by another assign). The pending-config row persists in the DB and gets applied on the next AMS push that flips `tray_type` non-empty. **Regression tests:** 3 in [`test_inventory_assign.py`](backend/tests/integration/test_inventory_assign.py) — `test_state_never_eleven_firmware_with_loaded_tray_fires_mqtt` (state=3 + tray_type='PLA' → MQTT fires; pins the reporter's primary symptom and the PETG-over-PLA secondary symptom which goes through the same predicate), `test_state_never_eleven_firmware_with_empty_tray_marks_pending` (state=3 + tray_type='' still pending — confirms the disjunction didn't accidentally turn truly empty slots into the loaded branch), and `test_on_ams_change_fires_replay_when_tray_type_appears_without_state_11` (pre-existing SpoolBuddy-style assignment with empty fingerprint; tray_type going `''→'PLA'` on a state=3 firmware fires the deferred publish even though state never becomes 11). All 28 tests in the file pass; ruff clean. diff --git a/static/assets/index-CG1DM53r.js b/static/assets/index-CntkZk2s.js similarity index 96% rename from static/assets/index-CG1DM53r.js rename to static/assets/index-CntkZk2s.js index 7041327d9..cff8d32fa 100644 --- a/static/assets/index-CG1DM53r.js +++ b/static/assets/index-CntkZk2s.js @@ -8705,11 +8705,11 @@ Accuracy: ${t.time_accuracy.toFixed(0)}%`:t.actual_time_seconds?`Actual: ${ds(t. ${!d&&!H?"border-bambu-dark-tertiary hover:border-bambu-dark-tertiary/80":""} ${re?"sm:cursor-default":""} `,onClick:re?()=>{window.innerWidth<640&&u()}:void 0,children:[re&&d&&r.jsx("div",{className:"sm:hidden absolute left-0 top-3 bottom-3 w-1 rounded-full bg-bambu-green"}),r.jsxs("div",{className:"flex items-start sm:items-center gap-2 sm:gap-4 p-3 sm:p-4",children:[R&&u&&r.jsx("button",{onClick:J=>{J.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&&r.jsx(_r,{className:"w-4 h-4"})}),R?r.jsx("div",{...T,...A,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:r.jsx(Ph,{className:"w-4 h-4 text-bambu-gray"})}):e!==void 0?r.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]}):r.jsx("div",{className:"hidden sm:block w-8 shrink-0"}),r.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?r.jsx("img",{src:t.plate_id!=null?se.getArchivePlateThumbnail(t.archive_id,t.plate_id):se.getArchiveThumbnail(t.archive_id),alt:"",className:"w-full h-full object-cover"}):t.library_file_thumbnail?r.jsx("img",{src:t.plate_id!=null?se.getLibraryFilePlateThumbnail(t.library_file_id,t.plate_id):se.getLibraryFileThumbnailUrl(t.library_file_id),alt:"",className:"w-full h-full object-cover"}):r.jsx("div",{className:"w-full h-full flex items-center justify-center text-bambu-gray",children:r.jsx(oa,{className:"w-5 h-5 sm:w-6 sm:h-6"})})}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[r.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(J=>J.index===t.plate_id)?.name||b("queue.plateNumber",{index:t.plate_id})}`]}),t.archive_id?r.jsx(Is,{to:`/archives?highlight=${t.archive_id}`,className:"text-bambu-gray hover:text-bambu-green transition-colors flex-shrink-0",title:b("queue.viewArchive"),children:r.jsx(Rr,{className:"w-3.5 h-3.5"})}):t.library_file_id?r.jsx(Is,{to:`/library?highlight=${t.library_file_id}`,className:"text-bambu-gray hover:text-bambu-green transition-colors flex-shrink-0",title:b("queue.viewInFileManager"),children:r.jsx(Rr,{className:"w-3.5 h-3.5"})}):null,t.batch_name&&r.jsx("span",{className:"flex-shrink-0 px-1.5 py-0.5 text-[10px] sm:text-xs bg-purple-500/20 text-purple-300 rounded border border-purple-500/30",children:t.batch_name})]}),r.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1 text-xs sm:text-sm text-bambu-gray",children:[r.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&&!t.printer_id?"text-blue-400":""}`,children:[r.jsx(pr,{className:"w-3 h-3 sm:w-3.5 sm:h-3.5"}),r.jsx("span",{className:"truncate max-w-[120px] sm:max-w-none",children:t.target_model&&!t.printer_id?`${b("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?b("queue.filter.unassigned"):t.printer_name||`${b("common.printer")} #${t.printer_id}`})]}),t.print_time_seconds&&r.jsxs("span",{className:"flex items-center gap-1 sm:gap-1.5",children:[r.jsx(Xd,{className:"w-3 h-3 sm:w-3.5 sm:h-3.5"}),ds(t.print_time_seconds)]}),t.filament_used_grams&&r.jsxs("span",{className:"flex items-center gap-1 sm:gap-1.5",children:[r.jsx(BZ,{className:"w-3 h-3 sm:w-3.5 sm:h-3.5"}),Xnt(t.filament_used_grams)]}),t.created_by_username&&r.jsxs("span",{className:"hidden sm:flex items-center gap-1.5",title:b("queue.addedBy",{name:t.created_by_username}),children:[r.jsx(Vm,{className:"w-3.5 h-3.5"}),t.created_by_username]}),R&&!t.manual_start&&r.jsxs("span",{className:"flex items-center gap-1.5",children:[r.jsx(Zn,{className:"w-3.5 h-3.5"}),t.scheduled_time?(Xn(t.scheduled_time)?.getTime()??0)-Date.now()<-6e4?b?.("queue.time.overdue")??"Overdue":jh(t.scheduled_time,c,b):b?.("queue.time.asap")??"ASAP"]})]}),r.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 sm:gap-2 mt-1.5 sm:mt-2",children:[t.manual_start&&r.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:[r.jsx(MZ,{className:"w-2.5 h-2.5 sm:w-3 sm:h-3"}),b("queue.badges.staged")]}),t.require_previous_success&&r.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:b("queue.badges.requiresPrevious")}),t.auto_off_after&&r.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:[r.jsx(wu,{className:"w-2.5 h-2.5 sm:w-3 sm:h-3"}),b("queue.badges.autoPowerOff")]}),t.gcode_injection&&r.jsxs("span",{className:"text-[10px] sm:text-xs px-1.5 sm:px-2 py-0.5 bg-emerald-500/10 text-emerald-400 rounded-full border border-emerald-500/20 flex items-center gap-1",children:[r.jsx(Gy,{className:"w-2.5 h-2.5 sm:w-3 sm:h-3"}),b("queue.badges.gcodeInjection")]})]}),H&&w&&(()=>{const J=w.state==="RUNNING"||w.state==="PAUSE",de=J&&w.progress||0,pe=J?w.remaining_time:null,ue=J?w.layer_num:null,X=J?w.total_layers:null;return r.jsxs("div",{className:"mt-2 sm:mt-3",children:[r.jsxs("div",{className:"flex items-center justify-between text-xs sm:text-sm",children:[r.jsx("div",{className:"flex-1 bg-bambu-dark-tertiary rounded-full h-1.5 sm:h-2 mr-3",children:r.jsx("div",{className:"bg-bambu-green h-1.5 sm:h-2 rounded-full transition-all",style:{width:`${de}%`}})}),r.jsxs("span",{className:"text-white",children:[Math.round(de),"%"]})]}),r.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:[pe!=null&&pe>0&&r.jsxs(r.Fragment,{children:[r.jsxs("span",{className:"flex items-center gap-1",children:[r.jsx(Zn,{className:"w-3 h-3"}),ds(pe*60)]}),r.jsxs("span",{className:"text-bambu-green font-medium",title:b("printers.estimatedCompletion"),children:["ETA ",CO(pe,c,b)]})]}),ue!=null&&X!=null&&X>0&&r.jsxs("span",{className:"flex items-center gap-1",children:[r.jsx(oa,{className:"w-3 h-3"}),ue,"/",X]})]})]})})(),t.waiting_reason&&t.status==="pending"&&r.jsxs("p",{className:"text-[10px] sm:text-xs text-purple-400 mt-1.5 sm:mt-2 flex items-start gap-1",children:[r.jsx($a,{className:"w-3 h-3 mt-0.5 flex-shrink-0"}),r.jsx("span",{children:t.waiting_reason})]}),t.error_message&&r.jsxs("p",{className:"text-[10px] sm:text-xs text-red-400 mt-1.5 sm:mt-2 flex items-center gap-1",children:[r.jsx($a,{className:"w-3 h-3"}),t.error_message]})]}),r.jsxs("div",{className:"flex flex-col sm:flex-row items-end sm:items-center gap-2 sm:gap-1 shrink-0",onClick:J=>J.stopPropagation(),children:[r.jsx(Qnt,{status:t.status,waitingReason:t.waiting_reason,printerState:f,t:b}),r.jsxs("div",{className:"flex items-center gap-0.5 sm:gap-1",children:[H&&r.jsx(Me,{variant:"ghost",size:"sm",onClick:s,disabled:!m("printers:control"),title:m("printers:control")?b("queue.actions.stopPrint"):b("queue.permissions.noStopPrint"),className:"text-red-400 hover:text-red-300 hover:bg-red-500/10 p-1.5 sm:p-2",children:r.jsx(ige,{className:"w-4 h-4"})}),R&&r.jsxs(r.Fragment,{children:[t.manual_start&&r.jsx(Me,{variant:"ghost",size:"sm",onClick:l,disabled:!m("printers:control"),title:m("printers:control")?b("queue.actions.startPrint"):b("queue.permissions.noStartPrint"),className:"text-bambu-green hover:text-bambu-green-light hover:bg-bambu-green/10 p-1.5 sm:p-2",children:r.jsx(fs,{className:"w-4 h-4"})}),r.jsx(Me,{variant:"ghost",size:"sm",onClick:n,disabled:!p("queue","update",t.created_by_id),title:p("queue","update",t.created_by_id)?b("common.edit"):b("queue.permissions.noEdit"),className:"p-1.5 sm:p-2",children:r.jsx(oi,{className:"w-4 h-4"})}),r.jsx(Me,{variant:"ghost",size:"sm",onClick:a,disabled:!p("queue","delete",t.created_by_id),title:p("queue","delete",t.created_by_id)?b("common.cancel"):b("queue.permissions.noCancel"),className:"text-red-400 hover:text-red-300 hover:bg-red-500/10 p-1.5 sm:p-2",children:r.jsx(Ht,{className:"w-4 h-4"})})]}),Q&&r.jsxs(r.Fragment,{children:[r.jsx(Me,{variant:"ghost",size:"sm",onClick:o,disabled:!m("queue:create"),title:m("queue:create")?b("queue.actions.requeue"):b("queue.permissions.noRequeue"),className:"text-bambu-green hover:text-bambu-green/80 hover:bg-bambu-green/10 p-1.5 sm:p-2",children:r.jsx(sr,{className:"w-4 h-4"})}),r.jsx(Me,{variant:"ghost",size:"sm",onClick:i,disabled:!p("queue","delete",t.created_by_id),title:p("queue","delete",t.created_by_id)?b("common.remove"):b("queue.permissions.noRemove"),className:"p-1.5 sm:p-2",children:r.jsx(Jt,{className:"w-4 h-4"})})]})]})]})]})]})}function Jnt(){const{t}=kt(),e=en(),{showToast:n}=rn(),{hasPermission:a,hasAnyPermission:i,canModify:s}=cr(),[o,l]=y.useState(null),[c,d]=y.useState(""),[u,m]=y.useState(""),[p,f]=y.useState(!1),[b,w]=y.useState(null),[g,x]=y.useState(null),[_,N]=y.useState(null),[C,P]=y.useState([]),[T,A]=y.useState(!1),[F,S]=y.useState(()=>localStorage.getItem("queue.historySortBy")||"date"),[E,U]=y.useState(()=>{const ve=localStorage.getItem("queue.historySortAsc");return ve!==null?ve==="true":!1}),[I,H]=y.useState(()=>localStorage.getItem("queue.pendingSortBy")||"position"),[R,Q]=y.useState(()=>{const ve=localStorage.getItem("queue.pendingSortAsc");return ve!==null?ve==="true":!0}),[re,J]=y.useState(()=>localStorage.getItem("queue.historyCollapsed")!=="false"),[de,pe]=y.useState(()=>localStorage.getItem("queue.viewMode")||"list");y.useEffect(()=>{localStorage.setItem("queue.historySortBy",F)},[F]),y.useEffect(()=>{localStorage.setItem("queue.historySortAsc",String(E))},[E]),y.useEffect(()=>{localStorage.setItem("queue.pendingSortBy",I)},[I]),y.useEffect(()=>{localStorage.setItem("queue.pendingSortAsc",String(R))},[R]),y.useEffect(()=>{localStorage.setItem("queue.historyCollapsed",String(re))},[re]),y.useEffect(()=>{localStorage.setItem("queue.viewMode",de)},[de]);const ue=ece(mT(JA,{activationConstraint:{distance:8}}),mT(ZA,{coordinateGetter:_ce})),{data:X}=Ve({queryKey:["settings"],queryFn:se.getSettings}),ae=X?.time_format||"system",{data:me,isLoading:be}=Ve({queryKey:["queue",o,c],queryFn:()=>se.getQueue(o||void 0,c||void 0),refetchInterval:5e3}),{data:Ce}=Ve({queryKey:["printers"],queryFn:()=>se.getPrinters()}),$=it({mutationFn:ve=>se.updateSettings({queue_shortest_first:ve}),onSuccess:()=>{e.invalidateQueries({queryKey:["settings"]})}}),W=it({mutationFn:ve=>se.cancelQueueItem(ve),onSuccess:()=>{e.invalidateQueries({queryKey:["queue"]}),n(t("queue.toast.cancelled"))},onError:()=>n(t("queue.toast.cancelFailed"),"error")}),D=it({mutationFn:ve=>se.removeFromQueue(ve),onSuccess:()=>{e.invalidateQueries({queryKey:["queue"]}),n(t("queue.toast.removed"))},onError:()=>n(t("queue.toast.removeFailed"),"error")}),j=it({mutationFn:ve=>se.stopQueueItem(ve),onSuccess:()=>{e.invalidateQueries({queryKey:["queue"]}),n(t("queue.toast.stopped"))},onError:()=>n(t("queue.toast.stopFailed"),"error")}),B=it({mutationFn:ve=>se.startQueueItem(ve),onSuccess:()=>{e.invalidateQueries({queryKey:["queue"]}),n(t("queue.toast.released"))},onError:()=>n(t("queue.toast.startFailed"),"error")}),Y=it({mutationFn:ve=>se.reorderQueue(ve),onSuccess:()=>{e.invalidateQueries({queryKey:["queue"]})},onError:()=>n(t("queue.toast.reorderFailed"),"error")}),O=it({mutationFn:async()=>{const ve=me?.filter(xe=>["completed","failed","skipped","cancelled"].includes(xe.status))||[];for(const xe of ve)await se.removeFromQueue(xe.id);return ve.length},onSuccess:ve=>{e.invalidateQueries({queryKey:["queue"]}),n(t("queue.toast.historyCleared",{count:ve}))},onError:()=>n(t("queue.toast.clearHistoryFailed"),"error")}),ie=it({mutationFn:ve=>se.bulkUpdateQueue(ve),onSuccess:ve=>{e.invalidateQueries({queryKey:["queue"]}),P([]),A(!1),n(ve.message)},onError:()=>n(t("queue.toast.updateFailed"),"error")}),z=it({mutationFn:async ve=>{for(const xe of ve)await se.cancelQueueItem(xe);return ve.length},onSuccess:ve=>{e.invalidateQueries({queryKey:["queue"]}),P([]),n(t("queue.toast.bulkCancelled",{count:ve}))},onError:()=>n(t("queue.toast.bulkCancelFailed"),"error")}),G=ve=>{P(xe=>xe.includes(ve)?xe.filter(Ee=>Ee!==ve):[...xe,ve])},K=y.useMemo(()=>{const ve=new Set;return Ce?.forEach(xe=>{xe.location&&ve.add(xe.location)}),me?.forEach(xe=>{xe.target_location&&ve.add(xe.target_location)}),Array.from(ve).sort()},[Ce,me]),Z=y.useCallback(ve=>u?ve.target_location?ve.target_location===u:ve.printer_id?Ce?.find(Ee=>Ee.id===ve.printer_id)?.location===u:!1:!0,[u,Ce]),oe=y.useMemo(()=>{let ve=me?.filter(Ee=>Ee.status==="pending")||[];u&&(ve=ve.filter(Z));const xe=Ee=>{if(!Ee.scheduled_time)return 0;const ze=Xn(Ee.scheduled_time)?.getTime()??0,_e=Date.now()+4320*60*60*1e3;return ze>_e?0:ze};return X?.queue_shortest_first?[...ve].sort((Ee,ze)=>{const _e=Ee.printer_id??-(Ee.target_model?.charCodeAt(0)??0),Oe=ze.printer_id??-(ze.target_model?.charCodeAt(0)??0);if(_e!==Oe)return _e-Oe;const Ie=Ee.been_jumped?1:0,We=ze.been_jumped?1:0;if(Ie!==We)return We-Ie;const at=Ee.print_time_seconds??1/0,lt=ze.print_time_seconds??1/0;return at!==lt?at-lt:Ee.position-ze.position}):[...ve].sort((Ee,ze)=>{let _e;if(I==="name"){const Oe=Ee.archive_name||Ee.library_file_name||"",Ie=ze.archive_name||ze.library_file_name||"";_e=Oe.localeCompare(Ie)}else I==="printer"?_e=(Ee.printer_name||"").localeCompare(ze.printer_name||""):I==="time"?_e=xe(Ee)-xe(ze):_e=Ee.position-ze.position;return R?_e:-_e})},[me,I,R,Z,u,X?.queue_shortest_first]),ee=()=>{const ve=oe.map(xe=>xe.id);C.length===ve.length?P([]):P(ve)},ge=y.useMemo(()=>{let ve=me?.filter(xe=>xe.status==="printing")||[];return u&&(ve=ve.filter(Z)),ve},[me,u,Z]),ce=y.useMemo(()=>{const ve=new Set;return ge.forEach(xe=>{xe.printer_id&&ve.add(xe.printer_id)}),Array.from(ve)},[ge]),le=ef({queries:ce.map(ve=>({queryKey:["printerStatus",ve],queryFn:()=>se.getPrinterStatus(ve),refetchInterval:5e3}))}),q=y.useMemo(()=>{const ve={};return ce.forEach((xe,Ee)=>{const ze=le[Ee];ze?.data?.state&&(ve[xe]=ze.data.state)}),ve},[ce,le]),L=y.useMemo(()=>{const ve={};return ce.forEach((xe,Ee)=>{const ze=le[Ee];ze?.data&&(ve[xe]={progress:ze.data.progress??void 0,remaining_time:ze.data.remaining_time??void 0,state:ze.data.state??void 0})}),ve},[ce,le]),ne=y.useMemo(()=>{let ve=me?.filter(xe=>["completed","failed","skipped","cancelled"].includes(xe.status))||[];return u&&(ve=ve.filter(Z)),[...ve].sort((xe,Ee)=>{let ze;if(F==="name"){const _e=xe.archive_name||xe.library_file_name||"",Oe=Ee.archive_name||Ee.library_file_name||"";ze=_e.localeCompare(Oe)}else F==="printer"?ze=(xe.printer_name||"").localeCompare(Ee.printer_name||""):ze=(Xn(Ee.completed_at||Ee.created_at)?.getTime()??0)-(Xn(xe.completed_at||xe.created_at)?.getTime()??0);return E?-ze:ze})},[me,F,E,Z,u]),ye=y.useMemo(()=>oe.reduce((ve,xe)=>ve+(xe.print_time_seconds||0),0),[oe]),we=y.useMemo(()=>oe.reduce((ve,xe)=>ve+(xe.filament_used_grams||0),0),[oe]),Ne=ve=>{const{active:xe,over:Ee}=ve;if(!Ee||xe.id===Ee.id)return;const ze=oe.findIndex(Oe=>Oe.id===xe.id),_e=oe.findIndex(Oe=>Oe.id===Ee.id);if(ze!==-1&&_e!==-1){const Ie=nj(oe,ze,_e).map((We,at)=>({id:We.id,position:at+1}));Y.mutate(Ie)}};return r.jsxs("div",{className:"p-4 md:p-8",children:[r.jsx("div",{className:"flex items-center justify-between mb-8",children:r.jsxs("div",{children:[r.jsxs("h1",{className:"text-2xl font-bold text-white flex items-center gap-3",children:[r.jsx(jw,{className:"w-7 h-7 text-bambu-green"}),t("queue.title")]}),r.jsx("p",{className:"text-bambu-gray mt-1",children:t("queue.subtitle")})]})}),r.jsx(Hnt,{activeCount:ge.length,pendingCount:oe.length,totalTime:ye,totalWeight:we,historyCount:ne.length,t}),r.jsxs("div",{className:"flex flex-wrap items-center gap-2 sm:gap-4 mb-6",children:[r.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:ve=>{const xe=ve.target.value;l(xe==="unassigned"?-1:xe===""?null:Number(xe))},children:[r.jsx("option",{value:"",children:t("queue.filter.allPrinters")}),r.jsx("option",{value:"unassigned",children:t("queue.filter.unassigned")}),Ce?.map(ve=>r.jsx("option",{value:ve.id,children:ve.name},ve.id))]}),r.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:ve=>d(ve.target.value),children:[r.jsx("option",{value:"",children:t("queue.filter.allStatus")}),r.jsx("option",{value:"pending",children:t("queue.status.pending")}),r.jsx("option",{value:"printing",children:t("queue.status.printing")}),r.jsx("option",{value:"completed",children:t("queue.status.completed")}),r.jsx("option",{value:"failed",children:t("queue.status.failed")}),r.jsx("option",{value:"skipped",children:t("queue.status.skipped")}),r.jsx("option",{value:"cancelled",children:t("queue.status.cancelled")})]}),K.length>0&&r.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:ve=>m(ve.target.value),children:[r.jsx("option",{value:"",children:t("queue.filter.allLocations")}),K.map(ve=>r.jsx("option",{value:ve,children:ve},ve))]}),r.jsx("div",{className:"hidden sm:block flex-1"}),ne.length>0&&r.jsxs(Me,{className:"w-full sm:w-auto",variant:"secondary",size:"sm",onClick:()=>f(!0),disabled:!a("queue:delete_all"),title:a("queue:delete_all")?void 0:t("queue.permissions.noClearHistory"),children:[r.jsx(Jt,{className:"w-4 h-4"}),t("queue.clearHistory")]})]}),r.jsxs("div",{className:"flex items-center gap-3 mb-6",children:[r.jsxs("div",{className:"hidden sm:flex items-center border border-bambu-dark-tertiary rounded-lg overflow-hidden",children:[r.jsx("button",{className:`p-2 transition-colors ${de==="list"?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white"}`,onClick:()=>pe("list"),title:t("queue.timeline.listView"),children:r.jsx(AS,{className:"w-4 h-4"})}),r.jsx("button",{className:`p-2 transition-colors ${de==="timeline"?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white"}`,onClick:()=>pe("timeline"),title:t("queue.timeline.timelineView"),children:r.jsx($fe,{className:"w-4 h-4"})})]}),r.jsxs("button",{onClick:()=>{const ve=!(X?.queue_shortest_first??!1);$.mutate(ve)},className:`flex items-center gap-1 px-2 py-1.5 text-xs rounded-lg border transition-colors ${X?.queue_shortest_first?"bg-bambu-green/20 border-bambu-green text-bambu-green":"bg-bambu-dark-secondary border-bambu-dark-tertiary text-bambu-gray hover:text-white hover:border-bambu-gray"}`,title:t("queue.sjf.tooltip","Shortest Job First — scheduler prioritizes shorter prints"),children:[r.jsx(_ye,{className:"w-4 h-4"}),r.jsx("span",{className:"hidden sm:inline",children:t("queue.sjf.label","SJF")}),r.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${X?.queue_shortest_first?"bg-bambu-green":"bg-bambu-gray"}`})]})]}),be?r.jsx("div",{className:"text-center py-12 text-bambu-gray",children:t("common.loading")}):me?.length===0?r.jsxs(Ct,{className:"p-12 text-center border-dashed",children:[r.jsx(Sa,{className:"w-16 h-16 text-bambu-gray mx-auto mb-4 opacity-50"}),r.jsx("h3",{className:"text-xl font-medium text-white mb-2",children:t("queue.empty.title")}),r.jsx("p",{className:"text-bambu-gray max-w-md mx-auto",children:t("queue.empty.description")})]}):de==="timeline"?r.jsx(Ynt,{queueItems:me||[],printerStatuses:L,onItemClick:ve=>{["completed","failed","skipped","cancelled"].includes(ve.status)?x(ve):ve.status==="pending"?w(ve):ve.status==="printing"&&N({type:"stop",item:ve})},t}):r.jsxs("div",{className:"space-y-6 sm:space-y-8",children:[ge.length>0&&r.jsxs("div",{children:[r.jsxs("h2",{className:"text-base sm:text-lg font-semibold text-white mb-3 sm:mb-4 flex items-center gap-2",children:[r.jsx("div",{className:"w-2 h-2 rounded-full bg-blue-400 animate-pulse"}),t("queue.sections.currentlyPrinting")]}),r.jsx("div",{className:"space-y-2 sm:space-y-3",children:ge.map(ve=>r.jsx(QX,{item:ve,onEdit:()=>{},onCancel:()=>{},onRemove:()=>{},onStop:()=>N({type:"stop",item:ve}),onRequeue:()=>{},onStart:()=>{},timeFormat:ae,hasPermission:a,canModify:s,printerState:ve.printer_id?q[ve.printer_id]:null,t},ve.id))})]}),oe.length>0&&r.jsxs("div",{children:[r.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 mb-3 sm:mb-4",children:[r.jsxs("h2",{className:"text-base sm:text-lg font-semibold text-white flex items-center gap-2",children:[r.jsx(Zn,{className:"w-4 h-4 sm:w-5 sm:h-5 text-yellow-400"}),t("queue.sections.queued"),r.jsxs("span",{className:"text-xs sm:text-sm font-normal text-bambu-gray",children:["(",t("queue.itemCount",{count:oe.length}),")"]}),r.jsx("span",{className:"hidden sm:inline text-xs text-bambu-gray ml-2",title:t("queue.reorderHint"),children:t("queue.dragToReorder")})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.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:I,onChange:ve=>H(ve.target.value),children:[r.jsx("option",{value:"position",children:t("queue.sort.byPosition")}),r.jsx("option",{value:"name",children:t("queue.sort.byName")}),r.jsx("option",{value:"printer",children:t("queue.sort.byPrinter")}),r.jsx("option",{value:"time",children:t("queue.sort.bySchedule")})]}),r.jsx(Me,{variant:"ghost",size:"sm",onClick:()=>Q(!R),title:t(R?"common.ascending":"common.descending"),className:"px-2",children:R?r.jsx(Hm,{className:"w-4 h-4"}):r.jsx(Bh,{className:"w-4 h-4"})})]})]}),r.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:[r.jsxs(Me,{variant:"ghost",size:"sm",onClick:ee,className:"flex items-center gap-1.5 sm:gap-2 text-xs sm:text-sm",children:[C.length===oe.length&&oe.length>0?r.jsx(bs,{className:"w-4 h-4 text-bambu-green"}):r.jsx(so,{className:"w-4 h-4"}),C.length===oe.length&&oe.length>0?t("queue.bulkEdit.deselectAll"):t("queue.bulkEdit.selectAll")]}),C.length>0&&r.jsxs(r.Fragment,{children:[r.jsx("span",{className:"text-xs sm:text-sm text-bambu-gray",children:t("queue.bulkEdit.selected",{count:C.length})}),r.jsx("div",{className:"hidden sm:block h-4 w-px bg-bambu-dark-tertiary"}),r.jsxs(Me,{variant:"ghost",size:"sm",onClick:()=>A(!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:!i("queue:update_own","queue:update_all"),title:i("queue:update_own","queue:update_all")?t("queue.bulkEdit.editSelected"):t("queue.permissions.noEditItems"),children:[r.jsx(oi,{className:"w-3.5 h-3.5 sm:w-4 sm:h-4"}),r.jsx("span",{className:"hidden sm:inline",children:t("queue.bulkEdit.editSelected")})]}),r.jsxs(Me,{variant:"ghost",size:"sm",onClick:()=>z.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:z.isPending||!i("queue:delete_own","queue:delete_all"),title:i("queue:delete_own","queue:delete_all")?t("queue.bulkEdit.cancelSelected"):t("queue.permissions.noCancelItems"),children:[r.jsx(Ht,{className:"w-3.5 h-3.5 sm:w-4 sm:h-4"}),r.jsx("span",{className:"hidden sm:inline",children:t("queue.bulkEdit.cancelSelected")})]})]})]}),r.jsx(bce,{sensors:ue,collisionDetection:ace,onDragEnd:Ne,children:r.jsx(vce,{items:oe.map(ve=>ve.id),strategy:jnt,children:r.jsx("div",{className:"space-y-2 sm:space-y-3",children:oe.map((ve,xe)=>r.jsx(QX,{item:ve,position:xe+1,onEdit:()=>w(ve),onCancel:()=>N({type:"cancel",item:ve}),onRemove:()=>{},onStop:()=>{},onRequeue:()=>{},onStart:()=>B.mutate(ve.id),timeFormat:ae,isSelected:C.includes(ve.id),onToggleSelect:()=>G(ve.id),hasPermission:a,canModify:s,t},ve.id))})})})]}),ne.length>0&&r.jsxs("div",{children:[r.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 mb-3 sm:mb-4",children:[r.jsxs("button",{onClick:()=>J(!re),className:"text-base sm:text-lg font-semibold text-white flex items-center gap-2 hover:text-bambu-green transition-colors",children:[re?r.jsx(Va,{className:"w-4 h-4 sm:w-5 sm:h-5"}):r.jsx(Ln,{className:"w-4 h-4 sm:w-5 sm:h-5"}),t("queue.sections.history"),r.jsxs("span",{className:"text-xs sm:text-sm font-normal text-bambu-gray",children:["(",t("queue.itemCount",{count:ne.length}),")"]})]}),!re&&r.jsxs("div",{className:"flex items-center gap-2",children:[r.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:F,onChange:ve=>S(ve.target.value),children:[r.jsx("option",{value:"date",children:t("queue.sort.byDate")}),r.jsx("option",{value:"name",children:t("queue.sort.byName")}),r.jsx("option",{value:"printer",children:t("queue.sort.byPrinter")})]}),r.jsx(Me,{variant:"ghost",size:"sm",onClick:()=>U(!E),title:t(E?"queue.sort.ascendingOldest":"queue.sort.descendingNewest"),className:"px-2",children:E?r.jsx(Hm,{className:"w-4 h-4"}):r.jsx(Bh,{className:"w-4 h-4"})})]})]}),!re&&r.jsx("div",{className:"space-y-1.5 sm:space-y-2",children:ne.slice(0,50).map(ve=>r.jsx(qnt,{item:ve,onRemove:()=>N({type:"remove",item:ve}),onRequeue:()=>x(ve),timeFormat:ae,hasPermission:a,canModify:s,t},ve.id))})]})]}),b&&r.jsx(wc,{mode:"edit-queue-item",archiveId:b.archive_id??void 0,libraryFileId:b.library_file_id??void 0,archiveName:b.archive_name||b.library_file_name||`File #${b.archive_id||b.library_file_id}`,queueItem:b,onClose:()=>w(null)}),g&&r.jsx(wc,{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:()=>x(null)}),_&&r.jsx(vn,{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"?W.mutate(_.item.id):_.type==="stop"?j.mutate(_.item.id):D.mutate(_.item.id),N(null)},onCancel:()=>N(null)}),p&&r.jsx(vn,{title:t("queue.confirm.clearHistoryTitle"),message:t("queue.confirm.clearHistoryMessage",{count:ne.length}),confirmText:t("queue.clearHistory"),variant:"danger",onConfirm:()=>{O.mutate(),f(!1)},onCancel:()=>f(!1)}),T&&r.jsx(Znt,{selectedCount:C.length,printers:Ce?.map(ve=>({id:ve.id,name:ve.name}))||[],onSave:ve=>{Object.keys(ve).length>0&&ie.mutate({item_ids:C,...ve})},onClose:()=>A(!1),isSaving:ie.isPending,canControlPrinter:a("printers:control"),t})]})}function ert({printDates:t,months:e=3}){const n=y.useRef(null),[a,i]=y.useState(0);y.useEffect(()=>{const _=n.current;if(!_)return;const N=new ResizeObserver(C=>{const P=C[0]?.contentRect.width||0;i(P)});return N.observe(_),()=>N.disconnect()},[]);const{weeks:s,monthLabels:o,printCounts:l}=y.useMemo(()=>{const _={};t.forEach(U=>{const I=U.split("T")[0];_[I]=(_[I]||0)+1});const N=new Date,C=new Date(N);C.setMonth(C.getMonth()-e),C.setDate(C.getDate()-C.getDay());const P=[],T=[];let A=[],F=-1;const S=new Date(C);let E=0;for(;S<=N;)S.getDay()===0&&A.length>0&&(P.push(A),A=[],E++),S.getMonth()!==F&&(T.push({month:S.toLocaleDateString("en-US",{month:"short"}),weekIndex:E}),F=S.getMonth()),A.push(new Date(S)),S.setDate(S.getDate()+1);return A.length>0&&P.push(A),{weeks:P,monthLabels:T,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,b=a-p-16,w=m>0?Math.floor((b-(m-1)*f)/m):12,g=Math.max(8,Math.min(20,w)),x=g<=10?10:12;return r.jsx("div",{ref:n,className:"w-full flex justify-center",children:a>0&&r.jsxs("div",{children:[r.jsx("div",{className:"flex mb-1",style:{marginLeft:p+4},children:o.map(({month:_,weekIndex:N},C)=>r.jsx("div",{className:"text-bambu-gray",style:{fontSize:x,marginLeft:C===0?0:`${(N-(o[C-1]?.weekIndex||0))*(g+f)-24}px`},children:_},C))}),r.jsxs("div",{className:"flex",style:{gap:f},children:[r.jsx("div",{className:"flex flex-col",style:{gap:f,marginRight:4,width:p},children:u.map((_,N)=>r.jsx("div",{className:"text-bambu-gray flex items-center",style:{width:p,height:g,fontSize:x,visibility:N%2===1?"visible":"hidden"},children:_},_))}),s.map((_,N)=>r.jsx("div",{className:"flex flex-col",style:{gap:f},children:[0,1,2,3,4,5,6].map(C=>{const P=_.find(S=>S.getDay()===C);if(!P)return r.jsx("div",{style:{width:g,height:g}},C);const T=P.toISOString().split("T")[0],A=l[T]||0,F=T===new Date().toISOString().split("T")[0];return r.jsx("div",{className:`rounded-sm ${d(A)} ${F?"ring-1 ring-white":""}`,style:{width:g,height:g},title:`${P.toLocaleDateString()}: ${A} print${A!==1?"s":""}`},C)})},N))]}),r.jsxs("div",{className:"flex items-center gap-2 mt-3 text-bambu-gray",style:{fontSize:x},children:[r.jsx("span",{children:"Less"}),r.jsxs("div",{className:"flex",style:{gap:f},children:[r.jsx("div",{className:"rounded-sm bg-bambu-dark",style:{width:g,height:g}}),r.jsx("div",{className:"rounded-sm bg-bambu-green/30",style:{width:g,height:g}}),r.jsx("div",{className:"rounded-sm bg-bambu-green/50",style:{width:g,height:g}}),r.jsx("div",{className:"rounded-sm bg-bambu-green/75",style:{width:g,height:g}}),r.jsx("div",{className:"rounded-sm bg-bambu-green",style:{width:g,height:g}})]}),r.jsx("span",{children:"More"})]})]})})}const ZX=["weight","prints","time"];function fT({value:t,onChange:e,exclude:n}){const{t:a}=kt(),i={weight:a("stats.filamentByWeight"),prints:a("stats.filamentByPrints"),time:a("stats.filamentByTime")},s=n?ZX.filter(o=>!n.includes(o)):ZX;return r.jsx("div",{className:"flex gap-0.5 bg-bambu-dark rounded-lg p-0.5",children:s.map(o=>r.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:i[o]},o))})}function fh(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 oN=["#00ae42","#3b82f6","#f59e0b","#ef4444","#8b5cf6","#ec4899","#14b8a6","#f97316"],trt=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],JX=["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 nrt({archives:t,currency:e="$",dateFrom:n,dateTo:a}){const{t:i}=kt(),[s,o]=y.useState("weight"),[l,c]=y.useState("weight"),d=y.useMemo(()=>{const F=new Map;return t.forEach(S=>{const E=Xn(S.completed_at||S.created_at)||new Date,U=`${E.getFullYear()}-${String(E.getMonth()+1).padStart(2,"0")}-${String(E.getDate()).padStart(2,"0")}`,I=F.get(U)||{date:U,filament:0,cost:0,prints:0};I.filament+=S.filament_used_grams||0,I.cost+=S.cost||0,I.prints+=S.quantity||1,F.set(U,I)}),Array.from(F.values()).sort((S,E)=>S.date.localeCompare(E.date)).map(S=>({...S,dateLabel:new Date(S.date).toLocaleDateString("en-US",{month:"short",day:"numeric"})}))},[t]),u=y.useMemo(()=>{if(n&&a)return Math.max((new Date(a).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 F=t.map(S=>new Date(S.completed_at||S.created_at).getTime());return(Math.max(...F)-Math.min(...F))/864e5},[t,n,a]),m=y.useMemo(()=>{if(u>7)return[];const F=new Map,S=u>1;return t.forEach(E=>{const U=Xn(E.completed_at||E.created_at)||new Date,I=U.getHours(),H=`${U.getFullYear()}-${String(U.getMonth()+1).padStart(2,"0")}-${String(U.getDate()).padStart(2,"0")}T${String(I).padStart(2,"0")}`,R=F.get(H)||{date:H,filament:0,cost:0,prints:0};R.filament+=E.filament_used_grams||0,R.cost+=E.cost||0,R.prints+=E.quantity||1,F.set(H,R)}),Array.from(F.values()).sort((E,U)=>E.date.localeCompare(U.date)).map(E=>{const[U,I]=E.date.split("T"),H=new Date(U),R=parseInt(I,10),Q=S?`${trt[H.getDay()]} ${JX[R]}`:JX[R];return{...E,dateLabel:Q}})},[t,u]),p=y.useMemo(()=>{if(d.length<=60)return d;const F=new Map;return d.forEach(S=>{const E=new Date(S.date),U=new Date(E);U.setDate(E.getDate()-E.getDay());const I=`${U.getFullYear()}-${String(U.getMonth()+1).padStart(2,"0")}-${String(U.getDate()).padStart(2,"0")}`,H=F.get(I)||{week:I,filament:0,cost:0,prints:0};H.filament+=S.filament,H.cost+=S.cost,H.prints+=S.prints,F.set(I,H)}),Array.from(F.values()).sort((S,E)=>S.week.localeCompare(E.week)).map(S=>({date:S.week,dateLabel:`Week of ${new Date(S.week).toLocaleDateString("en-US",{month:"short",day:"numeric"})}`,...S}))},[d]),f=y.useMemo(()=>{const F=new Map;return t.forEach(S=>{const U=(S.filament_type||"Unknown").split(", ");U.forEach(I=>{const H=(S.filament_used_grams||0)/U.length;F.set(I,(F.get(I)||0)+H)})}),Array.from(F.entries()).map(([S,E])=>({name:S,value:Math.round(E)})).sort((S,E)=>E.value-S.value)},[t]),b=y.useMemo(()=>{const F=new Map;return t.forEach(S=>{(S.filament_type||"Unknown").split(", ").forEach(I=>{F.set(I,(F.get(I)||0)+1)})}),Array.from(F.entries()).map(([S,E])=>({name:S,value:E})).sort((S,E)=>E.value-S.value)},[t]),w=y.useMemo(()=>{const F=new Map;return t.forEach(S=>{const U=(S.filament_type||"Unknown").split(", "),I=(S.actual_time_seconds||S.print_time_seconds||0)/U.length;U.forEach(H=>{F.set(H,(F.get(H)||0)+I)})}),Array.from(F.entries()).map(([S,E])=>({name:S,value:Math.round(E/3600*10)/10})).sort((S,E)=>E.value-S.value)},[t]),g=y.useMemo(()=>{const F=new Map;return t.forEach(S=>{if(S.status!=="completed"&&S.status!=="failed")return;(S.filament_type||"Unknown").split(", ").forEach(U=>{const I=F.get(U)||{completed:0,failed:0};S.status==="completed"?I.completed++:I.failed++,F.set(U,I)})}),Array.from(F.entries()).filter(([,S])=>S.completed+S.failed>=2).map(([S,E])=>{const U=E.completed+E.failed,I=Math.round(E.completed/U*100);return{name:S,rate:I,total:U}}).sort((S,E)=>E.rate-S.rate)},[t]),x=y.useMemo(()=>{const F=new Map;return t.forEach(S=>{if(!S.filament_color)return;const E=S.filament_color.split(",").map(I=>I.trim()),U=(S.filament_used_grams||0)/E.length;E.forEach(I=>{const H=F.get(I)||{count:0,weight:0};H.count++,H.weight+=U,F.set(I,H)})}),Array.from(F.entries()).map(([S,E])=>({hex:S,value:l==="prints"?E.count:Math.round(E.weight)})).sort((S,E)=>E.value-S.value)},[t,l]),_=s==="weight"?f:s==="prints"?b:w,N=u<=7&&m.length>0?m:p,C=t.reduce((F,S)=>F+(S.filament_used_grams||0),0),P=t.reduce((F,S)=>F+(S.cost||0),0),T=t.reduce((F,S)=>F+(S.quantity||1),0),A=new Set(t.map(F=>F.printer_id).filter(Boolean)).size;return r.jsxs("div",{className:"space-y-4",children:[r.jsxs("div",{className:"grid grid-cols-3 gap-2 max-[640px]:grid-cols-1",children:[r.jsxs("div",{className:"bg-bambu-dark rounded-lg p-4",children:[r.jsxs("div",{className:"flex items-center justify-between gap-2",children:[r.jsx("p",{className:"text-sm text-bambu-gray leading-none",children:i("stats.periodFilament")}),r.jsx("p",{className:"text-2xl font-bold text-white leading-none",children:fh(C)})]}),r.jsxs("p",{className:"text-xs text-bambu-gray",children:[A," ",i("nav.printers").toLowerCase()]})]}),r.jsxs("div",{className:"bg-bambu-dark rounded-lg p-4",children:[r.jsxs("div",{className:"flex items-center justify-between gap-2",children:[r.jsx("p",{className:"text-sm text-bambu-gray leading-none",children:i("stats.periodCost")}),r.jsxs("p",{className:"text-2xl font-bold text-white leading-none",children:[e,P.toFixed(2)]})]}),r.jsxs("p",{className:"text-xs text-bambu-gray",children:[T," ",i("common.prints")]})]}),r.jsxs("div",{className:"bg-bambu-dark rounded-lg p-4",children:[r.jsxs("div",{className:"flex items-center justify-between gap-2",children:[r.jsx("p",{className:"text-sm text-bambu-gray leading-none",children:i("stats.avgPerPrint")}),r.jsxs("p",{className:"text-2xl font-bold text-white leading-none",children:[T>0?(C/T).toFixed(0):0,"g"]})]}),r.jsxs("p",{className:"text-xs text-bambu-gray",children:[e,T>0?(P/T).toFixed(2):"0.00"," avg"]})]})]}),N.length>0?r.jsxs("div",{className:"bg-bambu-dark rounded-lg p-4",children:[r.jsx("h4",{className:"text-sm font-medium text-bambu-gray mb-4",children:i("stats.usageOverTime")}),r.jsx(eu,{width:"100%",height:250,children:r.jsxs(s5,{data:N,children:[r.jsx("defs",{children:r.jsxs("linearGradient",{id:"colorFilament",x1:"0",y1:"0",x2:"0",y2:"1",children:[r.jsx("stop",{offset:"5%",stopColor:"#00ae42",stopOpacity:.3}),r.jsx("stop",{offset:"95%",stopColor:"#00ae42",stopOpacity:0})]})}),r.jsx(Cm,{strokeDasharray:"3 3",stroke:"#3d3d3d"}),r.jsx(Pm,{dataKey:"dateLabel",stroke:"#9ca3af",tick:{fontSize:12},interval:"preserveStartEnd"}),r.jsx(Tm,{stroke:"#9ca3af",tick:{fontSize:12},tickFormatter:F=>`${F}g`}),r.jsx(nu,{contentStyle:{backgroundColor:"#2d2d2d",border:"1px solid #3d3d3d",borderRadius:"8px"},labelStyle:{color:"#fff"},formatter:F=>[`${Number(F??0).toFixed(0)}g`,"Filament"]}),r.jsx(DA,{type:"monotone",dataKey:"filament",stroke:"#00ae42",strokeWidth:2,fillOpacity:1,fill:"url(#colorFilament)"})]})})]}):r.jsx("div",{className:"bg-bambu-dark rounded-lg p-8 text-center text-bambu-gray",children:i("stats.noPrintDataInRange")}),r.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-4",children:[r.jsxs("div",{className:"bg-bambu-dark rounded-lg p-4",children:[r.jsxs("div",{className:"flex items-center justify-between mb-4",children:[r.jsx("h4",{className:"text-sm font-medium text-bambu-gray",children:i("stats.byMaterial")}),r.jsx(fT,{value:s,onChange:o})]}),_.length>0?r.jsxs("div",{className:"flex items-center gap-4",children:[r.jsx(eu,{width:160,height:160,children:r.jsxs(TK,{children:[r.jsx(WR,{data:_,cx:"50%",cy:"50%",innerRadius:40,outerRadius:70,paddingAngle:2,dataKey:"value",children:_.map((F,S)=>r.jsx(Dy,{fill:oN[S%oN.length]},`cell-${S}`))}),r.jsx(nu,{contentStyle:{backgroundColor:"#2d2d2d",border:"1px solid #3d3d3d",borderRadius:"8px"},formatter:F=>[s==="weight"?fh(Number(F??0)):s==="time"?`${Number(F??0)}h`:`${F??0}`,s==="weight"?"Usage":s==="time"?"Time":"Prints"]})]})}),r.jsx("div",{className:"flex-1 space-y-2 overflow-hidden",children:_.map((F,S)=>{const E=_.reduce((I,H)=>I+H.value,0),U=E>0?(F.value/E*100).toFixed(0):0;return r.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[r.jsx("div",{className:"w-3 h-3 rounded-sm flex-shrink-0",style:{backgroundColor:oN[S%oN.length]}}),r.jsx("span",{className:"text-white truncate flex-1",children:F.name}),r.jsxs("span",{className:"text-bambu-gray flex-shrink-0",children:[s==="weight"?fh(F.value):s==="time"?`${F.value}h`:F.value," · ",U,"%"]})]},F.name)})})]}):r.jsx("div",{className:"h-[160px] flex items-center justify-center text-bambu-gray",children:i("stats.noFilamentData")})]}),r.jsxs("div",{className:"bg-bambu-dark rounded-lg p-4",children:[r.jsx("h4",{className:"text-sm font-medium text-bambu-gray mb-4",children:i("stats.filamentSuccess")}),g.length>0?r.jsx("div",{className:"space-y-1.5",children:g.map(F=>r.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[r.jsx("span",{className:"text-white truncate w-20 flex-shrink-0",children:F.name}),r.jsx("div",{className:"flex-1 h-1.5 bg-bambu-dark-secondary rounded-full",children:r.jsx("div",{className:`h-full rounded-full transition-all ${F.rate>=90?"bg-status-ok":F.rate>=70?"bg-status-warning":"bg-status-error"}`,style:{width:`${F.rate}%`}})}),r.jsxs("span",{className:`font-medium flex-shrink-0 tabular-nums ${F.rate>=90?"text-status-ok":F.rate>=70?"text-status-warning":"text-status-error"}`,children:[F.rate,"%"]}),r.jsxs("span",{className:"text-bambu-gray flex-shrink-0 text-xs",children:["(",F.total,")"]})]},F.name))}):r.jsx("div",{className:"h-[160px] flex items-center justify-center text-bambu-gray",children:i("stats.noArchiveData")})]}),r.jsxs("div",{className:"bg-bambu-dark rounded-lg p-4",children:[r.jsxs("div",{className:"flex items-center justify-between mb-4",children:[r.jsx("h4",{className:"text-sm font-medium text-bambu-gray",children:i("stats.colorDistribution")}),r.jsx(fT,{value:l,onChange:c,exclude:["time"]})]}),x.length>0?(()=>{const F=x.reduce((S,E)=>S+E.value,0);return r.jsxs("div",{children:[r.jsxs("div",{className:"relative mx-auto",style:{width:160,height:160},children:[r.jsx(eu,{width:"100%",height:"100%",children:r.jsxs(TK,{children:[r.jsx(WR,{data:x,cx:"50%",cy:"50%",innerRadius:45,outerRadius:70,paddingAngle:2,dataKey:"value",children:x.map((S,E)=>r.jsx(Dy,{fill:S.hex,stroke:"#1a1a1a",strokeWidth:1},`color-${E}`))}),r.jsx(nu,{contentStyle:{backgroundColor:"#2d2d2d",border:"1px solid #3d3d3d",borderRadius:"8px"},formatter:S=>[l==="weight"?fh(Number(S??0)):`${S??0}`,i(l==="weight"?"stats.filamentByWeight":"stats.filamentByPrints")]})]})}),r.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center",children:[r.jsx("span",{className:"text-lg font-bold text-white",children:l==="weight"?fh(F):F}),r.jsxs("span",{className:"text-[10px] text-bambu-gray",children:[x.length," ",x.length===1?"color":"colors"]})]})]}),r.jsx("div",{className:"grid grid-cols-2 gap-x-3 gap-y-1 mt-2",children:x.slice(0,8).map(S=>{const E=F>0?(S.value/F*100).toFixed(0):0;return r.jsxs("div",{className:"flex items-center gap-1.5 text-xs min-w-0",children:[r.jsx("div",{className:"w-2.5 h-2.5 rounded-full flex-shrink-0 border border-black/20",style:{backgroundColor:S.hex}}),r.jsxs("span",{className:"text-bambu-gray truncate",children:[E,"%"]})]},S.hex)})}),x.length>8&&r.jsxs("p",{className:"text-[10px] text-bambu-gray mt-1 text-center",children:["+",x.length-8," more"]})]})})():r.jsx("div",{className:"h-[160px] flex items-center justify-center text-bambu-gray",children:i("stats.noColorData")})]})]})]})}function rrt({id:t,title:e,component:n,isHidden:a,size:i,columnSpan:s,onToggleVisibility:o,onToggleSize:l}){const{attributes:c,listeners:d,setNodeRef:u,transform:m,transition:p,isDragging:f}=Sce({id:t}),b={transform:By.Transform.toString(m),transition:p,opacity:f?.5:1};return a?null:r.jsxs("div",{ref:u,style:{...b,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:[r.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-bambu-dark-tertiary bg-bambu-dark/30",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.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:r.jsx(Ph,{className:"w-6 h-6 md:w-4 md:h-4 text-bambu-gray"})}),r.jsx("h3",{className:"text-sm font-medium text-white",children:e})]}),r.jsxs("div",{className:"flex items-center gap-1",children:[r.jsx("button",{onClick:l,className:"p-1 hover:bg-bambu-dark-tertiary rounded transition-colors",title:`Size: ${i===1?"1/4":i===2?"1/2":"Full"} - Click to cycle`,children:i===4?r.jsx(xO,{className:"w-4 h-4 text-bambu-gray hover:text-white"}):r.jsx(kT,{className:"w-4 h-4 text-bambu-gray hover:text-white"})}),r.jsx("button",{onClick:o,className:"p-1 hover:bg-bambu-dark-tertiary rounded transition-colors",title:"Hide widget",children:r.jsx(sb,{className:"w-4 h-4 text-bambu-gray hover:text-white"})})]})]}),r.jsx("div",{className:"p-4",children:typeof n=="function"?n(i):n})]})}function art({widgets:t,storageKey:e,columns:n=4,stackBelow:a,hideControls:i=!1,onResetLayout:s,renderControls:o}){const l=()=>{const F={};return t.forEach(S=>{F[S.id]=S.defaultSize||4}),F},[c,d]=y.useState(()=>{const F=localStorage.getItem(e);if(F)try{const S=JSON.parse(F);if(!S.sizes)S.sizes=l();else{const E=l();for(const U in E)U in S.sizes||(S.sizes[U]=E[U])}return S}catch{}return{order:t.map(S=>S.id),hidden:t.filter(S=>S.defaultVisible===!1).map(S=>S.id),sizes:l()}}),[u,m]=y.useState(!1),[p,f]=y.useState(!1);y.useEffect(()=>{if(!a)return;const F=window.matchMedia(`(max-width: ${a}px)`),S=U=>{f(U.matches)};S(F);const E=U=>S(U);return F.addEventListener?F.addEventListener("change",E):F.addListener(E),()=>{F.removeEventListener?F.removeEventListener("change",E):F.removeListener(E)}},[a]);const b=a&&p?1:n;y.useEffect(()=>{const F=()=>m(S=>!S);return window.addEventListener("toggle-hidden-panel",F),()=>window.removeEventListener("toggle-hidden-panel",F)},[]),y.useEffect(()=>{localStorage.setItem(e,JSON.stringify(c))},[c,e]),y.useEffect(()=>{const S=t.map(E=>E.id).filter(E=>!c.order.includes(E));S.length>0&&d(E=>({...E,order:[...E.order,...S]}))},[t,c.order]);const w=ece(mT(JA,{activationConstraint:{distance:8}}),mT(ZA,{coordinateGetter:_ce})),g=F=>{const{active:S,over:E}=F;E&&S.id!==E.id&&d(U=>{const I=U.order.indexOf(S.id),H=U.order.indexOf(E.id);return{...U,order:nj(U.order,I,H)}})},x=F=>{d(S=>({...S,hidden:S.hidden.includes(F)?S.hidden.filter(E=>E!==F):[...S.hidden,F]}))},_=F=>{d(S=>{const E=S.sizes[F]||4,U=E===1?2:E===2?4:1;return{...S,sizes:{...S.sizes,[F]:U}}})},N=()=>{const F={order:t.map(S=>S.id),hidden:t.filter(S=>S.defaultVisible===!1).map(S=>S.id),sizes:l()};d(F),s?.()},C=c.order.map(F=>t.find(S=>S.id===F)).filter(Boolean),P=C.filter(F=>!c.hidden.includes(F.id)),T=C.filter(F=>c.hidden.includes(F.id)),A=o?.({hiddenCount:T.length,showHiddenPanel:u,setShowHiddenPanel:m,resetLayout:N});return r.jsxs("div",{className:"space-y-4",children:[A,!i&&!o&&r.jsxs("div",{className:"flex items-center justify-end gap-2",children:[r.jsxs(Me,{variant:"secondary",size:"sm",onClick:N,children:[r.jsx(gs,{className:"w-4 h-4"}),"Reset Layout"]}),T.length>0&&r.jsxs(Me,{variant:"secondary",size:"sm",onClick:()=>m(!u),children:[r.jsx(Dl,{className:"w-4 h-4"}),T.length," Hidden"]})]}),u&&T.length>0&&r.jsxs("div",{className:"p-4 bg-bambu-dark rounded-xl border border-bambu-dark-tertiary",children:[r.jsx("p",{className:"text-sm text-bambu-gray mb-3",children:"Hidden widgets (click to show):"}),r.jsx("div",{className:"flex flex-wrap gap-2",children:T.map(F=>r.jsxs("button",{onClick:()=>x(F.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:[r.jsx(Dl,{className:"w-3 h-3"}),F.title]},F.id))})]}),r.jsx(bce,{sensors:w,collisionDetection:ace,onDragEnd:g,children:r.jsx(vce,{items:P.map(F=>F.id),strategy:nU,children:r.jsx("div",{className:"grid gap-6",style:{gridTemplateColumns:`repeat(${b}, minmax(0, 1fr))`},children:P.map(F=>{const S=c.sizes[F.id]||2,E=Math.min(S,b);return r.jsx(rrt,{id:F.id,title:F.title,component:F.component,isHidden:c.hidden.includes(F.id),size:S,columnSpan:E,onToggleVisibility:()=>x(F.id),onToggleSize:()=>_(F.id)},F.id)})})})}),P.length===0&&r.jsxs("div",{className:"text-center py-12 text-bambu-gray",children:[r.jsx("p",{children:"All widgets are hidden."}),r.jsx(Me,{className:"mt-4",onClick:N,children:"Reset Layout"})]})]})}function irt(t){const e=new Date,n=e.getUTCFullYear(),a=e.getUTCMonth(),i=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,a,i-(l===0?6:l-1)));return{dateFrom:s(c),dateTo:o}}case"this-month":return{dateFrom:s(new Date(Date.UTC(n,a,1))),dateTo:o};case"last-7":return{dateFrom:s(new Date(Date.UTC(n,a,i-6))),dateTo:o};case"last-30":return{dateFrom:s(new Date(Date.UTC(n,a,i-29))),dateTo:o};case"last-90":return{dateFrom:s(new Date(Date.UTC(n,a,i-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 srt=["today","this-week","this-month","last-7","last-30","last-90","this-year","all-time"],ort=["Mon","Tue","Wed","Thu","Fri","Sat","Sun"],GI=["12am","1am","2am","3am","4am","5am","6am","7am","8am","9am","10am","11am","12pm","1pm","2pm","3pm","4pm","5pm","6pm","7pm","8pm","9pm","10pm","11pm"],rF=[{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}],lN={backgroundColor:"#2d2d2d",border:"1px solid #3d3d3d",borderRadius:"8px"};function lrt({stats:t,currency:e}){const{t:n}=kt(),a=t?.energy_data_warming_up===!0,i=a?n("stats.energyWarmingUpTooltip"):void 0,s=[{icon:Br,color:"text-bambu-green",label:n("stats.totalPrints"),value:`${t?.total_prints||0}`},{icon:Zn,color:"text-blue-400",label:n("stats.printTime"),value:`${t?.total_print_time_hours?.toFixed(1)??"0"}h`},{icon:Br,color:"text-orange-400",label:n("stats.filamentUsed"),value:fh(t?.total_filament_grams||0)},{icon:QN,color:"text-green-400",label:n("stats.filamentCost"),value:`${e} ${t?.total_cost?.toFixed(2)??"0.00"}`},{icon:Nc,color:"text-yellow-400",label:n("stats.energyUsed"),value:`${t?.total_energy_kwh?.toFixed(3)??"0.000"} kWh`,warning:a,tooltip:i},{icon:QN,color:"text-yellow-500",label:n("stats.energyCost"),value:`${e} ${t?.total_energy_cost?.toFixed(2)??"0.00"}`,warning:a,tooltip:i}];return r.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 gap-4",children:s.map(o=>r.jsxs("div",{className:"flex items-start gap-3",title:o.tooltip,children:[r.jsx("div",{className:`p-2 rounded-lg bg-bambu-dark ${o.color}`,children:r.jsx(o.icon,{className:"w-5 h-5"})}),r.jsxs("div",{children:[r.jsxs("p",{className:"text-xs text-bambu-gray flex items-center gap-1",children:[o.label,o.warning&&r.jsx(Nn,{className:"w-3 h-3 text-yellow-400","aria-label":o.tooltip})]}),r.jsx("p",{className:"text-xl font-bold text-white",children:o.value})]})]},o.label))})}function crt({stats:t,printerMap:e,size:n=1}){const{t:a}=kt(),i=(t?.successful_prints||0)+(t?.failed_prints||0),s=i?Math.round(t.successful_prints/i*100):0,o=n===1?112:n===2?128:144,l=o/2-8,c=l*2*Math.PI;return r.jsxs("div",{className:"flex items-center gap-6",children:[r.jsxs("div",{className:"relative flex-shrink-0",style:{width:o,height:o},children:[r.jsxs("svg",{className:"w-full h-full -rotate-90",children:[r.jsx("circle",{cx:o/2,cy:o/2,r:l,fill:"none",stroke:"#3d3d3d",strokeWidth:"10"}),r.jsx("circle",{cx:o/2,cy:o/2,r:l,fill:"none",stroke:"#00ae42",strokeWidth:"10",strokeLinecap:"round",strokeDasharray:`${s/100*c} ${c}`})]}),r.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:r.jsxs("span",{className:`font-bold text-white ${n>=2?"text-2xl":"text-xl"}`,children:[s,"%"]})})]}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsxs("div",{className:"space-y-2",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(wr,{className:"w-4 h-4 text-status-ok flex-shrink-0"}),r.jsx("span",{className:"text-sm text-bambu-gray",children:a("stats.successful")}),r.jsx("span",{className:"text-sm text-white font-medium",children:t?.successful_prints||0})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(Da,{className:"w-4 h-4 text-status-error flex-shrink-0"}),r.jsx("span",{className:"text-sm text-bambu-gray",children:a("stats.failed")}),r.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&&r.jsxs("div",{className:"mt-4 pt-4 border-t border-bambu-dark-tertiary",children:[r.jsx("p",{className:"text-xs text-bambu-gray font-medium mb-2",children:a("stats.printsByPrinter")}),r.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])=>r.jsxs("div",{className:"flex items-center gap-3 text-sm",children:[r.jsx("span",{className:"text-bambu-gray truncate max-w-[120px]",children:e.get(d)||`${a("common.printer")} ${d}`}),r.jsx("span",{className:"text-white font-medium",children:u})]},d))})]})]})]})}function drt({stats:t,printerMap:e,size:n=1}){const{t:a}=kt(),i=t?.average_time_accuracy;if(i==null)return r.jsx("div",{className:"flex items-center justify-center h-full",children:r.jsx("p",{className:"text-bambu-gray text-center py-4",children:a("stats.noTimeAccuracyData")})});const o=(Math.min(150,Math.max(50,i))-50)/100*100,c=(w=>w>=95&&w<=105?"#00ae42":w>105?"#3b82f6":"#f97316")(i),d=i-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,b=t?.time_accuracy_by_printer?Object.entries(t.time_accuracy_by_printer).slice(0,f):[];return r.jsxs("div",{className:"flex items-center gap-6",children:[r.jsxs("div",{className:"relative flex-shrink-0",style:{width:u,height:u},children:[r.jsxs("svg",{className:"w-full h-full -rotate-90",children:[r.jsx("circle",{cx:u/2,cy:u/2,r:m,fill:"none",stroke:"#3d3d3d",strokeWidth:"10"}),r.jsx("circle",{cx:u/2,cy:u/2,r:m,fill:"none",stroke:c,strokeWidth:"10",strokeLinecap:"round",strokeDasharray:`${o/100*p} ${p}`})]}),r.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center",children:[r.jsxs("span",{className:`font-bold text-white ${n>=2?"text-2xl":"text-xl"}`,children:[i.toFixed(0),"%"]}),r.jsxs("span",{className:`text-xs ${d>=0?"text-blue-400":"text-orange-400"}`,children:[d>=0?"+":"",d.toFixed(0),"%"]})]})]}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsxs("div",{className:"flex items-center gap-2 text-xs text-bambu-gray",children:[r.jsx(OZ,{className:"w-3 h-3 flex-shrink-0"}),r.jsx("span",{children:a("stats.perfectEstimate")})]}),b.length>0&&r.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:b.map(([w,g])=>r.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[r.jsx("span",{className:"text-bambu-gray truncate max-w-[100px]",children:e.get(w)||`${a("common.printer")} ${w}`}),r.jsxs("span",{className:`font-medium ${g>=95&&g<=105?"text-status-ok":g>105?"text-blue-400":"text-status-warning"}`,children:[g.toFixed(0),"%"]})]},w))})]})]})}function urt({printDates:t,dateFrom:e,dateTo:n}){const{days:a,hourlyCounts:i,maxCount:s}=y.useMemo(()=>{const u=new Date(e+"T00:00:00"),m=new Date(n+"T00:00:00"),p=[],f=x=>`${x.getFullYear()}-${String(x.getMonth()+1).padStart(2,"0")}-${String(x.getDate()).padStart(2,"0")}`,b=new Date(u);for(;b<=m;)p.push({key:f(b),label:b.toLocaleDateString(void 0,{weekday:"short",month:"short",day:"numeric"})}),b.setDate(b.getDate()+1);const w={};let g=0;return t.forEach(x=>{const _=Xn(x);if(!_)return;const C=`${`${_.getFullYear()}-${String(_.getMonth()+1).padStart(2,"0")}-${String(_.getDate()).padStart(2,"0")}`}-${_.getHours()}`;w[C]=(w[C]||0)+1,w[C]>g&&(g=w[C])}),{days:p,hourlyCounts:w,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 r.jsxs("div",{className:"w-full overflow-x-auto",children:[r.jsxs("div",{className:"inline-flex flex-col",style:{gap:c},children:[r.jsx("div",{className:"flex",style:{gap:c,marginLeft:d+4},children:GI.map((u,m)=>r.jsx("div",{className:"text-bambu-gray text-[10px] text-center",style:{width:l,visibility:m%2===0?"visible":"hidden"},children:u},m))}),a.map(u=>r.jsxs("div",{className:"flex items-center",style:{gap:c},children:[r.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=i[`${u.key}-${p}`]||0;return r.jsx("div",{className:`rounded-sm ${o(f)}`,style:{width:l,height:l},title:`${u.label} ${GI[p]}: ${f} print${f!==1?"s":""}`},p)})]},u.key))]}),r.jsxs("div",{className:"flex items-center gap-2 mt-3 text-bambu-gray text-xs",children:[r.jsx("span",{children:"Less"}),r.jsxs("div",{className:"flex",style:{gap:c},children:[r.jsx("div",{className:"rounded-sm bg-bambu-dark",style:{width:l,height:l}}),r.jsx("div",{className:"rounded-sm bg-bambu-green/30",style:{width:l,height:l}}),r.jsx("div",{className:"rounded-sm bg-bambu-green/50",style:{width:l,height:l}}),r.jsx("div",{className:"rounded-sm bg-bambu-green/75",style:{width:l,height:l}}),r.jsx("div",{className:"rounded-sm bg-bambu-green",style:{width:l,height:l}})]}),r.jsx("span",{children:"More"})]})]})}function mrt({printDates:t,size:e=2,dateFrom:n,dateTo:a}){const i=y.useMemo(()=>n&&a?Math.max((new Date(a).getTime()-new Date(n).getTime())/864e5,0)+1:n?Math.max((Date.now()-new Date(n).getTime())/864e5,0)+1:1/0,[n,a]);if(i<=7&&n&&a)return r.jsx(urt,{printDates:t,dateFrom:n,dateTo:a});const o=i===1/0?e===1?3:e===2?6:12:Math.max(1,Math.ceil(i/30));return r.jsx(ert,{printDates:t,months:o})}function prt({stats:t,archives:e,printerMap:n}){const{t:a}=kt(),[i,s]=y.useState("weight"),[o,l]=y.useState("weight"),c=y.useMemo(()=>{const x=new Map;return t?.prints_by_printer&&Object.entries(t.prints_by_printer).forEach(([_,N])=>{const C=x.get(_)||{prints:0,weight:0,time:0};C.prints=N,x.set(_,C)}),e.forEach(_=>{if(!_.printer_id)return;const N=String(_.printer_id),C=x.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++,x.set(N,C)}),Array.from(x.entries()).map(([_,N])=>({name:n.get(_)||`${a("common.printer")} ${_}`,value:i==="prints"?N.prints:i==="weight"?Math.round(N.weight):Math.round(N.time/3600*10)/10})).sort((_,N)=>N.value-_.value)},[t,e,n,i,a]),d=y.useMemo(()=>{const x=Array.from({length:24},(_,N)=>({hour:N,label:GI[N],total:0,failures:0}));return e.forEach(_=>{if(!_.started_at)return;const N=Xn(_.started_at);if(!N)return;const C=N.getHours();x[C].total++,_.status==="failed"&&x[C].failures++}),x},[e]),u=y.useMemo(()=>{const x=rF.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 x=[0,0,0,0,0,0,0],_=new Set;e.forEach(C=>{const P=Xn(C.created_at)||new Date(C.created_at);let T=P.getDay()-1;T<0&&(T=6),o==="prints"?x[T]++:o==="weight"?x[T]+=C.filament_used_grams||0:x[T]+=(C.actual_time_seconds||C.print_time_seconds||0)/3600;const A=new Date(P);A.setDate(P.getDate()-(P.getDay()+6)%7),_.add(`${A.getFullYear()}-${String(A.getMonth()+1).padStart(2,"0")}-${String(A.getDate()).padStart(2,"0")}`)});const N=Math.max(_.size,1);return ort.map((C,P)=>({name:C,avg:Math.round(x[P]/N*10)/10}))},[e,o]),p=x=>({unit:x==="weight"?"g":x==="time"?"h":"",color:x==="weight"?"#00ae42":x==="time"?"#3b82f6":"#f59e0b"}),f=p(i),b=a(i==="weight"?"stats.filamentByWeight":i==="time"?"stats.hours":"common.prints"),w=p(o),g=a(o==="weight"?"stats.avgWeight":o==="time"?"stats.avgTime":"stats.avgPrints");return r.jsxs("div",{className:"space-y-4",children:[r.jsxs("div",{className:"bg-bambu-dark rounded-lg p-4",children:[r.jsxs("div",{className:"flex items-center justify-between mb-3",children:[r.jsx("h4",{className:"text-sm font-medium text-bambu-gray",children:a("stats.printsByPrinter")}),r.jsx(fT,{value:i,onChange:s})]}),c.length>0?r.jsx(eu,{width:"100%",height:Math.max(140,c.length*40),children:r.jsxs(q1,{data:c,layout:"vertical",margin:{left:10},children:[r.jsx(Cm,{strokeDasharray:"3 3",stroke:"#3d3d3d"}),r.jsx(Pm,{type:"number",stroke:"#9ca3af",tick:{fontSize:11},unit:f.unit}),r.jsx(Tm,{type:"category",dataKey:"name",stroke:"#9ca3af",tick:{fontSize:11},width:100}),r.jsx(nu,{contentStyle:lN,formatter:x=>[i==="weight"?fh(Number(x??0)):`${x??0}${f.unit}`,b]}),r.jsx(Ux,{dataKey:"value",fill:f.color,radius:[0,4,4,0]})]})}):r.jsx("p",{className:"text-bambu-gray text-center py-4",children:a("stats.noPrinterData")})]}),r.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-4",children:[r.jsxs("div",{className:"bg-bambu-dark rounded-lg p-4",children:[r.jsx("h4",{className:"text-sm font-medium text-bambu-gray mb-3",children:a("stats.printDuration")}),e.length>0?r.jsx(eu,{width:"100%",height:160,children:r.jsxs(q1,{data:u,children:[r.jsx(Cm,{strokeDasharray:"3 3",stroke:"#3d3d3d"}),r.jsx(Pm,{dataKey:"name",stroke:"#9ca3af",tick:{fontSize:11}}),r.jsx(Tm,{stroke:"#9ca3af",tick:{fontSize:11},allowDecimals:!1}),r.jsx(nu,{contentStyle:lN}),r.jsx(Ux,{dataKey:"count",name:a("common.prints"),fill:"#00ae42",radius:[4,4,0,0]})]})}):r.jsx("p",{className:"text-bambu-gray text-center py-4",children:a("stats.noArchiveData")})]}),r.jsxs("div",{className:"bg-bambu-dark rounded-lg p-4",children:[r.jsxs("div",{className:"flex items-center justify-between mb-3",children:[r.jsx("h4",{className:"text-sm font-medium text-bambu-gray",children:a("stats.printHabits")}),r.jsx(fT,{value:o,onChange:l})]}),e.length>0?r.jsx(eu,{width:"100%",height:160,children:r.jsxs(q1,{data:m,children:[r.jsx(Cm,{strokeDasharray:"3 3",stroke:"#3d3d3d"}),r.jsx(Pm,{dataKey:"name",stroke:"#9ca3af",tick:{fontSize:11}}),r.jsx(Tm,{stroke:"#9ca3af",tick:{fontSize:11},unit:w.unit}),r.jsx(nu,{contentStyle:lN,formatter:x=>[`${x??0}${w.unit}`,g]}),r.jsx(Ux,{dataKey:"avg",fill:w.color,radius:[4,4,0,0]})]})}):r.jsx("p",{className:"text-bambu-gray text-center py-4",children:a("stats.noArchiveData")})]}),r.jsxs("div",{className:"bg-bambu-dark rounded-lg p-4",children:[r.jsx("h4",{className:"text-sm font-medium text-bambu-gray mb-3",children:a("stats.printTimeOfDay")}),e.length>0?r.jsx(eu,{width:"100%",height:160,children:r.jsxs(q1,{data:d,children:[r.jsx(Cm,{strokeDasharray:"3 3",stroke:"#3d3d3d"}),r.jsx(Pm,{dataKey:"label",stroke:"#9ca3af",tick:{fontSize:10},interval:5}),r.jsx(Tm,{stroke:"#9ca3af",tick:{fontSize:11},allowDecimals:!1}),r.jsx(nu,{contentStyle:lN}),r.jsx(Ux,{dataKey:"total",name:a("stats.totalPrints"),fill:"#00ae42",radius:[2,2,0,0]}),r.jsx(Ux,{dataKey:"failures",name:a("stats.failed"),fill:"#ef4444",radius:[2,2,0,0]})]})}):r.jsx("p",{className:"text-bambu-gray text-center py-4",children:a("stats.noArchiveData")})]})]})]})}function hrt({archives:t,currency:e,dateFrom:n,dateTo:a}){const{t:i}=kt();return!t||t.length===0?r.jsx("p",{className:"text-bambu-gray text-center py-4",children:i("stats.noPrintData")}):r.jsx(nrt,{archives:t,currency:e,dateFrom:n,dateTo:a})}function frt({size:t=1,dateFrom:e,dateTo:n,createdById:a}){const{t:i}=kt(),s=!!(e||n),{data:o,isLoading:l}=Ve({queryKey:["failureAnalysis",e,n,a??"all"],queryFn:()=>se.getFailureAnalysis({...s?{dateFrom:e,dateTo:n}:{days:30},createdById:a})});if(l)return r.jsx("div",{className:"flex justify-center py-4",children:r.jsx(pt,{className:"w-6 h-6 text-bambu-green animate-spin"})});if(!o||o.total_prints===0)return r.jsx("p",{className:"text-bambu-gray text-center py-4",children:i(s?"stats.noPrintDataInRange":"stats.noPrintDataLast30Days")});const c=t===1?5:t===2?8:999,d=Object.entries(o.failures_by_reason).sort(([,p],[,f])=>f-p),u=d.slice(0,c),m=d.length>c;return r.jsxs("div",{className:`${t>=2?"flex gap-8":"space-y-4"}`,children:[r.jsxs("div",{className:t>=2?"flex-shrink-0":"",children:[r.jsx("div",{className:"flex items-center gap-4",children:r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(Nn,{className:`w-5 h-5 ${o.failure_rate>20?"text-status-error":o.failure_rate>10?"text-status-warning":"text-status-ok"}`}),r.jsxs("span",{className:`font-bold text-white ${t>=2?"text-3xl":"text-2xl"}`,children:[o.failure_rate.toFixed(1),"%"]})]})}),r.jsx("div",{className:"text-sm text-bambu-gray mt-1",children:i("stats.failedPrintsCount",{failed:o.failed_prints,total:o.total_prints})}),o.trend&&o.trend.length>=2&&r.jsx("div",{className:`${t>=2?"mt-4":"mt-2 pt-2 border-t border-bambu-dark-tertiary"}`,children:r.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[r.jsx(LS,{className:`w-4 h-4 ${o.trend[o.trend.length-1].failure_rate0&&r.jsxs("div",{className:`flex-1 ${t>=2?"border-l border-bambu-dark-tertiary pl-8":"pt-2"}`,children:[r.jsx("p",{className:"text-xs text-bambu-gray font-medium mb-2",children:t>=2?i("stats.failureReasons"):i("stats.topFailureReasons")}),r.jsx("div",{className:`${t===4?"grid grid-cols-2 gap-x-6 gap-y-1":"space-y-1"}`,children:u.map(([p,f])=>r.jsxs("div",{className:"flex items-center justify-between text-sm",children:[r.jsx("span",{className:`text-white truncate ${t===4?"max-w-[200px]":"max-w-[160px]"}`,children:p||i("common.unknown")}),r.jsx("span",{className:"text-bambu-gray ml-2",children:f})]},p))}),m&&r.jsx("p",{className:"text-xs text-bambu-gray mt-2",children:i("common.more",{count:d.length-c})})]})]})}function grt({archives:t,currency:e}){const{t:n}=kt(),a=y.useMemo(()=>{const i=[];if(t.length===0)return i;const s=b=>{let w=null,g=0;return t.forEach(x=>{const _=b(x);_&&_>g&&(g=_,w=x)}),{archive:w,value:g}},o=s(b=>b.actual_time_seconds);o.archive&&i.push({icon:Zn,iconColor:"text-blue-400",label:n("stats.longestPrint"),value:ds(o.value),detail:o.archive.print_name||null});const l=s(b=>b.filament_used_grams);l.archive&&i.push({icon:Br,iconColor:"text-orange-400",label:n("stats.heaviestPrint"),value:fh(l.value),detail:l.archive.print_name||null});const c=s(b=>b.cost);c.archive&&i.push({icon:QN,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(b=>{const w=Xn(b.created_at)||new Date(b.created_at),g=`${w.getFullYear()}-${String(w.getMonth()+1).padStart(2,"0")}-${String(w.getDate()).padStart(2,"0")}`;d.set(g,(d.get(g)||0)+1)});let u="",m=0;d.forEach((b,w)=>{b>m&&(m=b,u=w)}),m>1&&i.push({icon:Sa,iconColor:"text-purple-400",label:n("stats.busiestDay"),value:`${m} ${n("common.prints")}`,detail:(()=>{const[b,w,g]=u.split("-").map(Number);return new Date(b,w-1,g).toLocaleDateString(void 0,{month:"short",day:"numeric",year:"numeric"})})()});const p=[...t].filter(b=>b.status==="completed"||b.status==="failed").sort((b,w)=>new Date(w.completed_at||w.created_at).getTime()-new Date(b.completed_at||b.created_at).getTime());let f=0;for(const b of p)if(b.status==="completed")f++;else break;return f>0&&i.push({icon:Nc,iconColor:"text-yellow-400",label:n("stats.successStreak"),value:`${f}`,detail:f===1?n("stats.streakPrint"):n("stats.streakPrints",{count:f})}),i},[t,e,n]);return a.length===0?r.jsx("p",{className:"text-bambu-gray text-center py-4",children:n("stats.noArchiveData")}):r.jsx("div",{className:"space-y-3",children:a.map((i,s)=>r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx("div",{className:`p-1.5 rounded-lg bg-bambu-dark ${i.iconColor}`,children:r.jsx(i.icon,{className:"w-4 h-4"})}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("p",{className:"text-xs text-bambu-gray",children:i.label}),r.jsxs("div",{className:"flex items-baseline gap-2",children:[r.jsx("span",{className:"text-sm font-bold text-white",children:i.value}),i.detail&&r.jsx("span",{className:"text-xs text-bambu-gray truncate",children:i.detail})]})]})]},s))})}function brt(){const{t}=kt(),{showToast:e}=rn(),{hasPermission:n,authEnabled:a}=cr(),[i,s]=y.useState(!1),[o,l]=y.useState(!1),[c,d]=y.useState(0),[u,m]=y.useState(0),[p,f]=y.useState(!1),[b,w]=y.useState(null),[g,x]=y.useState(!1),_=a&&n("stats:filter_by_user"),[N,C]=y.useState(()=>{try{const W=localStorage.getItem("bambusy-stats-timeframe");if(W){const D=JSON.parse(W);if(D.preset)return D}}catch{}return{preset:"all-time",dateFrom:void 0,dateTo:void 0}}),[P,T]=y.useState(!1);y.useEffect(()=>{localStorage.setItem("bambusy-stats-timeframe",JSON.stringify(N))},[N]);const A=y.useMemo(()=>N.preset==="custom"?{dateFrom:N.dateFrom,dateTo:N.dateTo}:irt(N.preset),[N]);y.useEffect(()=>{const W=()=>{try{const j=localStorage.getItem("bambusy-dashboard-layout-v2");if(j){const B=JSON.parse(j);m(B.hidden?.length||0)}}catch{m(0)}};W(),window.addEventListener("storage",W);const D=setInterval(W,2e3);return()=>{window.removeEventListener("storage",W),clearInterval(D)}},[c]);const F=b!==null?b:void 0,{data:S,isLoading:E,isFetching:U,refetch:I}=Ve({queryKey:["archiveStats",A.dateFrom,A.dateTo,F??"all"],queryFn:()=>se.getArchiveStats({dateFrom:A.dateFrom,dateTo:A.dateTo,createdById:F})}),{data:H}=Ve({queryKey:["printers"],queryFn:se.getPrinters}),{data:R,isFetching:Q,refetch:re}=Ve({queryKey:["archivesSlim",A.dateFrom,A.dateTo,F??"all"],queryFn:()=>se.getArchivesSlim(A.dateFrom,A.dateTo,F)}),{data:J}=Ve({queryKey:["settings"],queryFn:se.getSettings}),{data:de}=Ve({queryKey:["users"],queryFn:se.getUsers,enabled:_}),pe=y.useMemo(()=>b===null?t("stats.allUsers","All Users"):b===-1?t("stats.noUser","No User (System)"):de?.find(W=>W.id===b)?.username??"?",[b,de,t]),ue=async W=>{l(!1),s(!0);try{const{blob:D,filename:j}=await se.exportStats({format:W,days:90,createdById:F}),B=URL.createObjectURL(D),Y=document.createElement("a");Y.href=B,Y.download=j,Y.click(),URL.revokeObjectURL(B),e(t("stats.exportDownloaded"))}catch{e(t("stats.exportFailed"),"error")}finally{s(!1)}},X=async()=>{f(!0);try{const W=await se.recalculateCosts();await Promise.all([I(),re()]),e(t("stats.recalculatedCosts",{count:W.updated}))}catch{e(t("stats.recalculateFailed"),"error")}finally{f(!1)}},ae=(U||Q)&&!E,me=Vo(J?.currency||"USD"),be=new Map(H?.map(W=>[String(W.id),W.name])||[]),Ce=y.useMemo(()=>R?.map(W=>W.created_at)||[],[R]);if(E)return r.jsx("div",{className:"p-4 md:p-8",children:r.jsx("div",{className:"text-center py-12 text-bambu-gray",children:t("stats.loadingStats")})});const $=[{id:"quick-stats",title:t("stats.quickStats"),component:r.jsx(lrt,{stats:S,currency:me}),defaultSize:2},{id:"success-rate",title:t("stats.successRate"),component:W=>r.jsx(crt,{stats:S,printerMap:be,size:W}),defaultSize:1},{id:"time-accuracy",title:t("stats.timeAccuracy"),component:W=>r.jsx(drt,{stats:S,printerMap:be,size:W}),defaultSize:1},{id:"failure-analysis",title:t("stats.failureAnalysis"),component:W=>r.jsx(frt,{size:W,dateFrom:A.dateFrom,dateTo:A.dateTo,createdById:F}),defaultSize:1},{id:"print-activity",title:t("stats.printActivity"),component:W=>r.jsx(mrt,{printDates:Ce,size:W,dateFrom:A.dateFrom,dateTo:A.dateTo}),defaultSize:2},{id:"records",title:t("stats.records"),component:r.jsx(grt,{archives:R||[],currency:me}),defaultSize:1},{id:"printer-stats",title:t("stats.printerStats"),component:r.jsx(prt,{stats:S,archives:R||[],printerMap:be}),defaultSize:4},{id:"filament-trends",title:t("stats.filamentTrends"),component:r.jsx(hrt,{archives:R||[],currency:me,dateFrom:A.dateFrom,dateTo:A.dateTo}),defaultSize:4}];return r.jsxs("div",{className:"p-4 md:p-8",children:[r.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4 mb-6",children:[r.jsxs("div",{children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsxs("h1",{className:"text-2xl font-bold text-white flex items-center gap-3",children:[r.jsx(PZ,{className:"w-7 h-7 text-bambu-green"}),t("stats.title")]}),ae&&r.jsx(pt,{className:"w-5 h-5 text-bambu-green animate-spin"})]}),r.jsx("p",{className:"text-bambu-gray mt-1",children:t("stats.subtitle")})]}),r.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[u>0&&r.jsxs(Me,{variant:"secondary",onClick:()=>{window.dispatchEvent(new CustomEvent("toggle-hidden-panel"))},children:[r.jsx(Dl,{className:"w-4 h-4"}),t("stats.hiddenCount",{count:u})]}),r.jsxs(Me,{variant:"secondary",onClick:()=>{localStorage.removeItem("bambusy-dashboard-layout-v2"),d(W=>W+1),e(t("stats.layoutReset"))},disabled:!n("settings:update"),title:n("settings:update")?void 0:t("stats.noPermissionResetLayout"),children:[r.jsx(gs,{className:"w-4 h-4"}),t("stats.resetLayout")]}),r.jsxs(Me,{variant:"secondary",onClick:X,disabled:p||!n("archives:update_all"),title:n("archives:update_all")?t("stats.recalculateCostsHint"):t("stats.noPermissionRecalculate"),children:[p?r.jsx(pt,{className:"w-4 h-4 animate-spin"}):r.jsx(Dfe,{className:"w-4 h-4"}),t("stats.recalculateCosts")]}),r.jsxs("div",{className:"relative",children:[r.jsxs(Me,{variant:"secondary",onClick:()=>l(!o),disabled:i,children:[i?r.jsx(pt,{className:"w-4 h-4 animate-spin"}):r.jsx(JN,{className:"w-4 h-4"}),t("stats.exportStats")]}),o&&r.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:[r.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:()=>ue("csv"),children:[r.jsx(Bs,{className:"w-4 h-4"}),t("stats.exportAsCsv")]}),r.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:()=>ue("xlsx"),children:[r.jsx(JN,{className:"w-4 h-4"}),t("stats.exportAsExcel")]})]})]}),_&&de&&de.length>0&&r.jsxs("div",{className:"relative",children:[r.jsxs(Me,{variant:"secondary",onClick:()=>x(!g),children:[r.jsx(gm,{className:"w-4 h-4"}),pe,r.jsx(Ln,{className:"w-3 h-3"})]}),g&&r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"fixed inset-0 z-10",onClick:()=>x(!1)}),r.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 p-2 max-h-64 overflow-y-auto",children:[r.jsx("button",{className:`w-full px-3 py-2 text-left text-sm rounded-md transition-colors ${b===null?"bg-bambu-green text-white":"text-white hover:bg-bambu-dark-tertiary"}`,onClick:()=>{w(null),x(!1)},children:t("stats.allUsers","All Users")}),r.jsx("button",{className:`w-full px-3 py-2 text-left text-sm rounded-md transition-colors ${b===-1?"bg-bambu-green text-white":"text-white hover:bg-bambu-dark-tertiary"}`,onClick:()=>{w(-1),x(!1)},children:t("stats.noUser","No User (System)")}),r.jsx("div",{className:"border-t border-bambu-dark-tertiary my-1"}),de.map(W=>r.jsx("button",{className:`w-full px-3 py-2 text-left text-sm rounded-md transition-colors ${b===W.id?"bg-bambu-green text-white":"text-white hover:bg-bambu-dark-tertiary"}`,onClick:()=>{w(W.id),x(!1)},children:W.username},W.id))]})]})]}),r.jsxs("div",{className:"relative",children:[r.jsxs(Me,{variant:"secondary",onClick:()=>T(!P),children:[r.jsx(Sa,{className:"w-4 h-4"}),t(`stats.timeframe.${N.preset}`),r.jsx(Ln,{className:"w-3 h-3"})]}),P&&r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"fixed inset-0 z-10",onClick:()=>T(!1)}),r.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:[srt.map(W=>r.jsx("button",{className:`w-full px-3 py-2 text-left text-sm rounded-md transition-colors ${N.preset===W?"bg-bambu-green text-white":"text-white hover:bg-bambu-dark-tertiary"}`,onClick:()=>{C({preset:W,dateFrom:void 0,dateTo:void 0}),T(!1)},children:t(`stats.timeframe.${W}`)},W)),r.jsx("div",{className:"border-t border-bambu-dark-tertiary my-2"}),r.jsx("button",{className:`w-full px-3 py-2 text-left text-sm rounded-md transition-colors ${N.preset==="custom"?"bg-bambu-green text-white":"text-white hover:bg-bambu-dark-tertiary"}`,onClick:()=>C(W=>({...W,preset:"custom"})),children:t("stats.timeframe.custom")}),N.preset==="custom"&&r.jsxs("div",{className:"mt-2 px-1 pb-1 space-y-2",children:[r.jsxs("div",{children:[r.jsx("label",{className:"text-xs text-bambu-gray block mb-1",children:t("stats.timeframe.from")}),r.jsx("input",{type:"date",value:N.dateFrom||"",max:N.dateTo||new Date().toISOString().split("T")[0],onChange:W=>C(D=>({...D,dateFrom:W.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]"})]}),r.jsxs("div",{children:[r.jsx("label",{className:"text-xs text-bambu-gray block mb-1",children:t("stats.timeframe.to")}),r.jsx("input",{type:"date",value:N.dateTo||"",min:N.dateFrom,max:new Date().toISOString().split("T")[0],onChange:W=>C(D=>({...D,dateTo:W.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]"})]}),r.jsx(Me,{variant:"primary",onClick:()=>T(!1),className:"w-full",children:t("common.apply")})]})]})]})]})]})]}),r.jsx(art,{widgets:$,storageKey:"bambusy-dashboard-layout-v2",stackBelow:640,hideControls:!0},c)]})}function cN(t){return t.length<8?"tooShort":/[A-Z]/.test(t)?/[a-z]/.test(t)?/\d/.test(t)?/[^A-Za-z0-9]/.test(t)?null:"needsSpecial":"needsDigit":"needsLowercase":"needsUppercase"}function xrt(){const{t}=kt(),e=en(),{showToast:n}=rn(),a=y.useRef(null),[i,s]=y.useState(null),{data:o,isLoading:l}=Ve({queryKey:["slicer-bundles"],queryFn:se.listSlicerBundles}),c=it({mutationFn:m=>se.importSlicerBundle(m),onSuccess:m=>{e.invalidateQueries({queryKey:["slicer-bundles"]}),n(t("settings.slicerBundles.uploadSuccess",{defaultValue:"Imported {{name}}",name:m.printer_preset_name}),"success"),a.current&&(a.current.value="")},onError:m=>{n(t("settings.slicerBundles.uploadError",{defaultValue:"Bundle upload failed: {{message}}",message:m.message}),"error"),a.current&&(a.current.value="")}}),d=it({mutationFn:m=>se.deleteSlicerBundle(m),onSuccess:()=>{e.invalidateQueries({queryKey:["slicer-bundles"]}),s(null),n(t("settings.slicerBundles.deleteSuccess",{defaultValue:"Bundle removed"}),"success")},onError:m=>{n(t("settings.slicerBundles.deleteError",{defaultValue:"Bundle delete failed: {{message}}",message:m.message}),"error"),s(null)}}),u=m=>{const p=m.target.files?.[0];p&&c.mutate(p)};return r.jsxs(Ct,{children:[r.jsx(pn,{children:r.jsxs("h3",{className:"text-base font-semibold text-white flex items-center gap-2",children:[r.jsx(Br,{className:"w-4 h-4 text-bambu-green"}),t("settings.slicerBundles.title",{defaultValue:"Slicer Bundles"})]})}),r.jsxs(At,{className:"space-y-3",children:[r.jsx("p",{className:"text-xs text-bambu-gray",children:t("settings.slicerBundles.description",{defaultValue:'Import a Printer Preset Bundle (.bbscfg) exported from BambuStudio (File → Export → Export Preset Bundle → "Printer preset bundle"). Once imported, slice requests can pick presets from the bundle by name without re-uploading the JSON profile triplet.'})}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("input",{ref:a,type:"file",accept:".bbscfg,.zip,application/zip",onChange:u,className:"hidden",disabled:c.isPending}),r.jsx(Me,{variant:"primary",onClick:()=>a.current?.click(),disabled:c.isPending,children:c.isPending?r.jsxs(r.Fragment,{children:[r.jsx(pt,{className:"w-4 h-4 animate-spin"}),t("settings.slicerBundles.uploading",{defaultValue:"Uploading…"})]}):r.jsxs(r.Fragment,{children:[r.jsx(ka,{className:"w-4 h-4"}),t("settings.slicerBundles.uploadButton",{defaultValue:"Upload bundle"})]})})]}),l?r.jsxs("div",{className:"flex items-center gap-2 text-sm text-bambu-gray",children:[r.jsx(pt,{className:"w-4 h-4 animate-spin"}),t("settings.slicerBundles.loading",{defaultValue:"Loading bundles…"})]}):o&&o.length>0?r.jsx("ul",{className:"divide-y divide-bambu-dark-tertiary border border-bambu-dark-tertiary rounded-lg",children:o.map(m=>r.jsxs("li",{className:"flex items-center justify-between px-3 py-2 hover:bg-bambu-dark-tertiary/30",children:[r.jsxs("div",{className:"min-w-0 flex-1",children:[r.jsx("p",{className:"text-sm text-white truncate",children:m.printer_preset_name}),r.jsxs("p",{className:"text-xs text-bambu-gray mt-0.5",children:[t("settings.slicerBundles.summary",{defaultValue:"{{processCount}} process · {{filamentCount}} filament presets",processCount:m.process.length,filamentCount:m.filament.length}),m.version&&` · v${m.version}`]})]}),r.jsx("button",{type:"button",onClick:()=>s(m),disabled:d.isPending,className:"ml-3 p-1.5 text-bambu-gray hover:text-red-400 disabled:opacity-40","aria-label":t("settings.slicerBundles.delete",{defaultValue:"Delete"}),children:r.jsx(Jt,{className:"w-4 h-4"})})]},m.id))}):r.jsx("p",{className:"text-sm text-bambu-gray italic",children:t("settings.slicerBundles.empty",{defaultValue:"No bundles imported yet."})})]}),i&&r.jsx(vn,{title:t("settings.slicerBundles.confirmDeleteTitle",{defaultValue:"Remove this bundle?"}),message:t("settings.slicerBundles.confirmDeleteMessage",{defaultValue:'Slice requests that reference "{{name}}" will fail until the bundle is re-imported.',name:i.printer_preset_name}),confirmText:t("common.delete",{defaultValue:"Delete"}),variant:"danger",isLoading:d.isPending,onConfirm:()=>d.mutate(i.id),onCancel:()=>s(null)})]})}const eQ=90,tQ=365;function aF(t){return t?new Date(t).toLocaleString():"—"}function yrt(t){return new Date(t).getTime(){if(u.preventDefault(),!!a.trim()){c(!0);try{const m=await se.createLongLivedCameraToken({name:a.trim(),expires_in_days:s});t(m),i(""),o(eQ),n(e("cameraTokens.toast.created","Token created"))}catch(m){n(m instanceof Error?m.message:e("cameraTokens.toast.createFailed","Failed to create token"),"error")}finally{c(!1)}}};return r.jsxs("form",{onSubmit:d,className:"bg-bambu-dark-secondary rounded-lg p-4 mb-6 border border-bambu-dark-tertiary",children:[r.jsx("h3",{className:"text-base font-semibold text-white mb-3",children:e("cameraTokens.create.title","Create new token")}),r.jsxs("div",{className:"grid gap-3 md:grid-cols-[1fr_140px_auto]",children:[r.jsx("input",{type:"text",maxLength:100,required:!0,value:a,onChange:u=>i(u.target.value),placeholder:e("cameraTokens.create.namePlaceholder","e.g. Home Assistant"),className:"px-3 py-2 bg-bambu-dark rounded-md text-white border border-bambu-dark-tertiary focus:border-bambu-green focus:outline-none","aria-label":e("cameraTokens.create.nameLabel","Token name")}),r.jsx("input",{type:"number",min:1,max:tQ,required:!0,value:s,onChange:u=>{const m=Number(u.target.value);o(Math.min(Math.max(m,1),tQ))},className:"px-3 py-2 bg-bambu-dark rounded-md text-white border border-bambu-dark-tertiary focus:border-bambu-green focus:outline-none","aria-label":e("cameraTokens.create.daysLabel","Days until expiry")}),r.jsxs("button",{type:"submit",disabled:l||!a.trim(),className:"flex items-center gap-2 px-4 py-2 bg-bambu-green text-white rounded-md hover:bg-bambu-green/90 disabled:opacity-50 disabled:cursor-not-allowed",children:[r.jsx(ar,{className:"w-4 h-4"}),e("cameraTokens.create.submit","Create")]})]}),r.jsx("p",{className:"text-xs text-bambu-gray mt-2",children:e("cameraTokens.create.hint","Maximum lifetime is 365 days. The token value is shown only once on creation — copy it now.")})]})}function wrt({token:t,onConfirm:e,onCancel:n}){const{t:a}=kt();return r.jsx("div",{className:"fixed inset-0 bg-black/60 flex items-center justify-center z-50 p-4",role:"dialog","aria-modal":"true",children:r.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg p-6 max-w-md w-full border border-red-500/40",children:[r.jsxs("div",{className:"flex items-start gap-3 mb-4",children:[r.jsx(Nn,{className:"w-6 h-6 text-red-400 flex-shrink-0 mt-0.5"}),r.jsxs("div",{children:[r.jsx("h2",{className:"text-lg font-semibold text-white",children:a("cameraTokens.confirmRevoke.title","Revoke this token?")}),r.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:a("cameraTokens.confirmRevoke.body",'Any device using "{{name}}" will lose access immediately. This cannot be undone.',{name:t.name})})]})]}),r.jsxs("div",{className:"flex justify-end gap-2",children:[r.jsx("button",{type:"button",onClick:n,className:"px-4 py-2 bg-bambu-dark-tertiary text-white rounded-md hover:bg-bambu-dark-tertiary/80",children:a("cameraTokens.confirmRevoke.cancel","Cancel")}),r.jsx("button",{type:"button",onClick:e,className:"px-4 py-2 bg-red-500 text-white rounded-md hover:bg-red-600",children:a("cameraTokens.confirmRevoke.confirm","Revoke")})]})]})})}function Srt({token:t,onClose:e}){const{t:n}=kt(),{showToast:a}=rn(),i=t.token??"",s=async()=>{if(i)try{if(navigator.clipboard&&window.isSecureContext)await navigator.clipboard.writeText(i);else{const o=document.createElement("textarea");o.value=i,o.style.position="fixed",o.style.opacity="0",document.body.appendChild(o);try{o.select(),document.execCommand("copy")}finally{document.body.removeChild(o)}}a(n("cameraTokens.toast.copied","Copied to clipboard"))}catch{a(n("cameraTokens.toast.copyFailed","Copy failed — select and copy manually"),"error")}};return r.jsx("div",{className:"fixed inset-0 bg-black/60 flex items-center justify-center z-50 p-4",children:r.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg p-6 max-w-2xl w-full border border-bambu-green/40",children:[r.jsxs("div",{className:"flex items-start gap-3 mb-4",children:[r.jsx(Nn,{className:"w-6 h-6 text-yellow-400 flex-shrink-0 mt-0.5"}),r.jsxs("div",{children:[r.jsx("h2",{className:"text-lg font-semibold text-white",children:n("cameraTokens.created.title","Token created — copy it now")}),r.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:n("cameraTokens.created.warning","This is the only time this token will be visible. After you close this dialog you can never view it again.")})]})]}),r.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[r.jsx("code",{className:"flex-1 px-3 py-2 bg-bambu-dark rounded-md text-bambu-green text-xs break-all font-mono select-all",children:i}),r.jsxs("button",{type:"button",onClick:s,className:"flex items-center gap-2 px-3 py-2 bg-bambu-green text-white rounded-md hover:bg-bambu-green/90",children:[r.jsx(Mi,{className:"w-4 h-4"}),n("cameraTokens.created.copy","Copy")]})]}),r.jsx("div",{className:"flex justify-end",children:r.jsx("button",{type:"button",onClick:e,className:"px-4 py-2 bg-bambu-dark-tertiary text-white rounded-md hover:bg-bambu-dark-tertiary/80",children:n("cameraTokens.created.dismiss","I've saved it")})})]})})}function _rt({token:t,showOwner:e,ownerLabel:n,onRevoke:a}){const{t:i}=kt(),s=yrt(t.expires_at);return r.jsxs("tr",{className:"border-b border-bambu-dark-tertiary last:border-b-0",children:[r.jsx("td",{className:"py-3 px-3 text-white",children:t.name}),e&&r.jsx("td",{className:"py-3 px-3 text-bambu-gray",children:n}),r.jsxs("td",{className:"py-3 px-3 text-bambu-gray font-mono text-xs",children:[t.lookup_prefix,"…"]}),r.jsx("td",{className:"py-3 px-3 text-bambu-gray",children:aF(t.created_at)}),r.jsxs("td",{className:`py-3 px-3 ${s?"text-red-400":"text-bambu-gray"}`,children:[aF(t.expires_at),s&&r.jsx("span",{className:"ml-2 px-2 py-0.5 text-xs bg-red-500/20 text-red-300 rounded",children:i("cameraTokens.list.expired","Expired")})]}),r.jsx("td",{className:"py-3 px-3 text-bambu-gray",children:aF(t.last_used_at)}),r.jsx("td",{className:"py-3 px-3 text-right",children:r.jsxs("button",{type:"button",onClick:()=>a(t.id),className:"inline-flex items-center gap-1 px-2 py-1 text-sm text-red-400 hover:text-red-300",title:i("cameraTokens.list.revoke","Revoke"),children:[r.jsx(Jt,{className:"w-4 h-4"}),i("cameraTokens.list.revoke","Revoke")]})})]})}function nQ({tokens:t,showOwner:e,userIdToName:n,onRevoke:a,emptyMessage:i}){const{t:s}=kt();return t.length===0?r.jsx("p",{className:"text-sm text-bambu-gray italic",children:i}):r.jsx("div",{className:"overflow-x-auto",children:r.jsxs("table",{className:"w-full text-sm",children:[r.jsx("thead",{className:"text-bambu-gray text-left border-b border-bambu-dark-tertiary",children:r.jsxs("tr",{children:[r.jsx("th",{className:"py-2 px-3 font-medium",children:s("cameraTokens.list.name","Name")}),e&&r.jsx("th",{className:"py-2 px-3 font-medium",children:s("cameraTokens.list.owner","Owner")}),r.jsx("th",{className:"py-2 px-3 font-medium",children:s("cameraTokens.list.prefix","Prefix")}),r.jsx("th",{className:"py-2 px-3 font-medium",children:s("cameraTokens.list.created","Created")}),r.jsx("th",{className:"py-2 px-3 font-medium",children:s("cameraTokens.list.expires","Expires")}),r.jsx("th",{className:"py-2 px-3 font-medium",children:s("cameraTokens.list.lastUsed","Last used")}),r.jsx("th",{className:"py-2 px-3"})]})}),r.jsx("tbody",{children:t.map(o=>r.jsx(_rt,{token:o,showOwner:e,ownerLabel:n?.get(o.user_id)??`#${o.user_id}`,onRevoke:a},o.id))})]})})}function krt(){const{t}=kt(),{user:e,isAdmin:n}=cr(),{showToast:a}=rn(),[i,s]=y.useState([]),[o,l]=y.useState([]),[c,d]=y.useState(new Map),[u,m]=y.useState(!0),[p,f]=y.useState(null),[b,w]=y.useState(null),g=async()=>{m(!0);try{const C=await se.listMyLongLivedCameraTokens();if(s(C),n){const P=await se.listAllLongLivedCameraTokens();l(P);try{const T=await se.getUsers();d(new Map(T.map(A=>[A.id,A.username])))}catch{d(new Map)}}}catch(C){a(C instanceof Error?C.message:t("cameraTokens.toast.loadFailed","Failed to load tokens"),"error")}finally{m(!1)}};y.useEffect(()=>{g()},[n]);const x=async C=>{const P=[...i,...o].find(T=>T.id===C);P&&w(P)},_=async()=>{if(!b)return;const C=b.id;w(null);try{await se.revokeLongLivedCameraToken(C),a(t("cameraTokens.toast.revoked","Token revoked")),await g()}catch(P){a(P instanceof Error?P.message:t("cameraTokens.toast.revokeFailed","Failed to revoke token"),"error")}},N=y.useMemo(()=>o.filter(C=>C.user_id!==e?.id),[o,e?.id]);return r.jsxs(r.Fragment,{children:[r.jsx("p",{className:"text-sm text-bambu-gray mb-4",children:t("cameraTokens.description","Long-lived tokens for embedding the camera stream into Home Assistant, Frigate, kiosks, or any other tool that needs a stable URL. Each token is camera-stream-only and can be revoked at any time.")}),r.jsx(vrt,{onCreated:C=>{f(C),g()}}),r.jsxs("div",{className:"mb-6",children:[r.jsx("h3",{className:"text-base font-semibold text-white mb-3",children:t("cameraTokens.list.myTitle","My tokens")}),u?r.jsx("p",{className:"text-sm text-bambu-gray",children:t("cameraTokens.loading","Loading…")}):r.jsx(nQ,{tokens:i,onRevoke:x,emptyMessage:t("cameraTokens.list.empty","No tokens yet.")})]}),n&&r.jsxs("div",{children:[r.jsx("h3",{className:"text-base font-semibold text-white mb-3",children:t("cameraTokens.list.allTitle","All users (admin view)")}),r.jsx(nQ,{tokens:N,showOwner:!0,userIdToName:c,onRevoke:x,emptyMessage:t("cameraTokens.list.empty","No tokens yet.")})]}),p&&r.jsx(Srt,{token:p,onClose:()=>f(null)}),b&&r.jsx(wrt,{token:b,onConfirm:()=>{_()},onCancel:()=>w(null)})]})}function Nrt({plug:t,onEdit:e}){const{t:n}=kt(),a=en(),{showToast:i}=rn(),[s,o]=y.useState(!1),[l,c]=y.useState(!1),[d,u]=y.useState(!1),[m,p]=y.useState(!1),{data:f,isLoading:b}=Ve({queryKey:["smart-plug-status",t.id],queryFn:()=>se.getSmartPlugStatus(t.id),refetchInterval:3e4}),{data:w}=Ve({queryKey:["printers"],queryFn:se.getPrinters}),g=w?.find(E=>E.id===t.printer_id),x=it({mutationFn:E=>se.controlSmartPlug(t.id,E),onMutate:async E=>{await a.cancelQueries({queryKey:["smart-plug-status",t.id]});const U=a.getQueryData(["smart-plug-status",t.id]),I=E==="on"?"ON":E==="off"||f?.state==="ON"?"OFF":"ON";return a.setQueryData(["smart-plug-status",t.id],H=>({...H,state:I})),{previousStatus:U}},onError:(E,U,I)=>{I?.previousStatus&&a.setQueryData(["smart-plug-status",t.id],I.previousStatus),i(n("smartPlugs.failedToTurn",{action:U,name:t.name}),"error")},onSettled:()=>{setTimeout(()=>{a.invalidateQueries({queryKey:["smart-plug-status",t.id]}),a.invalidateQueries({queryKey:["smart-plugs"]})},1e3)}}),_=it({mutationFn:E=>se.updateSmartPlug(t.id,E),onSuccess:()=>{a.invalidateQueries({queryKey:["smart-plugs"]}),t.printer_id&&(a.invalidateQueries({queryKey:["smartPlugByPrinter",t.printer_id]}),a.invalidateQueries({queryKey:["scriptPlugsByPrinter",t.printer_id]}))}}),N=it({mutationFn:()=>se.deleteSmartPlug(t.id),onSuccess:()=>{a.invalidateQueries({queryKey:["smart-plugs"]}),t.printer_id&&a.invalidateQueries({queryKey:["scriptPlugsByPrinter",t.printer_id]})}}),C=f?.state==="ON",P=t.plug_type==="mqtt"&&f?.energy?.power!==null&&f?.energy?.power!==void 0,T=(f?.reachable??!1)||P,A=x.isPending,S=(()=>{if(t.plug_type!=="tasmota"||!t.ip_address)return null;const E=t.ip_address;return t.username&&t.password?`http://${encodeURIComponent(t.username)}:${encodeURIComponent(t.password)}@${E}/`:`http://${E}/`})();return r.jsxs(r.Fragment,{children:[r.jsx(Ct,{className:"relative",children:r.jsxs(At,{className:"p-4",children:[r.jsxs("div",{className:"flex items-start justify-between gap-2 mb-3",children:[r.jsxs("div",{className:"flex items-center gap-3 min-w-0 flex-1",children:[r.jsx("div",{className:`p-2 rounded-lg flex-shrink-0 ${t.plug_type==="mqtt"?T?"bg-teal-500/20":"bg-red-500/20":T?C?"bg-bambu-green/20":"bg-bambu-dark":"bg-red-500/20"}`,children:t.plug_type==="mqtt"?r.jsx(vO,{className:`w-5 h-5 ${T?"text-teal-400":"text-red-400"}`}):t.plug_type==="homeassistant"?r.jsx(PS,{className:`w-5 h-5 ${T?C?"text-bambu-green":"text-bambu-gray":"text-red-400"}`}):t.plug_type==="rest"?r.jsx(no,{className:`w-5 h-5 ${T?C?"text-bambu-green":"text-bambu-gray":"text-red-400"}`}):r.jsx(xc,{className:`w-5 h-5 ${T?C?"text-bambu-green":"text-bambu-gray":"text-red-400"}`})}),r.jsxs("div",{className:"min-w-0",children:[r.jsx("h3",{className:"font-medium text-white truncate",children:t.name}),r.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.plug_type==="rest"?t.rest_on_url??t.rest_off_url??void 0:t.ip_address??void 0,children:t.plug_type==="mqtt"?t.mqtt_topic:t.plug_type==="homeassistant"?t.ha_entity_id:t.plug_type==="rest"?t.rest_on_url||t.rest_off_url:t.ip_address})]})]}),r.jsxs("div",{className:"flex flex-col items-end gap-1 flex-shrink-0",children:[b?r.jsx(pt,{className:"w-4 h-4 text-bambu-gray animate-spin"}):t.plug_type==="mqtt"?r.jsxs("div",{className:"flex items-center gap-1.5 text-sm whitespace-nowrap",children:[r.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"}),T&&r.jsx("span",{className:"text-status-ok",children:"✓"})]}):t.plug_type==="homeassistant"?r.jsxs("div",{className:"flex items-center gap-1 text-sm",children:[r.jsx("span",{className:"px-1 py-0.5 bg-blue-500/20 text-blue-400 text-[10px] font-medium rounded",children:"HA"}),r.jsx("span",{className:T?C?"text-status-ok":"text-bambu-gray":"text-status-error",children:T?f?.state||"?":n("smartPlugs.offline")})]}):t.plug_type==="rest"?r.jsxs("div",{className:"flex items-center gap-1 text-sm",children:[r.jsx("span",{className:"px-1 py-0.5 bg-purple-500/20 text-purple-400 text-[10px] font-medium rounded",children:"REST"}),r.jsx("span",{className:T?C?"text-status-ok":"text-bambu-gray":"text-status-error",children:T?f?.state||"?":n("smartPlugs.offline")})]}):T?r.jsxs("div",{className:"flex items-center gap-1 text-sm",children:[r.jsx(Ah,{className:"w-4 h-4 text-status-ok"}),r.jsx("span",{className:C?"text-status-ok":"text-bambu-gray",children:f?.state||n("smartPlugs.unknown")})]}):r.jsxs("div",{className:"flex items-center gap-1 text-sm text-status-error",children:[r.jsx(mu,{className:"w-4 h-4"}),r.jsx("span",{children:n("smartPlugs.offline")})]}),S&&r.jsxs("a",{href:S,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:[r.jsx(Rr,{className:"w-3 h-3"}),n("smartPlugs.admin")]})]})]}),g&&r.jsxs("div",{className:"mb-3 px-2 py-1.5 bg-bambu-dark rounded-lg",children:[r.jsxs("span",{className:"text-xs text-bambu-gray",children:[n("smartPlugs.linkedTo")," "]}),r.jsx("span",{className:"text-sm text-white",children:g.name})]}),(t.power_alert_enabled||t.schedule_enabled||t.plug_type==="mqtt")&&r.jsxs("div",{className:"flex flex-wrap gap-1.5 mb-3",children:[t.plug_type==="mqtt"&&r.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:[r.jsx(Dl,{className:"w-3 h-3"}),n("smartPlugs.monitorOnly")]}),t.power_alert_enabled&&r.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:[r.jsx(kh,{className:"w-3 h-3"}),n("smartPlugs.alerts")]}),t.schedule_enabled&&r.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:[r.jsx(Sa,{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"&&r.jsxs("div",{className:"flex gap-2 mb-3",children:[r.jsxs(Me,{size:"sm",variant:C?"primary":"secondary",disabled:!T||A,onClick:()=>c(!0),className:"flex-1",children:[A?r.jsx(pt,{className:"w-4 h-4 animate-spin"}):r.jsx(wu,{className:"w-4 h-4"}),n("smartPlugs.on")]}),r.jsxs(Me,{size:"sm",variant:C?"secondary":"primary",disabled:!T||A,onClick:()=>u(!0),className:"flex-1",children:[A?r.jsx(pt,{className:"w-4 h-4 animate-spin"}):r.jsx(ES,{className:"w-4 h-4"}),n("smartPlugs.off")]})]}),t.plug_type==="mqtt"&&f?.energy&&r.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&&r.jsxs("div",{className:"flex-1 text-center",children:[r.jsxs("p",{className:"text-lg font-semibold text-white",children:[Math.round(f.energy.power),"W"]}),r.jsx("p",{className:"text-xs text-bambu-gray",children:n("smartPlugs.power")})]}),f.energy.today!==null&&f.energy.today!==void 0&&r.jsxs("div",{className:"flex-1 text-center border-l border-bambu-dark-tertiary",children:[r.jsx("p",{className:"text-lg font-semibold text-white",children:f.energy.today.toFixed(3)}),r.jsx("p",{className:"text-xs text-bambu-gray",children:n("smartPlugs.kwhToday")})]})]}),r.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:[r.jsxs("span",{className:"flex items-center gap-2",children:[r.jsx(uu,{className:"w-4 h-4"}),t.plug_type==="mqtt"?n("smartPlugs.settings"):n("smartPlugs.automationSettings")]}),r.jsx("span",{children:m?"-":"+"})]}),m&&r.jsxs("div",{className:"pt-3 border-t border-bambu-dark-tertiary space-y-4",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(TS,{className:"w-4 h-4 text-bambu-green"}),r.jsxs("div",{children:[r.jsx("p",{className:"text-sm text-white",children:n("smartPlugs.showInSwitchbar")}),r.jsx("p",{className:"text-xs text-bambu-gray",children:n("smartPlugs.quickAccessSidebar")})]})]}),r.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:t.show_in_switchbar,onChange:E=>_.mutate({show_in_switchbar:E.target.checked}),className:"sr-only peer"}),r.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"&&r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-sm text-white",children:n("smartPlugs.enabled")}),r.jsx("p",{className:"text-xs text-bambu-gray",children:n("smartPlugs.enableAutomation")})]}),r.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:t.enabled,onChange:E=>_.mutate({enabled:E.target.checked}),className:"sr-only peer"}),r.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"})]})]}),r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-sm text-white",children:n("smartPlugs.autoOn")}),r.jsx("p",{className:"text-xs text-bambu-gray",children:n("smartPlugs.autoOnDescription")})]}),r.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:t.auto_on,onChange:E=>_.mutate({auto_on:E.target.checked}),className:"sr-only peer"}),r.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"})]})]}),r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-sm text-white",children:n("smartPlugs.autoOff")}),r.jsx("p",{className:"text-xs text-bambu-gray",children:n("smartPlugs.autoOffDescription")})]}),r.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:t.auto_off,onChange:E=>_.mutate({auto_off:E.target.checked}),className:"sr-only peer"}),r.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&&r.jsxs("div",{className:"flex items-center justify-between pl-4 border-l-2 border-bambu-dark-tertiary",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-sm text-white",children:n("smartPlugs.autoOffPersistent")}),r.jsx("p",{className:"text-xs text-bambu-gray",children:n("smartPlugs.autoOffPersistentDescription")})]}),r.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:t.auto_off_persistent,onChange:E=>_.mutate({auto_off_persistent:E.target.checked}),className:"sr-only peer"}),r.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&&r.jsxs("div",{className:"space-y-3 pl-4 border-l-2 border-bambu-dark-tertiary",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-sm text-white mb-2",children:n("smartPlugs.turnOffDelayMode")}),r.jsxs("div",{className:"flex gap-2",children:[r.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:[r.jsx(Zn,{className:"w-4 h-4"}),n("smartPlugs.time")]}),r.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:[r.jsx(FS,{className:"w-4 h-4"}),n("smartPlugs.temp")]})]})]}),t.off_delay_mode==="time"?r.jsxs("div",{children:[r.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:n("smartPlugs.delayMinutes")}),r.jsx("input",{type:"number",min:"1",max:"60",value:t.off_delay_minutes,onChange:E=>_.mutate({off_delay_minutes:parseInt(E.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"})]}):r.jsxs("div",{children:[r.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:n("smartPlugs.tempThreshold")}),r.jsx("input",{type:"number",min:"30",max:"100",value:t.off_temp_threshold,onChange:E=>_.mutate({off_temp_threshold:parseInt(E.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"}),r.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:n("smartPlugs.tempThresholdDescription")})]})]})]}),r.jsxs("div",{className:"flex gap-2 pt-2",children:[r.jsxs(Me,{size:"sm",variant:"secondary",onClick:()=>e(t),className:"flex-1",children:[r.jsx(fc,{className:"w-4 h-4"}),n("smartPlugs.edit")]}),r.jsx(Me,{size:"sm",variant:"secondary",onClick:()=>o(!0),className:"text-red-400 hover:text-red-300",children:r.jsx(Jt,{className:"w-4 h-4"})})]})]})]})}),s&&r.jsx(vn,{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&&r.jsx(vn,{title:n("smartPlugs.turnOnSmartPlug"),message:n("smartPlugs.turnOnConfirm",{name:t.name}),confirmText:n("smartPlugs.turnOn"),variant:"default",onConfirm:()=>{x.mutate("on"),c(!1)},onCancel:()=>c(!1)}),d&&r.jsx(vn,{title:n("smartPlugs.turnOffSmartPlug"),message:n("smartPlugs.turnOffConfirm",{name:t.name}),confirmText:n("smartPlugs.turnOff"),variant:"danger",onConfirm:()=>{x.mutate("off"),u(!1)},onCancel:()=>u(!1)})]})}function Crt({plug:t,onClose:e}){const{t:n}=kt(),a=en(),i=!!t,[s,o]=y.useState(t?.plug_type||"tasmota"),[l,c]=y.useState(t?.name||""),[d,u]=y.useState(t?.ip_address||""),[m,p]=y.useState(t?.username||""),[f,b]=y.useState(t?.password||""),[w,g]=y.useState(t?.ha_entity_id||""),[x,_]=y.useState(t?.mqtt_power_topic||t?.mqtt_topic||""),[N,C]=y.useState(t?.mqtt_power_path||""),[P,T]=y.useState((t?.mqtt_power_multiplier??t?.mqtt_multiplier??1).toString()),[A,F]=y.useState(t?.mqtt_energy_topic||""),[S,E]=y.useState(t?.mqtt_energy_path||""),[U,I]=y.useState((t?.mqtt_energy_multiplier??1).toString()),[H,R]=y.useState(t?.mqtt_state_topic||""),[Q,re]=y.useState(t?.mqtt_state_path||""),[J,de]=y.useState(t?.mqtt_state_on_value||""),[pe,ue]=y.useState(t?.rest_on_url||""),[X,ae]=y.useState(t?.rest_on_body||""),[me,be]=y.useState(t?.rest_off_url||""),[Ce,$]=y.useState(t?.rest_off_body||""),[W,D]=y.useState(t?.rest_method||"POST"),[j,B]=y.useState(t?.rest_headers||""),[Y,O]=y.useState(t?.rest_status_url||""),[ie,z]=y.useState(t?.rest_status_path||""),[G,K]=y.useState(t?.rest_status_on_value||""),[Z,oe]=y.useState(t?.rest_power_url||""),[ee,ge]=y.useState(t?.rest_power_path||""),[ce,le]=y.useState((t?.rest_power_multiplier??1).toString()),[q,L]=y.useState(t?.rest_energy_url||""),[ne,ye]=y.useState(t?.rest_energy_path||""),[we,Ne]=y.useState((t?.rest_energy_multiplier??1).toString()),[ve,xe]=y.useState(t?.ha_power_entity||""),[Ee,ze]=y.useState(t?.ha_energy_today_entity||""),[_e,Oe]=y.useState(t?.ha_energy_total_entity||""),[Ie,We]=y.useState(""),[at,lt]=y.useState(""),[Fe,tt]=y.useState(!1),Pe=y.useRef(null),[Ye,Ue]=y.useState(""),[fe,Ae]=y.useState(!1),qe=y.useRef(null),[nt,Qe]=y.useState(""),[gt,ct]=y.useState(!1),rt=y.useRef(null),[Ot,Wt]=y.useState(""),[Zt,Yt]=y.useState(!1),un=y.useRef(null),[bn,dt]=y.useState(t?.printer_id||null),[st,vt]=y.useState(null),[_t,Dt]=y.useState(null),[De,je]=y.useState(t?.power_alert_enabled||!1),[$e,Je]=y.useState(t?.power_alert_high?.toString()||""),[Re,mt]=y.useState(t?.power_alert_low?.toString()||""),[he,Le]=y.useState(t?.schedule_enabled||!1),[Xe,Ze]=y.useState(t?.schedule_on_time||""),[Ke,bt]=y.useState(t?.schedule_off_time||""),[et,jt]=y.useState(t?.show_in_switchbar||!1),[St,It]=y.useState(t?.show_on_printer_card??!0),[zt,He]=y.useState(!1),[Ge,Vt]=y.useState({scanned:0,total:0}),[Qt,mn]=y.useState([]),wn=y.useRef(null),{data:gn}=Ve({queryKey:["printers"],queryFn:se.getPrinters}),{data:Cn}=Ve({queryKey:["smart-plugs"],queryFn:se.getSmartPlugs}),{data:Mn}=Ve({queryKey:["settings"],queryFn:se.getSettings}),xr=!!(Mn?.ha_enabled&&Mn?.ha_url&&Mn?.ha_token);y.useEffect(()=>{const Ft=setTimeout(()=>{lt(Ie)},300);return()=>clearTimeout(Ft)},[Ie]),y.useEffect(()=>{const Ft=cn=>{Pe.current&&!Pe.current.contains(cn.target)&&tt(!1),qe.current&&!qe.current.contains(cn.target)&&Ae(!1),rt.current&&!rt.current.contains(cn.target)&&ct(!1),un.current&&!un.current.contains(cn.target)&&Yt(!1)};return document.addEventListener("mousedown",Ft),()=>document.removeEventListener("mousedown",Ft)},[]);const{data:Er,isLoading:zn,error:Xa}=Ve({queryKey:["ha-entities",at],queryFn:()=>se.getHAEntities(at||void 0),enabled:s==="homeassistant"&&xr,retry:!1,staleTime:0}),{data:Kn}=Ve({queryKey:["ha-sensor-entities"],queryFn:se.getHASensorEntities,enabled:s==="homeassistant"&&xr,retry:!1,staleTime:0});y.useEffect(()=>{const Ft=cn=>{cn.key==="Escape"&&e()};return window.addEventListener("keydown",Ft),()=>{window.removeEventListener("keydown",Ft),wn.current&&clearInterval(wn.current)}},[e]);const Ar=async()=>{He(!0),mn([]),Vt({scanned:0,total:0}),Dt(null);try{await se.startTasmotaScan();const Ft=async()=>{try{const cn=await se.getTasmotaScanStatus();Vt({scanned:cn.scanned,total:cn.total});const hr=await se.getDiscoveredTasmotaDevices();mn(hr),cn.running||(He(!1),wn.current&&(clearInterval(wn.current),wn.current=null))}catch(cn){console.error("Polling error:",cn)}};await Ft(),wn.current=setInterval(Ft,500)}catch(Ft){He(!1);const cn=Ft instanceof Error?Ft.message:typeof Ft=="string"?Ft:JSON.stringify(Ft);Dt(cn||n("smartPlugs.failedToStartScan"))}},ca=async()=>{try{await se.stopTasmotaScan()}catch{}He(!1),wn.current&&(clearInterval(wn.current),wn.current=null)},jr=Ft=>{u(Ft.ip_address),c(Ft.name),vt(null)},da=it({mutationFn:()=>se.testSmartPlugConnection(d,m||null,f||null),onSuccess:Ft=>{vt(Ft),Dt(null),!l&&Ft.device_name&&c(Ft.device_name)},onError:Ft=>{vt(null),Dt(Ft.message)}}),Ki=it({mutationFn:Ft=>se.createSmartPlug(Ft),onSuccess:()=>{a.invalidateQueries({queryKey:["smart-plugs"]}),a.invalidateQueries({queryKey:["scriptPlugsByPrinter"]}),e()},onError:Ft=>{Dt(Ft.message)}}),Yi=it({mutationFn:Ft=>se.updateSmartPlug(t.id,Ft),onSuccess:()=>{a.invalidateQueries({queryKey:["smart-plugs"]}),a.invalidateQueries({queryKey:["scriptPlugsByPrinter"]}),e()},onError:Ft=>{Dt(Ft.message)}}),bd=gn?.filter(Ft=>s==="tasmota"?!Cn?.some(hr=>hr.printer_id===Ft.id&&hr.id!==t?.id&&hr.plug_type==="tasmota"):!0),Lc=Ft=>{if(Ft.preventDefault(),Dt(null),!l.trim()){Dt(n("smartPlugs.nameRequired"));return}if(s==="tasmota"&&!d.trim()){Dt("IP address is required for Tasmota plugs");return}if(s==="homeassistant"&&!w){Dt(n("smartPlugs.entityRequired"));return}if(s==="mqtt"){const hr=x.trim(),Gt=A.trim(),Ol=H.trim();if(!hr&&!Gt&&!Ol){Dt(n("smartPlugs.mqttTopicRequired"));return}}if(s==="rest"&&!pe.trim()&&!me.trim()){Dt(n("smartPlugs.restUrlRequired"));return}const cn={name:l.trim(),plug_type:s,ip_address:s==="tasmota"?d.trim():null,ha_entity_id:s==="homeassistant"?w:null,ha_power_entity:s==="homeassistant"&&ve||null,ha_energy_today_entity:s==="homeassistant"&&Ee||null,ha_energy_total_entity:s==="homeassistant"&&_e||null,mqtt_power_topic:s==="mqtt"&&x.trim()||null,mqtt_power_path:s==="mqtt"&&N.trim()||null,mqtt_power_multiplier:s==="mqtt"&&parseFloat(P)||1,mqtt_energy_topic:s==="mqtt"&&A.trim()||null,mqtt_energy_path:s==="mqtt"&&S.trim()||null,mqtt_energy_multiplier:s==="mqtt"&&parseFloat(U)||1,mqtt_state_topic:s==="mqtt"&&H.trim()||null,mqtt_state_path:s==="mqtt"&&Q.trim()||null,mqtt_state_on_value:s==="mqtt"&&J.trim()||null,rest_on_url:s==="rest"&&pe.trim()||null,rest_on_body:s==="rest"&&X.trim()||null,rest_off_url:s==="rest"&&me.trim()||null,rest_off_body:s==="rest"&&Ce.trim()||null,rest_method:s==="rest"?W:null,rest_headers:s==="rest"&&j.trim()||null,rest_status_url:s==="rest"&&Y.trim()||null,rest_status_path:s==="rest"&&ie.trim()||null,rest_status_on_value:s==="rest"&&G.trim()||null,rest_power_url:s==="rest"&&Z.trim()||null,rest_power_path:s==="rest"&&ee.trim()||null,rest_power_multiplier:s==="rest"&&parseFloat(ce)||1,rest_energy_url:s==="rest"&&q.trim()||null,rest_energy_path:s==="rest"&&ne.trim()||null,rest_energy_multiplier:s==="rest"&&parseFloat(we)||1,username:s==="tasmota"&&m.trim()||null,password:s==="tasmota"&&f.trim()||null,printer_id:bn,power_alert_enabled:De,power_alert_high:$e?parseFloat($e):null,power_alert_low:Re?parseFloat(Re):null,schedule_enabled:he,schedule_on_time:Xe||null,schedule_off_time:Ke||null,show_in_switchbar:et,show_on_printer_card:St};i?Yi.mutate(cn):Ki.mutate(cn)},$s=Ki.isPending||Yi.isPending;return r.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",onClick:e,children:r.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:Ft=>Ft.stopPropagation(),children:[r.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary flex-shrink-0",children:[r.jsx("h2",{className:"text-lg font-semibold text-white",children:n(i?"smartPlugs.editTitle":"smartPlugs.addTitle")}),r.jsx("button",{onClick:e,className:"text-bambu-gray hover:text-white transition-colors",children:r.jsx(Ht,{className:"w-5 h-5"})})]}),r.jsxs("form",{onSubmit:Lc,className:"p-6 space-y-4 overflow-y-auto",children:[_t&&r.jsx("div",{className:"p-3 bg-red-500/20 border border-red-500/50 rounded-lg text-sm text-red-400",children:_t}),!i&&r.jsxs("div",{className:"flex gap-2 mb-2",children:[r.jsxs("button",{type:"button",onClick:()=>{o("tasmota"),vt(null),Dt(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:[r.jsx(xc,{className:"w-4 h-4"}),"Tasmota"]}),r.jsxs("button",{type:"button",onClick:()=>{o("homeassistant"),vt(null),Dt(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:[r.jsx(PS,{className:"w-4 h-4"}),"HA"]}),r.jsxs("button",{type:"button",onClick:()=>{o("mqtt"),vt(null),Dt(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:[r.jsx(vO,{className:"w-4 h-4"}),"MQTT"]}),r.jsxs("button",{type:"button",onClick:()=>{o("rest"),vt(null),Dt(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2.5 rounded-lg font-medium transition-colors ${s==="rest"?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white border border-bambu-dark-tertiary"}`,children:[r.jsx(no,{className:"w-4 h-4"}),"REST"]})]}),!i&&s==="tasmota"&&r.jsxs("div",{className:"space-y-3",children:[zt?r.jsxs(Me,{type:"button",variant:"secondary",onClick:ca,className:"w-full",children:[r.jsx(Ht,{className:"w-4 h-4"}),n("smartPlugs.stopScanning")]}):r.jsxs(Me,{type:"button",variant:"primary",onClick:Ar,className:"w-full",children:[r.jsx(Sr,{className:"w-4 h-4"}),n("smartPlugs.discoverTasmota")]}),zt&&Ge.total>0&&r.jsxs("div",{className:"space-y-1",children:[r.jsxs("div",{className:"flex justify-between text-xs text-bambu-gray",children:[r.jsx("span",{children:n("smartPlugs.addSmartPlug.scanningNetwork")}),r.jsxs("span",{children:[Ge.scanned," / ",Ge.total]})]}),r.jsx("div",{className:"w-full bg-bambu-dark-tertiary rounded-full h-2",children:r.jsx("div",{className:"bg-bambu-green h-2 rounded-full transition-all duration-300",style:{width:`${Ge.scanned/Ge.total*100}%`}})})]}),Qt.length>0&&r.jsxs("div",{className:"space-y-2",children:[r.jsx("p",{className:"text-xs text-bambu-gray",children:n("smartPlugs.foundDevices",{count:Qt.length})}),r.jsx("div",{className:"max-h-40 overflow-y-auto space-y-1",children:Qt.map(Ft=>r.jsxs("button",{type:"button",onClick:()=>jr(Ft),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:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(xc,{className:"w-4 h-4 text-bambu-green"}),r.jsxs("div",{children:[r.jsx("p",{className:"text-sm text-white",children:Ft.name}),r.jsx("p",{className:"text-xs text-bambu-gray",children:Ft.ip_address})]})]}),Ft.state&&r.jsxs("span",{className:`flex items-center gap-1 text-xs ${Ft.state==="ON"?"text-bambu-green":"text-bambu-gray"}`,children:[r.jsx(wu,{className:"w-3 h-3"}),Ft.state]})]},Ft.ip_address))})]}),!zt&&Qt.length===0&&Ge.total>0&&r.jsx("p",{className:"text-xs text-bambu-gray text-center py-2",children:n("smartPlugs.noDevicesFound")})]}),s==="homeassistant"&&r.jsxs("div",{className:"space-y-3",children:[!xr&&r.jsxs("div",{className:"space-y-3",children:[r.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")," ",r.jsx("span",{className:"font-medium",children:n("smartPlugs.haSettingsPath")})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1 opacity-50",children:n("smartPlugs.selectEntity")}),r.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:r.jsx("option",{children:n("smartPlugs.addSmartPlug.chooseEntity")})})]})]}),xr&&r.jsxs(r.Fragment,{children:[zn&&r.jsxs("div",{className:"flex items-center justify-center py-4 text-bambu-gray",children:[r.jsx(pt,{className:"w-5 h-5 animate-spin mr-2"}),n("smartPlugs.loadingEntities")]}),Xa&&r.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:Xa.message})}),(()=>{const Ft=Cn?.filter(Gt=>Gt.ha_entity_id&&Gt.id!==t?.id).map(Gt=>Gt.ha_entity_id)||[],cn=(Er||[]).filter(Gt=>!Ft.includes(Gt.entity_id)),hr=Er?.find(Gt=>Gt.entity_id===w);return r.jsxs("div",{ref:Pe,className:"relative",children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.selectEntity")}),r.jsxs("div",{className:"relative",children:[r.jsx(Sr,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"}),r.jsx("input",{type:"text",value:Fe?Ie:hr?`${hr.friendly_name} (${hr.entity_id})`:"",onChange:Gt=>{We(Gt.target.value),Fe||tt(!0)},onFocus:()=>{tt(!0),We("")},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"}),w&&!Fe&&r.jsx("button",{type:"button",onClick:()=>{g(""),We("")},className:"absolute right-2 top-1/2 -translate-y-1/2 p-1 hover:bg-bambu-dark-tertiary rounded",children:r.jsx(Ht,{className:"w-4 h-4 text-bambu-gray hover:text-white"})}),zn&&r.jsx(pt,{className:"absolute right-2 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray animate-spin"})]}),Fe&&r.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:[zn&&r.jsxs("div",{className:"px-3 py-2 text-sm text-bambu-gray flex items-center gap-2",children:[r.jsx(pt,{className:"w-4 h-4 animate-spin"}),n("smartPlugs.loading")]}),!zn&&cn.length===0&&r.jsx("div",{className:"px-3 py-2 text-sm text-bambu-gray",children:at?n("smartPlugs.noEntitiesMatching",{search:at}):n("smartPlugs.noEntitiesAvailable")}),!zn&&cn.map(Gt=>r.jsxs("button",{type:"button",onClick:()=>{g(Gt.entity_id),tt(!1),We(""),l||c(Gt.friendly_name)},className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary transition-colors ${Gt.entity_id===w?"bg-bambu-green/20 text-bambu-green":"text-white"}`,children:[r.jsx("div",{className:"font-medium",children:Gt.friendly_name}),r.jsxs("div",{className:"text-xs text-bambu-gray flex items-center justify-between",children:[r.jsx("span",{children:Gt.entity_id}),r.jsx("span",{className:Gt.state==="on"?"text-bambu-green":"",children:Gt.state})]})]},Gt.entity_id))]}),r.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:at?n("smartPlugs.searchingEntities",{count:cn.length}):n("smartPlugs.showingEntities",{count:cn.length})})]})})(),w&&Kn&&Kn.length>0&&r.jsxs("div",{className:"border-t border-bambu-dark-tertiary pt-4 mt-4 space-y-3",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-white font-medium mb-1",children:n("smartPlugs.energyMonitoringOptional")}),r.jsx("p",{className:"text-xs text-bambu-gray mb-3",children:n("smartPlugs.energyMonitoringHint")})]}),(()=>{const Ft=Kn.filter(Gt=>Gt.unit_of_measurement==="W"||Gt.unit_of_measurement==="kW"||Gt.unit_of_measurement==="mW"),cn=Ye?Ft.filter(Gt=>Gt.entity_id.toLowerCase().includes(Ye.toLowerCase())||Gt.friendly_name.toLowerCase().includes(Ye.toLowerCase())):Ft,hr=Kn.find(Gt=>Gt.entity_id===ve);return r.jsxs("div",{ref:qe,className:"relative",children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.powerSensorW")}),r.jsxs("div",{className:"relative",children:[r.jsx(Sr,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"}),r.jsx("input",{type:"text",value:fe?Ye:hr?`${hr.friendly_name} (${hr.state} ${hr.unit_of_measurement})`:"",onChange:Gt=>{Ue(Gt.target.value),fe||Ae(!0)},onFocus:()=>{Ae(!0),Ue("")},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"}),ve&&!fe&&r.jsx("button",{type:"button",onClick:()=>{xe(""),Ue("")},className:"absolute right-2 top-1/2 -translate-y-1/2 p-1 hover:bg-bambu-dark-tertiary rounded",children:r.jsx(Ht,{className:"w-4 h-4 text-bambu-gray hover:text-white"})})]}),fe&&r.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:[r.jsx("button",{type:"button",onClick:()=>{xe(""),Ae(!1),Ue("")},className:"w-full px-3 py-2 text-left text-sm text-bambu-gray hover:bg-bambu-dark-tertiary",children:n("smartPlugs.none")}),cn.map(Gt=>r.jsxs("button",{type:"button",onClick:()=>{xe(Gt.entity_id),Ae(!1),Ue("")},className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary ${Gt.entity_id===ve?"bg-bambu-green/20 text-bambu-green":"text-white"}`,children:[r.jsx("div",{className:"font-medium",children:Gt.friendly_name}),r.jsxs("div",{className:"text-xs text-bambu-gray",children:[Gt.entity_id," • ",Gt.state," ",Gt.unit_of_measurement]})]},Gt.entity_id)),cn.length===0&&r.jsx("div",{className:"px-3 py-2 text-sm text-bambu-gray",children:n("smartPlugs.noMatchingSensors")})]})]})})(),(()=>{const Ft=Kn.filter(Gt=>Gt.unit_of_measurement==="kWh"||Gt.unit_of_measurement==="Wh"||Gt.unit_of_measurement==="MWh"),cn=nt?Ft.filter(Gt=>Gt.entity_id.toLowerCase().includes(nt.toLowerCase())||Gt.friendly_name.toLowerCase().includes(nt.toLowerCase())):Ft,hr=Kn.find(Gt=>Gt.entity_id===Ee);return r.jsxs("div",{ref:rt,className:"relative",children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.energyTodayKwh")}),r.jsxs("div",{className:"relative",children:[r.jsx(Sr,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"}),r.jsx("input",{type:"text",value:gt?nt:hr?`${hr.friendly_name} (${hr.state} ${hr.unit_of_measurement})`:"",onChange:Gt=>{Qe(Gt.target.value),gt||ct(!0)},onFocus:()=>{ct(!0),Qe("")},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"}),Ee&&!gt&&r.jsx("button",{type:"button",onClick:()=>{ze(""),Qe("")},className:"absolute right-2 top-1/2 -translate-y-1/2 p-1 hover:bg-bambu-dark-tertiary rounded",children:r.jsx(Ht,{className:"w-4 h-4 text-bambu-gray hover:text-white"})})]}),gt&&r.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:[r.jsx("button",{type:"button",onClick:()=>{ze(""),ct(!1),Qe("")},className:"w-full px-3 py-2 text-left text-sm text-bambu-gray hover:bg-bambu-dark-tertiary",children:n("smartPlugs.none")}),cn.map(Gt=>r.jsxs("button",{type:"button",onClick:()=>{ze(Gt.entity_id),ct(!1),Qe("")},className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary ${Gt.entity_id===Ee?"bg-bambu-green/20 text-bambu-green":"text-white"}`,children:[r.jsx("div",{className:"font-medium",children:Gt.friendly_name}),r.jsxs("div",{className:"text-xs text-bambu-gray",children:[Gt.entity_id," • ",Gt.state," ",Gt.unit_of_measurement]})]},Gt.entity_id)),cn.length===0&&r.jsx("div",{className:"px-3 py-2 text-sm text-bambu-gray",children:n("smartPlugs.noMatchingSensors")})]})]})})(),(()=>{const Ft=Kn.filter(Gt=>Gt.unit_of_measurement==="kWh"||Gt.unit_of_measurement==="Wh"||Gt.unit_of_measurement==="MWh"),cn=Ot?Ft.filter(Gt=>Gt.entity_id.toLowerCase().includes(Ot.toLowerCase())||Gt.friendly_name.toLowerCase().includes(Ot.toLowerCase())):Ft,hr=Kn.find(Gt=>Gt.entity_id===_e);return r.jsxs("div",{ref:un,className:"relative",children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.totalEnergyKwh")}),r.jsxs("div",{className:"relative",children:[r.jsx(Sr,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"}),r.jsx("input",{type:"text",value:Zt?Ot:hr?`${hr.friendly_name} (${hr.state} ${hr.unit_of_measurement})`:"",onChange:Gt=>{Wt(Gt.target.value),Zt||Yt(!0)},onFocus:()=>{Yt(!0),Wt("")},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"}),_e&&!Zt&&r.jsx("button",{type:"button",onClick:()=>{Oe(""),Wt("")},className:"absolute right-2 top-1/2 -translate-y-1/2 p-1 hover:bg-bambu-dark-tertiary rounded",children:r.jsx(Ht,{className:"w-4 h-4 text-bambu-gray hover:text-white"})})]}),Zt&&r.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:[r.jsx("button",{type:"button",onClick:()=>{Oe(""),Yt(!1),Wt("")},className:"w-full px-3 py-2 text-left text-sm text-bambu-gray hover:bg-bambu-dark-tertiary",children:n("smartPlugs.none")}),cn.map(Gt=>r.jsxs("button",{type:"button",onClick:()=>{Oe(Gt.entity_id),Yt(!1),Wt("")},className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary ${Gt.entity_id===_e?"bg-bambu-green/20 text-bambu-green":"text-white"}`,children:[r.jsx("div",{className:"font-medium",children:Gt.friendly_name}),r.jsxs("div",{className:"text-xs text-bambu-gray",children:[Gt.entity_id," • ",Gt.state," ",Gt.unit_of_measurement]})]},Gt.entity_id)),cn.length===0&&r.jsx("div",{className:"px-3 py-2 text-sm text-bambu-gray",children:n("smartPlugs.noMatchingSensors")})]})]})})()]})]})]}),s==="mqtt"&&r.jsxs("div",{className:"space-y-3",children:[!Mn?.mqtt_broker&&r.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")," ",r.jsx("span",{className:"font-medium",children:n("smartPlugs.mqttSettingsPath")})," ",n("smartPlugs.mqttNotConfiguredSuffix")]}),Mn?.mqtt_broker&&r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"p-3 bg-blue-500/10 border border-blue-500/30 rounded-lg text-sm text-blue-300",children:[r.jsx("p",{className:"font-medium mb-1",children:n("smartPlugs.monitorOnly")}),r.jsx("p",{className:"text-xs opacity-80",children:n("smartPlugs.mqttMonitorOnlyDescription")})]}),r.jsxs("div",{className:"space-y-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary",children:[r.jsx("p",{className:"text-white font-medium text-sm",children:n("smartPlugs.powerMonitoring")}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.topic")}),r.jsx("input",{type:"text",value:x,onChange:Ft=>_(Ft.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"})]}),r.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.jsonPath")}),r.jsx("input",{type:"text",value:N,onChange:Ft=>C(Ft.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"})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.multiplier")}),r.jsx("input",{type:"text",value:P,onChange:Ft=>T(Ft.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"})]})]}),r.jsx("p",{className:"text-xs text-bambu-gray",style:{whiteSpace:"pre-line"},children:n("smartPlugs.mqttPowerHint")})]}),r.jsxs("div",{className:"space-y-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary",children:[r.jsxs("p",{className:"text-white font-medium text-sm",children:[n("smartPlugs.energyMonitoring")," ",r.jsxs("span",{className:"text-bambu-gray font-normal",children:["(",n("smartPlugs.optional"),")"]})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.topic")}),r.jsx("input",{type:"text",value:A,onChange:Ft=>F(Ft.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"})]}),r.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.jsonPath")}),r.jsx("input",{type:"text",value:S,onChange:Ft=>E(Ft.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"})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.multiplier")}),r.jsx("input",{type:"text",value:U,onChange:Ft=>I(Ft.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"})]})]}),r.jsx("p",{className:"text-xs text-bambu-gray",style:{whiteSpace:"pre-line"},children:n("smartPlugs.mqttEnergyHint")})]}),r.jsxs("div",{className:"space-y-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary",children:[r.jsxs("p",{className:"text-white font-medium text-sm",children:[n("smartPlugs.stateMonitoring")," ",r.jsxs("span",{className:"text-bambu-gray font-normal",children:["(",n("smartPlugs.optional"),")"]})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.topic")}),r.jsx("input",{type:"text",value:H,onChange:Ft=>R(Ft.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"})]}),r.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.jsonPath")}),r.jsx("input",{type:"text",value:Q,onChange:Ft=>re(Ft.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"})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.onValue")}),r.jsx("input",{type:"text",value:J,onChange:Ft=>de(Ft.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"})]})]}),r.jsx("p",{className:"text-xs text-bambu-gray",style:{whiteSpace:"pre-line"},children:n("smartPlugs.mqttStateHint")})]})]})]}),s==="rest"&&r.jsxs("div",{className:"space-y-3",children:[r.jsxs("div",{className:"space-y-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary",children:[r.jsx("p",{className:"text-white font-medium text-sm",children:n("smartPlugs.restControl")}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.restMethod")}),r.jsxs("select",{value:W,onChange:Ft=>D(Ft.target.value),className:"w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[r.jsx("option",{value:"GET",children:"GET"}),r.jsx("option",{value:"POST",children:"POST"}),r.jsx("option",{value:"PUT",children:"PUT"}),r.jsx("option",{value:"PATCH",children:"PATCH"})]})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.restOnUrl")}),r.jsx("input",{type:"text",value:pe,onChange:Ft=>{ue(Ft.target.value),vt(null)},placeholder:"http://openhab:8080/rest/items/MyPlug",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"})]}),r.jsxs("div",{children:[r.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[n("smartPlugs.restOnBody")," ",r.jsxs("span",{className:"text-bambu-gray font-normal",children:["(",n("smartPlugs.optional"),")"]})]}),r.jsx("input",{type:"text",value:X,onChange:Ft=>ae(Ft.target.value),placeholder:n("smartPlugs.restBodyHint"),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"})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.restOffUrl")}),r.jsx("input",{type:"text",value:me,onChange:Ft=>{be(Ft.target.value),vt(null)},placeholder:"http://openhab:8080/rest/items/MyPlug",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"})]}),r.jsxs("div",{children:[r.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[n("smartPlugs.restOffBody")," ",r.jsxs("span",{className:"text-bambu-gray font-normal",children:["(",n("smartPlugs.optional"),")"]})]}),r.jsx("input",{type:"text",value:Ce,onChange:Ft=>$(Ft.target.value),placeholder:n("smartPlugs.restBodyHint"),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"})]})]}),r.jsxs("div",{className:"space-y-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary",children:[r.jsxs("p",{className:"text-white font-medium text-sm",children:[n("smartPlugs.restHeaders")," ",r.jsxs("span",{className:"text-bambu-gray font-normal",children:["(",n("smartPlugs.optional"),")"]})]}),r.jsx("div",{children:r.jsx("textarea",{value:j,onChange:Ft=>B(Ft.target.value),placeholder:n("smartPlugs.restHeadersHint"),rows:2,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 font-mono text-sm"})})]}),r.jsxs("div",{className:"space-y-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary",children:[r.jsxs("p",{className:"text-white font-medium text-sm",children:[n("smartPlugs.stateMonitoring")," ",r.jsxs("span",{className:"text-bambu-gray font-normal",children:["(",n("smartPlugs.optional"),")"]})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.restStatusUrl")}),r.jsx("input",{type:"text",value:Y,onChange:Ft=>O(Ft.target.value),placeholder:n("smartPlugs.restStatusHint"),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"})]}),r.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.restStatusPath")}),r.jsx("input",{type:"text",value:ie,onChange:Ft=>z(Ft.target.value),placeholder:n("smartPlugs.restPathHint"),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"})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.restStatusOnValue")}),r.jsx("input",{type:"text",value:G,onChange:Ft=>K(Ft.target.value),placeholder:"ON",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"})]})]})]}),r.jsxs("div",{className:"space-y-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary",children:[r.jsxs("p",{className:"text-white font-medium text-sm",children:[n("smartPlugs.energyMonitoring")," ",r.jsxs("span",{className:"text-bambu-gray font-normal",children:["(",n("smartPlugs.optional"),")"]})]}),r.jsxs("div",{children:[r.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[n("smartPlugs.restPowerUrl")," ",r.jsxs("span",{className:"text-bambu-gray font-normal",children:["(",n("smartPlugs.optional"),")"]})]}),r.jsx("input",{type:"text",value:Z,onChange:Ft=>oe(Ft.target.value),placeholder:n("smartPlugs.restPowerUrlHint"),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"})]}),r.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.restPowerPath")}),r.jsx("input",{type:"text",value:ee,onChange:Ft=>ge(Ft.target.value),placeholder:n("smartPlugs.restPathHint"),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"})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.restPowerMultiplier")}),r.jsx("input",{type:"text",value:ce,onChange:Ft=>le(Ft.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"})]})]}),r.jsxs("div",{children:[r.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[n("smartPlugs.restEnergyUrl")," ",r.jsxs("span",{className:"text-bambu-gray font-normal",children:["(",n("smartPlugs.optional"),")"]})]}),r.jsx("input",{type:"text",value:q,onChange:Ft=>L(Ft.target.value),placeholder:n("smartPlugs.restEnergyUrlHint"),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"})]}),r.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.restEnergyPath")}),r.jsx("input",{type:"text",value:ne,onChange:Ft=>ye(Ft.target.value),placeholder:n("smartPlugs.restPathHint"),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"})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.restEnergyMultiplier")}),r.jsx("input",{type:"text",value:we,onChange:Ft=>Ne(Ft.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"})]})]}),r.jsx("p",{className:"text-xs text-bambu-gray",children:n("smartPlugs.restEnergyHint")})]}),(pe.trim()||me.trim())&&r.jsx("div",{className:"flex gap-2",children:r.jsxs(Me,{type:"button",variant:"secondary",onClick:async()=>{vt(null);try{const Ft=pe.trim()||me.trim(),cn=await se.testRESTConnection(Ft,W,j.trim()||null);vt({success:cn.success}),cn.success||Dt(cn.error||n("smartPlugs.addSmartPlug.connectionFailed"))}catch{vt({success:!1}),Dt(n("smartPlugs.addSmartPlug.connectionFailed"))}},className:"w-full",children:[r.jsx(Ah,{className:"w-4 h-4"}),n("smartPlugs.testConnection")]})}),st&&r.jsxs("div",{className:`flex items-center gap-2 text-sm ${st.success?"text-green-400":"text-red-400"}`,children:[st.success?r.jsx(wr,{className:"w-4 h-4"}):r.jsx(mu,{className:"w-4 h-4"}),st.success?n("smartPlugs.connectionSuccess"):n("smartPlugs.addSmartPlug.connectionFailed")]})]}),s==="tasmota"&&r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.ipAddress")}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx("input",{type:"text",value:d,onChange:Ft=>{u(Ft.target.value),vt(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"}),r.jsxs(Me,{type:"button",variant:"secondary",onClick:()=>da.mutate(),disabled:!d.trim()||da.isPending,children:[da.isPending?r.jsx(pt,{className:"w-4 h-4 animate-spin"}):r.jsx(Ah,{className:"w-4 h-4"}),n("smartPlugs.test")]})]})]}),s==="tasmota"&&st&&r.jsx("div",{className:`p-3 rounded-lg flex items-center gap-2 ${st.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:st.success?r.jsxs(r.Fragment,{children:[r.jsx(wr,{className:"w-5 h-5"}),r.jsxs("div",{children:[r.jsx("p",{className:"font-medium",children:n("smartPlugs.connectedResult")}),r.jsxs("p",{className:"text-sm opacity-80",children:[st.device_name&&n("smartPlugs.deviceLabel",{name:st.device_name}),n("smartPlugs.stateLabel",{state:st.state})]})]})]}):r.jsxs(r.Fragment,{children:[r.jsx(mu,{className:"w-5 h-5"}),r.jsx("span",{children:n("smartPlugs.addSmartPlug.connectionFailed")})]})}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.nameLabel")}),r.jsx("input",{type:"text",value:l,onChange:Ft=>c(Ft.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"&&r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.username")}),r.jsx("input",{type:"text",value:m,onChange:Ft=>p(Ft.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"})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.password")}),r.jsx("input",{type:"password",value:f,onChange:Ft=>b(Ft.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"})]})]}),r.jsx("p",{className:"text-xs text-bambu-gray -mt-2",children:n("smartPlugs.authHint")})]}),s!=="mqtt"&&r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.linkToPrinter")}),r.jsxs("select",{value:bn??"",onChange:Ft=>dt(Ft.target.value?Number(Ft.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:[r.jsx("option",{value:"",children:n("smartPlugs.noPrinter")}),bd?.map(Ft=>r.jsx("option",{value:Ft.id,children:Ft.name},Ft.id))]}),r.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:n("smartPlugs.linkingDescription")})]}),r.jsxs("div",{className:"border-t border-bambu-dark-tertiary pt-4",children:[r.jsxs("div",{className:"flex items-center justify-between mb-3",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(kh,{className:"w-4 h-4 text-bambu-green"}),r.jsx("span",{className:"text-white font-medium",children:n("smartPlugs.powerAlerts")})]}),r.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:De,onChange:Ft=>je(Ft.target.checked),className:"sr-only peer"}),r.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"})]})]}),De&&r.jsxs("div",{className:"space-y-3",children:[r.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.alertAbove")}),r.jsx("input",{type:"number",value:$e,onChange:Ft=>Je(Ft.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"})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.alertBelow")}),r.jsx("input",{type:"number",value:Re,onChange:Ft=>mt(Ft.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"})]})]}),r.jsx("p",{className:"text-xs text-bambu-gray",children:n("smartPlugs.alertDescription")})]})]}),s!=="mqtt"&&r.jsxs("div",{className:"border-t border-bambu-dark-tertiary pt-4",children:[r.jsxs("div",{className:"flex items-center justify-between mb-3",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(Zn,{className:"w-4 h-4 text-bambu-green"}),r.jsx("span",{className:"text-white font-medium",children:n("smartPlugs.dailySchedule")})]}),r.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:he,onChange:Ft=>Le(Ft.target.checked),className:"sr-only peer"}),r.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"})]})]}),he&&r.jsxs("div",{className:"space-y-3",children:[r.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.turnOnAt")}),r.jsx("input",{type:"time",value:Xe,onChange:Ft=>Ze(Ft.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"})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("smartPlugs.turnOffAt")}),r.jsx("input",{type:"time",value:Ke,onChange:Ft=>bt(Ft.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"})]})]}),r.jsx("p",{className:"text-xs text-bambu-gray",children:n("smartPlugs.scheduleDescription")})]})]}),r.jsx("div",{className:"border-t border-bambu-dark-tertiary pt-4",children:r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(TS,{className:"w-4 h-4 text-bambu-green"}),r.jsxs("div",{children:[r.jsx("span",{className:"text-white font-medium",children:n("smartPlugs.showInSwitchbar")}),r.jsx("p",{className:"text-xs text-bambu-gray",children:n("smartPlugs.quickAccessSidebar")})]})]}),r.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:et,onChange:Ft=>jt(Ft.target.checked),className:"sr-only peer"}),r.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"&&r.jsx("div",{className:"border-t border-bambu-dark-tertiary pt-4",children:r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(Dl,{className:"w-4 h-4 text-bambu-green"}),r.jsxs("div",{children:[r.jsx("span",{className:"text-white font-medium",children:n("smartPlugs.showOnPrinterCard")}),r.jsx("p",{className:"text-xs text-bambu-gray",children:n("smartPlugs.displayOnPrinterCard")})]})]}),r.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:St,onChange:Ft=>It(Ft.target.checked),className:"sr-only peer"}),r.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"})]})]})}),r.jsxs("div",{className:"flex gap-3 pt-2",children:[r.jsx(Me,{type:"button",variant:"secondary",onClick:e,className:"flex-1",children:n("smartPlugs.cancel")}),r.jsxs(Me,{type:"submit",disabled:$s,className:"flex-1",children:[$s?r.jsx(pt,{className:"w-4 h-4 animate-spin"}):r.jsx(us,{className:"w-4 h-4"}),n(i?"smartPlugs.save":"smartPlugs.add")]})]})]})]})})}function En({checked:t,onChange:e,disabled:n}){const a=i=>{i.preventDefault(),i.stopPropagation(),n||e(!t)};return r.jsx("button",{type:"button",role:"switch","aria-checked":t,disabled:n,onClick:a,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:r.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 Prt({provider:t,onEdit:e}){const{t:n}=kt(),a=en(),[i,s]=y.useState(!1),[o,l]=y.useState(!1),[c,d]=y.useState(null),{data:u}=Ve({queryKey:["printers"],queryFn:se.getPrinters}),m=u?.find(g=>g.id===t.printer_id),p=it({mutationFn:g=>se.updateNotificationProvider(t.id,g),onSuccess:()=>{a.invalidateQueries({queryKey:["notification-providers"]})}}),f=it({mutationFn:()=>se.deleteNotificationProvider(t.id),onSuccess:()=>{a.invalidateQueries({queryKey:["notification-providers"]})}}),b=it({mutationFn:()=>se.testNotificationProvider(t.id),onSuccess:g=>{d(g),a.invalidateQueries({queryKey:["notification-providers"]})},onError:g=>{d({success:!1,message:g.message})}}),w=g=>g||"";return r.jsxs(r.Fragment,{children:[r.jsx(Ct,{className:"relative",children:r.jsxs(At,{className:"p-3",children:[r.jsxs("div",{className:`flex items-start justify-between ${t.enabled?"mb-3":"mb-0"}`,children:[r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx("div",{className:`p-2 rounded-lg ${t.enabled?"bg-bambu-green/20":"bg-bambu-dark"}`,children:r.jsx(kh,{className:`w-5 h-5 ${t.enabled?"text-bambu-green":"text-bambu-gray"}`})}),r.jsxs("div",{children:[r.jsx("h3",{className:"font-medium text-white",children:t.name}),r.jsx("p",{className:"text-sm text-bambu-gray",children:n(`notifications.providerTypes.${t.provider_type}`,t.provider_type)})]})]}),r.jsxs("div",{className:"flex items-center gap-3",children:[t.last_success&&r.jsx("span",{className:"text-xs text-status-ok hidden sm:inline",children:n("notifications.lastSuccess",{date:Lg(t.last_success)})}),t.last_error&&t.last_error_at&&(!t.last_success||(Xn(t.last_error_at)?.getTime()||0)>(Xn(t.last_success)?.getTime()||0))&&r.jsx("span",{className:"text-xs text-status-error",title:t.last_error,children:n("notifications.error")}),r.jsx(En,{checked:t.enabled,onChange:g=>p.mutate({enabled:g})})]})]}),t.enabled&&r.jsxs(r.Fragment,{children:[m&&r.jsxs("div",{className:"mb-3 px-2 py-1.5 bg-bambu-dark rounded-lg",children:[r.jsxs("span",{className:"text-xs text-bambu-gray",children:[n("notifications.printer")," "]}),r.jsx("span",{className:"text-sm text-white",children:m.name})]}),!m&&!t.printer_id&&r.jsx("div",{className:"mb-3 px-2 py-1.5 bg-bambu-dark rounded-lg",children:r.jsx("span",{className:"text-xs text-bambu-gray",children:n("notifications.allPrinters")})}),r.jsxs("div",{className:"mb-3 flex flex-wrap gap-1",children:[t.on_print_start&&r.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&&r.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&&r.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&&r.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&&r.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&&r.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&&r.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&&r.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&&r.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&&r.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&&r.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&&r.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&&r.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&&r.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&&r.jsx("span",{className:"px-2 py-0.5 bg-teal-500/20 text-teal-400 text-xs rounded",children:n("notifications.bedCooled")}),t.on_first_layer_complete&&r.jsx("span",{className:"px-2 py-0.5 bg-emerald-600/20 text-emerald-300 text-xs rounded",children:n("notifications.firstLayer")}),t.on_print_missing_spool_assignment&&r.jsx("span",{className:"px-2 py-0.5 bg-amber-500/20 text-amber-300 text-xs rounded",children:n("notifications.missingSpoolAssignmentLabel")}),t.on_stock_reorder_alert&&r.jsx("span",{className:"px-2 py-0.5 bg-lime-500/20 text-lime-400 text-xs rounded",children:n("notifications.stockReorderAlert")}),t.on_stock_break_alert&&r.jsx("span",{className:"px-2 py-0.5 bg-red-600/20 text-red-300 text-xs rounded",children:n("notifications.stockBreakAlert")}),t.quiet_hours_enabled&&r.jsxs("span",{className:"px-2 py-0.5 bg-indigo-500/20 text-indigo-400 text-xs rounded flex items-center gap-1",children:[r.jsx(nC,{className:"w-3 h-3"}),n("notifications.quiet")]}),t.daily_digest_enabled&&r.jsxs("span",{className:"px-2 py-0.5 bg-emerald-500/20 text-emerald-400 text-xs rounded flex items-center gap-1",children:[r.jsx(Sa,{className:"w-3 h-3"}),n("notifications.digest",{time:t.daily_digest_time})]})]}),r.jsx("div",{className:"mb-3",children:r.jsxs(Me,{size:"sm",variant:"secondary",disabled:b.isPending,onClick:()=>{d(null),b.mutate()},className:"w-full",children:[b.isPending?r.jsx(pt,{className:"w-4 h-4 animate-spin"}):r.jsx(DS,{className:"w-4 h-4"}),n("notifications.sendTestNotification")]})}),c&&r.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?r.jsx(wr,{className:"w-4 h-4"}):r.jsx(Da,{className:"w-4 h-4"}),r.jsx("span",{children:c.message})]})]}),r.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 ${t.enabled?"border-t border-bambu-dark-tertiary":"mt-2 border-t border-bambu-dark-tertiary"}`,children:[r.jsxs("span",{className:"flex items-center gap-2",children:[r.jsx(uu,{className:"w-4 h-4"}),n("notifications.eventSettings")]}),o?r.jsx(tl,{className:"w-4 h-4"}):r.jsx(Ln,{className:"w-4 h-4"})]}),o&&r.jsxs("div",{className:"pt-3 border-t border-bambu-dark-tertiary space-y-4",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-sm text-white",children:n("notifications.enabled")}),r.jsx("p",{className:"text-xs text-bambu-gray",children:n("notifications.sendFromProvider")})]}),r.jsx(En,{checked:t.enabled,onChange:g=>p.mutate({enabled:g})})]}),r.jsxs("div",{className:"space-y-2",children:[r.jsx("p",{className:"text-xs text-bambu-gray uppercase tracking-wide",children:n("notifications.printEvents")}),r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsx("p",{className:"text-sm text-white",children:n("notifications.printStarted")}),r.jsx(En,{checked:t.on_print_start,onChange:g=>p.mutate({on_print_start:g})})]}),r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-sm text-white",children:n("notifications.plateNotEmpty")}),r.jsx("p",{className:"text-xs text-bambu-gray",children:n("notifications.plateNotEmptyDescription")})]}),r.jsx(En,{checked:t.on_plate_not_empty??!0,onChange:g=>p.mutate({on_plate_not_empty:g})})]}),r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsx("p",{className:"text-sm text-white",children:n("notifications.printCompleted")}),r.jsx(En,{checked:t.on_print_complete,onChange:g=>p.mutate({on_print_complete:g})})]}),r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-sm text-white",children:n("notifications.bedCooledLabel")}),r.jsx("p",{className:"text-xs text-bambu-gray",children:n("notifications.bedCooledDescription")})]}),r.jsx(En,{checked:t.on_bed_cooled??!1,onChange:g=>p.mutate({on_bed_cooled:g})})]}),r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-sm text-white",children:n("notifications.firstLayerCompleteLabel")}),r.jsx("p",{className:"text-xs text-bambu-gray",children:n("notifications.firstLayerCompleteDescription")})]}),r.jsx(En,{checked:t.on_first_layer_complete??!1,onChange:g=>p.mutate({on_first_layer_complete:g})})]}),r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-sm text-white",children:n("notifications.missingSpoolAssignmentLabel")}),r.jsx("p",{className:"text-xs text-bambu-gray",children:n("notifications.missingSpoolAssignmentDescription")})]}),r.jsx(En,{checked:t.on_print_missing_spool_assignment??!1,onChange:g=>p.mutate({on_print_missing_spool_assignment:g})})]}),r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsx("p",{className:"text-sm text-white",children:n("notifications.printFailed")}),r.jsx(En,{checked:t.on_print_failed,onChange:g=>p.mutate({on_print_failed:g})})]}),r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsx("p",{className:"text-sm text-white",children:n("notifications.printStopped")}),r.jsx(En,{checked:t.on_print_stopped,onChange:g=>p.mutate({on_print_stopped:g})})]}),r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-sm text-white",children:n("notifications.progressMilestones")}),r.jsx("p",{className:"text-xs text-bambu-gray",children:n("notifications.progressMilestonesDescription")})]}),r.jsx(En,{checked:t.on_print_progress,onChange:g=>p.mutate({on_print_progress:g})})]})]}),r.jsxs("div",{className:"space-y-2",children:[r.jsx("p",{className:"text-xs text-bambu-gray uppercase tracking-wide",children:n("notifications.printerStatus")}),r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsx("p",{className:"text-sm text-white",children:n("notifications.printerOffline")}),r.jsx(En,{checked:t.on_printer_offline,onChange:g=>p.mutate({on_printer_offline:g})})]}),r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsx("p",{className:"text-sm text-white",children:n("notifications.printerError")}),r.jsx(En,{checked:t.on_printer_error,onChange:g=>p.mutate({on_printer_error:g})})]}),r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsx("p",{className:"text-sm text-white",children:n("notifications.lowFilamentLabel")}),r.jsx(En,{checked:t.on_filament_low,onChange:g=>p.mutate({on_filament_low:g})})]}),r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-sm text-white",children:n("notifications.maintenanceDue")}),r.jsx("p",{className:"text-xs text-bambu-gray",children:n("notifications.maintenanceDueDescription")})]}),r.jsx(En,{checked:t.on_maintenance_due??!1,onChange:g=>p.mutate({on_maintenance_due:g})})]})]}),r.jsxs("div",{className:"space-y-2",children:[r.jsx("p",{className:"text-xs text-bambu-gray uppercase tracking-wide",children:n("notifications.amsAlarms")}),r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-sm text-white",children:n("notifications.amsHumidityHigh")}),r.jsx("p",{className:"text-xs text-bambu-gray",children:n("notifications.amsHumidityHighDescription")})]}),r.jsx(En,{checked:t.on_ams_humidity_high??!1,onChange:g=>p.mutate({on_ams_humidity_high:g})})]}),r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-sm text-white",children:n("notifications.amsTemperatureHigh")}),r.jsx("p",{className:"text-xs text-bambu-gray",children:n("notifications.amsTemperatureHighDescription")})]}),r.jsx(En,{checked:t.on_ams_temperature_high??!1,onChange:g=>p.mutate({on_ams_temperature_high:g})})]})]}),r.jsxs("div",{className:"space-y-2",children:[r.jsx("p",{className:"text-xs text-bambu-gray uppercase tracking-wide",children:n("notifications.amsHtAlarms")}),r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-sm text-white",children:n("notifications.amsHtHumidityHigh")}),r.jsx("p",{className:"text-xs text-bambu-gray",children:n("notifications.amsHtHumidityHighDescription")})]}),r.jsx(En,{checked:t.on_ams_ht_humidity_high??!1,onChange:g=>p.mutate({on_ams_ht_humidity_high:g})})]}),r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-sm text-white",children:n("notifications.amsHtTemperatureHigh")}),r.jsx("p",{className:"text-xs text-bambu-gray",children:n("notifications.amsHtTemperatureHighDescription")})]}),r.jsx(En,{checked:t.on_ams_ht_temperature_high??!1,onChange:g=>p.mutate({on_ams_ht_temperature_high:g})})]})]}),r.jsxs("div",{className:"space-y-2",children:[r.jsx("p",{className:"text-xs text-bambu-gray uppercase tracking-wide",children:n("notifications.inventoryAlerts")}),r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-sm text-white",children:n("notifications.stockReorderAlert")}),r.jsx("p",{className:"text-xs text-bambu-gray",children:n("notifications.stockReorderAlertDescription")})]}),r.jsx(En,{checked:t.on_stock_reorder_alert??!1,onChange:g=>p.mutate({on_stock_reorder_alert:g})})]}),r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-sm text-white",children:n("notifications.stockBreakAlert")}),r.jsx("p",{className:"text-xs text-bambu-gray",children:n("notifications.stockBreakAlertDescription")})]}),r.jsx(En,{checked:t.on_stock_break_alert??!1,onChange:g=>p.mutate({on_stock_break_alert:g})})]})]}),r.jsxs("div",{className:"space-y-2",children:[r.jsx("p",{className:"text-xs text-bambu-gray uppercase tracking-wide",children:n("notifications.printQueue")}),r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-sm text-white",children:n("notifications.jobAdded")}),r.jsx("p",{className:"text-xs text-bambu-gray",children:n("notifications.jobAddedDescription")})]}),r.jsx(En,{checked:t.on_queue_job_added??!1,onChange:g=>p.mutate({on_queue_job_added:g})})]}),r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-sm text-white",children:n("notifications.jobAssigned")}),r.jsx("p",{className:"text-xs text-bambu-gray",children:n("notifications.jobAssignedDescription")})]}),r.jsx(En,{checked:t.on_queue_job_assigned??!1,onChange:g=>p.mutate({on_queue_job_assigned:g})})]}),r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-sm text-white",children:n("notifications.jobStarted")}),r.jsx("p",{className:"text-xs text-bambu-gray",children:n("notifications.jobStartedDescription")})]}),r.jsx(En,{checked:t.on_queue_job_started??!1,onChange:g=>p.mutate({on_queue_job_started:g})})]}),r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-sm text-white",children:n("notifications.jobWaiting")}),r.jsx("p",{className:"text-xs text-bambu-gray",children:n("notifications.jobWaitingDescription")})]}),r.jsx(En,{checked:t.on_queue_job_waiting??!0,onChange:g=>p.mutate({on_queue_job_waiting:g})})]}),r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-sm text-white",children:n("notifications.jobSkipped")}),r.jsx("p",{className:"text-xs text-bambu-gray",children:n("notifications.jobSkippedDescription")})]}),r.jsx(En,{checked:t.on_queue_job_skipped??!0,onChange:g=>p.mutate({on_queue_job_skipped:g})})]}),r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-sm text-white",children:n("notifications.jobFailed")}),r.jsx("p",{className:"text-xs text-bambu-gray",children:n("notifications.jobFailedDescription")})]}),r.jsx(En,{checked:t.on_queue_job_failed??!0,onChange:g=>p.mutate({on_queue_job_failed:g})})]}),r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-sm text-white",children:n("notifications.queueComplete")}),r.jsx("p",{className:"text-xs text-bambu-gray",children:n("notifications.queueCompleteDescription")})]}),r.jsx(En,{checked:t.on_queue_completed??!1,onChange:g=>p.mutate({on_queue_completed:g})})]})]}),r.jsxs("div",{className:"space-y-2",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(nC,{className:"w-4 h-4 text-purple-400"}),r.jsx("p",{className:"text-sm text-white",children:n("notifications.quietHours")})]}),r.jsx(En,{checked:t.quiet_hours_enabled,onChange:g=>p.mutate({quiet_hours_enabled:g})})]}),t.quiet_hours_enabled&&r.jsxs("div",{className:"pl-4 border-l-2 border-bambu-dark-tertiary space-y-2",children:[r.jsx("p",{className:"text-xs text-bambu-gray",children:n("notifications.noNotificationsDuring")}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(Zn,{className:"w-4 h-4 text-bambu-gray"}),r.jsxs("span",{className:"text-sm text-white",children:[w(t.quiet_hours_start)||"22:00"," - ",w(t.quiet_hours_end)||"07:00"]})]}),r.jsx("p",{className:"text-xs text-bambu-gray",children:n("notifications.editProviderToChangeQuietHours")})]})]}),r.jsxs("div",{className:"space-y-2",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(Sa,{className:"w-4 h-4 text-emerald-400"}),r.jsx("p",{className:"text-sm text-white",children:n("notifications.dailyDigest")})]}),r.jsx(En,{checked:t.daily_digest_enabled,onChange:g=>p.mutate({daily_digest_enabled:g})})]}),t.daily_digest_enabled&&r.jsxs("div",{className:"pl-4 border-l-2 border-bambu-dark-tertiary space-y-2",children:[r.jsx("p",{className:"text-xs text-bambu-gray",children:n("notifications.batchNotifications")}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(Zn,{className:"w-4 h-4 text-bambu-gray"}),r.jsx("span",{className:"text-sm text-white",children:n("notifications.sendAt",{time:w(t.daily_digest_time)||"08:00"})})]}),r.jsx("p",{className:"text-xs text-bambu-gray",children:n("notifications.editProviderToChangeDigestTime")})]})]}),r.jsxs("div",{className:"flex gap-2 pt-2",children:[r.jsxs(Me,{size:"sm",variant:"secondary",onClick:()=>e(t),className:"flex-1",children:[r.jsx(fc,{className:"w-4 h-4"}),n("notifications.edit")]}),r.jsx(Me,{size:"sm",variant:"secondary",onClick:()=>s(!0),className:"text-red-400 hover:text-red-300",children:r.jsx(Jt,{className:"w-4 h-4"})})]})]})]})}),i&&r.jsx(vn,{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 Trt=["email","telegram","discord","ntfy","pushover","callmebot","webhook","homeassistant"];function Art({provider:t,onClose:e}){const{t:n}=kt(),a=en(),i=!!t,[s,o]=y.useState(t?.name||""),[l,c]=y.useState(t?.provider_type||"email"),[d,u]=y.useState(t?.printer_id||null),[m,p]=y.useState(t?.quiet_hours_enabled||!1),[f,b]=y.useState(t?.quiet_hours_start||"22:00"),[w,g]=y.useState(t?.quiet_hours_end||"07:00"),[x,_]=y.useState(t?.daily_digest_enabled||!1),[N,C]=y.useState(t?.daily_digest_time||"08:00"),[P,T]=y.useState(t?.on_print_start??!1),[A,F]=y.useState(t?.on_print_complete??!0),[S,E]=y.useState(t?.on_print_failed??!0),[U,I]=y.useState(t?.on_print_stopped??!0),[H,R]=y.useState(t?.on_print_progress??!1),[Q,re]=y.useState(t?.on_printer_offline??!1),[J,de]=y.useState(t?.on_printer_error??!1),[pe,ue]=y.useState(t?.on_filament_low??!1),[X,ae]=y.useState(t?.on_maintenance_due??!1),[me,be]=y.useState(t?.on_stock_reorder_alert??!1),[Ce,$]=y.useState(t?.on_stock_break_alert??!1),[W,D]=y.useState(t?.on_bed_cooled??!1),[j,B]=y.useState(t?.on_first_layer_complete??!1),[Y,O]=y.useState(t?.config?Object.fromEntries(Object.entries(t.config).filter(([ve])=>ve!=="event_priorities").map(([ve,xe])=>[ve,String(xe)])):{}),ie=(()=>{const ve=t?.config?.event_priorities;if(!ve||typeof ve!="object")return{};const xe={};for(const[Ee,ze]of Object.entries(ve)){const _e=Number(ze);Number.isInteger(_e)&&_e>=1&&_e<=5&&(xe[Ee]=_e)}return xe})(),[z,G]=y.useState(ie),[K,Z]=y.useState(null),[oe,ee]=y.useState(null),{data:ge}=Ve({queryKey:["printers"],queryFn:se.getPrinters});y.useEffect(()=>{const ve=xe=>{xe.key==="Escape"&&e()};return window.addEventListener("keydown",ve),()=>window.removeEventListener("keydown",ve)},[e]);const ce=it({mutationFn:()=>se.testNotificationConfig({provider_type:l,config:Y}),onSuccess:ve=>{Z(ve),ee(null)},onError:ve=>{Z({success:!1,message:ve.message})}}),le=it({mutationFn:ve=>se.createNotificationProvider(ve),onSuccess:()=>{a.invalidateQueries({queryKey:["notification-providers"]}),e()},onError:ve=>{ee(ve.message)}}),q=it({mutationFn:ve=>se.updateNotificationProvider(t.id,ve),onSuccess:()=>{a.invalidateQueries({queryKey:["notification-providers"]}),e()},onError:ve=>{ee(ve.message)}}),L=ve=>{if(ve.preventDefault(),ee(null),!s.trim()){ee(n("notifications.nameRequired"));return}const xe=we(l);for(const _e of xe)if(!Y[_e.key]?.trim()){ee(n("notifications.fieldRequired",{field:_e.label}));return}const Ee=l==="ntfy"&&Object.keys(z).length>0?{...Y,event_priorities:z}:Y,ze={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?w:null,daily_digest_enabled:x,daily_digest_time:x?N:null,on_print_start:P,on_print_complete:A,on_print_failed:S,on_print_stopped:U,on_print_progress:H,on_printer_offline:Q,on_printer_error:J,on_filament_low:pe,on_maintenance_due:X,on_stock_reorder_alert:me,on_stock_break_alert:Ce,on_bed_cooled:W,on_first_layer_complete:j};i?q.mutate(ze):le.mutate(ze)},ne=le.isPending||q.isPending,ye=ve=>{switch(ve){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:xe=>xe.payload_format!=="slack"},{key:"field_message",label:"Message Field Name",placeholder:"message",type:"text",required:!1,showIf:xe=>xe.payload_format!=="slack"}];case"homeassistant":return[{key:"service",label:"Home Assistant Service",placeholder:"notify.mobile_app_myphone",type:"text",required:!1}];default:return[]}},we=ve=>ye(ve).filter(xe=>xe.required),Ne=ye(l);return r.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4 overflow-y-auto",onClick:e,children:r.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:ve=>ve.stopPropagation(),children:[r.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary",children:[r.jsx("h2",{className:"text-lg font-semibold text-white",children:n(i?"notifications.editTitle":"notifications.addTitle")}),r.jsx("button",{onClick:e,className:"text-bambu-gray hover:text-white transition-colors",children:r.jsx(Ht,{className:"w-5 h-5"})})]}),r.jsxs("form",{onSubmit:L,className:"p-6 space-y-4",children:[oe&&r.jsx("div",{className:"p-3 bg-red-500/20 border border-red-500/50 rounded-lg text-sm text-red-400",children:oe}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("notifications.nameLabel")}),r.jsx("input",{type:"text",value:s,onChange:ve=>o(ve.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"})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("notifications.providerTypeLabel")}),r.jsx("select",{value:l,onChange:ve=>{c(ve.target.value),O({}),Z(null)},disabled:i,className:"w-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:Trt.map(ve=>r.jsx("option",{value:ve,children:n(`notifications.providerTypes.${ve}`,ve)},ve))}),r.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:n(`notifications.providerDescriptions.${l}`,"")})]}),r.jsxs("div",{className:"space-y-3",children:[r.jsx("p",{className:"text-sm text-bambu-gray",children:n("notifications.configuration")}),Ne.filter(ve=>!("showIf"in ve)||ve.showIf?.(Y)!==!1).map(ve=>r.jsxs("div",{children:[r.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[ve.label," ",ve.required&&"*"]}),ve.type==="select"&&"options"in ve&&ve.options?r.jsx("select",{value:Y[ve.key]||ve.options[0]?.value||"",onChange:xe=>{O({...Y,[ve.key]:xe.target.value}),Z(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:ve.options.map(xe=>r.jsx("option",{value:xe.value,children:xe.label},xe.value))}):r.jsx("input",{type:ve.type,value:Y[ve.key]||"",onChange:xe=>{O({...Y,[ve.key]:xe.target.value}),Z(null)},placeholder:ve.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"})]},ve.key))]}),r.jsx("div",{className:"flex gap-2",children:r.jsxs(Me,{type:"button",variant:"secondary",onClick:()=>{Z(null),ce.mutate()},disabled:ce.isPending||we(l).length>0&&!Y[we(l)[0]?.key],className:"flex-1",children:[ce.isPending?r.jsx(pt,{className:"w-4 h-4 animate-spin"}):r.jsx(DS,{className:"w-4 h-4"}),n("notifications.testConfiguration")]})}),K&&r.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?r.jsxs(r.Fragment,{children:[r.jsx(wr,{className:"w-5 h-5"}),r.jsx("span",{children:K.message})]}):r.jsxs(r.Fragment,{children:[r.jsx(Da,{className:"w-5 h-5"}),r.jsx("span",{children:K.message})]})}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("notifications.printerFilter")}),r.jsxs("select",{value:d??"",onChange:ve=>u(ve.target.value?Number(ve.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:[r.jsx("option",{value:"",children:n("notifications.allPrinters")}),ge?.map(ve=>r.jsx("option",{value:ve.id,children:ve.name},ve.id))]}),r.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:n("notifications.onlyFromPrinter")})]}),r.jsxs("div",{className:"space-y-2",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsx("label",{className:"text-sm text-white",children:n("notifications.quietHoursDnd")}),r.jsx(En,{checked:m,onChange:p})]}),m&&r.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:n("notifications.quietStart")}),r.jsx("input",{type:"time",value:f,onChange:ve=>b(ve.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"})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:n("notifications.quietEnd")}),r.jsx("input",{type:"time",value:w,onChange:ve=>g(ve.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"})]})]})]}),r.jsxs("div",{className:"space-y-2",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("label",{className:"text-sm text-white",children:n("notifications.dailyDigestLabel")}),r.jsx("p",{className:"text-xs text-bambu-gray",children:n("notifications.batchNotifications")})]}),r.jsx(En,{checked:x,onChange:_})]}),x&&r.jsxs("div",{children:[r.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:n("notifications.sendDigestAt")}),r.jsx("input",{type:"time",value:N,onChange:ve=>C(ve.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"}),r.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:n("notifications.digestCollected")})]})]}),r.jsxs("div",{className:"space-y-3",children:[r.jsx("p",{className:"text-sm text-bambu-gray",children:n("notifications.notificationEvents")}),r.jsxs("div",{className:"space-y-2 p-3 bg-bambu-dark rounded-lg",children:[r.jsx("p",{className:"text-xs text-bambu-gray uppercase tracking-wide mb-2",children:n("notifications.printEvents")}),r.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsx("span",{className:"text-sm text-white",children:n("notifications.start")}),r.jsx(En,{checked:P,onChange:T})]}),r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsx("span",{className:"text-sm text-white",children:n("notifications.complete")}),r.jsx(En,{checked:A,onChange:F})]}),r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsx("span",{className:"text-sm text-white",children:n("notifications.failed")}),r.jsx(En,{checked:S,onChange:E})]}),r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsx("span",{className:"text-sm text-white",children:n("notifications.stopped")}),r.jsx(En,{checked:U,onChange:I})]}),r.jsxs("div",{className:"flex items-center justify-between col-span-2",children:[r.jsxs("div",{children:[r.jsx("span",{className:"text-sm text-white",children:n("notifications.progress")}),r.jsx("span",{className:"text-xs text-bambu-gray ml-1",children:n("notifications.progressPercent")})]}),r.jsx(En,{checked:H,onChange:R})]}),r.jsxs("div",{className:"flex items-center justify-between col-span-2",children:[r.jsxs("div",{children:[r.jsx("span",{className:"text-sm text-white",children:n("notifications.bedCooled")}),r.jsx("span",{className:"text-xs text-bambu-gray ml-1",children:n("notifications.bedCooledAfterPrint")})]}),r.jsx(En,{checked:W,onChange:D})]}),r.jsxs("div",{className:"flex items-center justify-between col-span-2",children:[r.jsxs("div",{children:[r.jsx("span",{className:"text-sm text-white",children:n("notifications.firstLayerCompleteLabel")}),r.jsx("span",{className:"text-xs text-bambu-gray ml-1",children:n("notifications.firstLayerCompleteDescription")})]}),r.jsx(En,{checked:j,onChange:B})]})]})]}),r.jsxs("div",{className:"space-y-2 p-3 bg-bambu-dark rounded-lg",children:[r.jsx("p",{className:"text-xs text-bambu-gray uppercase tracking-wide mb-2",children:n("notifications.printerStatus")}),r.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsx("span",{className:"text-sm text-white",children:n("notifications.offline")}),r.jsx(En,{checked:Q,onChange:re})]}),r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsx("span",{className:"text-sm text-white",children:n("notifications.error")}),r.jsx(En,{checked:J,onChange:de})]}),r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsx("span",{className:"text-sm text-white",children:n("notifications.lowFilament")}),r.jsx(En,{checked:pe,onChange:ue})]}),r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsx("span",{className:"text-sm text-white",children:n("notifications.maintenance")}),r.jsx(En,{checked:X,onChange:ae})]})]})]}),r.jsxs("div",{className:"space-y-2 p-3 bg-bambu-dark rounded-lg",children:[r.jsx("p",{className:"text-xs text-bambu-gray uppercase tracking-wide mb-2",children:n("notifications.inventoryAlerts")}),r.jsxs("div",{className:"grid grid-cols-1 gap-2",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("span",{className:"text-sm text-white",children:n("notifications.stockReorderAlert")}),r.jsx("span",{className:"text-xs text-bambu-gray ml-1",children:n("notifications.stockReorderAlertDescription")})]}),r.jsx(En,{checked:me,onChange:be})]}),r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("span",{className:"text-sm text-white",children:n("notifications.stockBreakAlert")}),r.jsx("span",{className:"text-xs text-bambu-gray ml-1",children:n("notifications.stockBreakAlertDescription")})]}),r.jsx(En,{checked:Ce,onChange:$})]})]})]}),l==="ntfy"&&(()=>{const ve=[];return P&&ve.push({key:"on_print_start",label:n("notifications.start")}),A&&ve.push({key:"on_print_complete",label:n("notifications.complete")}),S&&ve.push({key:"on_print_failed",label:n("notifications.failed")}),U&&ve.push({key:"on_print_stopped",label:n("notifications.stopped")}),H&&ve.push({key:"on_print_progress",label:n("notifications.progress")}),W&&ve.push({key:"on_bed_cooled",label:n("notifications.bedCooled")}),j&&ve.push({key:"on_first_layer_complete",label:n("notifications.firstLayerCompleteLabel")}),Q&&ve.push({key:"on_printer_offline",label:n("notifications.offline")}),J&&ve.push({key:"on_printer_error",label:n("notifications.error")}),pe&&ve.push({key:"on_filament_low",label:n("notifications.lowFilament")}),X&&ve.push({key:"on_maintenance_due",label:n("notifications.maintenance")}),me&&ve.push({key:"on_stock_reorder_alert",label:n("notifications.stockReorderAlert")}),Ce&&ve.push({key:"on_stock_break_alert",label:n("notifications.stockBreakAlert")}),ve.length===0?null:r.jsxs("div",{className:"space-y-2 p-3 bg-bambu-dark rounded-lg",children:[r.jsx("p",{className:"text-xs text-bambu-gray uppercase tracking-wide mb-1",children:n("notifications.eventPriority.sectionTitle")}),r.jsx("p",{className:"text-xs text-bambu-gray mb-2",children:n("notifications.eventPriority.helpNtfy")}),r.jsx("div",{className:"space-y-2",children:ve.map(xe=>r.jsxs("div",{className:"flex items-center justify-between gap-3",children:[r.jsx("span",{className:"text-sm text-white",children:xe.label}),r.jsxs("select",{value:z[xe.key]??3,onChange:Ee=>{const ze=Number(Ee.target.value);G(_e=>({..._e,[xe.key]:ze}))},className:"px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-sm text-white focus:border-bambu-green focus:outline-none",children:[r.jsx("option",{value:1,children:n("notifications.eventPriority.min")}),r.jsx("option",{value:2,children:n("notifications.eventPriority.low")}),r.jsx("option",{value:3,children:n("notifications.eventPriority.default")}),r.jsx("option",{value:4,children:n("notifications.eventPriority.high")}),r.jsx("option",{value:5,children:n("notifications.eventPriority.urgent")})]})]},xe.key))})]})})()]}),r.jsxs("div",{className:"flex gap-3 pt-2",children:[r.jsx(Me,{type:"button",variant:"secondary",onClick:e,className:"flex-1",children:n("notifications.cancel")}),r.jsxs(Me,{type:"submit",disabled:ne,className:"flex-1",children:[ne?r.jsx(pt,{className:"w-4 h-4 animate-spin"}):r.jsx(us,{className:"w-4 h-4"}),n(i?"notifications.save":"notifications.add")]})]})]})]})})}function jrt({template:t,onClose:e}){const{t:n}=kt(),a=en(),i=y.useRef(null),[s,o]=y.useState(t.title_template),[l,c]=y.useState(t.body_template),[d,u]=y.useState(null),[m,p]=y.useState(!0),{data:f}=Ve({queryKey:["template-variables"],queryFn:se.getTemplateVariables}),b=f?.find(T=>T.event_type===t.event_type),{data:w,isLoading:g}=Ve({queryKey:["template-preview",t.event_type,s,l],queryFn:()=>se.previewTemplate({event_type:t.event_type,title_template:s,body_template:l}),enabled:m&&s.length>0&&l.length>0});y.useEffect(()=>{const T=A=>{A.key==="Escape"&&e()};return window.addEventListener("keydown",T),()=>window.removeEventListener("keydown",T)},[e]);const x=it({mutationFn:T=>se.updateNotificationTemplate(t.id,T),onSuccess:()=>{a.invalidateQueries({queryKey:["notification-templates"]}),e()},onError:T=>{u(T.message)}}),_=it({mutationFn:()=>se.resetNotificationTemplate(t.id),onSuccess:T=>{o(T.title_template),c(T.body_template),a.invalidateQueries({queryKey:["notification-templates"]})},onError:T=>{u(T.message)}}),N=T=>{if(T.preventDefault(),u(null),!s.trim()){u(n("notifications.titleRequired"));return}if(!l.trim()){u(n("notifications.bodyRequired"));return}x.mutate({title_template:s,body_template:l})},C=T=>{const A=i.current;if(!A)return;const F=A.selectionStart,S=A.selectionEnd,E=l,U=E.substring(0,F),I=E.substring(S),H=U+`{${T}}`+I;c(H),setTimeout(()=>{A.focus();const R=F+T.length+2;A.setSelectionRange(R,R)},0)},P=s!==t.title_template||l!==t.body_template;return r.jsx("div",{className:"fixed inset-0 bg-black/80 flex items-center justify-center z-50 p-4",children:r.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg w-full max-w-2xl max-h-[90vh] flex flex-col",children:[r.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary shrink-0",children:[r.jsx("h2",{className:"text-lg font-semibold text-white",children:n("notifications.editTemplate",{name:t.name})}),r.jsx("button",{onClick:e,className:"p-1 hover:bg-bambu-dark-tertiary rounded transition-colors",children:r.jsx(Ht,{className:"w-5 h-5 text-bambu-gray"})})]}),r.jsxs("form",{onSubmit:N,className:"flex-1 overflow-y-auto p-4 space-y-4",children:[d&&r.jsx("div",{className:"p-3 bg-red-500/20 border border-red-500/50 rounded text-red-400 text-sm",children:d}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm font-medium text-bambu-gray mb-1",children:n("notifications.titleLabel")}),r.jsx("input",{type:"text",value:s,onChange:T=>o(T.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")})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm font-medium text-bambu-gray mb-1",children:n("notifications.bodyLabel")}),r.jsx("textarea",{ref:i,value:l,onChange:T=>c(T.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")})]}),b&&r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm font-medium text-bambu-gray mb-2",children:n("notifications.availableVariables")}),r.jsx("div",{className:"flex flex-wrap gap-2",children:b.variables.map(T=>r.jsxs("button",{type:"button",onClick:()=>C(T),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:[r.jsx(ar,{className:"w-3 h-3"}),T]},T))}),r.jsx("p",{className:"text-xs text-bambu-gray/60 mt-1",children:n("notifications.clickToInsert")})]}),r.jsxs("div",{children:[r.jsxs("div",{className:"flex items-center justify-between mb-2",children:[r.jsxs("label",{className:"text-sm font-medium text-bambu-gray flex items-center gap-2",children:[r.jsx(Dl,{className:"w-4 h-4"}),n("notifications.livePreview")]}),r.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&&r.jsx("div",{className:"bg-bambu-dark border border-bambu-dark-tertiary rounded p-3 space-y-2",children:g?r.jsxs("div",{className:"flex items-center gap-2 text-bambu-gray text-sm",children:[r.jsx(pt,{className:"w-4 h-4 animate-spin"}),n("notifications.loadingPreview")]}):w?r.jsxs(r.Fragment,{children:[r.jsxs("div",{children:[r.jsx("span",{className:"text-xs text-bambu-gray",children:n("notifications.titlePreview")}),r.jsx("div",{className:"text-white font-medium",children:w.title})]}),r.jsxs("div",{children:[r.jsx("span",{className:"text-xs text-bambu-gray",children:n("notifications.bodyPreview")}),r.jsx("div",{className:"text-white whitespace-pre-wrap text-sm",children:w.body})]})]}):r.jsx("div",{className:"text-bambu-gray text-sm",children:n("notifications.enterTemplateContent")})})]})]}),r.jsxs("div",{className:"flex items-center justify-between p-4 border-t border-bambu-dark-tertiary shrink-0",children:[r.jsxs(Me,{type:"button",variant:"ghost",onClick:()=>_.mutate(),disabled:_.isPending,className:"text-orange-400 hover:text-orange-300",children:[_.isPending?r.jsx(pt,{className:"w-4 h-4 animate-spin mr-2"}):r.jsx(gs,{className:"w-4 h-4 mr-2"}),n("notifications.resetToDefault")]}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx(Me,{type:"button",variant:"secondary",onClick:e,children:n("notifications.cancel")}),r.jsxs(Me,{onClick:N,disabled:x.isPending||!P,children:[x.isPending?r.jsx(pt,{className:"w-4 h-4 animate-spin mr-2"}):r.jsx(us,{className:"w-4 h-4 mr-2"}),n("notifications.save")]})]})]})]})})}const Mrt={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 Ert({onClose:t}){const{t:e}=kt(),n=en(),{showToast:a}=rn(),[i,s]=y.useState(7),[o,l]=y.useState(null),[c,d]=y.useState(!1),{data:u}=Ve({queryKey:["settings"],queryFn:se.getSettings}),m=u?.time_format||"system",{data:p,isLoading:f,refetch:b,isRefetching:w}=Ve({queryKey:["notification-logs",i,c],queryFn:()=>se.getNotificationLogs({days:i,limit:100,success:c?!1:void 0})}),{data:g}=Ve({queryKey:["notification-log-stats",i],queryFn:()=>se.getNotificationLogStats(i)}),x=it({mutationFn:()=>se.clearNotificationLogs(30),onSuccess:N=>{a(N.message,"success"),n.invalidateQueries({queryKey:["notification-logs"]}),n.invalidateQueries({queryKey:["notification-log-stats"]})},onError:N=>{a(`Failed to clear logs: ${N.message}`,"error")}}),_=N=>{const C=Xn(N);if(!C)return"";const T=new Date().getTime()-C.getTime();return T<6e4?e("notifications.justNow"):T<36e5?`${Math.floor(T/6e4)}m ago`:T<864e5?`${Math.floor(T/36e5)}h ago`:C.toLocaleDateString()+" "+ZZ(C,m)};return r.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",children:r.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:[r.jsxs("div",{className:"p-4 border-b border-bambu-dark-tertiary flex items-center justify-between",children:[r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx(Aw,{className:"w-5 h-5 text-bambu-green"}),r.jsx("h2",{className:"text-lg font-semibold text-white",children:e("notifications.notificationLog")})]}),r.jsx("button",{onClick:t,className:"text-bambu-gray hover:text-white transition-colors",children:"×"})]}),g&&r.jsx("div",{className:"px-4 py-3 border-b border-bambu-dark-tertiary bg-bambu-dark/50",children:r.jsxs("div",{className:"flex items-center gap-6 text-sm",children:[r.jsxs("span",{className:"text-bambu-gray",children:[e("notifications.statsSummary",{days:i})," ",r.jsx("span",{className:"text-white font-medium",children:g.total})," ",e("notifications.statsNotifications")]}),r.jsxs("span",{className:"flex items-center gap-1 text-bambu-green",children:[r.jsx(wr,{className:"w-4 h-4"}),e("notifications.statsSent",{count:g.success_count})]}),g.failure_count>0&&r.jsxs("span",{className:"flex items-center gap-1 text-red-400",children:[r.jsx(Da,{className:"w-4 h-4"}),e("notifications.statsFailed",{count:g.failure_count})]})]})}),r.jsxs("div",{className:"px-4 py-3 border-b border-bambu-dark-tertiary flex items-center gap-4",children:[r.jsxs("select",{value:i,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:[r.jsx("option",{value:1,children:e("notifications.last24Hours")}),r.jsx("option",{value:7,children:e("notifications.last7Days")}),r.jsx("option",{value:30,children:e("notifications.last30Days")}),r.jsx("option",{value:90,children:e("notifications.last90Days")})]}),r.jsxs("label",{className:"flex items-center gap-2 text-sm text-bambu-gray cursor-pointer",children:[r.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")]}),r.jsx("div",{className:"flex-1"}),r.jsxs(Me,{size:"sm",variant:"secondary",onClick:()=>b(),disabled:w,children:[w?r.jsx(pt,{className:"w-4 h-4 animate-spin"}):r.jsx(sr,{className:"w-4 h-4"}),e("notifications.refresh")]}),r.jsxs(Me,{size:"sm",variant:"secondary",onClick:()=>x.mutate(),disabled:x.isPending,className:"text-red-400 hover:text-red-300",children:[x.isPending?r.jsx(pt,{className:"w-4 h-4 animate-spin"}):r.jsx(Jt,{className:"w-4 h-4"}),e("notifications.clearOld")]})]}),r.jsx("div",{className:"flex-1 overflow-y-auto p-4",children:f?r.jsx("div",{className:"flex justify-center py-12",children:r.jsx(pt,{className:"w-6 h-6 text-bambu-green animate-spin"})}):p&&p.length>0?r.jsx("div",{className:"space-y-2",children:p.map(N=>r.jsx(Drt,{log:N,isExpanded:o===N.id,onToggle:()=>l(o===N.id?null:N.id),formatDate:_,formatFullDate:C=>Rg(C,m)},N.id))}):r.jsxs("div",{className:"text-center py-12 text-bambu-gray",children:[r.jsx(Aw,{className:"w-12 h-12 mx-auto mb-3 opacity-30"}),r.jsx("p",{className:"text-sm",children:e(c?"notifications.noFailedNotifications":"notifications.noNotificationsLogged")})]})})]})})}function Drt({log:t,isExpanded:e,onToggle:n,formatDate:a,formatFullDate:i}){const{t:s}=kt();return r.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:[r.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?r.jsx(wr,{className:"w-4 h-4 text-bambu-green shrink-0"}):r.jsx(Da,{className:"w-4 h-4 text-red-400 shrink-0"}),r.jsx("span",{className:`text-xs font-medium ${Mrt[t.event_type]||"text-bambu-gray"}`,children:s(`notifications.eventTypes.${t.event_type}`,t.event_type)}),r.jsx("span",{className:"text-sm text-white truncate flex-1",children:t.provider_name||s("notifications.unknownProvider")}),t.printer_name&&r.jsx("span",{className:"text-xs text-bambu-gray",children:t.printer_name}),r.jsx("span",{className:"text-xs text-bambu-gray shrink-0",children:a(t.created_at)}),e?r.jsx(tl,{className:"w-4 h-4 text-bambu-gray shrink-0"}):r.jsx(Ln,{className:"w-4 h-4 text-bambu-gray shrink-0"})]}),e&&r.jsxs("div",{className:"px-3 py-2 border-t border-bambu-dark-tertiary bg-bambu-dark/20 space-y-2",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-xs text-bambu-gray mb-1",children:s("notifications.logTitle")}),r.jsx("p",{className:"text-sm text-white",children:t.title})]}),r.jsxs("div",{children:[r.jsx("p",{className:"text-xs text-bambu-gray mb-1",children:s("notifications.logMessage")}),r.jsx("p",{className:"text-sm text-white whitespace-pre-wrap",children:t.message})]}),!t.success&&t.error_message&&r.jsxs("div",{children:[r.jsx("p",{className:"text-xs text-red-400 mb-1",children:s("notifications.logError")}),r.jsx("p",{className:"text-sm text-red-300",children:t.error_message})]}),r.jsxs("div",{className:"flex gap-4 text-xs text-bambu-gray pt-1",children:[r.jsx("span",{children:s("notifications.logProvider",{type:t.provider_type})}),r.jsx("span",{children:s("notifications.logTime",{time:i(t.created_at)})})]})]})]})}function Frt({formData:t,setFormData:e,groups:n,onClose:a,onCreate:i,isCreating:s,isCreateButtonDisabled:o}){const{t:l}=kt();y.useEffect(()=>{const d=u=>{u.key==="Escape"&&a()};return window.addEventListener("keydown",d),()=>window.removeEventListener("keydown",d)},[a]);const c=d=>{e({...t,group_ids:t.group_ids.includes(d)?t.group_ids.filter(u=>u!==d):[...t.group_ids,d]})};return r.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",onClick:a,children:r.jsxs(Ct,{className:"w-full max-w-md",onClick:d=>d.stopPropagation(),children:[r.jsx(pn,{children:r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{className:"flex flex-col gap-1",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(gm,{className:"w-5 h-5 text-bambu-green"}),r.jsx("h2",{className:"text-lg font-semibold text-white",children:l("users.modal.createUser")})]}),r.jsx("p",{className:"text-sm text-bambu-gray ml-7",children:l("users.modal.advancedAuthSubtitle")||"with Advanced Authentication"})]}),r.jsx(Me,{variant:"ghost",size:"sm",onClick:a,children:r.jsx(Ht,{className:"w-5 h-5"})})]})}),r.jsxs(At,{children:[r.jsxs("div",{className:"space-y-4",children:[r.jsxs("div",{children:[r.jsxs("label",{className:"block text-sm font-medium text-white mb-2",children:[l("users.form.username")," ",r.jsx("span",{className:"text-red-400",children:"*"})]}),r.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})]}),r.jsxs("div",{children:[r.jsxs("label",{className:"block text-sm font-medium text-white mb-2",children:[l("users.form.email")||"Email"," ",r.jsx("span",{className:"text-red-400",children:"*"})]}),r.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})]}),r.jsx("div",{className:"bg-bambu-dark-secondary/50 border border-bambu-green/20 rounded-lg p-3",children:r.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."})}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:l("users.form.groups")}),r.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=>r.jsxs("label",{className:"flex items-center gap-3 px-2 py-1.5 rounded hover:bg-bambu-dark-tertiary cursor-pointer",children:[r.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"}),r.jsx("span",{className:"text-sm text-white",children:d.name}),d.is_system&&r.jsxs("span",{className:"text-xs text-yellow-400",children:["(",l("users.system"),")"]})]},d.id)),n.length===0&&r.jsx("p",{className:"text-sm text-bambu-gray",children:l("users.noGroupsAvailable")})]})]})]}),r.jsxs("div",{className:"mt-6 flex justify-end gap-3",children:[r.jsx(Me,{variant:"secondary",onClick:a,children:l("users.modal.cancel")}),r.jsx(Me,{onClick:i,disabled:o,children:s?r.jsxs(r.Fragment,{children:[r.jsx(pt,{className:"w-4 h-4 animate-spin"}),l("users.modal.creating")]}):r.jsxs(r.Fragment,{children:[r.jsx(ar,{className:"w-4 h-4"}),l("users.modal.createUser")]})})]})]})]})})}function Lrt(){const{t}=kt(),e=en(),{showToast:n}=rn(),[a,i]=y.useState(!1),[s,o]=y.useState(""),[l,c]=y.useState("auto"),[d,u]=y.useState(!1),[m,p]=y.useState(!0),[f,b]=y.useState("all"),[w,g]=y.useState(!1),[x,_]=y.useState(!1),[N,C]=y.useState(!1),[P,T]=y.useState(!1),{data:A,isLoading:F}=Ve({queryKey:["spoolman-settings"],queryFn:se.getSpoolmanSettings}),{data:S,isLoading:E,refetch:U}=Ve({queryKey:["spoolman-status"],queryFn:se.getSpoolmanStatus,refetchInterval:3e4}),{data:I}=Ve({queryKey:["printers"],queryFn:se.getPrinters});y.useEffect(()=>{A&&(i(A.spoolman_enabled==="true"),o(A.spoolman_url||""),c(A.spoolman_sync_mode||"auto"),u(A.spoolman_disable_weight_sync==="true"),p(A.spoolman_report_partial_usage!=="false"),g(!0))},[A]),y.useEffect(()=>{if(!w||!A)return;if(A.spoolman_enabled==="true"!==a||(A.spoolman_url||"")!==s||(A.spoolman_sync_mode||"auto")!==l||A.spoolman_disable_weight_sync==="true"!==d||A.spoolman_report_partial_usage!=="false"!==m){const Ce=setTimeout(()=>{H.mutate()},500);return()=>clearTimeout(Ce)}},[a,s,l,d,m,w]);const H=it({mutationFn:()=>se.updateSpoolmanSettings({spoolman_enabled:a?"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"]}),e.invalidateQueries({queryKey:["settings"]}),e.invalidateQueries({queryKey:["spoolman-inventory-filaments"]}),n(t("settings.toast.settingsSaved"))},onError:()=>{n(t("settings.toast.saveFailed"),"error")}}),R=it({mutationFn:se.connectSpoolman,onSuccess:()=>{U()},onError:()=>{n(t("settings.toast.saveFailed"),"error")}}),Q=it({mutationFn:se.disconnectSpoolman,onSuccess:()=>{U()},onError:()=>{n(t("settings.toast.saveFailed"),"error")}}),re=it({mutationFn:se.syncAllPrintersAms,onSuccess:be=>{n(t("settings.spoolmanAmsSyncSuccess",{synced:be.synced_count,skipped:0}),"success")},onError:()=>{n(t("settings.toast.saveFailed"),"error")}}),J=it({mutationFn:be=>se.syncPrinterAms(be),onSuccess:be=>{n(t("settings.spoolmanAmsSyncSuccess",{synced:be.synced_count,skipped:0}),"success")},onError:()=>{n(t("settings.toast.saveFailed"),"error")}}),de=()=>{f==="all"?re.mutate():J.mutate(f)},pe=it({mutationFn:se.syncWeightsFromAms,onSuccess:be=>{e.invalidateQueries({queryKey:["spools"]}),e.invalidateQueries({queryKey:["inventory-spools"]}),n(t("settings.amsSyncSuccess",{synced:be.synced,skipped:be.skipped}),"success"),C(!1)},onError:()=>{n(t("settings.amsSyncError"),"error"),C(!1)}}),ue=it({mutationFn:se.syncSpoolmanAmsWeights,onSuccess:be=>{e.invalidateQueries({queryKey:["spoolman-inventory-spools"]}),n(t("settings.spoolmanAmsSyncSuccess",{synced:be.synced,skipped:be.skipped}),"success"),T(!1)},onError:be=>{be instanceof _i&&be.status===503?n(t("settings.spoolmanAmsSyncErrorUnreachable"),"error"):be instanceof _i&&be.status===400?n(t("settings.spoolmanAmsSyncErrorNotConfigured"),"error"):n(t("settings.spoolmanAmsSyncError"),"error"),T(!1)}}),X=re.isPending||J.isPending,ae=f==="all"?re.data:J.data,me=f==="all"?re.isSuccess:J.isSuccess;return F?r.jsxs(Ct,{id:"card-spoolman",children:[r.jsx(pn,{children:r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(hc,{className:"w-5 h-5 text-bambu-green"}),r.jsx("h2",{className:"text-lg font-semibold text-white",children:t("settings.filamentTracking")})]})}),r.jsx(At,{children:r.jsx("div",{className:"flex justify-center py-8",children:r.jsx(pt,{className:"w-6 h-6 text-bambu-green animate-spin"})})})]}):r.jsxs(Ct,{id:"card-spoolman",children:[r.jsx(pn,{children:r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(hc,{className:"w-5 h-5 text-bambu-green"}),r.jsx("h2",{className:"text-lg font-semibold text-white",children:t("settings.filamentTracking")})]}),H.isPending&&r.jsx(pt,{className:"w-4 h-4 text-bambu-green animate-spin"})]})}),r.jsxs(At,{className:"space-y-4",children:[r.jsx("p",{className:"text-sm text-bambu-gray",children:t("settings.filamentTrackingDesc")}),r.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[r.jsxs("button",{type:"button",onClick:()=>i(!1),className:`p-3 rounded-lg border-2 text-left transition-colors ${a?"border-bambu-dark-tertiary bg-bambu-dark hover:border-bambu-gray/50":"border-bambu-green bg-bambu-green/10"}`,children:[r.jsxs("div",{className:"flex items-center gap-2 mb-1.5",children:[r.jsx(Br,{className:`w-4 h-4 ${a?"text-bambu-gray":"text-bambu-green"}`}),r.jsx("span",{className:`text-sm font-medium ${a?"text-bambu-gray":"text-white"}`,children:t("settings.trackingModeBuiltIn")})]}),r.jsx("p",{className:`text-xs ${a?"text-bambu-gray/60":"text-bambu-gray"}`,children:t("settings.trackingModeBuiltInDesc")}),!a&&r.jsxs("div",{className:"flex items-center gap-1 mt-2",children:[r.jsx(_r,{className:"w-3 h-3 text-bambu-green"}),r.jsx("span",{className:"text-xs text-bambu-green",children:t("common.enabled")})]})]}),r.jsxs("button",{type:"button",onClick:()=>i(!0),className:`p-3 rounded-lg border-2 text-left transition-colors ${a?"border-bambu-green bg-bambu-green/10":"border-bambu-dark-tertiary bg-bambu-dark hover:border-bambu-gray/50"}`,children:[r.jsxs("div",{className:"flex items-center gap-2 mb-1.5",children:[r.jsx(Rr,{className:`w-4 h-4 ${a?"text-bambu-green":"text-bambu-gray"}`}),r.jsx("span",{className:`text-sm font-medium ${a?"text-white":"text-bambu-gray"}`,children:"Spoolman"})]}),r.jsx("p",{className:`text-xs ${a?"text-bambu-gray":"text-bambu-gray/60"}`,children:t("settings.trackingModeSpoolmanDesc")}),a&&r.jsxs("div",{className:"flex items-center gap-1 mt-2",children:[r.jsx(_r,{className:"w-3 h-3 text-bambu-green"}),r.jsx("span",{className:"text-xs text-bambu-green",children:t("common.enabled")})]})]})]}),!a&&r.jsxs("div",{className:"space-y-3",children:[r.jsx("div",{className:"p-3 bg-bambu-green/5 border border-bambu-green/20 rounded-lg",children:r.jsxs("div",{className:"flex gap-2",children:[r.jsx(Ci,{className:"w-4 h-4 text-bambu-green flex-shrink-0 mt-0.5"}),r.jsx("div",{className:"text-xs text-bambu-gray",children:r.jsxs("ul",{className:"list-disc list-inside space-y-0.5",children:[r.jsx("li",{children:t("settings.builtInFeatureRfid")}),r.jsx("li",{children:t("settings.builtInFeatureUsage")}),r.jsx("li",{children:t("settings.builtInFeatureCatalog")}),r.jsx("li",{children:t("settings.builtInFeatureThirdParty")})]})})]})}),r.jsxs(Me,{variant:"secondary",size:"sm",onClick:()=>C(!0),disabled:pe.isPending,children:[pe.isPending?r.jsx(pt,{className:"w-4 h-4 mr-2 animate-spin"}):r.jsx(sr,{className:"w-4 h-4 mr-2"}),t("settings.amsSyncButton")]})]}),a&&r.jsxs("div",{className:"space-y-4",children:[r.jsx("div",{className:"p-3 bg-blue-500/10 border border-blue-500/30 rounded-lg",children:r.jsxs("div",{className:"flex gap-2",children:[r.jsx(Ci,{className:"w-4 h-4 text-blue-400 flex-shrink-0 mt-0.5"}),r.jsxs("div",{className:"text-xs text-blue-300",children:[r.jsx("p",{className:"font-medium mb-1",children:t("settings.howSyncWorks")}),r.jsxs("ul",{className:"list-disc list-inside space-y-0.5 text-blue-300/80",children:[r.jsx("li",{children:t("settings.syncInfoRfidOnly")}),r.jsx("li",{children:t("settings.syncInfoAutoCreate")}),r.jsx("li",{children:t("settings.syncInfoThirdPartySkipped")})]}),r.jsx("p",{className:"font-medium mt-2 mb-1",children:t("settings.linkingExistingSpools")}),r.jsx("p",{className:"text-blue-300/80",children:t("settings.linkingExistingSpoolsDesc")})]})]})}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:t("settings.spoolmanUrl")}),r.jsx("input",{type:"text",placeholder:"http://192.168.1.100:7912",value:s,onChange:be=>o(be.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"}),r.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:t("settings.spoolmanUrlHint")})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:t("settings.syncMode")}),r.jsxs("select",{value:l,onChange:be=>c(be.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:[r.jsx("option",{value:"auto",children:t("settings.syncModeAuto")}),r.jsx("option",{value:"manual",children:t("settings.syncModeManual")})]}),r.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:t(l==="auto"?"settings.syncModeAutoDesc":"settings.syncModeManualDesc")})]}),l==="auto"&&r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-white",children:t("spoolman.disableWeightSync")}),r.jsx("p",{className:"text-sm text-bambu-gray",children:t("spoolman.disableWeightSyncDesc")})]}),r.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:d,onChange:be=>u(be.target.checked),className:"sr-only peer"}),r.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&&r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-white",children:t("spoolman.reportPartialUsage")}),r.jsx("p",{className:"text-sm text-bambu-gray",children:t("spoolman.reportPartialUsageDesc")})]}),r.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:m,onChange:be=>p(be.target.checked),className:"sr-only peer"}),r.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"})]})]}),r.jsxs("div",{className:"pt-2 border-t border-bambu-dark-tertiary",children:[r.jsxs("div",{className:"flex items-center justify-between mb-3",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsxs("span",{className:"text-sm text-bambu-gray",children:[t("settings.status"),":"]}),E?r.jsx(pt,{className:"w-4 h-4 text-bambu-gray animate-spin"}):S?.connected?r.jsxs("span",{className:"flex items-center gap-1 text-sm text-green-500",children:[r.jsx(_r,{className:"w-4 h-4"}),t("settings.spoolmanConnected")]}):r.jsxs("span",{className:"flex items-center gap-1 text-sm text-red-500",children:[r.jsx(Ht,{className:"w-4 h-4"}),t("settings.spoolmanDisconnected")]})]}),r.jsx("div",{className:"flex gap-2",children:S?.connected?r.jsxs(Me,{variant:"secondary",size:"sm",onClick:()=>Q.mutate(),disabled:Q.isPending,children:[Q.isPending?r.jsx(pt,{className:"w-4 h-4 animate-spin"}):r.jsx(Qbe,{className:"w-4 h-4"}),t("settings.disconnect")]}):r.jsxs(Me,{size:"sm",onClick:()=>R.mutate(),disabled:R.isPending||!s,children:[R.isPending?r.jsx(pt,{className:"w-4 h-4 animate-spin"}):r.jsx(Th,{className:"w-4 h-4"}),t("settings.connect")]})})]}),(R.isError||Q.isError)&&r.jsx("div",{className:"mb-3 p-2 bg-red-500/20 border border-red-500/50 rounded text-sm text-red-400",children:(R.error||Q.error).message}),S?.connected&&r.jsxs("div",{className:"space-y-3",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-sm text-white",children:t("settings.syncAmsData")}),r.jsx("p",{className:"text-xs text-bambu-gray",children:t("settings.syncAmsDataDesc")})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsxs("div",{className:"relative flex-1",children:[r.jsxs("select",{value:f,onChange:be=>b(be.target.value==="all"?"all":Number(be.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:[r.jsx("option",{value:"all",children:t("settings.allPrinters")}),I?.map(be=>r.jsx("option",{value:be.id,children:be.name},be.id))]}),r.jsx(Ln,{className:"absolute right-2 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}),r.jsxs(Me,{variant:"secondary",size:"sm",onClick:de,disabled:X,children:[X?r.jsx(pt,{className:"w-4 h-4 animate-spin"}):r.jsx(sr,{className:"w-4 h-4"}),t("spoolman.sync")]})]})]}),S?.connected&&r.jsx("div",{className:"mt-4 pt-4 border-t border-bambu-dark-tertiary",children:r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-sm text-white",children:t("settings.spoolmanAmsSyncButton")}),r.jsx("p",{className:"text-xs text-bambu-gray",children:t("settings.spoolmanAmsSyncMessage")})]}),r.jsxs(Me,{variant:"secondary",size:"sm",onClick:()=>T(!0),disabled:ue.isPending,children:[ue.isPending?r.jsx(pt,{className:"w-4 h-4 animate-spin"}):r.jsx(sr,{className:"w-4 h-4"}),ue.isPending?t("settings.spoolmanAmsSyncing"):t("settings.spoolmanAmsSyncButton")]})]})}),me&&ae&&r.jsxs("div",{className:"mt-3 space-y-2",children:[r.jsx("div",{className:`p-2 rounded text-sm ${ae.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:ae.success?`Synced ${ae.synced_count} spool${ae.synced_count!==1?"s":""} successfully`:`Synced ${ae.synced_count} spool${ae.synced_count!==1?"s":""} with ${ae.errors.length} error${ae.errors.length!==1?"s":""}`}),ae.skipped_count>0&&r.jsxs("div",{className:"p-2 bg-amber-500/10 border border-amber-500/30 rounded text-sm",children:[r.jsxs("div",{className:"flex items-center justify-between text-amber-400 mb-1",children:[r.jsxs("div",{className:"flex items-center gap-1.5",children:[r.jsx(Nn,{className:"w-3.5 h-3.5"}),r.jsxs("span",{className:"font-medium",children:[ae.skipped_count," spool",ae.skipped_count!==1?"s":""," skipped"]})]}),ae.skipped_count>5&&r.jsx("button",{onClick:()=>_(!x),className:"text-xs text-amber-400 hover:text-amber-300 underline",children:x?"Show less":"Show all"})]}),r.jsxs("ul",{className:"text-xs text-amber-300/80 space-y-0.5",children:[(x?ae.skipped:ae.skipped.slice(0,5)).map((be,Ce)=>r.jsxs("li",{className:"flex items-center gap-2",children:[be.color&&r.jsx("span",{className:"w-3 h-3 rounded-full border border-black/20",style:{backgroundColor:`#${be.color}`}}),r.jsx("span",{children:be.location}),r.jsxs("span",{className:"text-amber-300/60",children:["- ",be.reason]})]},Ce)),!x&&ae.skipped_count>5&&r.jsxs("li",{className:"text-amber-300/60 italic",children:["...and ",ae.skipped_count-5," more"]})]})]}),ae.errors.length>0&&r.jsxs("div",{className:"p-2 bg-red-500/10 border border-red-500/30 rounded text-sm",children:[r.jsx("div",{className:"text-red-400 font-medium mb-1",children:"Errors:"}),r.jsx("ul",{className:"text-xs text-red-300/80 space-y-0.5",children:ae.errors.map((be,Ce)=>r.jsx("li",{children:be},Ce))})]})]})]})]})]}),N&&r.jsx(vn,{title:t("settings.amsSyncTitle"),message:t("settings.amsSyncMessage"),confirmText:t("settings.amsSyncButton"),variant:"warning",isLoading:pe.isPending,loadingText:t("settings.amsSyncing"),onConfirm:()=>pe.mutate(),onCancel:()=>C(!1)}),P&&r.jsx(vn,{title:t("settings.spoolmanAmsSyncTitle"),message:t("settings.spoolmanAmsSyncMessage"),confirmText:t("settings.spoolmanAmsSyncButton"),variant:"warning",isLoading:ue.isPending,loadingText:t("settings.spoolmanAmsSyncing"),onConfirm:()=>ue.mutate(),onCancel:()=>T(!1)})]})}function Rrt({isOpen:t,filamentName:e,oldWeight:n,newWeight:a,onConfirm:i,onClose:s}){const{t:o}=kt(),[l,c]=y.useState(!1);if(y.useEffect(()=>{t&&c(!1)},[t]),!t)return null;const d=n!==null?`${n}g`:"—",u=`${a}g`;return r.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",onClick:s,children:r.jsx(Ct,{className:"w-full max-w-md",onClick:m=>m.stopPropagation(),children:r.jsxs(At,{className:"p-6",children:[r.jsx("h3",{className:"text-lg font-semibold text-white mb-1",children:o("settings.catalog.updateSpoolWeight")}),r.jsxs("p",{className:"text-bambu-gray text-sm mb-4",children:[e,": ",d," → ",u]}),r.jsxs("div",{className:"space-y-3",children:[r.jsxs("label",{className:"flex items-start gap-3 cursor-pointer p-3 rounded-lg border border-bambu-dark-tertiary hover:bg-bambu-dark transition-colors",children:[r.jsx("input",{type:"radio",name:"weight-update-mode",checked:!l,onChange:()=>c(!1),className:"mt-1 accent-bambu-green"}),r.jsxs("div",{children:[r.jsx("div",{className:"text-sm font-medium text-white",children:o("settings.catalog.applyToAllSpools")}),r.jsx("div",{className:"text-xs text-bambu-gray mt-0.5",children:o("settings.catalog.applyToAllSpoolsDesc")})]})]}),r.jsxs("label",{className:"flex items-start gap-3 cursor-pointer p-3 rounded-lg border border-bambu-dark-tertiary hover:bg-bambu-dark transition-colors",children:[r.jsx("input",{type:"radio",name:"weight-update-mode",checked:l,onChange:()=>c(!0),className:"mt-1 accent-bambu-green"}),r.jsxs("div",{children:[r.jsx("div",{className:"text-sm font-medium text-white",children:o("settings.catalog.keepExistingSpoolWeight")}),r.jsx("div",{className:"text-xs text-bambu-gray mt-0.5",children:o("settings.catalog.keepExistingSpoolWeightDesc")})]})]})]}),r.jsxs("div",{className:"flex gap-3 mt-6",children:[r.jsx(Me,{variant:"secondary",onClick:s,className:"flex-1",children:o("common.cancel")}),r.jsx(Me,{onClick:()=>i(l),className:"flex-1 bg-bambu-green hover:bg-bambu-green-dark",children:o("common.confirm")})]})]})})})}function Irt(){const{t}=kt(),{showToast:e}=rn(),n=en(),[a,i]=y.useState([]),[s,o]=y.useState(!0),[l,c]=y.useState(""),d=y.useRef(null),[u,m]=y.useState(null),[p,f]=y.useState(""),[b,w]=y.useState(""),[g,x]=y.useState(null),[_,N]=y.useState(!1),[C,P]=y.useState(null),[T,A]=y.useState(""),[F,S]=y.useState(""),[E,U]=y.useState(!1),[I,H]=y.useState(new Set),[R,Q]=y.useState(!1),[re,J]=y.useState(null),[de,pe]=y.useState(!1),{data:ue,isLoading:X,error:ae}=Ve({queryKey:["spoolman-inventory-filaments"],queryFn:()=>se.getSpoolmanInventoryFilaments(),retry:!1,staleTime:6e4}),me=!X&&ae instanceof _i&&ae.status===400,be=!X&&!me,Ce=it({mutationFn:({filamentId:le,data:q})=>se.patchSpoolmanFilament(le,q),onSuccess:()=>{n.invalidateQueries({queryKey:["spoolman-inventory-filaments"]}),e(t("settings.catalog.filamentUpdated"),"success"),m(null),f(""),w(""),x(null)},onError:le=>{le instanceof _i&&le.status===503?e(t("inventory.spoolmanUnreachable"),"error"):le instanceof _i&&le.status===422?e(t("settings.catalog.filamentUpdateInvalid"),"error"):e(t("settings.catalog.filamentUpdateFailed"),"error")}}),$=le=>{const q=p.trim()!==le.name,L=b!==""&&b!==String(le.spool_weight??""),ne=b!==""?parseFloat(b):null;if(L&&ne!==null&&!isNaN(ne)&&ne>0)x({filamentId:le.id,name:q?p.trim():le.name,oldWeight:le.spool_weight,newWeight:ne});else{const ye={};q&&p.trim()&&(ye.name=p.trim()),Object.keys(ye).length>0?Ce.mutate({filamentId:le.id,data:ye}):m(null)}},W=le=>{if(!g)return;const{filamentId:q,name:L,newWeight:ne}=g,ye=ue?.find(ve=>ve.id===q),we=ye&&L!==ye.name,Ne={spool_weight:ne,keep_existing_spools:le};we&&(Ne.name=L),Ce.mutate({filamentId:q,data:Ne})},D=y.useCallback(async()=>{try{const le=await se.getSpoolCatalog();i(le)}catch(le){console.error("SpoolCatalogSettings.loadCatalog failed:",le),e(t("settings.catalog.loadFailed"),"error")}finally{o(!1)}},[e,t]);y.useEffect(()=>{D()},[D]);const j=a.filter(le=>le.name.toLowerCase().includes(l.toLowerCase())),B=(ue??[]).filter(le=>le.name.toLowerCase().includes(l.toLowerCase())||(le.vendor?.name??"").toLowerCase().includes(l.toLowerCase())),Y=async()=>{if(!T.trim()||!F){e(t("settings.catalog.nameWeightRequired"),"error");return}U(!0);try{const le=await se.addCatalogEntry({name:T.trim(),weight:parseInt(F)});i(q=>[...q,le].sort((L,ne)=>L.name.localeCompare(ne.name))),N(!1),A(""),S(""),e(t("settings.catalog.entryAdded"),"success")}catch(le){console.error("SpoolCatalogSettings.handleAdd failed:",le),e(t("settings.catalog.addFailed"),"error")}finally{U(!1)}},O=le=>{P(le.id),A(le.name),S(le.weight.toString())},ie=()=>{P(null),A(""),S("")},z=async le=>{if(!T.trim()||!F){e(t("settings.catalog.nameWeightRequired"),"error");return}U(!0);try{const q=await se.updateCatalogEntry(le,{name:T.trim(),weight:parseInt(F)});i(L=>L.map(ne=>ne.id===le?q:ne).sort((ne,ye)=>ne.name.localeCompare(ye.name))),P(null),A(""),S(""),e(t("settings.catalog.entryUpdated"),"success")}catch(q){console.error("SpoolCatalogSettings.handleUpdate failed:",q),e(t("settings.catalog.updateFailed"),"error")}finally{U(!1)}},G=async()=>{if(re)try{await se.deleteCatalogEntry(re.id),i(le=>le.filter(q=>q.id!==re.id)),e(t("settings.catalog.entryDeleted"),"success")}catch(le){console.error("SpoolCatalogSettings.handleDelete failed:",le),e(t("settings.catalog.deleteFailed"),"error")}finally{J(null)}},K=async()=>{pe(!1),o(!0);try{await se.resetSpoolCatalog(),await D(),e(t("settings.catalog.resetSuccess"),"success")}catch(le){console.error("SpoolCatalogSettings.handleReset failed:",le),e(t("settings.catalog.resetFailed"),"error"),o(!1)}},Z=le=>{H(q=>{const L=new Set(q);return L.has(le)?L.delete(le):L.add(le),L})},oe=()=>{I.size===j.length?H(new Set):H(new Set(j.map(le=>le.id)))},ee=async()=>{if(Q(!1),I.size!==0)try{const le=await se.bulkDeleteCatalogEntries([...I]);i(q=>q.filter(L=>!I.has(L.id))),H(new Set),e(t("settings.catalog.bulkDeleted",{count:le.deleted}),"success")}catch(le){console.error("SpoolCatalogSettings.handleBulkDelete failed:",le),e(t("settings.catalog.bulkDeleteFailed"),"error")}},ge=()=>{const le=a.map(({name:ye,weight:we})=>({name:ye,weight:we})),q=new Blob([JSON.stringify(le,null,2)],{type:"application/json"}),L=URL.createObjectURL(q),ne=document.createElement("a");ne.href=L,ne.download="spool-catalog.json",document.body.appendChild(ne),ne.click(),document.body.removeChild(ne),URL.revokeObjectURL(L),e(t("settings.catalog.exported",{count:a.length}),"success")},ce=async le=>{const q=le.target.files?.[0];if(q){try{const L=await q.text(),ne=JSON.parse(L);if(!Array.isArray(ne))throw new Error("Invalid format");let ye=0,we=0;for(const Ne of ne){if(!Ne.name||typeof Ne.weight!="number"){we++;continue}if(a.some(xe=>xe.name.toLowerCase()===Ne.name.toLowerCase())){we++;continue}try{const xe=await se.addCatalogEntry({name:Ne.name,weight:Ne.weight});i(Ee=>[...Ee,xe].sort((ze,_e)=>ze.name.localeCompare(_e.name))),ye++}catch(xe){console.error("SpoolCatalogSettings import item failed:",xe),we++}}e(t("settings.catalog.imported",{added:ye,skipped:we}),"success")}catch(L){console.error("SpoolCatalogSettings.handleImport failed:",L),e(t("settings.catalog.importFailed"),"error")}d.current&&(d.current.value="")}};return r.jsxs(Ct,{id:"card-spool-catalog",children:[r.jsxs(pn,{children:[r.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[r.jsx(hc,{className:"w-5 h-5 text-bambu-gray"}),r.jsx("h2",{className:"text-lg font-semibold text-white",children:t(be?"settings.spoolmanFilamentCatalogTitle":"settings.catalog.spoolCatalog")}),r.jsxs("span",{className:"text-sm text-bambu-gray",children:["(",X?"…":be?ue?.length??0:a.length,")"]})]}),!be&&!X&&r.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[r.jsxs("button",{onClick:ge,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:[r.jsx(Yr,{className:"w-4 h-4"}),r.jsx("span",{className:"hidden sm:inline",children:t("common.export")})]}),r.jsxs("button",{onClick:()=>d.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:[r.jsx(ka,{className:"w-4 h-4"}),r.jsx("span",{className:"hidden sm:inline",children:t("common.import")})]}),r.jsx("input",{ref:d,type:"file",accept:".json",className:"hidden",onChange:ce}),r.jsxs("button",{onClick:()=>pe(!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:[r.jsx(gs,{className:"w-4 h-4"}),r.jsx("span",{className:"hidden sm:inline",children:t("common.reset")})]}),r.jsxs("button",{onClick:()=>N(!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:[r.jsx(ar,{className:"w-4 h-4"}),r.jsx("span",{className:"hidden sm:inline",children:t("common.add")})]})]}),!be&&I.size>0&&r.jsxs("div",{className:"flex items-center gap-2 mt-2 px-3 py-2 bg-red-500/10 border border-red-500/30 rounded-lg",children:[r.jsx("span",{className:"text-sm text-red-400",children:t("settings.catalog.selectedCount",{count:I.size})}),r.jsxs("button",{onClick:()=>Q(!0),className:"ml-auto px-3 py-1.5 text-sm bg-red-500 text-white rounded-lg hover:bg-red-600 transition-colors flex items-center gap-1.5",children:[r.jsx(Jt,{className:"w-4 h-4"}),t("settings.catalog.deleteSelected")]}),r.jsx("button",{onClick:()=>H(new Set),className:"px-3 py-1.5 text-sm text-bambu-gray hover:text-white transition-colors",children:t("common.cancel")})]})]}),r.jsxs(At,{className:"space-y-4",children:[r.jsx("p",{className:"text-sm text-bambu-gray",children:t(be?"settings.spoolmanFilamentCatalogDesc":"settings.catalog.spoolCatalogDescription")}),r.jsxs("div",{className:"relative",children:[r.jsx(Sr,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray"}),r.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:l,onChange:le=>c(le.target.value)})]}),X&&r.jsxs("div",{className:"flex items-center justify-center py-8 text-bambu-gray",children:[r.jsx(pt,{className:"w-5 h-5 animate-spin mr-2"}),t("common.loading")]}),!X&&!be&&r.jsxs(r.Fragment,{children:[_&&r.jsxs("div",{className:"p-4 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary",children:[r.jsx("h3",{className:"text-sm font-medium text-white mb-3",children:t("settings.catalog.addNewEntry")}),r.jsxs("div",{className:"flex gap-2 items-center",children:[r.jsx("div",{className:"flex-1 min-w-0",children:r.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:T,onChange:le=>A(le.target.value)})}),r.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:F,onChange:le=>S(le.target.value)}),r.jsx("span",{className:"text-bambu-gray shrink-0",children:"g"}),r.jsxs("button",{onClick:Y,disabled:E,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:[E?r.jsx(pt,{className:"w-4 h-4 animate-spin"}):r.jsx(_r,{className:"w-4 h-4"}),t("common.add")]}),r.jsx("button",{onClick:()=>{N(!1),A(""),S("")},className:"p-2 rounded-lg text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary",children:r.jsx(Ht,{className:"w-4 h-4"})})]})]}),s?r.jsxs("div",{className:"flex items-center justify-center py-8 text-bambu-gray",children:[r.jsx(pt,{className:"w-5 h-5 animate-spin mr-2"}),t("common.loading")]}):r.jsx("div",{className:"max-h-[600px] overflow-y-auto border border-bambu-dark-tertiary rounded-lg",children:r.jsxs("table",{className:"w-full text-sm",children:[r.jsx("thead",{className:"bg-bambu-dark sticky top-0",children:r.jsxs("tr",{children:[r.jsx("th",{className:"px-2 py-2 w-10",children:r.jsx("input",{type:"checkbox",checked:j.length>0&&I.size===j.length,onChange:oe,className:"w-4 h-4 accent-bambu-green cursor-pointer"})}),r.jsx("th",{className:"px-4 py-2 text-left text-bambu-gray font-medium",children:t("common.name")}),r.jsx("th",{className:"px-4 py-2 text-right text-bambu-gray font-medium w-24",children:t("settings.catalog.weight")}),r.jsx("th",{className:"px-4 py-2 text-center text-bambu-gray font-medium w-20",children:t("settings.catalog.type")}),r.jsx("th",{className:"px-4 py-2 w-24"})]})}),r.jsx("tbody",{children:j.length===0?r.jsx("tr",{children:r.jsx("td",{colSpan:5,className:"px-4 py-8 text-center text-bambu-gray",children:t(l?"settings.catalog.noMatch":"settings.catalog.empty")})}):j.map(le=>r.jsx("tr",{className:`border-t border-bambu-dark-tertiary hover:bg-bambu-dark ${I.has(le.id)?"bg-bambu-dark":""}`,children:C===le.id?r.jsxs(r.Fragment,{children:[r.jsx("td",{className:"px-2 py-2",children:r.jsx("input",{type:"checkbox",checked:I.has(le.id),onChange:()=>Z(le.id),className:"w-4 h-4 accent-bambu-green cursor-pointer"})}),r.jsx("td",{className:"px-4 py-2",children:r.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:T,onChange:q=>A(q.target.value)})}),r.jsx("td",{className:"px-4 py-2",children:r.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:F,onChange:q=>S(q.target.value)})}),r.jsx("td",{className:"px-4 py-2 text-center",children:r.jsx("span",{className:"text-xs text-bambu-gray",children:"-"})}),r.jsx("td",{className:"px-4 py-2",children:r.jsxs("div",{className:"flex justify-end gap-1",children:[r.jsx("button",{onClick:()=>z(le.id),disabled:E,className:"p-1.5 rounded hover:bg-green-500/20 text-green-500",children:E?r.jsx(pt,{className:"w-4 h-4 animate-spin"}):r.jsx(_r,{className:"w-4 h-4"})}),r.jsx("button",{onClick:ie,className:"p-1.5 rounded hover:bg-bambu-dark-tertiary text-bambu-gray",children:r.jsx(Ht,{className:"w-4 h-4"})})]})})]}):r.jsxs(r.Fragment,{children:[r.jsx("td",{className:"px-2 py-2",children:r.jsx("input",{type:"checkbox",checked:I.has(le.id),onChange:()=>Z(le.id),className:"w-4 h-4 accent-bambu-green cursor-pointer"})}),r.jsx("td",{className:"px-4 py-2 text-white",children:le.name}),r.jsxs("td",{className:"px-4 py-2 text-right font-mono text-white",children:[le.weight,"g"]}),r.jsx("td",{className:"px-4 py-2 text-center",children:le.is_default?r.jsx("span",{className:"text-xs px-2 py-0.5 rounded bg-bambu-dark-tertiary text-bambu-gray",children:t("settings.catalog.default")}):r.jsx("span",{className:"text-xs px-2 py-0.5 rounded bg-bambu-green/20 text-bambu-green",children:t("settings.catalog.custom")})}),r.jsx("td",{className:"px-4 py-2",children:r.jsxs("div",{className:"flex justify-end gap-1",children:[r.jsx("button",{onClick:()=>O(le),className:"p-1.5 rounded hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white",children:r.jsx(oi,{className:"w-4 h-4"})}),r.jsx("button",{onClick:()=>J(le),className:"p-1.5 rounded bg-red-500/10 hover:bg-red-500/20 text-red-500",children:r.jsx(Jt,{className:"w-4 h-4"})})]})})]})},le.id))})]})})]}),!X&&be&&r.jsx("div",{className:"max-h-[600px] overflow-y-auto border border-bambu-dark-tertiary rounded-lg",children:ae?r.jsx("p",{className:"px-4 py-8 text-center text-sm text-red-400",children:t("inventory.spoolmanCatalogLoadFailed")}):B.length===0?r.jsx("p",{className:"px-4 py-8 text-center text-sm text-bambu-gray",children:t("inventory.noSpoolmanFilaments")}):r.jsxs("table",{className:"w-full text-sm",children:[r.jsx("thead",{className:"bg-bambu-dark sticky top-0",children:r.jsxs("tr",{children:[r.jsx("th",{className:"px-3 py-2 w-8"}),r.jsx("th",{className:"px-4 py-2 text-left text-bambu-gray font-medium",children:t("common.name")}),r.jsx("th",{className:"px-4 py-2 text-left text-bambu-gray font-medium w-28",children:t("settings.catalog.material")}),r.jsx("th",{className:"px-4 py-2 text-right text-bambu-gray font-medium w-24",children:t("settings.catalog.weight")}),r.jsx("th",{className:"px-4 py-2 text-right text-bambu-gray font-medium w-28",children:t("settings.catalog.spoolWeight")}),r.jsx("th",{className:"px-3 py-2 w-20"})]})}),r.jsx("tbody",{children:B.map(le=>{const q=u===le.id,L=Ce.isPending&&u===le.id;return r.jsxs("tr",{className:"border-t border-bambu-dark-tertiary hover:bg-bambu-dark",children:[r.jsx("td",{className:"px-3 py-2",children:r.jsx("span",{className:"w-4 h-4 rounded-full block shrink-0 border border-white/20",style:{backgroundColor:le.color_hex?`#${le.color_hex.replace("#","")}`:"#808080"},"aria-label":t("inventory.spoolmanFilamentColorSwatch")})}),r.jsx("td",{className:"px-4 py-2 text-white truncate max-w-0",children:q?r.jsx("input",{type:"text",value:p,onChange:ne=>f(ne.target.value),className:"w-full bg-bambu-dark-tertiary text-white rounded px-2 py-0.5 text-sm border border-bambu-dark-secondary focus:outline-none focus:border-bambu-green","aria-label":t("common.name")}):r.jsxs("span",{className:"block truncate",children:[le.vendor?.name?`${le.vendor.name} — `:"",le.name]})}),r.jsx("td",{className:"px-4 py-2 text-bambu-gray",children:le.material??"—"}),r.jsx("td",{className:"px-4 py-2 text-right font-mono text-white",children:le.weight?`${le.weight}g`:"—"}),r.jsx("td",{className:"px-4 py-2 text-right font-mono text-bambu-gray",children:q?r.jsx("input",{type:"number",value:b,onChange:ne=>w(ne.target.value),min:"0",step:"1",className:"w-20 bg-bambu-dark-tertiary text-white rounded px-2 py-0.5 text-sm border border-bambu-dark-secondary focus:outline-none focus:border-bambu-green text-right","aria-label":t("settings.catalog.spoolWeight")}):le.spool_weight!=null?`${le.spool_weight}g`:"—"}),r.jsx("td",{className:"px-3 py-2",children:q?r.jsxs("div",{className:"flex items-center gap-1 justify-end",children:[r.jsx("button",{onClick:()=>$(le),disabled:L||!p.trim()||b!==""&&(isNaN(parseFloat(b))||parseFloat(b)<=0),className:"p-1 text-bambu-green hover:text-white disabled:opacity-40 disabled:cursor-not-allowed","aria-label":t("common.save"),children:L?r.jsx(pt,{className:"w-4 h-4 animate-spin"}):r.jsx(_r,{className:"w-4 h-4"})}),r.jsx("button",{onClick:()=>{m(null),f(""),w("")},className:"p-1 text-bambu-gray hover:text-white","aria-label":t("common.cancel"),children:r.jsx(Ht,{className:"w-4 h-4"})})]}):r.jsx("button",{onClick:()=>{m(le.id),f(le.name),w(le.spool_weight!=null?String(le.spool_weight):"")},className:"p-1 text-bambu-gray hover:text-white","aria-label":t("common.edit"),children:r.jsx(oi,{className:"w-4 h-4"})})})]},le.id)})})]})})]}),!be&&re&&r.jsx(vn,{title:t("settings.catalog.deleteEntry"),message:t("settings.catalog.deleteConfirm",{name:re.name}),confirmText:t("common.delete"),variant:"danger",onConfirm:G,onCancel:()=>J(null)}),!be&&R&&r.jsx(vn,{title:t("settings.catalog.deleteSelected"),message:t("settings.catalog.bulkDeleteConfirm",{count:I.size}),confirmText:t("common.delete"),variant:"danger",onConfirm:ee,onCancel:()=>Q(!1)}),!be&&de&&r.jsx(vn,{title:t("settings.catalog.resetCatalog"),message:t("settings.catalog.resetConfirm"),confirmText:t("common.reset"),variant:"danger",onConfirm:K,onCancel:()=>pe(!1)}),r.jsx(Rrt,{isOpen:g!==null,filamentName:g?.name??"",oldWeight:g?.oldWeight??null,newWeight:g?.newWeight??0,onConfirm:W,onClose:()=>x(null)})]})}const Ort=2166136261,zrt=16777619;function Urt(...t){let e=Ort;const n=new TextEncoder,a=n.encode("__|");for(const i of t)typeof i=="string"?e=rQ(e,n.encode(i+"|")):i==null&&(e=rQ(e,a));return e>>>0}function rQ(t,e){for(const n of e)t^=n,t=Math.imul(t,zrt)>>>0;return t}function Brt(t){const e=()=>{t|=0,t=t+1831565813|0;let a=Math.imul(t^t>>>15,1|t);return a=a+Math.imul(a^a>>>7,61|a)^a,(a^a>>>14)>>>0},n=(a,i)=>{if(!Number.isFinite(a)||!Number.isFinite(i))throw new RangeError("from and to must be finite numbers");if(a>i)throw new RangeError("from must be less than or equal to to");return a===i?a:a+e()/4294967295*(i-a)};return{next:()=>e()/4294967295,floatBetween:(a,i)=>n(a,i),intBetween:(a,i)=>{if(!Number.isInteger(a)||!Number.isInteger(i))throw new RangeError("from and to must be integers");return Math.round(n(a,i))}}}const aQ={table:{dotCount:5,dotScale:1},preview:{dotCount:8,dotScale:1.5},card:{dotCount:40,dotScale:2},bar:{dotCount:20,dotScale:2},groupheader:{dotCount:80,dotScale:2}},WI=[{value:"",labelKey:"inventory.colorEffect.none"},{value:"sparkle",labelKey:"inventory.colorEffect.sparkle"},{value:"wood",labelKey:"inventory.colorEffect.wood"},{value:"marble",labelKey:"inventory.colorEffect.marble"},{value:"glow",labelKey:"inventory.colorEffect.glow"},{value:"matte",labelKey:"inventory.colorEffect.matte"},{value:"silk",labelKey:"inventory.colorEffect.silk"},{value:"galaxy",labelKey:"inventory.colorEffect.galaxy"},{value:"rainbow",labelKey:"inventory.colorEffect.rainbow"},{value:"metal",labelKey:"inventory.colorEffect.metal"},{value:"translucent",labelKey:"inventory.colorEffect.translucent"},{value:"gradient",labelKey:"inventory.colorEffect.gradient"},{value:"dual-color",labelKey:"inventory.colorEffect.dualColor"},{value:"tri-color",labelKey:"inventory.colorEffect.triColor"},{value:"multicolor",labelKey:"inventory.colorEffect.multicolor"}],Hrt="repeating-conic-gradient(#979797 0% 25%, #f5f5f5 0% 50%)",qrt="12px 12px",$rt={sparkle:(t=0,e="table")=>{const n=Brt(t),a=aQ[e]??aQ.table,i=[];for(let s=0;s"repeating-linear-gradient(90deg, rgba(0,0,0,0.18) 0 1px, transparent 1px 6px, rgba(0,0,0,0.08) 6px 7px, transparent 7px 12px)",marble:()=>"repeating-linear-gradient(135deg, rgba(255,255,255,0.18) 0 2px, transparent 2px 8px), repeating-linear-gradient(45deg, rgba(0,0,0,0.10) 0 1px, transparent 1px 7px)",glow:()=>"radial-gradient(circle at 50% 50%, rgba(255,255,255,0.35) 0%, rgba(255,255,255,0) 70%)",matte:()=>"linear-gradient(180deg, rgba(0,0,0,0.10) 0%, rgba(0,0,0,0) 50%, rgba(0,0,0,0.10) 100%)",silk:()=>"linear-gradient(110deg, rgba(255,255,255,0) 30%, rgba(255,255,255,0.30) 50%, rgba(255,255,255,0) 70%)",galaxy:()=>"linear-gradient(110deg, rgba(255,255,255,0) 25%, rgba(255,255,255,0.40) 50%, rgba(255,255,255,0) 75%)",metal:()=>"repeating-linear-gradient(90deg, rgba(255,255,255,0.10) 0 1px, transparent 1px 3px), linear-gradient(180deg, rgba(255,255,255,0.18) 0%, rgba(0,0,0,0.18) 100%)"};function Nce(t){const e=t.trim().replace(/^#/,"");return e.length!==6&&e.length!==8||!/^[0-9a-fA-F]+$/.test(e)?null:`#${e}`}function Cce(t){return t?t.split(",").map(e=>Nce(e)).filter(e=>!!e):[]}function Vrt(t,e,n,a){const i=t?Nce(t):null;if(e.length===0)return`linear-gradient(${i??"#808080"}, ${i??"#808080"})`;const s=e.length===1?[e[0],e[0]]:e,o=(n??"").toLowerCase(),l=(a??"").toLowerCase();if(o==="multicolor"||l==="multicolor"){const c=s.length;return`conic-gradient(from 0deg, ${s.map((u,m)=>{const p=(m/c*360).toFixed(3),f=((m+1)/c*360).toFixed(3);return`${u} ${p}deg ${f}deg`}).join(", ")})`}if(l==="dual-color"||l==="tri-color"){const c=s.length;return`linear-gradient(to right, ${s.map((u,m)=>{const p=(m/c*100).toFixed(3),f=((m+1)/c*100).toFixed(3);return`${u} ${p}% ${f}%`}).join(", ")})`}return`linear-gradient(135deg, ${s.join(", ")})`}function Grt(t,e,n){const a=$rt[t];return a?a(n,e):null}function rj(t){const e=Cce(t.extraColors),n=Vrt(t.rgba,e,t.subtype,t.effectType),a=Urt(t.rgba,t.extraColors,t.subtype,t.effectType),i=typeof t.effectType=="string"?Grt(t.effectType,t.effectSize,a):null,s=[];return i&&(Array.isArray(i)?i:[i]).forEach(l=>{s.push({image:l,size:"cover"})}),s.push({image:n,size:"cover"}),s.push({image:Hrt,size:qrt}),{backgroundImage:s.map(o=>o.image).join(", "),backgroundSize:s.map(o=>o.size).join(", ")}}function rU({rgba:t,extraColors:e,effectType:n,subtype:a,className:i="w-5 h-5",shape:s="circle",style:o,title:l,effectSize:c}){const d=y.useMemo(()=>Cce(e),[e]),u=y.useMemo(()=>rj({effectSize:c,rgba:t,extraColors:e,effectType:n,subtype:a}),[c,t,e,n,a]),m=u.backgroundImage,p=u.backgroundSize,f=s==="circle"||s==="pill"?"rounded-full":"rounded",b=l??(d.length>0?d.join(", "):t?`#${t.substring(0,6)}`:void 0);return r.jsx("span",{"data-testid":"filament-swatch",className:`${i} ${f} border border-black/20 inline-block flex-shrink-0`,style:{backgroundImage:m,backgroundSize:p,...o},title:b})}function Wrt(){const{t}=kt(),{showToast:e}=rn(),[n,a]=y.useState([]),[i,s]=y.useState(!0),[o,l]=y.useState(""),[c,d]=y.useState(""),u=y.useRef(null),[m,p]=y.useState(!1),[f,b]=y.useState(null),[w,g]=y.useState(""),[x,_]=y.useState(""),[N,C]=y.useState("#FFFFFF"),[P,T]=y.useState(""),[A,F]=y.useState(""),[S,E]=y.useState(""),[U,I]=y.useState(!1),[H,R]=y.useState(new Set),[Q,re]=y.useState(!1),[J,de]=y.useState(!1),[pe,ue]=y.useState(null),[X,ae]=y.useState(null),[me,be]=y.useState(!1),Ce=y.useCallback(async()=>{try{const ce=await se.getColorCatalog();a(ce)}catch{e(t("settings.colorCatalog.loadFailed"),"error")}finally{s(!1)}},[e,t]);y.useEffect(()=>{Ce()},[Ce]);const $=[...new Set(n.map(ce=>ce.manufacturer))].sort(),W=n.filter(ce=>{const le=o===""||ce.manufacturer.toLowerCase().includes(o.toLowerCase())||ce.color_name.toLowerCase().includes(o.toLowerCase())||(ce.material?.toLowerCase().includes(o.toLowerCase())??!1),q=c===""||ce.manufacturer===c;return le&&q}),D=()=>{g(""),_(""),C("#FFFFFF"),T(""),F(""),E("")},j=async()=>{if(!w.trim()||!x.trim()||!N){e(t("settings.colorCatalog.fieldsRequired"),"error");return}I(!0);try{const ce=await se.addColorEntry({manufacturer:w.trim(),color_name:x.trim(),hex_color:N,material:P.trim()||null,extra_colors:A.trim()||null,effect_type:S.trim()||null});a(le=>[...le,ce].sort((q,L)=>q.manufacturer.localeCompare(L.manufacturer)||(q.material||"").localeCompare(L.material||"")||q.color_name.localeCompare(L.color_name))),p(!1),D(),e(t("settings.colorCatalog.colorAdded"),"success")}catch{e(t("settings.colorCatalog.addFailed"),"error")}finally{I(!1)}},B=ce=>{b(ce.id),g(ce.manufacturer),_(ce.color_name),C(ce.hex_color),T(ce.material||""),F(ce.extra_colors||""),E(ce.effect_type||"")},Y=()=>{b(null),D()},O=async ce=>{if(!w.trim()||!x.trim()||!N){e(t("settings.colorCatalog.fieldsRequired"),"error");return}I(!0);try{const le=await se.updateColorEntry(ce,{manufacturer:w.trim(),color_name:x.trim(),hex_color:N,material:P.trim()||null,extra_colors:A.trim()||null,effect_type:S.trim()||null});a(q=>q.map(L=>L.id===ce?le:L).sort((L,ne)=>L.manufacturer.localeCompare(ne.manufacturer)||(L.material||"").localeCompare(ne.material||"")||L.color_name.localeCompare(ne.color_name))),b(null),D(),e(t("settings.colorCatalog.colorUpdated"),"success")}catch{e(t("settings.colorCatalog.updateFailed"),"error")}finally{I(!1)}},ie=async()=>{if(X)try{await se.deleteColorEntry(X.id),a(ce=>ce.filter(le=>le.id!==X.id)),e(t("settings.colorCatalog.colorDeleted"),"success")}catch{e(t("settings.colorCatalog.deleteFailed"),"error")}finally{ae(null)}},z=async()=>{be(!1),s(!0);try{await se.resetColorCatalog(),await Ce(),e(t("settings.colorCatalog.resetSuccess"),"success")}catch{e(t("settings.colorCatalog.resetFailed"),"error"),s(!1)}},G=async()=>{de(!0),ue(null);try{const ce={},le=Gm();le&&(ce.Authorization=`Bearer ${le}`);const q=await fetch("/api/v1/inventory/colors/sync",{method:"POST",headers:ce});if(!q.ok)throw new Error("Failed to start sync");const L=q.body?.getReader();if(!L)throw new Error("No response body");const ne=new TextDecoder;let ye="";for(;;){const{done:we,value:Ne}=await L.read();if(we)break;ye+=ne.decode(Ne,{stream:!0});const ve=ye.split(` -`);ye=ve.pop()||"";for(const xe of ve)if(xe.startsWith("data: "))try{const Ee=JSON.parse(xe.slice(6));Ee.type==="progress"?ue({fetched:Ee.total_fetched,total:Ee.total_available}):Ee.type==="complete"?Ee.added===0?e(t("settings.colorCatalog.syncUpToDate",{count:Ee.total_fetched}),"success"):e(t("settings.colorCatalog.syncComplete",{added:Ee.added,skipped:Ee.skipped}),"success"):Ee.type==="error"&&e(`${t("settings.colorCatalog.syncError")}: ${Ee.error}`,"error")}catch{}}await Ce()}catch{e(t("settings.colorCatalog.syncFailed"),"error")}finally{de(!1),ue(null)}},K=ce=>{R(le=>{const q=new Set(le);return q.has(ce)?q.delete(ce):q.add(ce),q})},Z=()=>{H.size===W.length?R(new Set):R(new Set(W.map(ce=>ce.id)))},oe=async()=>{if(re(!1),H.size!==0)try{const ce=await se.bulkDeleteColorEntries([...H]);a(le=>le.filter(q=>!H.has(q.id))),R(new Set),e(t("settings.colorCatalog.bulkDeleted",{count:ce.deleted}),"success")}catch{e(t("settings.colorCatalog.bulkDeleteFailed"),"error")}},ee=()=>{const ce=n.map(({manufacturer:ne,color_name:ye,hex_color:we,material:Ne,extra_colors:ve,effect_type:xe})=>({manufacturer:ne,color_name:ye,hex_color:we,material:Ne,extra_colors:ve,effect_type:xe})),le=new Blob([JSON.stringify(ce,null,2)],{type:"application/json"}),q=URL.createObjectURL(le),L=document.createElement("a");L.href=q,L.download="color-catalog.json",document.body.appendChild(L),L.click(),document.body.removeChild(L),URL.revokeObjectURL(q),e(t("settings.colorCatalog.exported",{count:n.length}),"success")},ge=async ce=>{const le=ce.target.files?.[0];if(le){try{const q=await le.text(),L=JSON.parse(q);if(!Array.isArray(L))throw new Error("Invalid format");let ne=0,ye=0;for(const we of L){if(!we.manufacturer||!we.color_name||!we.hex_color){ye++;continue}if(n.some(ve=>ve.manufacturer.toLowerCase()===we.manufacturer.toLowerCase()&&ve.color_name.toLowerCase()===we.color_name.toLowerCase()&&(ve.material||"").toLowerCase()===(we.material||"").toLowerCase())){ye++;continue}try{const ve=await se.addColorEntry({manufacturer:we.manufacturer,color_name:we.color_name,hex_color:we.hex_color,material:we.material||null,extra_colors:we.extra_colors||null,effect_type:we.effect_type||null});a(xe=>[...xe,ve].sort((Ee,ze)=>Ee.manufacturer.localeCompare(ze.manufacturer)||(Ee.material||"").localeCompare(ze.material||"")||Ee.color_name.localeCompare(ze.color_name))),ne++}catch{ye++}}e(t("settings.colorCatalog.imported",{added:ne,skipped:ye}),"success")}catch{e(t("settings.colorCatalog.importFailed"),"error")}u.current&&(u.current.value="")}};return r.jsxs(Ct,{id:"card-color-catalog",children:[r.jsxs(pn,{children:[r.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[r.jsx(jS,{className:"w-5 h-5 text-bambu-gray"}),r.jsx("h2",{className:"text-lg font-semibold text-white",children:t("settings.colorCatalog.title")}),r.jsxs("span",{className:"text-sm text-bambu-gray",children:["(",n.length,")"]})]}),r.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[r.jsxs("button",{onClick:ee,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:[r.jsx(Yr,{className:"w-4 h-4"}),r.jsx("span",{className:"hidden sm:inline",children:t("common.export")})]}),r.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:[r.jsx(ka,{className:"w-4 h-4"}),r.jsx("span",{className:"hidden sm:inline",children:t("common.import")})]}),r.jsx("input",{ref:u,type:"file",accept:".json",className:"hidden",onChange:ge}),r.jsxs("button",{onClick:G,disabled:J,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:[J?r.jsx(pt,{className:"w-4 h-4 animate-spin"}):r.jsx(Hh,{className:"w-4 h-4"}),r.jsx("span",{className:"hidden sm:inline",children:J?pe?`${Math.min(pe.fetched,pe.total)} / ${pe.total}`:t("settings.colorCatalog.starting"):t("settings.colorCatalog.sync")})]}),r.jsxs("button",{onClick:()=>be(!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:[r.jsx(gs,{className:"w-4 h-4"}),r.jsx("span",{className:"hidden sm:inline",children:t("common.reset")})]}),r.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:[r.jsx(ar,{className:"w-4 h-4"}),r.jsx("span",{className:"hidden sm:inline",children:t("common.add")})]})]}),H.size>0&&r.jsxs("div",{className:"flex items-center gap-2 mt-2 px-3 py-2 bg-red-500/10 border border-red-500/30 rounded-lg",children:[r.jsx("span",{className:"text-sm text-red-400",children:t("settings.colorCatalog.selectedCount",{count:H.size})}),r.jsxs("button",{onClick:()=>re(!0),className:"ml-auto px-3 py-1.5 text-sm bg-red-500 text-white rounded-lg hover:bg-red-600 transition-colors flex items-center gap-1.5",children:[r.jsx(Jt,{className:"w-4 h-4"}),t("settings.colorCatalog.deleteSelected")]}),r.jsx("button",{onClick:()=>R(new Set),className:"px-3 py-1.5 text-sm text-bambu-gray hover:text-white transition-colors",children:t("common.cancel")})]})]}),r.jsxs(At,{className:"space-y-4",children:[r.jsx("p",{className:"text-sm text-bambu-gray",children:t("settings.colorCatalog.description")}),r.jsxs("div",{className:"flex gap-2 flex-wrap",children:[r.jsxs("div",{className:"relative flex-1 min-w-[200px]",children:[r.jsx(Sr,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray"}),r.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:ce=>l(ce.target.value)})]}),r.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:ce=>d(ce.target.value),children:[r.jsx("option",{value:"",children:t("settings.colorCatalog.allManufacturers")}),$.map(ce=>r.jsx("option",{value:ce,children:ce},ce))]})]}),m&&r.jsxs("div",{className:"p-4 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary",children:[r.jsx("h3",{className:"text-sm font-medium text-white mb-3",children:t("settings.colorCatalog.addNewColor")}),r.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-5 gap-2 items-end",children:[r.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:w,onChange:ce=>g(ce.target.value)}),r.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:x,onChange:ce=>_(ce.target.value)}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("input",{type:"color",className:"w-20 h-10 rounded cursor-pointer border border-bambu-dark-tertiary",value:N,onChange:ce=>C(ce.target.value)}),r.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:ce=>C(ce.target.value)})]}),r.jsxs("div",{className:"flex items-center gap-1",children:[r.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:P,onChange:ce=>T(ce.target.value)}),r.jsxs("button",{onClick:j,disabled:U,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:[U?r.jsx(pt,{className:"w-4 h-4 animate-spin"}):r.jsx(_r,{className:"w-4 h-4"}),t("common.add")]}),r.jsx("button",{onClick:()=>{p(!1),D()},className:"p-2 ml-2 rounded-lg text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary",children:r.jsx(Ht,{className:"w-4 h-4"})})]})]}),r.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-2 mt-2",children:[r.jsx("input",{type:"text",className:"px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white text-sm font-mono placeholder-bambu-gray focus:border-bambu-green focus:outline-none",placeholder:t("inventory.extraColorsPlaceholder"),value:A,onChange:ce=>F(ce.target.value)}),r.jsx("select",{className:"px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none",value:S,onChange:ce=>E(ce.target.value),children:WI.map(ce=>r.jsx("option",{value:ce.value,children:t(ce.labelKey)},ce.value||"none"))})]})]}),(o||c)&&r.jsx("div",{className:"text-xs text-bambu-gray",children:t("settings.colorCatalog.showing",{filtered:W.length,total:n.length})}),i?r.jsxs("div",{className:"flex items-center justify-center py-8 text-bambu-gray",children:[r.jsx(pt,{className:"w-5 h-5 animate-spin mr-2"}),t("common.loading")]}):r.jsx("div",{className:"max-h-[600px] overflow-auto border border-bambu-dark-tertiary rounded-lg",children:r.jsxs("table",{className:"w-full text-sm",children:[r.jsx("thead",{className:"bg-bambu-dark sticky top-0",children:r.jsxs("tr",{children:[r.jsx("th",{className:"px-2 py-2 w-10",children:r.jsx("input",{type:"checkbox",checked:W.length>0&&H.size===W.length,onChange:Z,className:"w-4 h-4 accent-bambu-green cursor-pointer"})}),r.jsx("th",{className:"px-3 py-2 text-left text-bambu-gray font-medium w-12"}),r.jsx("th",{className:"px-3 py-2 text-left text-bambu-gray font-medium",children:t("settings.colorCatalog.manufacturer")}),r.jsx("th",{className:"px-3 py-2 text-left text-bambu-gray font-medium",children:t("inventory.material")}),r.jsx("th",{className:"px-3 py-2 text-left text-bambu-gray font-medium",children:t("settings.colorCatalog.colorName")}),r.jsx("th",{className:"px-3 py-2 text-left text-bambu-gray font-medium w-24",children:t("settings.colorCatalog.hex")}),r.jsx("th",{className:"px-3 py-2 w-16"})]})}),r.jsx("tbody",{children:W.length===0?r.jsx("tr",{children:r.jsx("td",{colSpan:7,className:"px-3 py-8 text-center text-bambu-gray",children:t(o||c?"settings.colorCatalog.noMatch":"settings.colorCatalog.empty")})}):W.map(ce=>r.jsxs(y.Fragment,{children:[r.jsx("tr",{className:`border-t border-bambu-dark-tertiary hover:bg-bambu-dark ${H.has(ce.id)?"bg-bambu-dark":""}`,children:f===ce.id?r.jsxs(r.Fragment,{children:[r.jsx("td",{className:"px-2 py-2",children:r.jsx("input",{type:"checkbox",checked:H.has(ce.id),onChange:()=>K(ce.id),className:"w-4 h-4 accent-bambu-green cursor-pointer"})}),r.jsx("td",{className:"px-3 py-2",children:r.jsx("input",{type:"color",className:"w-8 h-8 rounded cursor-pointer border border-bambu-dark-tertiary",value:N,onChange:le=>C(le.target.value)})}),r.jsx("td",{className:"px-3 py-2",children:r.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:w,onChange:le=>g(le.target.value)})}),r.jsx("td",{className:"px-3 py-2",children:r.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:P,onChange:le=>T(le.target.value)})}),r.jsx("td",{className:"px-3 py-2",children:r.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:x,onChange:le=>_(le.target.value)})}),r.jsx("td",{className:"px-3 py-2",children:r.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:le=>C(le.target.value)})}),r.jsx("td",{className:"px-3 py-2",children:r.jsxs("div",{className:"flex justify-end gap-1",children:[r.jsx("button",{onClick:()=>O(ce.id),disabled:U,className:"p-1.5 rounded hover:bg-green-500/20 text-green-500",children:U?r.jsx(pt,{className:"w-4 h-4 animate-spin"}):r.jsx(_r,{className:"w-4 h-4"})}),r.jsx("button",{onClick:Y,className:"p-1.5 rounded hover:bg-bambu-dark-tertiary text-bambu-gray",children:r.jsx(Ht,{className:"w-4 h-4"})})]})})]}):r.jsxs(r.Fragment,{children:[r.jsx("td",{className:"px-2 py-2",children:r.jsx("input",{type:"checkbox",checked:H.has(ce.id),onChange:()=>K(ce.id),className:"w-4 h-4 accent-bambu-green cursor-pointer"})}),r.jsx("td",{className:"px-3 py-2",children:r.jsx(rU,{rgba:ce.hex_color.replace(/^#/,"")+(ce.hex_color.length===7?"FF":""),extraColors:ce.extra_colors,effectType:ce.effect_type,className:"w-8 h-8",shape:"square",title:ce.hex_color,effectSize:"table"})}),r.jsx("td",{className:"px-3 py-2 text-white",children:ce.manufacturer}),r.jsx("td",{className:"px-3 py-2 text-bambu-gray",children:ce.material||"-"}),r.jsx("td",{className:"px-3 py-2 text-white",children:ce.color_name}),r.jsx("td",{className:"px-3 py-2 font-mono text-xs text-bambu-gray",children:ce.hex_color}),r.jsx("td",{className:"px-3 py-2",children:r.jsxs("div",{className:"flex justify-end gap-1",children:[r.jsx("button",{onClick:()=>B(ce),className:"p-1.5 rounded hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white",children:r.jsx(oi,{className:"w-4 h-4"})}),r.jsx("button",{onClick:()=>ae(ce),className:"p-1.5 rounded bg-red-500/10 hover:bg-red-500/20 text-red-500",children:r.jsx(Jt,{className:"w-4 h-4"})})]})})]})}),f===ce.id&&r.jsxs("tr",{className:"border-t border-bambu-dark-tertiary/50 bg-bambu-dark",children:[r.jsx("td",{colSpan:2}),r.jsx("td",{className:"px-3 py-2",colSpan:2,children:r.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 font-mono focus:border-bambu-green focus:outline-none",placeholder:t("inventory.extraColorsPlaceholder"),value:A,onChange:le=>F(le.target.value)})}),r.jsx("td",{className:"px-3 py-2",colSpan:2,children:r.jsx("select",{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:S,onChange:le=>E(le.target.value),children:WI.map(le=>r.jsx("option",{value:le.value,children:t(le.labelKey)},le.value||"none"))})}),r.jsx("td",{})]})]},ce.id))})]})})]}),X&&r.jsx(vn,{title:t("settings.colorCatalog.deleteColor"),message:t("settings.colorCatalog.deleteConfirm",{name:`${X.manufacturer} - ${X.color_name}`}),confirmText:t("common.delete"),variant:"danger",onConfirm:ie,onCancel:()=>ae(null)}),Q&&r.jsx(vn,{title:t("settings.colorCatalog.deleteSelected"),message:t("settings.colorCatalog.bulkDeleteConfirm",{count:H.size}),confirmText:t("common.delete"),variant:"danger",onConfirm:oe,onCancel:()=>re(!1)}),me&&r.jsx(vn,{title:t("settings.colorCatalog.resetCatalog"),message:t("settings.colorCatalog.resetConfirm"),confirmText:t("common.reset"),variant:"danger",onConfirm:z,onCancel:()=>be(!1)})]})}function Krt({link:t,onClose:e}){const{t:n}=kt(),a=en(),i=!!t,s=y.useRef(null),[o,l]=y.useState(t?.name||""),[c,d]=y.useState(t?.url||""),[u,m]=y.useState(t?.icon||"link"),[p,f]=y.useState(t?.open_in_new_tab||!1),[b,w]=y.useState(!!t?.custom_icon),[g,x]=y.useState(t?.custom_icon?se.getExternalLinkIconUrl(t.id):null),[_,N]=y.useState(null),[C,P]=y.useState(null);y.useEffect(()=>{const H=R=>{R.key==="Escape"&&e()};return window.addEventListener("keydown",H),()=>window.removeEventListener("keydown",H)},[e]);const T=it({mutationFn:async H=>{const R=await se.createExternalLink(H);return _?await se.uploadExternalLinkIcon(R.id,_):R},onSuccess:()=>{a.invalidateQueries({queryKey:["external-links"]}),e()},onError:H=>{P(H.message)}}),A=it({mutationFn:async H=>{let R=await se.updateExternalLink(t.id,H);return _?R=await se.uploadExternalLinkIcon(t.id,_):!b&&t?.custom_icon&&(R=await se.deleteExternalLinkIcon(t.id)),R},onSuccess:()=>{a.invalidateQueries({queryKey:["external-links"]}),e()},onError:H=>{P(H.message)}}),F=H=>{const R=H.target.files?.[0];if(R){if(!["image/png","image/jpeg","image/gif","image/svg+xml","image/webp","image/x-icon"].includes(R.type)){P("Please select a valid image file (PNG, JPG, GIF, SVG, WebP, or ICO)");return}if(R.size>1024*1024){P("Image file must be less than 1MB");return}N(R),w(!0);const re=new FileReader;re.onload=J=>{x(J.target?.result)},re.readAsDataURL(R)}},S=()=>{N(null),x(null),w(!1),s.current&&(s.current.value="")},E=H=>{if(H.preventDefault(),P(null),!o.trim()){P("Name is required");return}if(!c.trim()){P("URL is required");return}if(!c.startsWith("http://")&&!c.startsWith("https://")){P("URL must start with http:// or https://");return}const R={name:o.trim(),url:c.trim(),icon:u,open_in_new_tab:p};i?A.mutate(R):T.mutate(R)},U=T.isPending||A.isPending,I=CT(u);return r.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",onClick:e,children:r.jsxs("div",{className:"bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-md",onClick:H=>H.stopPropagation(),children:[r.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary",children:[r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx("div",{className:"p-2 rounded-full bg-bambu-green/20 text-bambu-green",children:b&&g?r.jsx("img",{src:g,alt:"",className:"w-5 h-5 rounded"}):r.jsx(I,{className:"w-5 h-5"})}),r.jsx("h2",{className:"text-lg font-semibold text-white",children:i?"Edit Link":"Add External Link"})]}),r.jsx("button",{onClick:e,className:"text-bambu-gray hover:text-white transition-colors",children:r.jsx(Ht,{className:"w-5 h-5"})})]}),r.jsxs("form",{onSubmit:E,className:"p-6 space-y-4",children:[C&&r.jsx("div",{className:"p-3 bg-red-500/20 border border-red-500/50 rounded-lg text-sm text-red-400",children:C}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Name *"}),r.jsx("input",{type:"text",value:o,onChange:H=>l(H.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"})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"URL *"}),r.jsx("input",{type:"text",value:c,onChange:H=>d(H.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"})]}),r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsx("label",{className:"text-sm text-bambu-gray",children:n("externalLinks.openInNewTab")}),r.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:r.jsx("span",{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${p?"translate-x-6":"translate-x-1"}`})})]}),r.jsxs("div",{className:"space-y-3",children:[r.jsx("label",{className:"block text-sm text-bambu-gray",children:"Icon"}),r.jsxs("div",{className:"p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary",children:[r.jsxs("div",{className:"flex items-center justify-between mb-2",children:[r.jsx("span",{className:"text-sm text-white",children:"Custom Icon"}),r.jsx("input",{ref:s,type:"file",accept:"image/png,image/jpeg,image/gif,image/svg+xml,image/webp,image/x-icon",className:"hidden",onChange:F}),b&&g?r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("img",{src:g,alt:"Custom icon",className:"w-8 h-8 rounded border border-bambu-dark-tertiary"}),r.jsx("button",{type:"button",onClick:S,className:"p-1 text-red-400 hover:text-red-300 transition-colors",title:"Remove custom icon",children:r.jsx(Jt,{className:"w-4 h-4"})})]}):r.jsxs(Me,{type:"button",variant:"secondary",size:"sm",onClick:()=>s.current?.click(),children:[r.jsx(ka,{className:"w-4 h-4"}),"Upload"]})]}),r.jsx("p",{className:"text-xs text-bambu-gray",children:"PNG, JPG, GIF, SVG, WebP, or ICO. Max 1MB."})]}),!b&&r.jsxs("div",{children:[r.jsx("span",{className:"text-sm text-bambu-gray block mb-2",children:"Or choose a preset icon"}),r.jsx(Sve,{value:u,onChange:m})]})]}),r.jsxs("div",{className:"flex gap-3 pt-2",children:[r.jsx(Me,{type:"button",variant:"secondary",onClick:e,className:"flex-1",children:"Cancel"}),r.jsxs(Me,{type:"submit",disabled:U,className:"flex-1",children:[U?r.jsx(pt,{className:"w-4 h-4 animate-spin"}):r.jsx(us,{className:"w-4 h-4"}),i?"Save":"Add"]})]})]})]})})}function Yrt(){const{t}=kt(),e=en(),[n,a]=y.useState(!1),[i,s]=y.useState(null),[o,l]=y.useState(null),[c,d]=y.useState(null),{data:u,isLoading:m}=Ve({queryKey:["external-links"],queryFn:se.getExternalLinks}),p=it({mutationFn:N=>se.deleteExternalLink(N),onSuccess:()=>{e.invalidateQueries({queryKey:["external-links"]})}}),f=it({mutationFn:N=>se.reorderExternalLinks(N),onSuccess:()=>{e.invalidateQueries({queryKey:["external-links"]})}}),b=(N,C)=>{d(C),N.dataTransfer.effectAllowed="move"},w=N=>{N.preventDefault(),N.dataTransfer.dropEffect="move"},g=(N,C)=>{if(N.preventDefault(),c===null||c===C||!u)return;const P=u.map(S=>S.id),T=P.indexOf(c),A=P.indexOf(C);if(T===-1||A===-1)return;const F=[...P];F.splice(T,1),F.splice(A,0,c),f.mutate(F),d(null)},x=N=>{l(N)},_=()=>{o&&(p.mutate(o.id),l(null))};return r.jsxs(r.Fragment,{children:[r.jsxs(Ct,{id:"card-sidebar-links",children:[r.jsx(pn,{children:r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(Th,{className:"w-5 h-5 text-bambu-green"}),r.jsx("h2",{className:"text-lg font-semibold text-white",children:"Sidebar Links"})]}),r.jsxs(Me,{size:"sm",onClick:()=>a(!0),children:[r.jsx(ar,{className:"w-4 h-4"}),"Add Link"]})]})}),r.jsxs(At,{children:[r.jsx("p",{className:"text-sm text-bambu-gray mb-4",children:"Add external links to the sidebar navigation. Drag to reorder."}),m?r.jsx("div",{className:"flex justify-center py-8",children:r.jsx(pt,{className:"w-6 h-6 text-bambu-green animate-spin"})}):u&&u.length>0?r.jsx("div",{className:"space-y-2",children:u.map(N=>{const C=CT(N.icon);return r.jsxs("div",{draggable:!0,onDragStart:P=>b(P,N.id),onDragOver:w,onDrop:P=>g(P,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:[r.jsx(Ph,{className:"w-6 h-6 md:w-4 md:h-4 text-bambu-gray cursor-grab flex-shrink-0"}),r.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark-tertiary text-bambu-gray",children:r.jsx(C,{className:"w-4 h-4"})}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:"text-white font-medium truncate",children:N.name}),r.jsx(Rr,{className:"w-3 h-3 text-bambu-gray flex-shrink-0"})]}),r.jsx("span",{className:"text-sm text-bambu-gray truncate block",children:N.url})]}),r.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[r.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:r.jsx(oi,{className:"w-4 h-4"})}),r.jsx("button",{onClick:()=>x(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:r.jsx(Jt,{className:"w-4 h-4"})})]})]},N.id)})}):r.jsxs("div",{className:"text-center py-8 text-bambu-gray",children:[r.jsx(Th,{className:"w-8 h-8 mx-auto mb-2 opacity-50"}),r.jsx("p",{children:t("externalLinks.noLinksConfigured")}),r.jsx("p",{className:"text-sm",children:'Click "Add Link" to add one'})]})]})]}),(n||i)&&r.jsx(Krt,{link:i,onClose:()=>{a(!1),s(null)}}),o&&r.jsx(vn,{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 iF={immediate:"archive",review:"review",print_queue:"queue",proxy:"proxy"};function Xrt({printer:t,models:e}){const{t:n}=kt(),a=en(),{showToast:i}=rn(),[s,o]=y.useState(!0),[l,c]=y.useState(t.enabled),[d,u]=y.useState(t.name),[m,p]=y.useState(""),[f,b]=y.useState(t.mode==="queue"?"review":t.mode),[w,g]=y.useState(t.target_printer_id),[x,_]=y.useState(t.bind_ip||""),[N,C]=y.useState(t.remote_interface_ip||""),[P,T]=y.useState(t.model||""),[A,F]=y.useState(t.auto_dispatch??!0),[S,E]=y.useState(t.queue_force_color_match??!1),[U,I]=y.useState(t.tailscale_disabled??!0),[H,R]=y.useState(!1),[Q,re]=y.useState(null),[J,de]=y.useState(!1),[pe,ue]=y.useState(!1),{data:X}=Ve({queryKey:["tailscale-status"],queryFn:X0.getTailscaleStatus,enabled:!U,staleTime:6e4}),ae=X?.available?X.fqdn:"",me=X?.available?X.tailscale_ips?.[0]??"":"",be=async ee=>{ee.stopPropagation();const ge=ae;if(!ge)return;let ce=!1;if(navigator.clipboard&&window.isSecureContext)try{await navigator.clipboard.writeText(ge),ce=!0}catch{}if(!ce){const le=document.createElement("textarea");le.value=ge,le.style.position="fixed",le.style.opacity="0",document.body.appendChild(le);try{le.select(),ce=document.execCommand("copy")}catch{ce=!1}finally{le.parentNode&&le.parentNode.removeChild(le)}}ce?(ue(!0),i(n("printers.copied")),setTimeout(()=>ue(!1),2e3)):i(n("virtualPrinter.toast.copyFailed"),"error")};y.useEffect(()=>{Q||(c(t.enabled),b(t.mode==="queue"?"review":t.mode),u(t.name),g(t.target_printer_id),_(t.bind_ip||""),C(t.remote_interface_ip||""),T(t.model||""),F(t.auto_dispatch??!0),E(t.queue_force_color_match??!1),I(t.tailscale_disabled??!0))},[t,Q]);const{data:Ce}=Ve({queryKey:["printers"],queryFn:se.getPrinters}),{data:$}=Ve({queryKey:["network-interfaces"],queryFn:()=>se.getNetworkInterfaces().then(ee=>ee.interfaces)}),W=it({mutationFn:ee=>X0.update(t.id,ee),onSuccess:()=>{a.invalidateQueries({queryKey:["virtual-printers"]}),i(n("virtualPrinter.toast.updated")),re(null)},onError:ee=>{i(ee.message||n("virtualPrinter.toast.failedToUpdate"),"error"),c(t.enabled),b(t.mode==="queue"?"review":t.mode),g(t.target_printer_id),_(t.bind_ip||""),I(t.tailscale_disabled??!0),re(null)}}),D=it({mutationFn:()=>X0.remove(t.id),onSuccess:()=>{a.invalidateQueries({queryKey:["virtual-printers"]}),i(n("virtualPrinter.toast.deleted")),de(!1)},onError:ee=>{i(ee.message||n("virtualPrinter.toast.failedToDelete"),"error"),de(!1)}}),j=ee=>{ee.stopPropagation();const ge=!l;if(ge){if(!x){i(n("virtualPrinter.toast.bindIpRequired"),"error");return}if(f==="proxy"){if(!w){i(n("virtualPrinter.toast.targetPrinterRequired"),"error");return}}else if(!m&&!t.access_code_set){i(n("virtualPrinter.toast.accessCodeRequired"),"error");return}}c(ge),re("toggle"),W.mutate({enabled:ge})},B=()=>{d.trim()&&(re("name"),W.mutate({name:d.trim()}))},Y=()=>{if(!m){i(n("virtualPrinter.toast.accessCodeEmpty"),"error");return}if(m.length!==8){i(n("virtualPrinter.toast.accessCodeLength"),"error");return}re("accessCode"),W.mutate({access_code:m}),p("")},O=ee=>{b(ee),re("mode"),W.mutate({mode:ee})},ie=ee=>{T(ee),re("model"),W.mutate({model:ee})},z=ee=>{g(ee),re("targetPrinter"),W.mutate({target_printer_id:ee})},G=ee=>{C(ee),re("remoteInterface"),W.mutate({remote_interface_ip:ee})},K=t.status?.running||!1,Z=n(`virtualPrinter.mode.${iF[f]||"archive"}`),oe=Ce?.find(ee=>ee.id===w)?.name;return r.jsxs(r.Fragment,{children:[r.jsxs(Ct,{children:[r.jsxs("div",{className:"px-4 py-3 flex items-center gap-3 cursor-pointer select-none",onClick:()=>o(!s),children:[r.jsx("button",{className:"text-bambu-gray flex-shrink-0",children:s?r.jsx(Ln,{className:"w-4 h-4"}):r.jsx(Va,{className:"w-4 h-4"})}),r.jsx("span",{className:`w-2 h-2 rounded-full flex-shrink-0 ${K?"bg-green-400 animate-pulse":"bg-gray-500"}`}),r.jsx("span",{className:"text-white font-medium truncate",children:t.name}),r.jsx("span",{className:"text-xs text-bambu-gray flex-shrink-0",children:Z}),t.model_name&&r.jsx("span",{className:"text-xs text-bambu-gray flex-shrink-0",children:t.model_name}),oe&&r.jsxs("span",{className:"text-xs text-bambu-gray flex-shrink-0 truncate",children:[f==="proxy"&&r.jsx(zF,{className:"w-3 h-3 inline mr-1"}),oe]}),x&&r.jsx("span",{className:"text-[10px] text-bambu-gray flex-shrink-0 font-mono",children:x}),N&&r.jsx("span",{className:"text-[10px] text-bambu-gray flex-shrink-0 font-mono",children:N}),r.jsx("div",{className:"ml-auto flex items-center gap-2 flex-shrink-0",onClick:ee=>ee.stopPropagation(),children:r.jsx("button",{onClick:j,disabled:Q==="toggle",className:`relative w-10 h-5 rounded-full transition-colors ${l?"bg-bambu-green":"bg-bambu-dark-tertiary"} ${Q==="toggle"?"opacity-50":""}`,children:r.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&&r.jsxs(At,{className:"pt-0 space-y-4",children:[r.jsx("div",{className:"border-t border-bambu-dark-tertiary"}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("input",{type:"text",value:d,onChange:ee=>u(ee.target.value),onBlur:B,onKeyDown:ee=>ee.key==="Enter"&&B(),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"}),r.jsx("button",{onClick:()=>de(!0),className:"p-1.5 text-bambu-gray hover:text-red-400 transition-colors flex-shrink-0",title:n("common.delete"),children:r.jsx(Jt,{className:"w-4 h-4"})})]}),r.jsxs("div",{className:"flex items-center gap-2 -mt-2",children:[ae&&r.jsxs("span",{className:"flex items-center gap-1 text-green-400/70 min-w-0",children:[r.jsx(Ew,{className:"w-3.5 h-3.5 flex-shrink-0"}),r.jsx("span",{className:"font-mono text-xs truncate",children:me?`${me} (${ae})`:ae}),r.jsx("button",{onClick:be,className:"p-0.5 rounded hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white transition-colors flex-shrink-0",title:n(pe?"printers.copied":"printers.copyToClipboard"),children:pe?r.jsx(_r,{className:"w-3.5 h-3.5 text-bambu-green"}):r.jsx(Mi,{className:"w-3.5 h-3.5"})})]}),r.jsx("span",{className:"text-xs text-bambu-gray font-mono ml-auto flex-shrink-0",children:t.serial})]}),r.jsxs("div",{children:[r.jsx("div",{className:"text-white text-sm font-medium mb-2",children:n("virtualPrinter.mode.title")}),r.jsx("div",{className:"grid grid-cols-2 gap-2",children:["immediate","review","print_queue","proxy"].map(ee=>r.jsxs("button",{onClick:()=>O(ee),disabled:Q==="mode",className:`p-2 rounded-lg border text-left transition-colors ${f===ee?ee==="proxy"?"border-blue-500 bg-blue-500/10":"border-bambu-green bg-bambu-green/10":"border-bambu-dark-tertiary hover:border-bambu-gray"}`,children:[r.jsxs("div",{className:"flex items-center gap-1.5 text-white text-xs font-medium",children:[ee==="proxy"&&r.jsx(zF,{className:"w-3 h-3"}),n(`virtualPrinter.mode.${iF[ee]}`)]}),r.jsx("div",{className:"text-[10px] text-bambu-gray",children:n(`virtualPrinter.mode.${iF[ee]}Desc`)})]},ee))})]}),f==="print_queue"&&r.jsx("div",{className:"pt-2 border-t border-bambu-dark-tertiary",children:r.jsxs("div",{className:"flex items-center justify-between gap-3",children:[r.jsxs("div",{className:"min-w-0",children:[r.jsx("div",{className:"text-white text-sm font-medium",children:n("virtualPrinter.autoDispatch.title")}),r.jsx("div",{className:"text-[10px] text-bambu-gray",children:n("virtualPrinter.autoDispatch.description")})]}),r.jsx("button",{onClick:()=>{const ee=!A;F(ee),re("autoDispatch"),W.mutate({auto_dispatch:ee})},disabled:Q==="autoDispatch",className:`relative w-10 h-5 rounded-full transition-colors flex-shrink-0 ${A?"bg-bambu-green":"bg-bambu-dark-tertiary"} ${Q==="autoDispatch"?"opacity-50":""}`,children:r.jsx("span",{className:`absolute top-0.5 left-0.5 w-4 h-4 bg-white rounded-full transition-transform ${A?"translate-x-5":""}`})})]})}),f==="print_queue"&&r.jsx("div",{className:"pt-2 border-t border-bambu-dark-tertiary",children:r.jsxs("div",{className:"flex items-center justify-between gap-3",children:[r.jsxs("div",{className:"min-w-0",children:[r.jsx("div",{className:"text-white text-sm font-medium",children:n("virtualPrinter.queueForceColorMatch.title")}),r.jsx("div",{className:"text-[10px] text-bambu-gray",children:n("virtualPrinter.queueForceColorMatch.description")})]}),r.jsx("button",{onClick:()=>{const ee=!S;E(ee),re("queueForceColorMatch"),W.mutate({queue_force_color_match:ee})},disabled:Q==="queueForceColorMatch",className:`relative w-10 h-5 rounded-full transition-colors flex-shrink-0 ${S?"bg-bambu-green":"bg-bambu-dark-tertiary"} ${Q==="queueForceColorMatch"?"opacity-50":""}`,children:r.jsx("span",{className:`absolute top-0.5 left-0.5 w-4 h-4 bg-white rounded-full transition-transform ${S?"translate-x-5":""}`})})]})}),r.jsx("div",{className:"pt-2 border-t border-bambu-dark-tertiary",children:r.jsxs("div",{className:"flex items-center justify-between gap-3",children:[r.jsxs("div",{className:"min-w-0",children:[r.jsx("div",{className:"text-white text-sm font-medium",children:n("virtualPrinter.tailscaleDisabled.title")}),r.jsx("div",{className:"text-[10px] text-bambu-gray",children:n("virtualPrinter.tailscaleDisabled.description")})]}),r.jsx("button",{onClick:()=>{const ee=!U;I(ee),re("tailscaleDisabled"),W.mutate({tailscale_disabled:ee})},disabled:Q==="tailscaleDisabled",className:`relative w-10 h-5 rounded-full transition-colors shrink-0 ${U?"bg-bambu-dark-tertiary":"bg-bambu-green"} ${Q==="tailscaleDisabled"?"opacity-50":""}`,children:r.jsx("span",{className:`absolute top-0.5 left-0.5 w-4 h-4 bg-white rounded-full transition-transform ${U?"":"translate-x-5"}`})})]})}),f!=="proxy"&&r.jsxs("div",{className:"pt-2 border-t border-bambu-dark-tertiary",children:[r.jsx("div",{className:"text-white text-sm font-medium mb-1",children:n("virtualPrinter.model.title")}),r.jsx("p",{className:"text-xs text-bambu-gray mb-2",children:n("virtualPrinter.model.description")}),r.jsxs("div",{className:"relative",children:[r.jsx("select",{value:P,onChange:ee=>ie(ee.target.value),disabled:Q==="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(([ee,ge])=>r.jsxs("option",{value:ee,children:[ge," (",ee,")"]},ee))}),r.jsx(Ln,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]})]}),f==="proxy"&&r.jsx("div",{className:"pt-2 border-t border-bambu-dark-tertiary",children:r.jsxs("div",{className:"flex items-start gap-2 p-2 rounded bg-blue-500/10 border border-blue-500/30",children:[r.jsx(Ci,{className:"w-4 h-4 text-blue-400 flex-shrink-0 mt-0.5"}),r.jsx("p",{className:"text-xs text-bambu-gray",children:n("virtualPrinter.proxy.accessCodeHint")})]})}),f!=="proxy"&&r.jsxs("div",{className:"pt-2 border-t border-bambu-dark-tertiary",children:[r.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[r.jsx("div",{className:"text-white text-sm font-medium",children:n("virtualPrinter.accessCode.title")}),t.access_code_set?r.jsxs("span",{className:"flex items-center gap-1 text-xs text-green-400",children:[r.jsx(_r,{className:"w-3 h-3"}),n("virtualPrinter.accessCode.isSet")]}):r.jsxs("span",{className:"flex items-center gap-1 text-xs text-yellow-400",children:[r.jsx(Nn,{className:"w-3 h-3"}),n("virtualPrinter.accessCode.notSet")]})]}),r.jsxs("div",{className:"flex gap-2",children:[r.jsxs("div",{className:"relative flex-1",children:[r.jsx("input",{type:H?"text":"password",value:m,onChange:ee=>p(ee.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"}),r.jsx("button",{onClick:()=>R(!H),className:"absolute right-2 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white",children:H?r.jsx(sb,{className:"w-4 h-4"}):r.jsx(Dl,{className:"w-4 h-4"})})]}),r.jsx(Me,{onClick:Y,disabled:!m||Q==="accessCode",variant:"primary",children:Q==="accessCode"?r.jsx(pt,{className:"w-4 h-4 animate-spin"}):n("common.save")})]}),m&&r.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:r.jsx("span",{className:m.length===8?"text-green-400":"text-yellow-400",children:n("virtualPrinter.accessCode.charCount",{count:m.length})})})]}),r.jsxs("div",{className:"pt-2 border-t border-bambu-dark-tertiary",children:[r.jsx("div",{className:"text-white text-sm font-medium mb-2",children:n("virtualPrinter.targetPrinter.title")}),r.jsxs("div",{className:"relative",children:[r.jsxs("select",{value:w??"",onChange:ee=>{const ge=parseInt(ee.target.value,10);isNaN(ge)||z(ge)},disabled:Q==="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:[r.jsx("option",{value:"",children:n("virtualPrinter.targetPrinter.placeholder")}),Ce?.map(ee=>r.jsxs("option",{value:ee.id,children:[ee.name," (",ee.ip_address,")"]},ee.id))]}),r.jsx(Ln,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]})]}),r.jsxs("div",{className:"pt-2 border-t border-bambu-dark-tertiary",children:[r.jsx("div",{className:"text-white text-sm font-medium mb-1",children:n("virtualPrinter.bindIp.title")}),r.jsxs("div",{className:"relative",children:[r.jsxs("select",{value:x,onChange:ee=>{_(ee.target.value),re("bindIp"),W.mutate({bind_ip:ee.target.value})},disabled:Q==="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:[r.jsx("option",{value:"",children:n("virtualPrinter.bindIp.placeholder")}),$?.map(ee=>r.jsxs("option",{value:ee.ip,children:[ee.name," (",ee.ip,")",ee.is_alias?" [alias]":""," - ",ee.subnet]},ee.ip))]}),r.jsx(Ln,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}),r.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:n("virtualPrinter.bindIp.hint")})]}),r.jsxs("div",{className:"pt-2 border-t border-bambu-dark-tertiary",children:[r.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[r.jsx("div",{className:"text-white text-sm font-medium",children:n("virtualPrinter.remoteInterface.title")}),N?r.jsx("span",{className:"flex items-center gap-1 text-xs text-green-400",children:r.jsx(_r,{className:"w-3 h-3"})}):r.jsx("span",{className:"flex items-center gap-1 text-xs text-bambu-gray",title:n("virtualPrinter.remoteInterface.optional"),children:r.jsx(Ci,{className:"w-3 h-3"})})]}),r.jsxs("div",{className:"relative",children:[r.jsxs("select",{value:N,onChange:ee=>G(ee.target.value),disabled:Q==="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:[r.jsx("option",{value:"",children:n("virtualPrinter.remoteInterface.placeholder")}),$?.map(ee=>r.jsxs("option",{value:ee.ip,children:[ee.name," (",ee.ip,") - ",ee.subnet]},ee.ip))]}),r.jsx(Ln,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]})]})]})]}),J&&r.jsx(vn,{title:n("virtualPrinter.deleteConfirm.title"),message:n("virtualPrinter.deleteConfirm.message",{name:t.name}),variant:"danger",confirmText:n("common.delete"),isLoading:D.isPending,onConfirm:()=>D.mutate(),onCancel:()=>de(!1)})]})}const iQ={immediate:"archive",review:"review",print_queue:"queue",proxy:"proxy"};function Qrt({onClose:t}){const{t:e}=kt(),n=en(),{showToast:a}=rn(),[i,s]=y.useState(""),[o,l]=y.useState("immediate"),[c,d]=y.useState(null),{data:u}=Ve({queryKey:["printers"],queryFn:se.getPrinters}),m=it({mutationFn:()=>X0.create({name:i.trim()||"Bambuddy",mode:o,target_printer_id:o==="proxy"?c??void 0:void 0}),onSuccess:()=>{n.invalidateQueries({queryKey:["virtual-printers"]}),a(e("virtualPrinter.toast.created")),t()},onError:p=>{a(p.message||e("virtualPrinter.toast.failedToCreate"),"error")}});return r.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",onClick:t,children:r.jsx(Ct,{className:"w-full max-w-md",onClick:p=>p.stopPropagation(),children:r.jsxs(At,{className:"p-6 space-y-4",children:[r.jsx("h3",{className:"text-lg font-semibold text-white",children:e("virtualPrinter.addDialog.title")}),r.jsxs("div",{children:[r.jsx("label",{className:"text-sm text-white font-medium block mb-1",children:e("virtualPrinter.addDialog.name")}),r.jsx("input",{type:"text",value:i,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})]}),r.jsxs("div",{children:[r.jsx("label",{className:"text-sm text-white font-medium block mb-1",children:e("virtualPrinter.mode.title")}),r.jsx("div",{className:"grid grid-cols-2 gap-2",children:["immediate","review","print_queue","proxy"].map(p=>r.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:[r.jsxs("div",{className:"flex items-center gap-1.5 text-white text-xs font-medium",children:[p==="proxy"&&r.jsx(zF,{className:"w-3 h-3"}),e(`virtualPrinter.mode.${iQ[p]}`)]}),r.jsx("div",{className:"text-[10px] text-bambu-gray",children:e(`virtualPrinter.mode.${iQ[p]}Desc`)})]},p))})]}),o==="proxy"&&r.jsxs("div",{children:[r.jsx("label",{className:"text-sm text-white font-medium block mb-1",children:e("virtualPrinter.targetPrinter.title")}),r.jsxs("div",{className:"relative",children:[r.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:[r.jsx("option",{value:"",children:e("virtualPrinter.targetPrinter.placeholder")}),u?.map(p=>r.jsxs("option",{value:p.id,children:[p.name," (",p.ip_address,")"]},p.id))]}),r.jsx(Ln,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]})]}),r.jsx("p",{className:"text-xs text-bambu-gray",children:e("virtualPrinter.addDialog.hint")}),r.jsxs("div",{className:"flex gap-3 pt-2",children:[r.jsx(Me,{variant:"secondary",onClick:t,className:"flex-1",disabled:m.isPending,children:e("common.cancel")}),r.jsx(Me,{variant:"primary",onClick:()=>m.mutate(),className:"flex-1",disabled:m.isPending,children:m.isPending?r.jsx(pt,{className:"w-4 h-4 animate-spin"}):e("virtualPrinter.addDialog.create")})]})]})})})}function Zrt(){const{t}=kt(),e=en(),{showToast:n}=rn(),[a,i]=y.useState(!1),{data:s,isLoading:o}=Ve({queryKey:["virtual-printers"],queryFn:X0.list,refetchInterval:1e4}),{data:l}=Ve({queryKey:["virtual-printer-settings"],queryFn:WF.getSettings}),c=it({mutationFn:p=>WF.updateSettings({archive_name_source:p}),onSuccess:()=>{e.invalidateQueries({queryKey:["virtual-printer-settings"]}),n(t("virtualPrinter.toast.updated"))},onError:p=>{n(p.message||t("virtualPrinter.toast.failedToUpdate"),"error")}}),d=l?.archive_name_source==="filename";if(o)return r.jsx(Ct,{children:r.jsx(At,{className:"py-8 flex justify-center",children:r.jsx(pt,{className:"w-6 h-6 animate-spin text-bambu-green"})})});const u=s?.printers||[],m=s?.models||{};return r.jsxs("div",{className:"space-y-4",children:[r.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-4 items-stretch",children:[r.jsx(Ct,{className:"border-l-4 border-l-yellow-500",children:r.jsx(At,{className:"py-3 px-4",children:r.jsxs("div",{className:"flex items-start gap-2",children:[r.jsx(Nn,{className:"w-4 h-4 text-yellow-500 flex-shrink-0 mt-0.5"}),r.jsxs("div",{className:"text-xs",children:[r.jsx("p",{className:"text-white font-medium",children:t("virtualPrinter.setupRequired.title")}),r.jsx("p",{className:"text-bambu-gray mt-1",children:t("virtualPrinter.setupRequired.description")}),r.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:[r.jsx(Rr,{className:"w-3 h-3"}),t("virtualPrinter.setupRequired.readGuide")]})]})]})})}),r.jsx(Ct,{className:"lg:col-span-2",children:r.jsx(At,{className:"py-3 px-4",children:r.jsxs("div",{className:"flex items-start gap-2",children:[r.jsx(Ci,{className:"w-4 h-4 text-blue-400 flex-shrink-0 mt-0.5"}),r.jsxs("div",{className:"text-xs text-bambu-gray",children:[r.jsx("p",{className:"text-white font-medium mb-1",children:t("virtualPrinter.howItWorks.title")}),r.jsxs("ul",{className:"space-y-1 list-disc list-inside",children:[r.jsx("li",{children:t("virtualPrinter.howItWorks.step1")}),r.jsx("li",{children:t("virtualPrinter.howItWorks.step2")}),r.jsx("li",{children:t("virtualPrinter.howItWorks.step3")})]})]})]})})})]}),r.jsx(Ct,{children:r.jsx(At,{className:"py-3 px-4",children:r.jsxs("div",{className:"flex items-start gap-3",children:[r.jsx(Bs,{className:"w-4 h-4 text-bambu-green flex-shrink-0 mt-1"}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsxs("div",{className:"flex items-center justify-between gap-3",children:[r.jsx("p",{className:"text-sm text-white font-medium",children:t("virtualPrinter.archiveNameSource.title")}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:`text-xs ${d?"text-bambu-gray":"text-white"}`,children:t("virtualPrinter.archiveNameSource.metadata")}),r.jsx(En,{checked:d,onChange:p=>c.mutate(p?"filename":"metadata"),disabled:c.isPending}),r.jsx("span",{className:`text-xs ${d?"text-white":"text-bambu-gray"}`,children:t("virtualPrinter.archiveNameSource.filename")})]})]}),r.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:t("virtualPrinter.archiveNameSource.description")})]})]})})}),r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(pr,{className:"w-5 h-5 text-bambu-green"}),r.jsx("h2",{className:"text-lg font-semibold text-white",children:t("virtualPrinter.list.title")}),r.jsxs("span",{className:"text-sm text-bambu-gray",children:["(",u.length,")"]})]}),r.jsxs(Me,{variant:"primary",onClick:()=>i(!0),children:[r.jsx(ar,{className:"w-4 h-4 mr-1"}),t("virtualPrinter.list.add")]})]}),u.length===0?r.jsx(Ct,{children:r.jsxs(At,{className:"py-8 text-center",children:[r.jsx(pr,{className:"w-12 h-12 text-bambu-gray mx-auto mb-3"}),r.jsx("p",{className:"text-bambu-gray mb-4",children:t("virtualPrinter.list.empty")}),r.jsxs(Me,{variant:"primary",onClick:()=>i(!0),children:[r.jsx(ar,{className:"w-4 h-4 mr-1"}),t("virtualPrinter.list.addFirst")]})]})}):r.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-4 items-start",children:u.map(p=>r.jsx(Xrt,{printer:p,models:m},p.id))}),a&&r.jsx(Qrt,{onClose:()=>i(!1)})]})}function sQ(t){if(t<60)return`${t}s`;const e=Math.floor(t/60);if(e<60)return`${e}m`;const n=Math.floor(e/60),a=e%60;if(n<24)return a?`${n}h ${a}m`:`${n}h`;const i=Math.floor(n/24),s=n%24;return s?`${i}d ${s}h`:`${i}d`}function oQ(t){return t==null?"—":t>=1024?`${(t/1024).toFixed(1)} GB`:`${Math.round(t)} MB`}function Jrt({device:t,onUnregister:e,isDeleting:n}){const{t:a}=kt(),{showToast:i}=rn(),s=t.system_stats,o=s?.memory,l=s?.disk,c=t.online,[d,u]=y.useState(null),[m,p]=y.useState(null),f=async x=>{p(x);try{x==="update"?await Xr.triggerUpdate(t.device_id):await Xr.systemCommand(t.device_id,x),i(a("settings.spoolbuddy.commandQueued"),"success")}catch(_){const N=_ instanceof Error?_.message:a("settings.spoolbuddy.commandError");i(N,"error")}finally{p(null),u(null)}},b=[{key:"update",label:a("settings.spoolbuddy.update"),icon:Yr},{key:"restart_browser",label:a("settings.spoolbuddy.restartBrowser"),icon:yO},{key:"restart_daemon",label:a("settings.spoolbuddy.restartDaemon"),icon:sr},{key:"reboot",label:a("settings.spoolbuddy.reboot"),icon:Mw},{key:"shutdown",label:a("settings.spoolbuddy.shutdown"),icon:wu,variant:"danger"}],w={update:a("settings.spoolbuddy.updateConfirmTitle"),restart_browser:a("settings.spoolbuddy.restartBrowserConfirmTitle"),restart_daemon:a("settings.spoolbuddy.restartDaemonConfirmTitle"),reboot:a("settings.spoolbuddy.rebootConfirmTitle"),shutdown:a("settings.spoolbuddy.shutdownConfirmTitle")},g={update:a("settings.spoolbuddy.updateConfirmBody",{hostname:t.hostname}),restart_browser:a("settings.spoolbuddy.restartBrowserConfirmBody",{hostname:t.hostname}),restart_daemon:a("settings.spoolbuddy.restartDaemonConfirmBody",{hostname:t.hostname}),reboot:a("settings.spoolbuddy.rebootConfirmBody",{hostname:t.hostname}),shutdown:a("settings.spoolbuddy.shutdownConfirmBody",{hostname:t.hostname})};return r.jsxs(Ct,{children:[r.jsx(pn,{children:r.jsxs("div",{className:"flex items-start justify-between gap-3 flex-wrap",children:[r.jsxs("div",{className:"min-w-0",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("h3",{className:"text-base font-semibold text-white truncate",children:t.hostname}),r.jsxs("span",{className:`inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-medium ${c?"bg-green-500/15 text-green-400 border border-green-500/40":"bg-gray-500/15 text-gray-400 border border-gray-500/40"}`,children:[c?r.jsx(Ah,{className:"w-3 h-3"}):r.jsx(mu,{className:"w-3 h-3"}),a(c?"settings.spoolbuddy.online":"settings.spoolbuddy.offline")]})]}),r.jsx("p",{className:"text-xs text-bambu-gray font-mono mt-1 truncate",children:t.device_id})]}),r.jsxs(Me,{variant:"danger",size:"sm",onClick:()=>e(t),disabled:n,"aria-label":a("settings.spoolbuddy.unregister"),children:[r.jsx(Jt,{className:"w-3.5 h-3.5"}),r.jsx("span",{className:"hidden sm:inline",children:a("settings.spoolbuddy.unregister")})]})]})}),r.jsxs(At,{className:"space-y-3",children:[r.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-3 text-xs",children:[r.jsxs("div",{children:[r.jsx("div",{className:"text-bambu-gray",children:a("settings.spoolbuddy.ipAddress")}),r.jsx("div",{className:"text-white font-mono",children:t.ip_address})]}),r.jsxs("div",{children:[r.jsx("div",{className:"text-bambu-gray",children:a("settings.spoolbuddy.firmware")}),r.jsx("div",{className:"text-white",children:t.firmware_version??"—"})]}),r.jsxs("div",{children:[r.jsxs("div",{className:"text-bambu-gray flex items-center gap-1",children:[r.jsx(Zn,{className:"w-3 h-3"}),a("settings.spoolbuddy.lastSeen")]}),r.jsx("div",{className:"text-white",children:t.last_seen?jh(t.last_seen):a("settings.spoolbuddy.never")})]}),r.jsxs("div",{children:[r.jsx("div",{className:"text-bambu-gray",children:a("settings.spoolbuddy.daemonUptime")}),r.jsx("div",{className:"text-white",children:sQ(t.uptime_s)})]})]}),r.jsx("div",{className:"flex flex-wrap gap-2",children:b.map(({key:x,label:_,icon:N,variant:C})=>r.jsxs(Me,{variant:C??"secondary",size:"sm",onClick:()=>u(x),disabled:!c||m!==null,"aria-label":_,children:[m===x?r.jsx(pt,{className:"w-3.5 h-3.5 animate-spin"}):r.jsx(N,{className:"w-3.5 h-3.5"}),r.jsx("span",{children:_})]},x))}),r.jsxs("div",{className:"flex items-center gap-3 text-xs flex-wrap",children:[r.jsxs("span",{className:"flex items-center gap-1 text-bambu-gray",children:[t.nfc_ok?r.jsx(rd,{className:"w-3.5 h-3.5 text-green-400"}):r.jsx(Da,{className:"w-3.5 h-3.5 text-red-400"}),a("settings.spoolbuddy.nfc"),t.nfc_reader_type&&r.jsxs("span",{className:"text-bambu-gray/70",children:["(",t.nfc_reader_type,")"]})]}),r.jsxs("span",{className:"flex items-center gap-1 text-bambu-gray",children:[t.scale_ok?r.jsx(rd,{className:"w-3.5 h-3.5 text-green-400"}):r.jsx(Da,{className:"w-3.5 h-3.5 text-red-400"}),a("settings.spoolbuddy.scale")]})]}),s&&r.jsxs("div",{className:"pt-2 border-t border-bambu-dark-tertiary",children:[r.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-3 text-xs",children:[s.cpu_temp_c!==void 0&&r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(FS,{className:"w-3.5 h-3.5 text-bambu-gray"}),r.jsxs("div",{children:[r.jsx("div",{className:"text-bambu-gray",children:a("settings.spoolbuddy.cpuTemp")}),r.jsxs("div",{className:"text-white",children:[s.cpu_temp_c.toFixed(1),"°C"]})]})]}),o&&o.percent!==void 0&&r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(M0,{className:"w-3.5 h-3.5 text-bambu-gray"}),r.jsxs("div",{children:[r.jsx("div",{className:"text-bambu-gray",children:a("settings.spoolbuddy.memory")}),r.jsxs("div",{className:"text-white",children:[o.percent.toFixed(0),"% (",oQ(o.used_mb)," / ",oQ(o.total_mb),")"]})]})]}),l&&l.percent!==void 0&&r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(ob,{className:"w-3.5 h-3.5 text-bambu-gray"}),r.jsxs("div",{children:[r.jsx("div",{className:"text-bambu-gray",children:a("settings.spoolbuddy.disk")}),r.jsxs("div",{className:"text-white",children:[l.percent.toFixed(0),"% (",l.used_gb?.toFixed(1)," / ",l.total_gb?.toFixed(1)," GB)"]})]})]}),s.system_uptime_s!==void 0&&r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(Zn,{className:"w-3.5 h-3.5 text-bambu-gray"}),r.jsxs("div",{children:[r.jsx("div",{className:"text-bambu-gray",children:a("settings.spoolbuddy.systemUptime")}),r.jsx("div",{className:"text-white",children:sQ(s.system_uptime_s)})]})]})]}),s.os&&r.jsx("div",{className:"mt-3 text-xs text-bambu-gray font-mono truncate",children:[s.os.os,s.os.kernel,s.os.arch,s.os.python&&`Python ${s.os.python}`].filter(Boolean).join(" · ")})]})]}),d&&r.jsx(vn,{variant:d==="shutdown"||d==="reboot"?"danger":"default",title:w[d],message:g[d],confirmText:a("settings.spoolbuddy.commandConfirm"),isLoading:m!==null,onConfirm:()=>f(d),onCancel:()=>u(null)})]})}function eat(){const{t}=kt(),e=en(),{showToast:n}=rn(),[a,i]=y.useState(null),{data:s=[],isLoading:o}=Ve({queryKey:["spoolbuddy-devices"],queryFn:()=>Xr.getDevices(),refetchInterval:15e3}),l=it({mutationFn:d=>Xr.deleteDevice(d),onSuccess:()=>{e.invalidateQueries({queryKey:["spoolbuddy-devices"]}),n(t("settings.spoolbuddy.unregisterSuccess"),"success"),i(null)},onError:d=>{n(d.message||t("settings.spoolbuddy.unregisterError"),"error")}});if(o)return r.jsx(Ct,{children:r.jsx(At,{className:"py-8 flex justify-center",children:r.jsx(pt,{className:"w-6 h-6 animate-spin text-bambu-green"})})});const c=s.length>1;return r.jsxs("div",{className:"space-y-4",children:[r.jsx(Ct,{children:r.jsx(At,{className:"py-3 px-4",children:r.jsxs("div",{className:"flex items-start gap-2 text-xs",children:[r.jsx(Ci,{className:"w-4 h-4 text-blue-400 flex-shrink-0 mt-0.5"}),r.jsxs("div",{className:"text-bambu-gray",children:[r.jsx("p",{className:"text-white font-medium mb-1",children:t("settings.spoolbuddy.infoTitle")}),r.jsx("p",{children:t("settings.spoolbuddy.infoBody")})]})]})})}),c&&r.jsx(Ct,{className:"border-l-4 border-l-yellow-500",children:r.jsx(At,{className:"py-3 px-4",children:r.jsxs("div",{className:"flex items-start gap-2 text-xs",children:[r.jsx(Nn,{className:"w-4 h-4 text-yellow-500 flex-shrink-0 mt-0.5"}),r.jsxs("div",{className:"text-bambu-gray",children:[r.jsx("p",{className:"text-white font-medium mb-1",children:t("settings.spoolbuddy.duplicatesTitle",{count:s.length})}),r.jsx("p",{children:t("settings.spoolbuddy.duplicatesBody")})]})]})})}),s.length===0?r.jsx(Ct,{children:r.jsx(At,{className:"py-8 text-center text-bambu-gray text-sm",children:t("settings.spoolbuddy.empty")})}):r.jsx("div",{className:"space-y-3",children:s.map(d=>r.jsx(Jrt,{device:d,onUnregister:i,isDeleting:l.isPending&&l.variables===d.device_id},d.id))}),a&&r.jsx(vn,{variant:"danger",title:t("settings.spoolbuddy.confirmTitle"),message:t("settings.spoolbuddy.confirmBody",{hostname:a.hostname,deviceId:a.device_id}),confirmText:t("settings.spoolbuddy.unregister"),isLoading:l.isPending,onConfirm:()=>l.mutate(a.device_id),onCancel:()=>i(null)})]})}function sF(t){if(!t)return"-";const e=Xn(t);return e?e.toLocaleString():"-"}function oF({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:r.jsx(wr,{className:"w-3 h-3"}),failed:r.jsx(Da,{className:"w-3 h-3"}),skipped:r.jsx(NT,{className:"w-3 h-3"}),running:r.jsx(pt,{className:"w-3 h-3 animate-spin"})};return r.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)]})}const tat={github:"backup.repoUrlPlaceholderGitHub",gitea:"backup.repoUrlPlaceholderGitea",forgejo:"backup.repoUrlPlaceholderForgejo",gitlab:"backup.repoUrlPlaceholderGitLab"},nat={github:"ghp_xxxxxxxxxxxx",gitea:"your_access_token",forgejo:"your_access_token",gitlab:"glpat-xxxxxxxxxxxx"};function lQ(t){return JSON.stringify(t)}function rat(t,e){if(!e)return t;const n={};for(const a of Object.keys(t))t[a]!==e[a]&&(n[a]=t[a]);return n}function aat(){const t=en(),{showToast:e}=rn(),{t:n}=kt(),[a,i]=y.useState(""),[s,o]=y.useState(""),[l,c]=y.useState("main"),[d,u]=y.useState("github"),[m,p]=y.useState(!1),[f,b]=y.useState("daily"),[w,g]=y.useState(!0),[x,_]=y.useState(!0),[N,C]=y.useState(!1),[P,T]=y.useState(!1),[A,F]=y.useState(!1),[S,E]=y.useState(!1),[U,I]=y.useState(!0),[H,R]=y.useState(!1),[Q,re]=y.useState(!1),[J,de]=y.useState(""),[pe,ue]=y.useState(!1),[X,ae]=y.useState(null),[me,be]=y.useState(null),Ce=y.useRef(null),[$,W]=y.useState(null),[D,j]=y.useState(null),[B,Y]=y.useState(""),{data:O,refetch:ie}=Ve({queryKey:["local-backup-status"],queryFn:se.getLocalBackupStatus,refetchInterval:rt=>rt.state.data?.is_running?1e3:1e4}),{data:z,refetch:G}=Ve({queryKey:["local-backup-files"],queryFn:se.getLocalBackups,refetchInterval:3e4});y.useEffect(()=>{O?.path!==void 0&&Y(O.path)},[O?.path]);const K=it({mutationFn:se.triggerLocalBackup,onSuccess:rt=>{rt.success?e(n("backup.scheduledBackupComplete")):e(rt.message,"error"),ie(),G()},onError:()=>e(n("backup.scheduledBackupFailed"),"error")}),Z=it({mutationFn:rt=>se.deleteLocalBackup(rt),onSuccess:()=>{G(),W(null)}}),oe=it({mutationFn:async rt=>(j(null),re(!0),be(null),de(n("backup.restoring")),se.restoreLocalBackup(rt)),onSuccess:rt=>{re(!1),de(""),rt.success?(be({success:!0,message:rt.message}),e(n("backup.backupRestoredRestart"),"success")):(be({success:!1,message:rt.message}),e(rt.message,"error"))},onError:rt=>{re(!1),de("");const Ot=rt instanceof Error?rt.message:n("backup.failedToRestore");be({success:!1,message:Ot}),e(Ot,"error")}});y.useEffect(()=>{if(H||Q){const Ot=Wt=>(Wt.preventDefault(),Wt.returnValue="A backup operation is in progress. Are you sure you want to leave?",Wt.returnValue);return window.addEventListener("beforeunload",Ot),()=>window.removeEventListener("beforeunload",Ot)}},[H,Q]);const[ee,ge]=y.useState(!1),[ce,le]=y.useState(null),q=y.useRef(null),L=y.useRef(null),ne=y.useRef(null),ye=y.useRef(null),we=y.useRef(""),[Ne,ve]=y.useState(!1),xe=y.useMemo(()=>({repository_url:a,branch:l,provider:d,allow_insecure_http:S,schedule_enabled:m,schedule_type:f,backup_kprofiles:w,backup_cloud_profiles:x,backup_settings:N,backup_spools:P,backup_archives:A,enabled:U}),[a,l,d,S,m,f,w,x,N,P,A,U]),Ee=y.useMemo(()=>lQ(xe),[xe]),{data:ze,isLoading:_e}=Ve({queryKey:["github-backup-config"],queryFn:se.getGitHubBackupConfig}),{data:Oe}=Ve({queryKey:["github-backup-status"],queryFn:se.getGitHubBackupStatus,refetchInterval:rt=>rt.state.data?.is_running?500:1e4}),{data:Ie}=Ve({queryKey:["github-backup-logs"],queryFn:()=>se.getGitHubBackupLogs(20)}),{data:We}=Ve({queryKey:["cloud-status"],queryFn:se.getCloudStatus}),{data:at}=Ve({queryKey:["printers"],queryFn:se.getPrinters}),lt=ef({queries:(at??[]).map(rt=>({queryKey:["printerStatus",rt.id],queryFn:()=>se.getPrinterStatus(rt.id),staleTime:1e4,refetchInterval:3e4}))}),Fe=(at??[]).map((rt,Ot)=>({printer:rt,connected:lt[Ot]?.data?.connected??!1})),tt=Fe.length,Pe=Fe.filter(rt=>rt.connected).length,Ye=tt>0&&Pe===0,Ue=Pe>0&&Pe(ne.current&&clearTimeout(ne.current),ze?(ve(!1),ye.current={repository_url:ze.repository_url,branch:ze.branch,provider:ze.provider??"github",allow_insecure_http:ze.allow_insecure_http??!1,schedule_enabled:ze.schedule_enabled,schedule_type:ze.schedule_type,backup_kprofiles:ze.backup_kprofiles,backup_cloud_profiles:ze.backup_cloud_profiles,backup_settings:ze.backup_settings,backup_spools:ze.backup_spools,backup_archives:ze.backup_archives,enabled:ze.enabled},i(ze.repository_url),c(ze.branch),u(ze.provider??"github"),p(ze.schedule_enabled),b(ze.schedule_type),g(ze.backup_kprofiles),_(ze.backup_cloud_profiles),C(ze.backup_settings),T(ze.backup_spools),F(ze.backup_archives),E(ze.allow_insecure_http??!1),I(ze.enabled),o(""),ne.current=setTimeout(()=>{ve(!0)},100)):(ve(!1),ye.current=null,o("")),()=>{ne.current&&clearTimeout(ne.current)}),[ze]);const fe=y.useCallback(async(rt=!1)=>{if(ze)try{rt&&s?(await se.saveGitHubBackupConfig({...xe,access_token:s}),o(""),e(n("backup.tokenUpdated")),we.current=""):(await se.updateGitHubBackupConfig(rat(xe,ye.current)),e(n("backup.settingsSaved"))),ye.current=xe,t.invalidateQueries({queryKey:["github-backup-config"]}),t.invalidateQueries({queryKey:["github-backup-status"]})}catch(Ot){e(n("backup.failedToSave",{message:Ot.message}),"error")}},[ze,s,xe,t,e,n]),Ae=y.useRef(fe);y.useEffect(()=>{Ae.current=fe},[fe]),y.useEffect(()=>{if(!(!Ne||!ze)&&!(ye.current&&Ee===lQ(ye.current)))return q.current&&clearTimeout(q.current),q.current=setTimeout(()=>{fe(!1)},500),()=>{q.current&&clearTimeout(q.current)}},[Ne,ze,Ee,fe]),y.useEffect(()=>{if(!(!Ne||!ze||!s)&&s!==we.current)return we.current=s,L.current&&clearTimeout(L.current),L.current=setTimeout(()=>{Ae.current(!0)},1e3),()=>{L.current&&clearTimeout(L.current)}},[Ne,s,ze]);const qe=it({mutationFn:rt=>se.saveGitHubBackupConfig(rt),onSuccess:()=>{t.invalidateQueries({queryKey:["github-backup-config"]}),t.invalidateQueries({queryKey:["github-backup-status"]}),e(n("backup.githubBackupEnabled")),o(""),ve(!0)},onError:rt=>{e(n("backup.failedToSave",{message:rt.message}),"error")}}),nt=it({mutationFn:se.triggerGitHubBackup,onSuccess:rt=>{t.invalidateQueries({queryKey:["github-backup-status"]}),t.invalidateQueries({queryKey:["github-backup-logs"]}),rt.success?rt.files_changed>0?e(n("backup.backupCompleteFiles",{count:rt.files_changed})):e(n("backup.backupSkippedNoChanges")):e(n("backup.backupFailed2",{message:rt.message}),"error")},onError:rt=>{e(n("backup.backupFailed2",{message:rt.message}),"error")}}),Qe=it({mutationFn:()=>se.clearGitHubBackupLogs(0),onSuccess:rt=>{t.invalidateQueries({queryKey:["github-backup-logs"]}),e(n("backup.clearedLogs",{count:rt.deleted}))},onError:rt=>{e(n("backup.failedToClearLogs",{message:rt.message}),"error")}}),gt=async()=>{ge(!0),le(null);try{let rt;if(s){if(!a){e(n("backup.enterRepoUrl"),"error"),ge(!1);return}rt=await se.testGitHubConnection(a,s,d)}else if(ze?.has_token)rt=await se.testGitHubStoredConnection();else{e(n("backup.enterRepoAndToken"),"error"),ge(!1);return}le({success:rt.success,message:rt.message})}catch(rt){le({success:!1,message:rt.message})}finally{ge(!1)}},ct=()=>{if(!a){e(n("backup.repoRequired"),"error");return}if(!s){e(n("backup.tokenRequired"),"error");return}qe.mutate({repository_url:a,access_token:s,branch:l,provider:d,allow_insecure_http:S,schedule_enabled:m,schedule_type:f,backup_kprofiles:w,backup_cloud_profiles:x,backup_settings:N,backup_spools:P,backup_archives:A,enabled:U})};return _e?r.jsx("div",{className:"flex items-center justify-center py-12",children:r.jsx(pt,{className:"w-8 h-8 animate-spin text-bambu-green"})}):r.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[r.jsxs("div",{className:"space-y-6",children:[r.jsxs(Ct,{id:"card-backup-github",children:[r.jsx(pn,{children:r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(BF,{className:"w-5 h-5 text-gray-400"}),r.jsx("h2",{className:"text-lg font-semibold text-white",children:n("backup.githubBackup")})]}),ze&&r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:"text-sm text-bambu-gray",children:n("backup.enabled")}),r.jsx(En,{checked:U,onChange:I})]})]})}),r.jsxs(At,{className:"space-y-4",children:[r.jsx("p",{className:"text-sm text-bambu-gray",children:n("backup.githubDescription")}),r.jsxs("div",{children:[r.jsx("label",{htmlFor:"git-provider-select",className:"block text-sm text-bambu-gray mb-1",children:n("backup.provider")}),r.jsxs("select",{id:"git-provider-select",value:d,onChange:rt=>{u(rt.target.value),le(null)},className:"w-full h-10 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[r.jsx("option",{value:"github",children:n("backup.providerGitHub")}),r.jsx("option",{value:"gitlab",children:n("backup.providerGitLab")}),r.jsx("option",{value:"gitea",children:n("backup.providerGitea")}),r.jsx("option",{value:"forgejo",children:n("backup.providerForgejo")})]})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("backup.repositoryUrl")}),r.jsx("input",{type:"text",value:a,onChange:rt=>{i(rt.target.value),le(null)},placeholder:n(tat[d]),className:"w-full h-10 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"}),r.jsxs("label",{className:"flex items-start gap-2 mt-2 cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:S,onChange:rt=>{E(rt.target.checked),le(null)},className:"w-4 h-4 mt-0.5 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),r.jsxs("div",{children:[r.jsx("span",{className:"text-sm text-white",children:n("backup.allowInsecureHttp")}),r.jsx("p",{className:"text-xs text-bambu-gray",children:n("backup.allowInsecureHttpHint")})]})]})]}),r.jsxs("div",{children:[r.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[n("backup.personalAccessToken")," ",ze?.has_token&&r.jsx("span",{className:"text-green-400",children:n("backup.tokenSaved")})]}),r.jsx("input",{type:"password",value:s,onChange:rt=>{o(rt.target.value),le(null)},placeholder:ze?.has_token?n("backup.enterNewToken"):nat[d],className:"w-full h-10 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"}),r.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:n("backup.tokenHint")})]}),r.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("backup.branch")}),r.jsx("input",{type:"text",value:l,onChange:rt=>c(rt.target.value),placeholder:"main",className:"w-full h-10 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("backup.autoBackup")}),r.jsxs("select",{value:m?f:"disabled",onChange:rt=>{rt.target.value==="disabled"?p(!1):(p(!0),b(rt.target.value))},className:"w-full h-10 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[r.jsx("option",{value:"disabled",children:n("backup.manualOnly")}),r.jsx("option",{value:"hourly",children:n("backup.hourly")}),r.jsx("option",{value:"daily",children:n("backup.daily")}),r.jsx("option",{value:"weekly",children:n("backup.weekly")})]})]})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-2",children:n("backup.includeInBackup")}),r.jsxs("div",{className:"space-y-2",children:[r.jsxs("label",{className:`flex items-start gap-2 ${Ye?"cursor-not-allowed opacity-60":"cursor-pointer"}`,children:[r.jsx("input",{type:"checkbox",checked:w,onChange:rt=>g(rt.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:Ye}),r.jsxs("div",{className:"flex-1",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:`text-sm ${Ye?"text-bambu-gray":"text-white"}`,children:n("backup.kProfiles")}),Ye&&r.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:[r.jsx(Nn,{className:"w-3 h-3"}),n("backup.noPrintersConnected")]}),Ue&&r.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:[r.jsx(Nn,{className:"w-3 h-3"}),n("backup.printersConnected",{connected:Pe,total:tt})]})]}),r.jsx("p",{className:"text-xs text-bambu-gray",children:n("backup.kProfilesDescription")})]})]}),r.jsxs("label",{className:`flex items-start gap-2 ${We?.is_authenticated?"cursor-pointer":"cursor-not-allowed opacity-60"}`,children:[r.jsx("input",{type:"checkbox",checked:x,onChange:rt=>_(rt.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:!We?.is_authenticated}),r.jsxs("div",{children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:`text-sm ${We?.is_authenticated?"text-white":"text-bambu-gray"}`,children:n("backup.cloudProfiles")}),!We?.is_authenticated&&r.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:[r.jsx(Nn,{className:"w-3 h-3"}),n("backup.cloudLoginRequiredShort")]})]}),r.jsx("p",{className:"text-xs text-bambu-gray",children:n("backup.cloudProfilesDescription")})]})]}),r.jsxs("label",{className:"flex items-start gap-2 cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:N,onChange:rt=>C(rt.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"}),r.jsxs("div",{children:[r.jsx("span",{className:"text-white text-sm",children:n("backup.appSettings")}),r.jsx("p",{className:"text-xs text-bambu-gray",children:n("backup.appSettingsDescription")})]})]}),r.jsxs("label",{className:"flex items-start gap-2 cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:P,onChange:rt=>T(rt.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"}),r.jsxs("div",{children:[r.jsx("span",{className:"text-white text-sm",children:n("backup.spoolInventory")}),r.jsx("p",{className:"text-xs text-bambu-gray",children:n("backup.spoolInventoryDescription")})]})]}),r.jsxs("label",{className:"flex items-start gap-2 cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:A,onChange:rt=>F(rt.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"}),r.jsxs("div",{children:[r.jsx("span",{className:"text-white text-sm",children:n("backup.printArchives")}),r.jsx("p",{className:"text-xs text-bambu-gray",children:n("backup.printArchivesDescription")})]})]})]})]}),r.jsxs("div",{className:"border-t border-bambu-dark-tertiary pt-4 space-y-3",children:[Oe?.configured&&r.jsxs("div",{className:"flex items-center justify-between text-sm",children:[r.jsx("div",{className:"flex items-center gap-2 text-bambu-gray",children:Oe.last_backup_at?r.jsxs(r.Fragment,{children:[r.jsxs("span",{children:[n("backup.lastBackupAt")," ",jh(Oe.last_backup_at,"system",n)]}),r.jsx(oF,{status:Oe.last_backup_status})]}):r.jsx("span",{children:n("backup.noBackupsYet")})}),Oe.next_scheduled_run&&r.jsxs("span",{className:"text-bambu-gray",children:[r.jsx(Zn,{className:"w-3 h-3 inline mr-1"}),n("backup.next")," ",jh(Oe.next_scheduled_run,"system",n)]})]}),ce&&r.jsxs("div",{className:`text-sm flex items-center gap-1 ${ce.success?"text-green-400":"text-red-400"}`,children:[ce.success?r.jsx(wr,{className:"w-4 h-4"}):r.jsx(Da,{className:"w-4 h-4"}),ce.message]}),r.jsx("div",{className:"flex flex-wrap items-center gap-2",children:Oe?.configured?r.jsx(r.Fragment,{children:nt.isPending||Oe.is_running?r.jsxs("div",{className:"flex items-center gap-2 text-bambu-green",children:[r.jsx(pt,{className:"w-4 h-4 animate-spin"}),r.jsx("span",{className:"text-sm",children:Oe.progress||n("backup.startingBackup")})]}):r.jsxs(r.Fragment,{children:[r.jsxs(Me,{variant:"primary",size:"sm",onClick:()=>nt.mutate(),disabled:!ze?.enabled,children:[r.jsx(fs,{className:"w-4 h-4"}),n("backup.backupNow")]}),r.jsxs(Me,{variant:"secondary",size:"sm",onClick:gt,disabled:ee,children:[ee?r.jsx(pt,{className:"w-4 h-4 animate-spin"}):r.jsx(sr,{className:"w-4 h-4"}),n("backup.test")]})]})}):r.jsxs(r.Fragment,{children:[r.jsxs(Me,{variant:"primary",size:"sm",onClick:ct,disabled:qe.isPending||!a||!s,children:[qe.isPending?r.jsx(pt,{className:"w-4 h-4 animate-spin"}):r.jsx(wr,{className:"w-4 h-4"}),n("backup.enableBackup")]}),r.jsxs(Me,{variant:"secondary",size:"sm",onClick:gt,disabled:ee||!a||!s,children:[ee?r.jsx(pt,{className:"w-4 h-4 animate-spin"}):r.jsx(sr,{className:"w-4 h-4"}),n("backup.testConnection")]})]})})]})]})]}),Ie&&Ie.length>0&&r.jsxs(Ct,{id:"card-backup-history",children:[r.jsx(pn,{children:r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(Aw,{className:"w-5 h-5 text-gray-400"}),r.jsx("h2",{className:"text-lg font-semibold text-white",children:n("backup.history")})]}),r.jsxs(Me,{variant:"ghost",size:"sm",onClick:()=>Qe.mutate(),disabled:Qe.isPending,children:[r.jsx(Jt,{className:"w-4 h-4"}),n("backup.clear")]})]})}),r.jsx(At,{children:r.jsx("div",{className:"overflow-x-auto",children:r.jsxs("table",{className:"w-full text-sm",children:[r.jsx("thead",{children:r.jsxs("tr",{className:"text-bambu-gray border-b border-bambu-dark-tertiary",children:[r.jsx("th",{className:"text-left py-2 px-2",children:n("backup.date")}),r.jsx("th",{className:"text-left py-2 px-2",children:n("backup.status")}),r.jsx("th",{className:"text-left py-2 px-2",children:n("backup.commit")})]})}),r.jsx("tbody",{children:Ie.slice(0,10).map(rt=>r.jsxs("tr",{className:"border-b border-bambu-dark-tertiary/50 hover:bg-bambu-dark-secondary",children:[r.jsx("td",{className:"py-2 px-2 text-white",children:sF(rt.started_at)}),r.jsx("td",{className:"py-2 px-2",children:r.jsx(oF,{status:rt.status})}),r.jsx("td",{className:"py-2 px-2",children:rt.commit_sha?r.jsxs("a",{href:`${ze?.repository_url}/commit/${rt.commit_sha}`,target:"_blank",rel:"noopener noreferrer",className:"text-bambu-green hover:underline inline-flex items-center gap-1",children:[rt.commit_sha.substring(0,7),r.jsx(Rr,{className:"w-3 h-3"})]}):r.jsx("span",{className:"text-bambu-gray",children:"-"})})]},rt.id))})]})})})]})]}),r.jsxs("div",{className:"space-y-6",children:[r.jsxs(Ct,{id:"card-backup-local",children:[r.jsx(pn,{children:r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(hc,{className:"w-5 h-5 text-gray-400"}),r.jsx("h2",{className:"text-lg font-semibold text-white",children:n("backup.localBackup")})]})}),r.jsxs(At,{className:"space-y-4",children:[r.jsx("p",{className:"text-sm text-bambu-gray",children:n("backup.localBackupDescription")}),r.jsxs("div",{className:"flex items-center justify-between py-3 border-b border-bambu-dark-tertiary",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-white",children:n("backup.downloadBackupLabel")}),r.jsx("p",{className:"text-sm text-bambu-gray",children:n("backup.completeBackupZip")})]}),r.jsxs(Me,{variant:"secondary",size:"sm",disabled:H||Q,onClick:async()=>{R(!0),de(n("backup.preparingBackup"));try{de(n("backup.creatingArchive"));const{blob:rt,filename:Ot}=await se.exportBackup();de(n("backup.downloadingFile"));const Wt=URL.createObjectURL(rt),Zt=document.createElement("a");Zt.href=Wt,Zt.download=Ot,Zt.click(),URL.revokeObjectURL(Wt),e(n("backup.backupDownloaded"))}catch(rt){e(n("backup.failedToCreateBackup",{message:rt instanceof Error?rt.message:"Unknown error"}),"error")}finally{R(!1),de("")}},children:[r.jsx(Yr,{className:"w-4 h-4"}),n("backup.download")]})]}),r.jsxs("div",{className:"flex items-center justify-between py-3 border-b border-bambu-dark-tertiary",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-white",children:n("backup.restoreBackup")}),r.jsx("p",{className:"text-sm text-bambu-gray",children:n("backup.restoreDescription")}),r.jsx("p",{className:"text-xs text-bambu-gray-light mt-1",children:n("backup.restoreNote")})]}),r.jsx("input",{ref:Ce,type:"file",accept:".zip",className:"hidden",onChange:rt=>{const Ot=rt.target.files?.[0];Ot&&(ae(Ot),ue(!0)),rt.target.value=""}}),r.jsxs(Me,{variant:"secondary",size:"sm",disabled:Q||H,onClick:()=>Ce.current?.click(),children:[r.jsx(ka,{className:"w-4 h-4"}),n("backup.restore")]})]}),me&&r.jsx("div",{className:`p-3 rounded-lg ${me.success?"bg-green-500/10 border border-green-500/30":"bg-red-500/10 border border-red-500/30"}`,children:r.jsxs("div",{className:"flex items-start gap-2 text-sm",children:[me.success?r.jsx(wr,{className:"w-4 h-4 text-green-400 mt-0.5 flex-shrink-0"}):r.jsx(Da,{className:"w-4 h-4 text-red-400 mt-0.5 flex-shrink-0"}),r.jsxs("div",{className:me.success?"text-green-200":"text-red-200",children:[me.message,me.success&&r.jsx("div",{className:"mt-2",children:r.jsxs(Me,{size:"sm",onClick:()=>window.location.reload(),children:[r.jsx(gs,{className:"w-3 h-3"}),n("backup.reloadNow")]})})]})]})}),r.jsx("div",{className:"p-3 rounded-lg bg-yellow-500/10 border border-yellow-500/30",children:r.jsxs("div",{className:"flex items-start gap-2 text-sm",children:[r.jsx(Nn,{className:"w-4 h-4 text-yellow-400 mt-0.5 flex-shrink-0"}),r.jsxs("div",{className:"text-yellow-200",children:[r.jsx("span",{className:"font-medium",children:n("backup.restoreReplacesAll")})," ",r.jsx("span",{className:"text-yellow-200/70",children:n("backup.restoreReplacesAllDetail")})]})]})})]})]}),r.jsxs(Ct,{id:"card-backup-scheduled",children:[r.jsx(pn,{children:r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(lbe,{className:"w-5 h-5 text-gray-400"}),r.jsx("h2",{className:"text-lg font-semibold text-white",children:n("backup.scheduledBackup")})]}),r.jsx(En,{checked:O?.enabled??!1,onChange:async rt=>{try{await se.updateSettings({local_backup_enabled:rt}),e(n("backup.settingsSaved"))}catch(Ot){e(n("backup.failedToSave",{message:Ot instanceof Error?Ot.message:"Unknown error"}),"error")}ie()}})]})}),r.jsxs(At,{className:"space-y-4",children:[r.jsx("p",{className:"text-sm text-bambu-gray",children:n("backup.scheduledBackupDescription")}),O?.enabled&&r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("backup.frequency")}),r.jsxs("select",{value:O?.schedule??"daily",className:"w-full h-10 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",onChange:async rt=>{try{await se.updateSettings({local_backup_schedule:rt.target.value}),e(n("backup.settingsSaved"))}catch(Ot){e(n("backup.failedToSave",{message:Ot instanceof Error?Ot.message:"Unknown error"}),"error")}ie()},children:[r.jsx("option",{value:"hourly",children:n("backup.hourly")}),r.jsx("option",{value:"daily",children:n("backup.daily")}),r.jsx("option",{value:"weekly",children:n("backup.weekly")})]})]}),(O?.schedule??"daily")!=="hourly"&&r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("backup.backupTime")}),r.jsx("input",{type:"time",value:O?.time??"03:00",className:"w-full h-10 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none [color-scheme:dark]",onChange:async rt=>{try{await se.updateSettings({local_backup_time:rt.target.value}),e(n("backup.settingsSaved"))}catch(Ot){e(n("backup.failedToSave",{message:Ot instanceof Error?Ot.message:"Unknown error"}),"error")}ie()}}),r.jsx("p",{className:"text-xs text-bambu-gray-light mt-1",children:n("backup.utc")})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("backup.retention")}),r.jsx("input",{type:"number",min:1,max:100,value:O?.retention??5,className:"w-full h-10 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",onChange:async rt=>{const Ot=Math.max(1,Math.min(100,parseInt(rt.target.value)||5));try{await se.updateSettings({local_backup_retention:Ot}),e(n("backup.settingsSaved"))}catch(Wt){e(n("backup.failedToSave",{message:Wt instanceof Error?Wt.message:"Unknown error"}),"error")}ie()}}),r.jsx("p",{className:"text-xs text-bambu-gray-light mt-1",children:n("backup.retentionDescription")})]})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("backup.outputPath")}),r.jsx("input",{type:"text",value:B,onChange:rt=>Y(rt.target.value),className:"w-full h-10 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",onBlur:async()=>{try{await se.updateSettings({local_backup_path:B}),e(n("backup.settingsSaved"))}catch(rt){e(n("backup.failedToSave",{message:rt instanceof Error?rt.message:"Unknown error"}),"error")}ie(),G()},onKeyDown:rt=>{rt.key==="Enter"&&rt.target.blur()}}),r.jsx("p",{className:"text-xs text-bambu-gray-light mt-1",children:B?n("backup.outputPathDescription"):r.jsxs(r.Fragment,{children:[n("backup.defaultPathLabel")," ",r.jsx("code",{className:"text-bambu-gray",children:O?.default_path||"..."})]})})]}),r.jsxs("div",{className:"flex items-center justify-between py-3 border-t border-bambu-dark-tertiary",children:[r.jsxs("div",{className:"text-sm",children:[O?.last_backup_at&&r.jsxs("div",{className:"flex items-center gap-2 text-bambu-gray",children:[r.jsxs("span",{children:[n("backup.lastBackup"),":"]}),r.jsx(oF,{status:O.last_status}),r.jsx("span",{children:jh(O.last_backup_at)})]}),O?.next_run&&r.jsxs("div",{className:"text-bambu-gray mt-1",children:[r.jsxs("span",{children:[n("backup.nextBackup"),": "]}),r.jsx("span",{children:sF(O.next_run)})]})]}),r.jsxs(Me,{variant:"secondary",size:"sm",disabled:O?.is_running||K.isPending,onClick:()=>K.mutate(),children:[O?.is_running||K.isPending?r.jsx(pt,{className:"w-4 h-4 animate-spin"}):r.jsx(fs,{className:"w-4 h-4"}),O?.is_running?n("backup.backupRunning"):n("backup.runNow")]})]}),z&&z.length>0&&r.jsxs("div",{className:"border-t border-bambu-dark-tertiary pt-3",children:[r.jsx("h3",{className:"text-sm font-medium text-white mb-2",children:n("backup.backupFiles")}),r.jsx("div",{className:"space-y-1",children:z.map(rt=>r.jsxs("div",{className:"flex items-center justify-between py-1.5 px-2 rounded hover:bg-bambu-dark-tertiary/50 text-sm",children:[r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("span",{className:"text-white truncate block",children:rt.filename}),r.jsxs("span",{className:"text-bambu-gray text-xs",children:[(rt.size/1024/1024).toFixed(1)," MB · ",sF(rt.created_at)]})]}),r.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[r.jsx("button",{className:"text-bambu-gray hover:text-bambu-green p-1",title:n("backup.download"),onClick:async()=>{try{const{blob:Ot,filename:Wt}=await se.downloadLocalBackup(rt.filename),Zt=URL.createObjectURL(Ot),Yt=document.createElement("a");Yt.href=Zt,Yt.download=Wt,Yt.click(),URL.revokeObjectURL(Zt)}catch{e(n("backup.scheduledBackupFailed"),"error")}},children:r.jsx(Yr,{className:"w-3.5 h-3.5"})}),r.jsx("button",{className:"text-bambu-gray hover:text-yellow-400 p-1",title:n("backup.restore"),onClick:()=>j(rt.filename),children:r.jsx(gs,{className:"w-3.5 h-3.5"})}),r.jsx("button",{className:"text-bambu-gray hover:text-red-400 p-1",onClick:()=>W(rt.filename),title:n("backup.deleteBackup"),children:r.jsx(Jt,{className:"w-3.5 h-3.5"})})]})]},rt.filename))})]}),z&&z.length===0&&r.jsx("p",{className:"text-sm text-bambu-gray text-center py-3 border-t border-bambu-dark-tertiary",children:n("backup.noScheduledBackups")})]})]})]})]}),$&&r.jsx(vn,{title:n("backup.deleteBackup"),message:n("backup.deleteBackupConfirm"),confirmText:n("backup.deleteBackup"),variant:"danger",onConfirm:()=>Z.mutate($),onCancel:()=>W(null)}),D&&r.jsx(vn,{title:n("backup.restoreConfirmTitle"),message:n("backup.restoreConfirmMessage",{filename:D}),confirmText:n("backup.restoreConfirmButton"),variant:"danger",onConfirm:()=>oe.mutate(D),onCancel:()=>j(null)}),pe&&X&&r.jsx(vn,{title:n("backup.restoreConfirmTitle"),message:n("backup.restoreConfirmMessage",{filename:X.name}),confirmText:n("backup.restoreConfirmButton"),variant:"danger",onConfirm:async()=>{ue(!1),re(!0),be(null);try{de(n("backup.uploadingFile"));const rt=await se.importBackup(X);be(rt),rt.success?e(n("backup.backupRestoredRestart"),"success"):e(rt.message,"error")}catch(rt){const Ot=rt instanceof Error?rt.message:n("backup.failedToRestore");be({success:!1,message:Ot}),e(Ot,"error")}finally{re(!1),de(""),ae(null)}},onCancel:()=>{ue(!1),ae(null)}}),(H||Q)&&r.jsx("div",{className:"fixed inset-0 bg-black/80 flex items-center justify-center z-[100]",children:r.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:[r.jsx("div",{className:"flex justify-center mb-4",children:r.jsxs("div",{className:"relative",children:[r.jsx("div",{className:"w-16 h-16 border-4 border-bambu-dark-tertiary rounded-full"}),r.jsx("div",{className:"w-16 h-16 border-4 border-bambu-green border-t-transparent rounded-full absolute inset-0 animate-spin"})]})}),r.jsx("h3",{className:"text-xl font-semibold text-white mb-2",children:n(H?"backup.creatingBackup":"backup.restoringBackup")}),r.jsx("p",{className:"text-bambu-gray mb-4",children:J||n(H?"backup.preparing":"backup.processing")}),r.jsx("div",{className:"p-3 rounded-lg bg-yellow-500/10 border border-yellow-500/30",children:r.jsxs("div",{className:"flex items-start gap-2 text-sm",children:[r.jsx(Nn,{className:"w-4 h-4 text-yellow-400 mt-0.5 flex-shrink-0"}),r.jsx("p",{className:"text-yellow-200 text-left",children:n("backup.doNotClosePage")})]})})]})})]})}function iat(){const{t}=kt(),e=en(),{showToast:n}=rn(),[a,i]=y.useState(!1),[s,o]=y.useState(""),[l,c]=y.useState("medium"),[d,u]=y.useState("notify"),[m,p]=y.useState(10),[f,b]=y.useState(null),[w,g]=y.useState(null),[x,_]=y.useState(!1),{data:N}=Ve({queryKey:["settings"],queryFn:se.getSettings}),{data:C,refetch:P}=Ve({queryKey:["obico-status"],queryFn:se.getObicoStatus,refetchInterval:1e4}),{data:T}=Ve({queryKey:["printers"],queryFn:se.getPrinters});y.useEffect(()=>{if(N){i(N.obico_enabled??!1),o(N.obico_ml_url??""),c(N.obico_sensitivity??"medium"),u(N.obico_action??"notify"),p(N.obico_poll_interval??10);try{const E=N.obico_enabled_printers?JSON.parse(N.obico_enabled_printers):null;b(Array.isArray(E)?E:null)}catch{b(null)}_(!0)}},[N]);const A=it({mutationFn:()=>se.updateSettings({obico_enabled:a,obico_ml_url:s,obico_sensitivity:l,obico_action:d,obico_poll_interval:m,obico_enabled_printers:f===null?"":JSON.stringify(f)}),onSuccess:()=>{e.invalidateQueries({queryKey:["settings"]}),e.invalidateQueries({queryKey:["obico-status"]}),n(t("settings.toast.settingsSaved"))}});y.useEffect(()=>{if(!x||!N||!(N.obico_enabled!==a||N.obico_ml_url!==s||N.obico_sensitivity!==l||N.obico_action!==d||N.obico_poll_interval!==m||N.obico_enabled_printers!==(f===null?"":JSON.stringify(f))))return;const U=setTimeout(()=>A.mutate(),500);return()=>clearTimeout(U)},[a,s,l,d,m,f,x]);const F=async()=>{g(null);try{const E=await se.testObicoConnection(s);E.ok?g({ok:!0,message:t("failureDetection.testSuccess")}):g({ok:!1,message:E.error||`HTTP ${E.status_code??"?"} — ${E.body??t("failureDetection.testFailed")}`})}catch(E){g({ok:!1,message:E instanceof Error?E.message:String(E)})}},S=(E,U)=>{if(f===null){const I=T?.map(R=>R.id)??[],H=U?I:I.filter(R=>R!==E);b(H);return}b(U?[...f,E]:f.filter(I=>I!==E))};return r.jsxs("div",{className:"flex flex-col lg:flex-row gap-4 lg:gap-6",children:[r.jsxs("div",{className:"space-y-3 flex-1 lg:max-w-xl",children:[r.jsxs(Ct,{id:"card-fd-ml",children:[r.jsxs(pn,{children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(LZ,{className:"w-5 h-5 text-bambu-green"}),r.jsx("h2",{className:"text-lg font-semibold text-white",children:t("failureDetection.title")})]}),r.jsx(En,{checked:a,onChange:i})]}),r.jsx("p",{className:"text-sm text-bambu-gray mt-2",children:t("failureDetection.description")})]}),r.jsxs(At,{className:"space-y-4",children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:t("failureDetection.mlUrl")}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx("input",{type:"text",value:s,onChange:E=>o(E.target.value),placeholder:"http://192.168.1.10:3333",className:"flex-1 bg-gray-800 border border-gray-700 rounded px-3 py-2 text-white text-sm",disabled:!a}),r.jsx(Me,{onClick:F,disabled:!s||A.isPending,variant:"secondary",children:t("failureDetection.test")})]}),r.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:t("failureDetection.mlUrlHint")}),w&&r.jsxs("div",{className:`flex items-start gap-2 mt-2 text-sm ${w.ok?"text-green-400":"text-red-400"}`,children:[w.ok?r.jsx(_r,{className:"w-4 h-4 mt-0.5"}):r.jsx(Ht,{className:"w-4 h-4 mt-0.5"}),r.jsx("span",{children:w.message})]})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:t("failureDetection.sensitivity")}),r.jsxs("select",{value:l,onChange:E=>c(E.target.value),disabled:!a,className:"w-full bg-gray-800 border border-gray-700 rounded px-3 py-2 text-white text-sm",children:[r.jsx("option",{value:"low",children:t("failureDetection.sensitivityLow")}),r.jsx("option",{value:"medium",children:t("failureDetection.sensitivityMedium")}),r.jsx("option",{value:"high",children:t("failureDetection.sensitivityHigh")})]}),r.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:t("failureDetection.sensitivityHint")})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:t("failureDetection.action")}),r.jsxs("select",{value:d,onChange:E=>u(E.target.value),disabled:!a,className:"w-full bg-gray-800 border border-gray-700 rounded px-3 py-2 text-white text-sm",children:[r.jsx("option",{value:"notify",children:t("failureDetection.actionNotify")}),r.jsx("option",{value:"pause",children:t("failureDetection.actionPause")}),r.jsx("option",{value:"pause_and_off",children:t("failureDetection.actionPauseOff")})]})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:t("failureDetection.pollInterval")}),r.jsx("input",{type:"number",value:m,onChange:E=>p(Math.max(5,Math.min(120,Number(E.target.value)||10))),min:5,max:120,disabled:!a,className:"w-full bg-gray-800 border border-gray-700 rounded px-3 py-2 text-white text-sm"}),r.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:t("failureDetection.pollIntervalHint")})]}),C&&!C.external_url_configured&&a&&r.jsxs("div",{className:"flex items-start gap-2 p-3 bg-amber-900/30 border border-amber-700 rounded text-sm text-amber-200",children:[r.jsx(Nn,{className:"w-4 h-4 mt-0.5 flex-shrink-0"}),r.jsxs("div",{children:[r.jsx("div",{className:"font-medium",children:t("failureDetection.externalUrlMissing")}),r.jsx("div",{className:"text-xs mt-1",children:t("failureDetection.externalUrlHint")})]})]})]})]}),r.jsxs(Ct,{id:"card-fd-perprinter",children:[r.jsxs(pn,{children:[r.jsx("h2",{className:"text-lg font-semibold text-white",children:t("failureDetection.perPrinterTitle")}),r.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:t("failureDetection.perPrinterHint")})]}),r.jsxs(At,{className:"space-y-2",children:[r.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[r.jsx("input",{type:"checkbox",checked:f===null,onChange:E=>b(E.target.checked?null:T?.map(U=>U.id)??[]),disabled:!a}),r.jsx("span",{className:"text-white",children:t("failureDetection.monitorAll")})]}),f!==null&&T&&r.jsx("div",{className:"pl-5 space-y-1 border-l border-gray-700",children:T.map(E=>r.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[r.jsx("input",{type:"checkbox",checked:f.includes(E.id),onChange:U=>S(E.id,U.target.checked),disabled:!a}),r.jsx("span",{className:"text-white",children:E.name})]},E.id))})]})]})]}),r.jsxs("div",{className:"space-y-3 flex-1 lg:max-w-xl",children:[r.jsxs(Ct,{id:"card-fd-status",children:[r.jsx(pn,{children:r.jsx("h2",{className:"text-lg font-semibold text-white",children:t("failureDetection.statusTitle")})}),r.jsx(At,{children:C?r.jsxs("div",{className:"space-y-3 text-sm",children:[r.jsxs("div",{className:"flex justify-between",children:[r.jsx("span",{className:"text-bambu-gray",children:t("failureDetection.serviceRunning")}),r.jsx("span",{className:C.is_running?"text-green-400":"text-red-400",children:C.is_running?t("common.yes"):t("common.no")})]}),r.jsxs("div",{className:"flex justify-between",children:[r.jsx("span",{className:"text-bambu-gray",children:t("failureDetection.thresholds")}),r.jsxs("span",{className:"text-white font-mono",children:[C.thresholds.low.toFixed(2)," / ",C.thresholds.high.toFixed(2)]})]}),C.last_error&&r.jsxs("div",{className:"flex items-start gap-2 text-red-400",children:[r.jsx(Ht,{className:"w-4 h-4 mt-0.5 flex-shrink-0"}),r.jsx("span",{className:"break-words",children:C.last_error})]}),r.jsxs("div",{children:[r.jsx("div",{className:"text-bambu-gray mb-1",children:t("failureDetection.activePrinters")}),Object.keys(C.per_printer).length===0?r.jsx("div",{className:"text-bambu-gray italic text-xs",children:t("failureDetection.noActivePrints")}):r.jsx("div",{className:"space-y-1",children:Object.entries(C.per_printer).map(([E,U])=>{const I=T?.find(R=>String(R.id)===E),H=U.class==="failure"?"text-red-400":U.class==="warning"?"text-amber-400":"text-green-400";return r.jsxs("div",{className:"flex justify-between",children:[r.jsx("span",{className:"text-white",children:I?.name??`Printer ${E}`}),r.jsxs("span",{className:`font-mono ${H}`,children:[U.class," (",U.score.toFixed(3),", ",U.frame_count,"f)"]})]},E)})})]})]}):r.jsxs("div",{className:"flex items-center gap-2 text-bambu-gray",children:[r.jsx(pt,{className:"w-4 h-4 animate-spin"}),r.jsx("span",{children:t("common.loading")})]})})]}),r.jsxs(Ct,{id:"card-fd-history",children:[r.jsx(pn,{children:r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsx("h2",{className:"text-lg font-semibold text-white",children:t("failureDetection.historyTitle")}),r.jsx("button",{onClick:()=>P(),className:"text-xs text-bambu-gray hover:text-white",children:t("common.refresh")})]})}),r.jsx(At,{children:!C||C.history.length===0?r.jsxs("div",{className:"flex items-center gap-2 text-bambu-gray text-sm",children:[r.jsx(Ci,{className:"w-4 h-4"}),r.jsx("span",{children:t("failureDetection.noHistory")})]}):r.jsx("div",{className:"space-y-1 max-h-96 overflow-y-auto text-xs font-mono",children:C.history.map((E,U)=>{const I=T?.find(R=>R.id===E.printer_id),H=E.class==="failure"?"text-red-400":E.class==="warning"?"text-amber-400":"text-bambu-gray";return r.jsxs("div",{className:"flex justify-between gap-2 py-1 border-b border-gray-800",children:[r.jsx("span",{className:"text-bambu-gray",children:new Date(E.timestamp).toLocaleTimeString()}),r.jsx("span",{className:"text-white truncate",children:I?.name??`#${E.printer_id}`}),r.jsxs("span",{className:H,children:[E.class," ",E.score.toFixed(3)]})]},U)})})})]})]})]})}const sat={starttls:587,ssl:465,none:25},oat={587:"starttls",465:"ssl",25:"none"};function lat(){const{t}=kt(),{showToast:e}=rn(),n=en(),[a,i]=y.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]=y.useState(""),{data:l,isLoading:c}=Ve({queryKey:["smtpSettings"],queryFn:()=>se.getSMTPSettings()}),{authEnabled:d}=cr(),{data:u}=Ve({queryKey:["advancedAuthStatus"],queryFn:()=>se.getAdvancedAuthStatus()});y.useEffect(()=>{l&&i({...l,smtp_password:""})},[l]);const m=A=>{i({...a,smtp_security:A,smtp_port:sat[A]})},p=A=>{const F=oat[A];i({...a,smtp_port:A,...F?{smtp_security:F}:{}})},f=A=>{i({...a,smtp_auth_enabled:A,...A?{}:{smtp_username:"",smtp_password:""}})},b=it({mutationFn:A=>se.saveSMTPSettings(A),onSuccess:()=>{n.invalidateQueries({queryKey:["smtpSettings"]}),n.invalidateQueries({queryKey:["advancedAuthStatus"]}),e(t("settings.email.success.settingsSaved"),"success")},onError:A=>{e(A.message,"error")}}),w=it({mutationFn:A=>se.testSMTP(A),onSuccess:A=>{e(A.message,A.success?"success":"error")},onError:A=>{e(A.message,"error")}}),g=it({mutationFn:A=>A?se.enableAdvancedAuth():se.disableAdvancedAuth(),onSuccess:A=>{n.invalidateQueries({queryKey:["advancedAuthStatus"]}),e(A.message,"success")},onError:A=>{e(A.message,"error")}}),x=()=>{if(!a.smtp_host||!a.smtp_from_email){e(t("settings.email.errors.requiredFields"),"error");return}if(a.smtp_auth_enabled&&!a.smtp_username){e(t("settings.email.errors.usernameRequired"),"error");return}b.mutate(a)},_=()=>{if(!s){e(t("settings.email.errors.enterTestEmail"),"error");return}w.mutate({test_recipient:s})},N=()=>{if(!d){e(t("settings.email.errors.enableAuthFirst"),"error");return}if(!u?.advanced_auth_enabled&&!u?.smtp_configured){e(t("settings.email.errors.configureSmtpFirst"),"error");return}g.mutate(!u?.advanced_auth_enabled)};if(c)return r.jsx("div",{className:"flex items-center justify-center p-12",children:r.jsx(pt,{className:"w-8 h-8 animate-spin text-bambu-green"})});const C=u?.advanced_auth_enabled??!1,P="w-full px-3 py-2 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-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white/40 placeholder-bambu-gray/40 cursor-not-allowed";return r.jsxs("div",{className:"space-y-3",children:[r.jsxs(Ct,{id:"card-email-advanced-auth",children:[r.jsx(pn,{children:r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(qm,{className:"w-5 h-5 text-bambu-green"}),r.jsx("h2",{className:"text-lg font-semibold text-white",children:t("settings.email.advancedAuth")||"Advanced Authentication"})]}),r.jsx(Me,{onClick:N,disabled:g.isPending,variant:C?"danger":"primary",children:C?r.jsxs(r.Fragment,{children:[r.jsx(K0,{className:"w-4 h-4"}),t("settings.email.disable")||"Disable"]}):r.jsxs(r.Fragment,{children:[r.jsx(lc,{className:"w-4 h-4"}),t("settings.email.enable")||"Enable"]})})]})}),r.jsx(At,{children:r.jsx("div",{className:"space-y-3",children:C?r.jsx("div",{className:"bg-green-500/10 border border-green-500/30 rounded-lg p-4",children:r.jsxs("div",{className:"flex items-start gap-3",children:[r.jsx(wr,{className:"w-5 h-5 text-green-400 mt-0.5 flex-shrink-0"}),r.jsxs("div",{className:"space-y-2",children:[r.jsx("p",{className:"text-white font-medium",children:t("settings.email.advancedAuthEnabled")||"Advanced Authentication is enabled"}),r.jsxs("ul",{className:"text-sm text-green-300 space-y-1 list-disc list-inside",children:[r.jsx("li",{children:t("settings.email.feature1")||"Passwords are auto-generated and emailed to new users"}),r.jsx("li",{children:t("settings.email.feature2")||"Users can login with username or email"}),r.jsx("li",{children:t("settings.email.feature3")||"Forgot password feature is available"}),r.jsx("li",{children:t("settings.email.feature4")||"Admins can reset user passwords via email"})]})]})]})}):r.jsx("div",{className:"bg-yellow-500/10 border border-yellow-500/30 rounded-lg p-4",children:r.jsxs("div",{className:"flex items-start gap-3",children:[r.jsx(Nn,{className:"w-5 h-5 text-yellow-400 mt-0.5 flex-shrink-0"}),r.jsxs("div",{className:"space-y-2",children:[r.jsx("p",{className:"text-white font-medium",children:t("settings.email.advancedAuthDisabled")||"Advanced Authentication is disabled"}),r.jsx("p",{className:"text-sm text-yellow-300",children:t("settings.email.advancedAuthDisabledDesc")||"Enable advanced authentication to activate email-based features for user management."})]})]})})})})]}),r.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-4",children:[r.jsx("div",{className:"lg:col-span-2",children:r.jsxs(Ct,{id:"card-smtp-config",children:[r.jsx(pn,{children:r.jsx("h2",{className:"text-lg font-semibold text-white",children:t("settings.email.smtpSettings")||"SMTP Configuration"})}),r.jsx(At,{children:r.jsxs("div",{className:"space-y-3",children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm font-medium text-white mb-1",children:t("settings.email.authentication")||"Authentication"}),r.jsxs("select",{value:a.smtp_auth_enabled?"true":"false",onChange:A=>f(A.target.value==="true"),className:P,children:[r.jsx("option",{value:"true",children:t("settings.email.authOptions.enabled")}),r.jsx("option",{value:"false",children:t("settings.email.authOptions.disabled")})]})]}),r.jsxs("div",{className:`grid grid-cols-1 md:grid-cols-2 gap-4 transition-opacity ${a.smtp_auth_enabled?"":"opacity-40 pointer-events-none"}`,children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm font-medium text-white mb-1",children:t("settings.email.username")||"Username"}),r.jsx("input",{type:"text",value:a.smtp_username||"",onChange:A=>i({...a,smtp_username:A.target.value}),placeholder:"your.email@gmail.com",disabled:!a.smtp_auth_enabled,className:a.smtp_auth_enabled?P:T})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm font-medium text-white mb-1",children:t("settings.email.password")||"Password"}),r.jsx("input",{type:"password",value:a.smtp_password||"",onChange:A=>i({...a,smtp_password:A.target.value}),placeholder:l?"••••••••":"App password",disabled:!a.smtp_auth_enabled,className:a.smtp_auth_enabled?P:T})]})]}),r.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[r.jsxs("div",{children:[r.jsxs("label",{className:"block text-sm font-medium text-white mb-1",children:[t("settings.email.smtpHost")||"SMTP Server"," *"]}),r.jsx("input",{type:"text",value:a.smtp_host,onChange:A=>i({...a,smtp_host:A.target.value}),placeholder:"smtp.gmail.com",className:P})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm font-medium text-white mb-1",children:t("settings.email.smtpPort")||"SMTP Port"}),r.jsx("input",{type:"number",value:a.smtp_port,onChange:A=>p(parseInt(A.target.value)||587),placeholder:"587",className:P})]})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm font-medium text-white mb-1",children:t("settings.email.security")||"Security"}),r.jsxs("select",{value:a.smtp_security,onChange:A=>m(A.target.value),className:P,children:[r.jsx("option",{value:"starttls",children:t("settings.email.securityOptions.starttls")}),r.jsx("option",{value:"ssl",children:t("settings.email.securityOptions.ssl")}),r.jsx("option",{value:"none",children:t("settings.email.securityOptions.none")})]})]}),r.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[r.jsxs("div",{children:[r.jsxs("label",{className:"block text-sm font-medium text-white mb-1",children:[t("settings.email.fromEmail")||"From Email"," *"]}),r.jsx("input",{type:"email",value:a.smtp_from_email,onChange:A=>i({...a,smtp_from_email:A.target.value}),placeholder:"your@email.com",className:P})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm font-medium text-white mb-1",children:t("settings.email.fromName")||"From Name"}),r.jsx("input",{type:"text",value:a.smtp_from_name,onChange:A=>i({...a,smtp_from_name:A.target.value}),placeholder:"BamBuddy",className:P})]})]}),r.jsx("div",{className:"flex gap-2",children:r.jsx(Me,{onClick:x,disabled:b.isPending,className:"flex-1",children:b.isPending?r.jsxs(r.Fragment,{children:[r.jsx(pt,{className:"w-4 h-4 animate-spin"}),t("settings.email.saving")||"Saving..."]}):t("settings.email.save")||"Save Settings"})})]})})]})}),r.jsx("div",{children:r.jsxs(Ct,{id:"card-email-test",children:[r.jsx(pn,{children:r.jsx("h2",{className:"text-lg font-semibold text-white",children:t("settings.email.testConnection")||"Test SMTP Connection"})}),r.jsx(At,{children:r.jsxs("div",{className:"space-y-3",children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm font-medium text-white mb-1",children:t("settings.email.testRecipient")||"Test Recipient Email"}),r.jsx("input",{type:"email",value:s,onChange:A=>o(A.target.value),placeholder:"test@example.com",className:P})]}),r.jsx(Me,{onClick:_,disabled:w.isPending,variant:"secondary",children:w.isPending?r.jsxs(r.Fragment,{children:[r.jsx(pt,{className:"w-4 h-4 animate-spin"}),t("settings.email.sending")||"Sending..."]}):r.jsxs(r.Fragment,{children:[r.jsx(DS,{className:"w-4 h-4"}),t("settings.email.sendTest")||"Send Test Email"]})})]})})]})})]})]})}const cat={starttls:"389",ldaps:"636"};function dat(){const{t}=kt(),{showToast:e}=rn(),n=en(),{authEnabled:a}=cr(),[i,s]=y.useState({ldap_server_url:"",ldap_bind_dn:"",ldap_bind_password:"",ldap_search_base:"",ldap_user_filter:"(sAMAccountName={username})",ldap_security:"starttls",ldap_group_mapping:"",ldap_auto_provision:!1,ldap_default_group:""}),{data:o,isLoading:l}=Ve({queryKey:["settings"],queryFn:()=>se.getSettings()}),{data:c}=Ve({queryKey:["ldapStatus"],queryFn:()=>se.getLDAPStatus()}),{data:d=[]}=Ve({queryKey:["groups"],queryFn:()=>se.getGroups()});y.useEffect(()=>{o&&s({ldap_server_url:o.ldap_server_url||"",ldap_bind_dn:o.ldap_bind_dn||"",ldap_bind_password:"",ldap_search_base:o.ldap_search_base||"",ldap_user_filter:o.ldap_user_filter||"(sAMAccountName={username})",ldap_security:o.ldap_security||"starttls",ldap_group_mapping:o.ldap_group_mapping||"",ldap_auto_provision:o.ldap_auto_provision??!1,ldap_default_group:o.ldap_default_group||""})},[o]);const u=it({mutationFn:x=>se.updateSettings(x),onSuccess:()=>{n.invalidateQueries({queryKey:["settings"]}),n.invalidateQueries({queryKey:["ldapStatus"]}),e(t("settings.ldap.settingsSaved")||"LDAP settings saved","success")},onError:x=>{e(x.message,"error")}}),m=it({mutationFn:x=>se.updateSettings({ldap_enabled:x}),onSuccess:()=>{n.invalidateQueries({queryKey:["settings"]}),n.invalidateQueries({queryKey:["ldapStatus"]}),e(c?.ldap_enabled?t("settings.ldap.disabled")||"LDAP authentication disabled":t("settings.ldap.enabled")||"LDAP authentication enabled","success")},onError:x=>{e(x.message,"error")}}),p=it({mutationFn:()=>se.testLDAP(),onSuccess:x=>{e(x.message,x.success?"success":"error")},onError:x=>{e(x.message,"error")}}),f=()=>{if(!i.ldap_server_url){e(t("settings.ldap.errors.serverRequired")||"LDAP server URL is required","error");return}if(!i.ldap_search_base){e(t("settings.ldap.errors.searchBaseRequired")||"Search base DN is required","error");return}const x={ldap_server_url:i.ldap_server_url,ldap_bind_dn:i.ldap_bind_dn,ldap_search_base:i.ldap_search_base,ldap_user_filter:i.ldap_user_filter,ldap_security:i.ldap_security,ldap_group_mapping:i.ldap_group_mapping,ldap_auto_provision:i.ldap_auto_provision,ldap_default_group:i.ldap_default_group};i.ldap_bind_password&&(x.ldap_bind_password=i.ldap_bind_password),u.mutate(x)},b=()=>{if(!a){e(t("settings.ldap.errors.enableAuthFirst")||"Enable authentication first","error");return}if(!c?.ldap_enabled&&!c?.ldap_configured){e(t("settings.ldap.errors.configureLdapFirst")||"Save LDAP settings first","error");return}m.mutate(!c?.ldap_enabled)};if(l)return r.jsx("div",{className:"flex items-center justify-center p-12",children:r.jsx(pt,{className:"w-8 h-8 animate-spin text-bambu-green"})});const w=c?.ldap_enabled??!1,g="w-full px-3 py-2 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";return r.jsxs("div",{className:"space-y-3",children:[r.jsxs(Ct,{id:"card-ldap-toggle",children:[r.jsx(pn,{children:r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(Sl,{className:"w-5 h-5 text-bambu-green"}),r.jsx("h2",{className:"text-lg font-semibold text-white",children:t("settings.ldap.title")||"LDAP Authentication"})]}),r.jsx(Me,{onClick:b,disabled:m.isPending,variant:w?"danger":"primary",children:w?r.jsxs(r.Fragment,{children:[r.jsx(K0,{className:"w-4 h-4"}),t("common.disable")||"Disable"]}):r.jsxs(r.Fragment,{children:[r.jsx(lc,{className:"w-4 h-4"}),t("common.enable")||"Enable"]})})]})}),r.jsx(At,{children:w?r.jsx("div",{className:"bg-green-500/10 border border-green-500/30 rounded-lg p-4",children:r.jsxs("div",{className:"flex items-start gap-3",children:[r.jsx(wr,{className:"w-5 h-5 text-green-400 mt-0.5 flex-shrink-0"}),r.jsxs("div",{className:"space-y-2",children:[r.jsx("p",{className:"text-white font-medium",children:t("settings.ldap.enabledDesc")||"LDAP authentication is enabled"}),r.jsxs("ul",{className:"text-sm text-green-300 space-y-1 list-disc list-inside",children:[r.jsx("li",{children:t("settings.ldap.feature1")||"Users can login with LDAP credentials"}),r.jsx("li",{children:t("settings.ldap.feature2")||"Local admin account remains as fallback"}),r.jsx("li",{children:t("settings.ldap.feature3")||"LDAP groups are mapped to BamBuddy groups on login"})]})]})]})}):r.jsx("div",{className:"bg-yellow-500/10 border border-yellow-500/30 rounded-lg p-4",children:r.jsxs("div",{className:"flex items-start gap-3",children:[r.jsx(Nn,{className:"w-5 h-5 text-yellow-400 mt-0.5 flex-shrink-0"}),r.jsxs("div",{children:[r.jsx("p",{className:"text-white font-medium",children:t("settings.ldap.disabledDesc")||"LDAP authentication is disabled"}),r.jsx("p",{className:"text-sm text-yellow-300 mt-1",children:t("settings.ldap.disabledHint")||"Configure and save LDAP settings below, then enable."})]})]})})})]}),r.jsxs(Ct,{id:"card-ldap-server",children:[r.jsx(pn,{children:r.jsx("h2",{className:"text-lg font-semibold text-white",children:t("settings.ldap.serverConfig")||"LDAP Server Configuration"})}),r.jsx(At,{children:r.jsxs("div",{className:"space-y-3",children:[r.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-3",children:[r.jsxs("div",{className:"md:col-span-2",children:[r.jsx("label",{className:"block text-sm font-medium text-bambu-gray mb-1",children:t("settings.ldap.serverUrl")||"Server URL"}),r.jsx("input",{type:"text",className:g,placeholder:"ldaps://ldap.example.com:636",value:i.ldap_server_url,onChange:x=>s({...i,ldap_server_url:x.target.value})}),r.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:t("settings.ldap.serverUrlHint")||"Use ldaps:// for SSL or ldap:// with StartTLS"})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm font-medium text-bambu-gray mb-1",children:t("settings.ldap.security")||"Security"}),r.jsx("div",{className:"flex gap-2",children:["starttls","ldaps"].map(x=>r.jsx("button",{onClick:()=>s({...i,ldap_security:x}),className:`flex-1 px-2 py-2 rounded-lg text-sm font-medium transition-colors ${i.ldap_security===x?"bg-bambu-green text-black":"bg-bambu-dark-secondary text-bambu-gray hover:text-white border border-bambu-dark-tertiary"}`,children:x==="starttls"?"StartTLS":"LDAPS"},x))}),r.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:t("settings.ldap.securityHint")||`Default port: ${cat[i.ldap_security]}`})]})]}),r.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm font-medium text-bambu-gray mb-1",children:t("settings.ldap.bindDn")||"Bind DN (Service Account)"}),r.jsx("input",{type:"text",className:g,placeholder:"cn=service-account,ou=service,dc=example,dc=com",value:i.ldap_bind_dn,onChange:x=>s({...i,ldap_bind_dn:x.target.value})})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm font-medium text-bambu-gray mb-1",children:t("settings.ldap.bindPassword")||"Bind Password"}),r.jsx("input",{type:"password",className:g,placeholder:o?.ldap_bind_dn?"••••••••":"",value:i.ldap_bind_password,onChange:x=>s({...i,ldap_bind_password:x.target.value})})]})]}),r.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm font-medium text-bambu-gray mb-1",children:t("settings.ldap.searchBase")||"Search Base DN"}),r.jsx("input",{type:"text",className:g,placeholder:"ou=users,dc=example,dc=com",value:i.ldap_search_base,onChange:x=>s({...i,ldap_search_base:x.target.value})})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm font-medium text-bambu-gray mb-1",children:t("settings.ldap.userFilter")||"User Search Filter"}),r.jsx("input",{type:"text",className:g,placeholder:"(sAMAccountName={username})",value:i.ldap_user_filter,onChange:x=>s({...i,ldap_user_filter:x.target.value})})]})]}),r.jsx(o5,{summary:r.jsx("span",{className:"text-sm font-medium text-bambu-gray",children:t("settings.ldap.advanced")||"Advanced"}),className:"border-t border-bambu-dark-tertiary pt-3",summaryClassName:"py-1",children:r.jsxs("div",{className:"space-y-3",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm font-medium text-white",children:t("settings.ldap.autoProvision")||"Auto-provision users"}),r.jsx("p",{className:"text-xs text-bambu-gray mt-0.5",children:t("settings.ldap.autoProvisionHint")||"Automatically create a BamBuddy account on first LDAP login"})]}),r.jsx("button",{onClick:()=>s({...i,ldap_auto_provision:!i.ldap_auto_provision}),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors flex-shrink-0 ${i.ldap_auto_provision?"bg-bambu-green":"bg-bambu-dark-tertiary"}`,children:r.jsx("span",{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${i.ldap_auto_provision?"translate-x-6":"translate-x-1"}`})})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm font-medium text-bambu-gray mb-1",children:t("settings.ldap.defaultGroup")||"Default group"}),r.jsxs("select",{className:g,value:i.ldap_default_group,onChange:x=>s({...i,ldap_default_group:x.target.value}),children:[r.jsx("option",{value:"",children:t("settings.ldap.defaultGroupNone")||"— None (reject login) —"}),d.map(x=>r.jsx("option",{value:x.name,children:x.name},x.id))]}),r.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:t("settings.ldap.defaultGroupHint")||"Fallback group assigned when an LDAP user authenticates but is not listed in any mapped group. Leave empty to leave unmapped users without permissions."})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm font-medium text-bambu-gray mb-1",children:t("settings.ldap.groupMapping")||"Group Mapping (JSON)"}),r.jsx("textarea",{className:`${g} font-mono text-sm`,rows:4,placeholder:`{ +`);ye=ve.pop()||"";for(const xe of ve)if(xe.startsWith("data: "))try{const Ee=JSON.parse(xe.slice(6));Ee.type==="progress"?ue({fetched:Ee.total_fetched,total:Ee.total_available}):Ee.type==="complete"?Ee.added===0?e(t("settings.colorCatalog.syncUpToDate",{count:Ee.total_fetched}),"success"):e(t("settings.colorCatalog.syncComplete",{added:Ee.added,skipped:Ee.skipped}),"success"):Ee.type==="error"&&e(`${t("settings.colorCatalog.syncError")}: ${Ee.error}`,"error")}catch{}}await Ce()}catch{e(t("settings.colorCatalog.syncFailed"),"error")}finally{de(!1),ue(null)}},K=ce=>{R(le=>{const q=new Set(le);return q.has(ce)?q.delete(ce):q.add(ce),q})},Z=()=>{H.size===W.length?R(new Set):R(new Set(W.map(ce=>ce.id)))},oe=async()=>{if(re(!1),H.size!==0)try{const ce=await se.bulkDeleteColorEntries([...H]);a(le=>le.filter(q=>!H.has(q.id))),R(new Set),e(t("settings.colorCatalog.bulkDeleted",{count:ce.deleted}),"success")}catch{e(t("settings.colorCatalog.bulkDeleteFailed"),"error")}},ee=()=>{const ce=n.map(({manufacturer:ne,color_name:ye,hex_color:we,material:Ne,extra_colors:ve,effect_type:xe})=>({manufacturer:ne,color_name:ye,hex_color:we,material:Ne,extra_colors:ve,effect_type:xe})),le=new Blob([JSON.stringify(ce,null,2)],{type:"application/json"}),q=URL.createObjectURL(le),L=document.createElement("a");L.href=q,L.download="color-catalog.json",document.body.appendChild(L),L.click(),document.body.removeChild(L),URL.revokeObjectURL(q),e(t("settings.colorCatalog.exported",{count:n.length}),"success")},ge=async ce=>{const le=ce.target.files?.[0];if(le){try{const q=await le.text(),L=JSON.parse(q);if(!Array.isArray(L))throw new Error("Invalid format");let ne=0,ye=0;for(const we of L){if(!we.manufacturer||!we.color_name||!we.hex_color){ye++;continue}if(n.some(ve=>ve.manufacturer.toLowerCase()===we.manufacturer.toLowerCase()&&ve.color_name.toLowerCase()===we.color_name.toLowerCase()&&(ve.material||"").toLowerCase()===(we.material||"").toLowerCase())){ye++;continue}try{const ve=await se.addColorEntry({manufacturer:we.manufacturer,color_name:we.color_name,hex_color:we.hex_color,material:we.material||null,extra_colors:we.extra_colors||null,effect_type:we.effect_type||null});a(xe=>[...xe,ve].sort((Ee,ze)=>Ee.manufacturer.localeCompare(ze.manufacturer)||(Ee.material||"").localeCompare(ze.material||"")||Ee.color_name.localeCompare(ze.color_name))),ne++}catch{ye++}}e(t("settings.colorCatalog.imported",{added:ne,skipped:ye}),"success")}catch{e(t("settings.colorCatalog.importFailed"),"error")}u.current&&(u.current.value="")}};return r.jsxs(Ct,{id:"card-color-catalog",children:[r.jsxs(pn,{children:[r.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[r.jsx(jS,{className:"w-5 h-5 text-bambu-gray"}),r.jsx("h2",{className:"text-lg font-semibold text-white",children:t("settings.colorCatalog.title")}),r.jsxs("span",{className:"text-sm text-bambu-gray",children:["(",n.length,")"]})]}),r.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[r.jsxs("button",{onClick:ee,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:[r.jsx(Yr,{className:"w-4 h-4"}),r.jsx("span",{className:"hidden sm:inline",children:t("common.export")})]}),r.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:[r.jsx(ka,{className:"w-4 h-4"}),r.jsx("span",{className:"hidden sm:inline",children:t("common.import")})]}),r.jsx("input",{ref:u,type:"file",accept:".json",className:"hidden",onChange:ge}),r.jsxs("button",{onClick:G,disabled:J,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:[J?r.jsx(pt,{className:"w-4 h-4 animate-spin"}):r.jsx(Hh,{className:"w-4 h-4"}),r.jsx("span",{className:"hidden sm:inline",children:J?pe?`${Math.min(pe.fetched,pe.total)} / ${pe.total}`:t("settings.colorCatalog.starting"):t("settings.colorCatalog.sync")})]}),r.jsxs("button",{onClick:()=>be(!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:[r.jsx(gs,{className:"w-4 h-4"}),r.jsx("span",{className:"hidden sm:inline",children:t("common.reset")})]}),r.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:[r.jsx(ar,{className:"w-4 h-4"}),r.jsx("span",{className:"hidden sm:inline",children:t("common.add")})]})]}),H.size>0&&r.jsxs("div",{className:"flex items-center gap-2 mt-2 px-3 py-2 bg-red-500/10 border border-red-500/30 rounded-lg",children:[r.jsx("span",{className:"text-sm text-red-400",children:t("settings.colorCatalog.selectedCount",{count:H.size})}),r.jsxs("button",{onClick:()=>re(!0),className:"ml-auto px-3 py-1.5 text-sm bg-red-500 text-white rounded-lg hover:bg-red-600 transition-colors flex items-center gap-1.5",children:[r.jsx(Jt,{className:"w-4 h-4"}),t("settings.colorCatalog.deleteSelected")]}),r.jsx("button",{onClick:()=>R(new Set),className:"px-3 py-1.5 text-sm text-bambu-gray hover:text-white transition-colors",children:t("common.cancel")})]})]}),r.jsxs(At,{className:"space-y-4",children:[r.jsx("p",{className:"text-sm text-bambu-gray",children:t("settings.colorCatalog.description")}),r.jsxs("div",{className:"flex gap-2 flex-wrap",children:[r.jsxs("div",{className:"relative flex-1 min-w-[200px]",children:[r.jsx(Sr,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray"}),r.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:ce=>l(ce.target.value)})]}),r.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:ce=>d(ce.target.value),children:[r.jsx("option",{value:"",children:t("settings.colorCatalog.allManufacturers")}),$.map(ce=>r.jsx("option",{value:ce,children:ce},ce))]})]}),m&&r.jsxs("div",{className:"p-4 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary",children:[r.jsx("h3",{className:"text-sm font-medium text-white mb-3",children:t("settings.colorCatalog.addNewColor")}),r.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-5 gap-2 items-end",children:[r.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:w,onChange:ce=>g(ce.target.value)}),r.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:x,onChange:ce=>_(ce.target.value)}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("input",{type:"color",className:"w-20 h-10 rounded cursor-pointer border border-bambu-dark-tertiary",value:N,onChange:ce=>C(ce.target.value)}),r.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:ce=>C(ce.target.value)})]}),r.jsxs("div",{className:"flex items-center gap-1",children:[r.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:P,onChange:ce=>T(ce.target.value)}),r.jsxs("button",{onClick:j,disabled:U,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:[U?r.jsx(pt,{className:"w-4 h-4 animate-spin"}):r.jsx(_r,{className:"w-4 h-4"}),t("common.add")]}),r.jsx("button",{onClick:()=>{p(!1),D()},className:"p-2 ml-2 rounded-lg text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary",children:r.jsx(Ht,{className:"w-4 h-4"})})]})]}),r.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-2 mt-2",children:[r.jsx("input",{type:"text",className:"px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white text-sm font-mono placeholder-bambu-gray focus:border-bambu-green focus:outline-none",placeholder:t("inventory.extraColorsPlaceholder"),value:A,onChange:ce=>F(ce.target.value)}),r.jsx("select",{className:"px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none",value:S,onChange:ce=>E(ce.target.value),children:WI.map(ce=>r.jsx("option",{value:ce.value,children:t(ce.labelKey)},ce.value||"none"))})]})]}),(o||c)&&r.jsx("div",{className:"text-xs text-bambu-gray",children:t("settings.colorCatalog.showing",{filtered:W.length,total:n.length})}),i?r.jsxs("div",{className:"flex items-center justify-center py-8 text-bambu-gray",children:[r.jsx(pt,{className:"w-5 h-5 animate-spin mr-2"}),t("common.loading")]}):r.jsx("div",{className:"max-h-[600px] overflow-auto border border-bambu-dark-tertiary rounded-lg",children:r.jsxs("table",{className:"w-full text-sm",children:[r.jsx("thead",{className:"bg-bambu-dark sticky top-0",children:r.jsxs("tr",{children:[r.jsx("th",{className:"px-2 py-2 w-10",children:r.jsx("input",{type:"checkbox",checked:W.length>0&&H.size===W.length,onChange:Z,className:"w-4 h-4 accent-bambu-green cursor-pointer"})}),r.jsx("th",{className:"px-3 py-2 text-left text-bambu-gray font-medium w-12"}),r.jsx("th",{className:"px-3 py-2 text-left text-bambu-gray font-medium",children:t("settings.colorCatalog.manufacturer")}),r.jsx("th",{className:"px-3 py-2 text-left text-bambu-gray font-medium",children:t("inventory.material")}),r.jsx("th",{className:"px-3 py-2 text-left text-bambu-gray font-medium",children:t("settings.colorCatalog.colorName")}),r.jsx("th",{className:"px-3 py-2 text-left text-bambu-gray font-medium w-24",children:t("settings.colorCatalog.hex")}),r.jsx("th",{className:"px-3 py-2 w-16"})]})}),r.jsx("tbody",{children:W.length===0?r.jsx("tr",{children:r.jsx("td",{colSpan:7,className:"px-3 py-8 text-center text-bambu-gray",children:t(o||c?"settings.colorCatalog.noMatch":"settings.colorCatalog.empty")})}):W.map(ce=>r.jsxs(y.Fragment,{children:[r.jsx("tr",{className:`border-t border-bambu-dark-tertiary hover:bg-bambu-dark ${H.has(ce.id)?"bg-bambu-dark":""}`,children:f===ce.id?r.jsxs(r.Fragment,{children:[r.jsx("td",{className:"px-2 py-2",children:r.jsx("input",{type:"checkbox",checked:H.has(ce.id),onChange:()=>K(ce.id),className:"w-4 h-4 accent-bambu-green cursor-pointer"})}),r.jsx("td",{className:"px-3 py-2",children:r.jsx("input",{type:"color",className:"w-8 h-8 rounded cursor-pointer border border-bambu-dark-tertiary",value:N,onChange:le=>C(le.target.value)})}),r.jsx("td",{className:"px-3 py-2",children:r.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:w,onChange:le=>g(le.target.value)})}),r.jsx("td",{className:"px-3 py-2",children:r.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:P,onChange:le=>T(le.target.value)})}),r.jsx("td",{className:"px-3 py-2",children:r.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:x,onChange:le=>_(le.target.value)})}),r.jsx("td",{className:"px-3 py-2",children:r.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:le=>C(le.target.value)})}),r.jsx("td",{className:"px-3 py-2",children:r.jsxs("div",{className:"flex justify-end gap-1",children:[r.jsx("button",{onClick:()=>O(ce.id),disabled:U,className:"p-1.5 rounded hover:bg-green-500/20 text-green-500",children:U?r.jsx(pt,{className:"w-4 h-4 animate-spin"}):r.jsx(_r,{className:"w-4 h-4"})}),r.jsx("button",{onClick:Y,className:"p-1.5 rounded hover:bg-bambu-dark-tertiary text-bambu-gray",children:r.jsx(Ht,{className:"w-4 h-4"})})]})})]}):r.jsxs(r.Fragment,{children:[r.jsx("td",{className:"px-2 py-2",children:r.jsx("input",{type:"checkbox",checked:H.has(ce.id),onChange:()=>K(ce.id),className:"w-4 h-4 accent-bambu-green cursor-pointer"})}),r.jsx("td",{className:"px-3 py-2",children:r.jsx(rU,{rgba:ce.hex_color.replace(/^#/,"")+(ce.hex_color.length===7?"FF":""),extraColors:ce.extra_colors,effectType:ce.effect_type,className:"w-8 h-8",shape:"square",title:ce.hex_color,effectSize:"table"})}),r.jsx("td",{className:"px-3 py-2 text-white",children:ce.manufacturer}),r.jsx("td",{className:"px-3 py-2 text-bambu-gray",children:ce.material||"-"}),r.jsx("td",{className:"px-3 py-2 text-white",children:ce.color_name}),r.jsx("td",{className:"px-3 py-2 font-mono text-xs text-bambu-gray",children:ce.hex_color}),r.jsx("td",{className:"px-3 py-2",children:r.jsxs("div",{className:"flex justify-end gap-1",children:[r.jsx("button",{onClick:()=>B(ce),className:"p-1.5 rounded hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white",children:r.jsx(oi,{className:"w-4 h-4"})}),r.jsx("button",{onClick:()=>ae(ce),className:"p-1.5 rounded bg-red-500/10 hover:bg-red-500/20 text-red-500",children:r.jsx(Jt,{className:"w-4 h-4"})})]})})]})}),f===ce.id&&r.jsxs("tr",{className:"border-t border-bambu-dark-tertiary/50 bg-bambu-dark",children:[r.jsx("td",{colSpan:2}),r.jsx("td",{className:"px-3 py-2",colSpan:2,children:r.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 font-mono focus:border-bambu-green focus:outline-none",placeholder:t("inventory.extraColorsPlaceholder"),value:A,onChange:le=>F(le.target.value)})}),r.jsx("td",{className:"px-3 py-2",colSpan:2,children:r.jsx("select",{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:S,onChange:le=>E(le.target.value),children:WI.map(le=>r.jsx("option",{value:le.value,children:t(le.labelKey)},le.value||"none"))})}),r.jsx("td",{})]})]},ce.id))})]})})]}),X&&r.jsx(vn,{title:t("settings.colorCatalog.deleteColor"),message:t("settings.colorCatalog.deleteConfirm",{name:`${X.manufacturer} - ${X.color_name}`}),confirmText:t("common.delete"),variant:"danger",onConfirm:ie,onCancel:()=>ae(null)}),Q&&r.jsx(vn,{title:t("settings.colorCatalog.deleteSelected"),message:t("settings.colorCatalog.bulkDeleteConfirm",{count:H.size}),confirmText:t("common.delete"),variant:"danger",onConfirm:oe,onCancel:()=>re(!1)}),me&&r.jsx(vn,{title:t("settings.colorCatalog.resetCatalog"),message:t("settings.colorCatalog.resetConfirm"),confirmText:t("common.reset"),variant:"danger",onConfirm:z,onCancel:()=>be(!1)})]})}function Krt({link:t,onClose:e}){const{t:n}=kt(),a=en(),i=!!t,s=y.useRef(null),[o,l]=y.useState(t?.name||""),[c,d]=y.useState(t?.url||""),[u,m]=y.useState(t?.icon||"link"),[p,f]=y.useState(t?.open_in_new_tab||!1),[b,w]=y.useState(!!t?.custom_icon),[g,x]=y.useState(t?.custom_icon?se.getExternalLinkIconUrl(t.id):null),[_,N]=y.useState(null),[C,P]=y.useState(null);y.useEffect(()=>{const H=R=>{R.key==="Escape"&&e()};return window.addEventListener("keydown",H),()=>window.removeEventListener("keydown",H)},[e]);const T=it({mutationFn:async H=>{const R=await se.createExternalLink(H);return _?await se.uploadExternalLinkIcon(R.id,_):R},onSuccess:()=>{a.invalidateQueries({queryKey:["external-links"]}),e()},onError:H=>{P(H.message)}}),A=it({mutationFn:async H=>{let R=await se.updateExternalLink(t.id,H);return _?R=await se.uploadExternalLinkIcon(t.id,_):!b&&t?.custom_icon&&(R=await se.deleteExternalLinkIcon(t.id)),R},onSuccess:()=>{a.invalidateQueries({queryKey:["external-links"]}),e()},onError:H=>{P(H.message)}}),F=H=>{const R=H.target.files?.[0];if(R){if(!["image/png","image/jpeg","image/gif","image/svg+xml","image/webp","image/x-icon"].includes(R.type)){P("Please select a valid image file (PNG, JPG, GIF, SVG, WebP, or ICO)");return}if(R.size>1024*1024){P("Image file must be less than 1MB");return}N(R),w(!0);const re=new FileReader;re.onload=J=>{x(J.target?.result)},re.readAsDataURL(R)}},S=()=>{N(null),x(null),w(!1),s.current&&(s.current.value="")},E=H=>{if(H.preventDefault(),P(null),!o.trim()){P("Name is required");return}if(!c.trim()){P("URL is required");return}if(!c.startsWith("http://")&&!c.startsWith("https://")){P("URL must start with http:// or https://");return}const R={name:o.trim(),url:c.trim(),icon:u,open_in_new_tab:p};i?A.mutate(R):T.mutate(R)},U=T.isPending||A.isPending,I=CT(u);return r.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",onClick:e,children:r.jsxs("div",{className:"bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-md",onClick:H=>H.stopPropagation(),children:[r.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary",children:[r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx("div",{className:"p-2 rounded-full bg-bambu-green/20 text-bambu-green",children:b&&g?r.jsx("img",{src:g,alt:"",className:"w-5 h-5 rounded"}):r.jsx(I,{className:"w-5 h-5"})}),r.jsx("h2",{className:"text-lg font-semibold text-white",children:i?"Edit Link":"Add External Link"})]}),r.jsx("button",{onClick:e,className:"text-bambu-gray hover:text-white transition-colors",children:r.jsx(Ht,{className:"w-5 h-5"})})]}),r.jsxs("form",{onSubmit:E,className:"p-6 space-y-4",children:[C&&r.jsx("div",{className:"p-3 bg-red-500/20 border border-red-500/50 rounded-lg text-sm text-red-400",children:C}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Name *"}),r.jsx("input",{type:"text",value:o,onChange:H=>l(H.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"})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"URL *"}),r.jsx("input",{type:"text",value:c,onChange:H=>d(H.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"})]}),r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsx("label",{className:"text-sm text-bambu-gray",children:n("externalLinks.openInNewTab")}),r.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:r.jsx("span",{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${p?"translate-x-6":"translate-x-1"}`})})]}),r.jsxs("div",{className:"space-y-3",children:[r.jsx("label",{className:"block text-sm text-bambu-gray",children:"Icon"}),r.jsxs("div",{className:"p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary",children:[r.jsxs("div",{className:"flex items-center justify-between mb-2",children:[r.jsx("span",{className:"text-sm text-white",children:"Custom Icon"}),r.jsx("input",{ref:s,type:"file",accept:"image/png,image/jpeg,image/gif,image/svg+xml,image/webp,image/x-icon",className:"hidden",onChange:F}),b&&g?r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("img",{src:g,alt:"Custom icon",className:"w-8 h-8 rounded border border-bambu-dark-tertiary"}),r.jsx("button",{type:"button",onClick:S,className:"p-1 text-red-400 hover:text-red-300 transition-colors",title:"Remove custom icon",children:r.jsx(Jt,{className:"w-4 h-4"})})]}):r.jsxs(Me,{type:"button",variant:"secondary",size:"sm",onClick:()=>s.current?.click(),children:[r.jsx(ka,{className:"w-4 h-4"}),"Upload"]})]}),r.jsx("p",{className:"text-xs text-bambu-gray",children:"PNG, JPG, GIF, SVG, WebP, or ICO. Max 1MB."})]}),!b&&r.jsxs("div",{children:[r.jsx("span",{className:"text-sm text-bambu-gray block mb-2",children:"Or choose a preset icon"}),r.jsx(Sve,{value:u,onChange:m})]})]}),r.jsxs("div",{className:"flex gap-3 pt-2",children:[r.jsx(Me,{type:"button",variant:"secondary",onClick:e,className:"flex-1",children:"Cancel"}),r.jsxs(Me,{type:"submit",disabled:U,className:"flex-1",children:[U?r.jsx(pt,{className:"w-4 h-4 animate-spin"}):r.jsx(us,{className:"w-4 h-4"}),i?"Save":"Add"]})]})]})]})})}function Yrt(){const{t}=kt(),e=en(),[n,a]=y.useState(!1),[i,s]=y.useState(null),[o,l]=y.useState(null),[c,d]=y.useState(null),{data:u,isLoading:m}=Ve({queryKey:["external-links"],queryFn:se.getExternalLinks}),p=it({mutationFn:N=>se.deleteExternalLink(N),onSuccess:()=>{e.invalidateQueries({queryKey:["external-links"]})}}),f=it({mutationFn:N=>se.reorderExternalLinks(N),onSuccess:()=>{e.invalidateQueries({queryKey:["external-links"]})}}),b=(N,C)=>{d(C),N.dataTransfer.effectAllowed="move"},w=N=>{N.preventDefault(),N.dataTransfer.dropEffect="move"},g=(N,C)=>{if(N.preventDefault(),c===null||c===C||!u)return;const P=u.map(S=>S.id),T=P.indexOf(c),A=P.indexOf(C);if(T===-1||A===-1)return;const F=[...P];F.splice(T,1),F.splice(A,0,c),f.mutate(F),d(null)},x=N=>{l(N)},_=()=>{o&&(p.mutate(o.id),l(null))};return r.jsxs(r.Fragment,{children:[r.jsxs(Ct,{id:"card-sidebar-links",children:[r.jsx(pn,{children:r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(Th,{className:"w-5 h-5 text-bambu-green"}),r.jsx("h2",{className:"text-lg font-semibold text-white",children:"Sidebar Links"})]}),r.jsxs(Me,{size:"sm",onClick:()=>a(!0),children:[r.jsx(ar,{className:"w-4 h-4"}),"Add Link"]})]})}),r.jsxs(At,{children:[r.jsx("p",{className:"text-sm text-bambu-gray mb-4",children:"Add external links to the sidebar navigation. Drag to reorder."}),m?r.jsx("div",{className:"flex justify-center py-8",children:r.jsx(pt,{className:"w-6 h-6 text-bambu-green animate-spin"})}):u&&u.length>0?r.jsx("div",{className:"space-y-2",children:u.map(N=>{const C=CT(N.icon);return r.jsxs("div",{draggable:!0,onDragStart:P=>b(P,N.id),onDragOver:w,onDrop:P=>g(P,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:[r.jsx(Ph,{className:"w-6 h-6 md:w-4 md:h-4 text-bambu-gray cursor-grab flex-shrink-0"}),r.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark-tertiary text-bambu-gray",children:r.jsx(C,{className:"w-4 h-4"})}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:"text-white font-medium truncate",children:N.name}),r.jsx(Rr,{className:"w-3 h-3 text-bambu-gray flex-shrink-0"})]}),r.jsx("span",{className:"text-sm text-bambu-gray truncate block",children:N.url})]}),r.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[r.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:r.jsx(oi,{className:"w-4 h-4"})}),r.jsx("button",{onClick:()=>x(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:r.jsx(Jt,{className:"w-4 h-4"})})]})]},N.id)})}):r.jsxs("div",{className:"text-center py-8 text-bambu-gray",children:[r.jsx(Th,{className:"w-8 h-8 mx-auto mb-2 opacity-50"}),r.jsx("p",{children:t("externalLinks.noLinksConfigured")}),r.jsx("p",{className:"text-sm",children:'Click "Add Link" to add one'})]})]})]}),(n||i)&&r.jsx(Krt,{link:i,onClose:()=>{a(!1),s(null)}}),o&&r.jsx(vn,{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 iF={immediate:"archive",review:"review",print_queue:"queue",proxy:"proxy"};function Xrt({printer:t,models:e}){const{t:n}=kt(),a=en(),{showToast:i}=rn(),[s,o]=y.useState(!0),[l,c]=y.useState(t.enabled),[d,u]=y.useState(t.name),[m,p]=y.useState(""),[f,b]=y.useState(t.mode==="queue"?"review":t.mode),[w,g]=y.useState(t.target_printer_id),[x,_]=y.useState(t.bind_ip||""),[N,C]=y.useState(t.remote_interface_ip||""),[P,T]=y.useState(t.model||""),[A,F]=y.useState(t.auto_dispatch??!0),[S,E]=y.useState(t.queue_force_color_match??!1),[U,I]=y.useState(t.tailscale_disabled??!0),[H,R]=y.useState(!1),[Q,re]=y.useState(null),[J,de]=y.useState(!1),[pe,ue]=y.useState(!1),{data:X}=Ve({queryKey:["tailscale-status"],queryFn:X0.getTailscaleStatus,enabled:!U,staleTime:6e4}),ae=X?.available?X.fqdn:"",me=X?.available?X.tailscale_ips?.[0]??"":"",be=async ee=>{ee.stopPropagation();const ge=ae;if(!ge)return;let ce=!1;if(navigator.clipboard&&window.isSecureContext)try{await navigator.clipboard.writeText(ge),ce=!0}catch{}if(!ce){const le=document.createElement("textarea");le.value=ge,le.style.position="fixed",le.style.opacity="0",document.body.appendChild(le);try{le.select(),ce=document.execCommand("copy")}catch{ce=!1}finally{le.parentNode&&le.parentNode.removeChild(le)}}ce?(ue(!0),i(n("printers.copied")),setTimeout(()=>ue(!1),2e3)):i(n("virtualPrinter.toast.copyFailed"),"error")};y.useEffect(()=>{Q||(c(t.enabled),b(t.mode==="queue"?"review":t.mode),u(t.name),g(t.target_printer_id),_(t.bind_ip||""),C(t.remote_interface_ip||""),T(t.model||""),F(t.auto_dispatch??!0),E(t.queue_force_color_match??!1),I(t.tailscale_disabled??!0))},[t,Q]);const{data:Ce}=Ve({queryKey:["printers"],queryFn:se.getPrinters}),{data:$}=Ve({queryKey:["network-interfaces"],queryFn:()=>se.getNetworkInterfaces().then(ee=>ee.interfaces)}),W=it({mutationFn:ee=>X0.update(t.id,ee),onSuccess:()=>{a.invalidateQueries({queryKey:["virtual-printers"]}),i(n("virtualPrinter.toast.updated")),re(null)},onError:ee=>{i(ee.message||n("virtualPrinter.toast.failedToUpdate"),"error"),c(t.enabled),b(t.mode==="queue"?"review":t.mode),g(t.target_printer_id),_(t.bind_ip||""),I(t.tailscale_disabled??!0),re(null)}}),D=it({mutationFn:()=>X0.remove(t.id),onSuccess:()=>{a.invalidateQueries({queryKey:["virtual-printers"]}),i(n("virtualPrinter.toast.deleted")),de(!1)},onError:ee=>{i(ee.message||n("virtualPrinter.toast.failedToDelete"),"error"),de(!1)}}),j=ee=>{ee.stopPropagation();const ge=!l;if(ge){if(!x){i(n("virtualPrinter.toast.bindIpRequired"),"error");return}if(f==="proxy"){if(!w){i(n("virtualPrinter.toast.targetPrinterRequired"),"error");return}}else if(!m&&!t.access_code_set){i(n("virtualPrinter.toast.accessCodeRequired"),"error");return}}c(ge),re("toggle"),W.mutate({enabled:ge})},B=()=>{d.trim()&&(re("name"),W.mutate({name:d.trim()}))},Y=()=>{if(!m){i(n("virtualPrinter.toast.accessCodeEmpty"),"error");return}if(m.length!==8){i(n("virtualPrinter.toast.accessCodeLength"),"error");return}re("accessCode"),W.mutate({access_code:m}),p("")},O=ee=>{b(ee),re("mode"),W.mutate({mode:ee})},ie=ee=>{T(ee),re("model"),W.mutate({model:ee})},z=ee=>{g(ee),re("targetPrinter"),W.mutate({target_printer_id:ee})},G=ee=>{C(ee),re("remoteInterface"),W.mutate({remote_interface_ip:ee})},K=t.status?.running||!1,Z=n(`virtualPrinter.mode.${iF[f]||"archive"}`),oe=Ce?.find(ee=>ee.id===w)?.name;return r.jsxs(r.Fragment,{children:[r.jsxs(Ct,{children:[r.jsxs("div",{className:"px-4 py-3 flex items-center gap-3 cursor-pointer select-none",onClick:()=>o(!s),children:[r.jsx("button",{className:"text-bambu-gray flex-shrink-0",children:s?r.jsx(Ln,{className:"w-4 h-4"}):r.jsx(Va,{className:"w-4 h-4"})}),r.jsx("span",{className:`w-2 h-2 rounded-full flex-shrink-0 ${K?"bg-green-400 animate-pulse":"bg-gray-500"}`}),r.jsx("span",{className:"text-white font-medium truncate",children:t.name}),r.jsx("span",{className:"text-xs text-bambu-gray flex-shrink-0",children:Z}),t.model_name&&r.jsx("span",{className:"text-xs text-bambu-gray flex-shrink-0",children:t.model_name}),oe&&r.jsxs("span",{className:"text-xs text-bambu-gray flex-shrink-0 truncate",children:[f==="proxy"&&r.jsx(zF,{className:"w-3 h-3 inline mr-1"}),oe]}),x&&r.jsx("span",{className:"text-[10px] text-bambu-gray flex-shrink-0 font-mono",children:x}),N&&r.jsx("span",{className:"text-[10px] text-bambu-gray flex-shrink-0 font-mono",children:N}),r.jsx("div",{className:"ml-auto flex items-center gap-2 flex-shrink-0",onClick:ee=>ee.stopPropagation(),children:r.jsx("button",{onClick:j,disabled:Q==="toggle",className:`relative w-10 h-5 rounded-full transition-colors ${l?"bg-bambu-green":"bg-bambu-dark-tertiary"} ${Q==="toggle"?"opacity-50":""}`,children:r.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&&r.jsxs(At,{className:"pt-0 space-y-4",children:[r.jsx("div",{className:"border-t border-bambu-dark-tertiary"}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("input",{type:"text",value:d,onChange:ee=>u(ee.target.value),onBlur:B,onKeyDown:ee=>ee.key==="Enter"&&B(),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"}),r.jsx("button",{onClick:()=>de(!0),className:"p-1.5 text-bambu-gray hover:text-red-400 transition-colors flex-shrink-0",title:n("common.delete"),children:r.jsx(Jt,{className:"w-4 h-4"})})]}),r.jsxs("div",{className:"flex items-center gap-2 -mt-2",children:[ae&&r.jsxs("span",{className:"flex items-center gap-1 text-green-400/70 min-w-0",children:[r.jsx(Ew,{className:"w-3.5 h-3.5 flex-shrink-0"}),r.jsx("span",{className:"font-mono text-xs truncate",children:me?`${me} (${ae})`:ae}),r.jsx("button",{onClick:be,className:"p-0.5 rounded hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white transition-colors flex-shrink-0",title:n(pe?"printers.copied":"printers.copyToClipboard"),children:pe?r.jsx(_r,{className:"w-3.5 h-3.5 text-bambu-green"}):r.jsx(Mi,{className:"w-3.5 h-3.5"})})]}),r.jsx("span",{className:"text-xs text-bambu-gray font-mono ml-auto flex-shrink-0",children:t.serial})]}),r.jsxs("div",{children:[r.jsx("div",{className:"text-white text-sm font-medium mb-2",children:n("virtualPrinter.mode.title")}),r.jsx("div",{className:"grid grid-cols-2 gap-2",children:["immediate","review","print_queue","proxy"].map(ee=>r.jsxs("button",{onClick:()=>O(ee),disabled:Q==="mode",className:`p-2 rounded-lg border text-left transition-colors ${f===ee?ee==="proxy"?"border-blue-500 bg-blue-500/10":"border-bambu-green bg-bambu-green/10":"border-bambu-dark-tertiary hover:border-bambu-gray"}`,children:[r.jsxs("div",{className:"flex items-center gap-1.5 text-white text-xs font-medium",children:[ee==="proxy"&&r.jsx(zF,{className:"w-3 h-3"}),n(`virtualPrinter.mode.${iF[ee]}`)]}),r.jsx("div",{className:"text-[10px] text-bambu-gray",children:n(`virtualPrinter.mode.${iF[ee]}Desc`)})]},ee))})]}),f==="print_queue"&&r.jsx("div",{className:"pt-2 border-t border-bambu-dark-tertiary",children:r.jsxs("div",{className:"flex items-center justify-between gap-3",children:[r.jsxs("div",{className:"min-w-0",children:[r.jsx("div",{className:"text-white text-sm font-medium",children:n("virtualPrinter.autoDispatch.title")}),r.jsx("div",{className:"text-[10px] text-bambu-gray",children:n("virtualPrinter.autoDispatch.description")})]}),r.jsx("button",{onClick:()=>{const ee=!A;F(ee),re("autoDispatch"),W.mutate({auto_dispatch:ee})},disabled:Q==="autoDispatch",className:`relative w-10 h-5 rounded-full transition-colors flex-shrink-0 ${A?"bg-bambu-green":"bg-bambu-dark-tertiary"} ${Q==="autoDispatch"?"opacity-50":""}`,children:r.jsx("span",{className:`absolute top-0.5 left-0.5 w-4 h-4 bg-white rounded-full transition-transform ${A?"translate-x-5":""}`})})]})}),f==="print_queue"&&r.jsx("div",{className:"pt-2 border-t border-bambu-dark-tertiary",children:r.jsxs("div",{className:"flex items-center justify-between gap-3",children:[r.jsxs("div",{className:"min-w-0",children:[r.jsx("div",{className:"text-white text-sm font-medium",children:n("virtualPrinter.queueForceColorMatch.title")}),r.jsx("div",{className:"text-[10px] text-bambu-gray",children:n("virtualPrinter.queueForceColorMatch.description")})]}),r.jsx("button",{onClick:()=>{const ee=!S;E(ee),re("queueForceColorMatch"),W.mutate({queue_force_color_match:ee})},disabled:Q==="queueForceColorMatch",className:`relative w-10 h-5 rounded-full transition-colors flex-shrink-0 ${S?"bg-bambu-green":"bg-bambu-dark-tertiary"} ${Q==="queueForceColorMatch"?"opacity-50":""}`,children:r.jsx("span",{className:`absolute top-0.5 left-0.5 w-4 h-4 bg-white rounded-full transition-transform ${S?"translate-x-5":""}`})})]})}),r.jsx("div",{className:"pt-2 border-t border-bambu-dark-tertiary",children:r.jsxs("div",{className:"flex items-center justify-between gap-3",children:[r.jsxs("div",{className:"min-w-0",children:[r.jsx("div",{className:"text-white text-sm font-medium",children:n("virtualPrinter.tailscaleDisabled.title")}),r.jsx("div",{className:"text-[10px] text-bambu-gray",children:n("virtualPrinter.tailscaleDisabled.description")})]}),r.jsx("button",{onClick:()=>{const ee=!U;I(ee),re("tailscaleDisabled"),W.mutate({tailscale_disabled:ee})},disabled:Q==="tailscaleDisabled",className:`relative w-10 h-5 rounded-full transition-colors shrink-0 ${U?"bg-bambu-dark-tertiary":"bg-bambu-green"} ${Q==="tailscaleDisabled"?"opacity-50":""}`,children:r.jsx("span",{className:`absolute top-0.5 left-0.5 w-4 h-4 bg-white rounded-full transition-transform ${U?"":"translate-x-5"}`})})]})}),f!=="proxy"&&r.jsxs("div",{className:"pt-2 border-t border-bambu-dark-tertiary",children:[r.jsx("div",{className:"text-white text-sm font-medium mb-1",children:n("virtualPrinter.model.title")}),r.jsx("p",{className:"text-xs text-bambu-gray mb-2",children:n("virtualPrinter.model.description")}),r.jsxs("div",{className:"relative",children:[r.jsx("select",{value:P,onChange:ee=>ie(ee.target.value),disabled:Q==="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(([ee,ge])=>r.jsxs("option",{value:ee,children:[ge," (",ee,")"]},ee))}),r.jsx(Ln,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]})]}),f==="proxy"&&r.jsx("div",{className:"pt-2 border-t border-bambu-dark-tertiary",children:r.jsxs("div",{className:"flex items-start gap-2 p-2 rounded bg-blue-500/10 border border-blue-500/30",children:[r.jsx(Ci,{className:"w-4 h-4 text-blue-400 flex-shrink-0 mt-0.5"}),r.jsx("p",{className:"text-xs text-bambu-gray",children:n("virtualPrinter.proxy.accessCodeHint")})]})}),f!=="proxy"&&r.jsxs("div",{className:"pt-2 border-t border-bambu-dark-tertiary",children:[r.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[r.jsx("div",{className:"text-white text-sm font-medium",children:n("virtualPrinter.accessCode.title")}),t.access_code_set?r.jsxs("span",{className:"flex items-center gap-1 text-xs text-green-400",children:[r.jsx(_r,{className:"w-3 h-3"}),n("virtualPrinter.accessCode.isSet")]}):r.jsxs("span",{className:"flex items-center gap-1 text-xs text-yellow-400",children:[r.jsx(Nn,{className:"w-3 h-3"}),n("virtualPrinter.accessCode.notSet")]})]}),r.jsxs("div",{className:"flex gap-2",children:[r.jsxs("div",{className:"relative flex-1",children:[r.jsx("input",{type:H?"text":"password",value:m,onChange:ee=>p(ee.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"}),r.jsx("button",{onClick:()=>R(!H),className:"absolute right-2 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white",children:H?r.jsx(sb,{className:"w-4 h-4"}):r.jsx(Dl,{className:"w-4 h-4"})})]}),r.jsx(Me,{onClick:Y,disabled:!m||Q==="accessCode",variant:"primary",children:Q==="accessCode"?r.jsx(pt,{className:"w-4 h-4 animate-spin"}):n("common.save")})]}),m&&r.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:r.jsx("span",{className:m.length===8?"text-green-400":"text-yellow-400",children:n("virtualPrinter.accessCode.charCount",{count:m.length})})})]}),r.jsxs("div",{className:"pt-2 border-t border-bambu-dark-tertiary",children:[r.jsx("div",{className:"text-white text-sm font-medium mb-2",children:n("virtualPrinter.targetPrinter.title")}),r.jsxs("div",{className:"relative",children:[r.jsxs("select",{value:w??"",onChange:ee=>{const ge=parseInt(ee.target.value,10);isNaN(ge)||z(ge)},disabled:Q==="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:[r.jsx("option",{value:"",children:n("virtualPrinter.targetPrinter.placeholder")}),Ce?.map(ee=>r.jsxs("option",{value:ee.id,children:[ee.name," (",ee.ip_address,")"]},ee.id))]}),r.jsx(Ln,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]})]}),r.jsxs("div",{className:"pt-2 border-t border-bambu-dark-tertiary",children:[r.jsx("div",{className:"text-white text-sm font-medium mb-1",children:n("virtualPrinter.bindIp.title")}),r.jsxs("div",{className:"relative",children:[r.jsxs("select",{value:x,onChange:ee=>{_(ee.target.value),re("bindIp"),W.mutate({bind_ip:ee.target.value})},disabled:Q==="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:[r.jsx("option",{value:"",children:n("virtualPrinter.bindIp.placeholder")}),$?.map(ee=>r.jsxs("option",{value:ee.ip,children:[ee.name," (",ee.ip,")",ee.is_alias?" [alias]":""," - ",ee.subnet]},ee.ip))]}),r.jsx(Ln,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}),r.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:n("virtualPrinter.bindIp.hint")})]}),r.jsxs("div",{className:"pt-2 border-t border-bambu-dark-tertiary",children:[r.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[r.jsx("div",{className:"text-white text-sm font-medium",children:n("virtualPrinter.remoteInterface.title")}),N?r.jsx("span",{className:"flex items-center gap-1 text-xs text-green-400",children:r.jsx(_r,{className:"w-3 h-3"})}):r.jsx("span",{className:"flex items-center gap-1 text-xs text-bambu-gray",title:n("virtualPrinter.remoteInterface.optional"),children:r.jsx(Ci,{className:"w-3 h-3"})})]}),r.jsxs("div",{className:"relative",children:[r.jsxs("select",{value:N,onChange:ee=>G(ee.target.value),disabled:Q==="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:[r.jsx("option",{value:"",children:n("virtualPrinter.remoteInterface.placeholder")}),$?.map(ee=>r.jsxs("option",{value:ee.ip,children:[ee.name," (",ee.ip,") - ",ee.subnet]},ee.ip))]}),r.jsx(Ln,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]})]})]})]}),J&&r.jsx(vn,{title:n("virtualPrinter.deleteConfirm.title"),message:n("virtualPrinter.deleteConfirm.message",{name:t.name}),variant:"danger",confirmText:n("common.delete"),isLoading:D.isPending,onConfirm:()=>D.mutate(),onCancel:()=>de(!1)})]})}const iQ={immediate:"archive",review:"review",print_queue:"queue",proxy:"proxy"};function Qrt({onClose:t}){const{t:e}=kt(),n=en(),{showToast:a}=rn(),[i,s]=y.useState(""),[o,l]=y.useState("immediate"),[c,d]=y.useState(null),{data:u}=Ve({queryKey:["printers"],queryFn:se.getPrinters}),m=it({mutationFn:()=>X0.create({name:i.trim()||"Bambuddy",mode:o,target_printer_id:o==="proxy"?c??void 0:void 0}),onSuccess:()=>{n.invalidateQueries({queryKey:["virtual-printers"]}),a(e("virtualPrinter.toast.created")),t()},onError:p=>{a(p.message||e("virtualPrinter.toast.failedToCreate"),"error")}});return r.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",onClick:t,children:r.jsx(Ct,{className:"w-full max-w-md",onClick:p=>p.stopPropagation(),children:r.jsxs(At,{className:"p-6 space-y-4",children:[r.jsx("h3",{className:"text-lg font-semibold text-white",children:e("virtualPrinter.addDialog.title")}),r.jsxs("div",{children:[r.jsx("label",{className:"text-sm text-white font-medium block mb-1",children:e("virtualPrinter.addDialog.name")}),r.jsx("input",{type:"text",value:i,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})]}),r.jsxs("div",{children:[r.jsx("label",{className:"text-sm text-white font-medium block mb-1",children:e("virtualPrinter.mode.title")}),r.jsx("div",{className:"grid grid-cols-2 gap-2",children:["immediate","review","print_queue","proxy"].map(p=>r.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:[r.jsxs("div",{className:"flex items-center gap-1.5 text-white text-xs font-medium",children:[p==="proxy"&&r.jsx(zF,{className:"w-3 h-3"}),e(`virtualPrinter.mode.${iQ[p]}`)]}),r.jsx("div",{className:"text-[10px] text-bambu-gray",children:e(`virtualPrinter.mode.${iQ[p]}Desc`)})]},p))})]}),o==="proxy"&&r.jsxs("div",{children:[r.jsx("label",{className:"text-sm text-white font-medium block mb-1",children:e("virtualPrinter.targetPrinter.title")}),r.jsxs("div",{className:"relative",children:[r.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:[r.jsx("option",{value:"",children:e("virtualPrinter.targetPrinter.placeholder")}),u?.map(p=>r.jsxs("option",{value:p.id,children:[p.name," (",p.ip_address,")"]},p.id))]}),r.jsx(Ln,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]})]}),r.jsx("p",{className:"text-xs text-bambu-gray",children:e("virtualPrinter.addDialog.hint")}),r.jsxs("div",{className:"flex gap-3 pt-2",children:[r.jsx(Me,{variant:"secondary",onClick:t,className:"flex-1",disabled:m.isPending,children:e("common.cancel")}),r.jsx(Me,{variant:"primary",onClick:()=>m.mutate(),className:"flex-1",disabled:m.isPending,children:m.isPending?r.jsx(pt,{className:"w-4 h-4 animate-spin"}):e("virtualPrinter.addDialog.create")})]})]})})})}function Zrt(){const{t}=kt(),e=en(),{showToast:n}=rn(),[a,i]=y.useState(!1),{data:s,isLoading:o}=Ve({queryKey:["virtual-printers"],queryFn:X0.list,refetchInterval:1e4}),{data:l}=Ve({queryKey:["virtual-printer-settings"],queryFn:WF.getSettings}),c=it({mutationFn:p=>WF.updateSettings({archive_name_source:p}),onSuccess:()=>{e.invalidateQueries({queryKey:["virtual-printer-settings"]}),n(t("virtualPrinter.toast.updated"))},onError:p=>{n(p.message||t("virtualPrinter.toast.failedToUpdate"),"error")}}),d=l?.archive_name_source==="filename";if(o)return r.jsx(Ct,{children:r.jsx(At,{className:"py-8 flex justify-center",children:r.jsx(pt,{className:"w-6 h-6 animate-spin text-bambu-green"})})});const u=s?.printers||[],m=s?.models||{};return r.jsxs("div",{className:"space-y-4",children:[r.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-4 items-stretch",children:[r.jsx(Ct,{className:"border-l-4 border-l-yellow-500",children:r.jsx(At,{className:"py-3 px-4",children:r.jsxs("div",{className:"flex items-start gap-2",children:[r.jsx(Nn,{className:"w-4 h-4 text-yellow-500 flex-shrink-0 mt-0.5"}),r.jsxs("div",{className:"text-xs",children:[r.jsx("p",{className:"text-white font-medium",children:t("virtualPrinter.setupRequired.title")}),r.jsx("p",{className:"text-bambu-gray mt-1",children:t("virtualPrinter.setupRequired.description")}),r.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:[r.jsx(Rr,{className:"w-3 h-3"}),t("virtualPrinter.setupRequired.readGuide")]})]})]})})}),r.jsx(Ct,{className:"lg:col-span-2",children:r.jsx(At,{className:"py-3 px-4",children:r.jsxs("div",{className:"flex items-start gap-2",children:[r.jsx(Ci,{className:"w-4 h-4 text-blue-400 flex-shrink-0 mt-0.5"}),r.jsxs("div",{className:"text-xs text-bambu-gray",children:[r.jsx("p",{className:"text-white font-medium mb-1",children:t("virtualPrinter.howItWorks.title")}),r.jsxs("ul",{className:"space-y-1 list-disc list-inside",children:[r.jsx("li",{children:t("virtualPrinter.howItWorks.step1")}),r.jsx("li",{children:t("virtualPrinter.howItWorks.step2")}),r.jsx("li",{children:t("virtualPrinter.howItWorks.step3")})]})]})]})})})]}),r.jsx(Ct,{children:r.jsx(At,{className:"py-3 px-4",children:r.jsxs("div",{className:"flex items-start gap-3",children:[r.jsx(Bs,{className:"w-4 h-4 text-bambu-green flex-shrink-0 mt-1"}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsxs("div",{className:"flex items-center justify-between gap-3",children:[r.jsx("p",{className:"text-sm text-white font-medium",children:t("virtualPrinter.archiveNameSource.title")}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:`text-xs ${d?"text-bambu-gray":"text-white"}`,children:t("virtualPrinter.archiveNameSource.metadata")}),r.jsx(En,{checked:d,onChange:p=>c.mutate(p?"filename":"metadata"),disabled:c.isPending}),r.jsx("span",{className:`text-xs ${d?"text-white":"text-bambu-gray"}`,children:t("virtualPrinter.archiveNameSource.filename")})]})]}),r.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:t("virtualPrinter.archiveNameSource.description")})]})]})})}),r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(pr,{className:"w-5 h-5 text-bambu-green"}),r.jsx("h2",{className:"text-lg font-semibold text-white",children:t("virtualPrinter.list.title")}),r.jsxs("span",{className:"text-sm text-bambu-gray",children:["(",u.length,")"]})]}),r.jsxs(Me,{variant:"primary",onClick:()=>i(!0),children:[r.jsx(ar,{className:"w-4 h-4 mr-1"}),t("virtualPrinter.list.add")]})]}),u.length===0?r.jsx(Ct,{children:r.jsxs(At,{className:"py-8 text-center",children:[r.jsx(pr,{className:"w-12 h-12 text-bambu-gray mx-auto mb-3"}),r.jsx("p",{className:"text-bambu-gray mb-4",children:t("virtualPrinter.list.empty")}),r.jsxs(Me,{variant:"primary",onClick:()=>i(!0),children:[r.jsx(ar,{className:"w-4 h-4 mr-1"}),t("virtualPrinter.list.addFirst")]})]})}):r.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-4 items-start",children:u.map(p=>r.jsx(Xrt,{printer:p,models:m},p.id))}),a&&r.jsx(Qrt,{onClose:()=>i(!1)})]})}function sQ(t){if(t<60)return`${t}s`;const e=Math.floor(t/60);if(e<60)return`${e}m`;const n=Math.floor(e/60),a=e%60;if(n<24)return a?`${n}h ${a}m`:`${n}h`;const i=Math.floor(n/24),s=n%24;return s?`${i}d ${s}h`:`${i}d`}function oQ(t){return t==null?"—":t>=1024?`${(t/1024).toFixed(1)} GB`:`${Math.round(t)} MB`}function Jrt({device:t,onUnregister:e,isDeleting:n}){const{t:a}=kt(),{showToast:i}=rn(),s=t.system_stats,o=s?.memory,l=s?.disk,c=t.online,[d,u]=y.useState(null),[m,p]=y.useState(null),f=async x=>{p(x);try{x==="update"?await Xr.triggerUpdate(t.device_id):await Xr.systemCommand(t.device_id,x),i(a("settings.spoolbuddy.commandQueued"),"success")}catch(_){const N=_ instanceof Error?_.message:a("settings.spoolbuddy.commandError");i(N,"error")}finally{p(null),u(null)}},b=[{key:"update",label:a("settings.spoolbuddy.update"),icon:Yr},{key:"restart_browser",label:a("settings.spoolbuddy.restartBrowser"),icon:yO},{key:"restart_daemon",label:a("settings.spoolbuddy.restartDaemon"),icon:sr},{key:"reboot",label:a("settings.spoolbuddy.reboot"),icon:Mw},{key:"shutdown",label:a("settings.spoolbuddy.shutdown"),icon:wu,variant:"danger"}],w={update:a("settings.spoolbuddy.updateConfirmTitle"),restart_browser:a("settings.spoolbuddy.restartBrowserConfirmTitle"),restart_daemon:a("settings.spoolbuddy.restartDaemonConfirmTitle"),reboot:a("settings.spoolbuddy.rebootConfirmTitle"),shutdown:a("settings.spoolbuddy.shutdownConfirmTitle")},g={update:a("settings.spoolbuddy.updateConfirmBody",{hostname:t.hostname}),restart_browser:a("settings.spoolbuddy.restartBrowserConfirmBody",{hostname:t.hostname}),restart_daemon:a("settings.spoolbuddy.restartDaemonConfirmBody",{hostname:t.hostname}),reboot:a("settings.spoolbuddy.rebootConfirmBody",{hostname:t.hostname}),shutdown:a("settings.spoolbuddy.shutdownConfirmBody",{hostname:t.hostname})};return r.jsxs(Ct,{children:[r.jsx(pn,{children:r.jsxs("div",{className:"flex items-start justify-between gap-3 flex-wrap",children:[r.jsxs("div",{className:"min-w-0",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("h3",{className:"text-base font-semibold text-white truncate",children:t.hostname}),r.jsxs("span",{className:`inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-medium ${c?"bg-green-500/15 text-green-400 border border-green-500/40":"bg-gray-500/15 text-gray-400 border border-gray-500/40"}`,children:[c?r.jsx(Ah,{className:"w-3 h-3"}):r.jsx(mu,{className:"w-3 h-3"}),a(c?"settings.spoolbuddy.online":"settings.spoolbuddy.offline")]})]}),r.jsx("p",{className:"text-xs text-bambu-gray font-mono mt-1 truncate",children:t.device_id})]}),r.jsxs(Me,{variant:"danger",size:"sm",onClick:()=>e(t),disabled:n,"aria-label":a("settings.spoolbuddy.unregister"),children:[r.jsx(Jt,{className:"w-3.5 h-3.5"}),r.jsx("span",{className:"hidden sm:inline",children:a("settings.spoolbuddy.unregister")})]})]})}),r.jsxs(At,{className:"space-y-3",children:[r.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-3 text-xs",children:[r.jsxs("div",{children:[r.jsx("div",{className:"text-bambu-gray",children:a("settings.spoolbuddy.ipAddress")}),r.jsx("div",{className:"text-white font-mono",children:t.ip_address})]}),r.jsxs("div",{children:[r.jsx("div",{className:"text-bambu-gray",children:a("settings.spoolbuddy.firmware")}),r.jsx("div",{className:"text-white",children:t.firmware_version??"—"})]}),r.jsxs("div",{children:[r.jsxs("div",{className:"text-bambu-gray flex items-center gap-1",children:[r.jsx(Zn,{className:"w-3 h-3"}),a("settings.spoolbuddy.lastSeen")]}),r.jsx("div",{className:"text-white",children:t.last_seen?jh(t.last_seen):a("settings.spoolbuddy.never")})]}),r.jsxs("div",{children:[r.jsx("div",{className:"text-bambu-gray",children:a("settings.spoolbuddy.daemonUptime")}),r.jsx("div",{className:"text-white",children:sQ(t.uptime_s)})]})]}),r.jsx("div",{className:"flex flex-wrap gap-2",children:b.map(({key:x,label:_,icon:N,variant:C})=>r.jsxs(Me,{variant:C??"secondary",size:"sm",onClick:()=>u(x),disabled:!c||m!==null,"aria-label":_,children:[m===x?r.jsx(pt,{className:"w-3.5 h-3.5 animate-spin"}):r.jsx(N,{className:"w-3.5 h-3.5"}),r.jsx("span",{children:_})]},x))}),r.jsxs("div",{className:"flex items-center gap-3 text-xs flex-wrap",children:[r.jsxs("span",{className:"flex items-center gap-1 text-bambu-gray",children:[t.nfc_ok?r.jsx(rd,{className:"w-3.5 h-3.5 text-green-400"}):r.jsx(Da,{className:"w-3.5 h-3.5 text-red-400"}),a("settings.spoolbuddy.nfc"),t.nfc_reader_type&&r.jsxs("span",{className:"text-bambu-gray/70",children:["(",t.nfc_reader_type,")"]})]}),r.jsxs("span",{className:"flex items-center gap-1 text-bambu-gray",children:[t.scale_ok?r.jsx(rd,{className:"w-3.5 h-3.5 text-green-400"}):r.jsx(Da,{className:"w-3.5 h-3.5 text-red-400"}),a("settings.spoolbuddy.scale")]})]}),s&&r.jsxs("div",{className:"pt-2 border-t border-bambu-dark-tertiary",children:[r.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-3 text-xs",children:[s.cpu_temp_c!==void 0&&r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(FS,{className:"w-3.5 h-3.5 text-bambu-gray"}),r.jsxs("div",{children:[r.jsx("div",{className:"text-bambu-gray",children:a("settings.spoolbuddy.cpuTemp")}),r.jsxs("div",{className:"text-white",children:[s.cpu_temp_c.toFixed(1),"°C"]})]})]}),o&&o.percent!==void 0&&r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(M0,{className:"w-3.5 h-3.5 text-bambu-gray"}),r.jsxs("div",{children:[r.jsx("div",{className:"text-bambu-gray",children:a("settings.spoolbuddy.memory")}),r.jsxs("div",{className:"text-white",children:[o.percent.toFixed(0),"% (",oQ(o.used_mb)," / ",oQ(o.total_mb),")"]})]})]}),l&&l.percent!==void 0&&r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(ob,{className:"w-3.5 h-3.5 text-bambu-gray"}),r.jsxs("div",{children:[r.jsx("div",{className:"text-bambu-gray",children:a("settings.spoolbuddy.disk")}),r.jsxs("div",{className:"text-white",children:[l.percent.toFixed(0),"% (",l.used_gb?.toFixed(1)," / ",l.total_gb?.toFixed(1)," GB)"]})]})]}),s.system_uptime_s!==void 0&&r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(Zn,{className:"w-3.5 h-3.5 text-bambu-gray"}),r.jsxs("div",{children:[r.jsx("div",{className:"text-bambu-gray",children:a("settings.spoolbuddy.systemUptime")}),r.jsx("div",{className:"text-white",children:sQ(s.system_uptime_s)})]})]})]}),s.os&&r.jsx("div",{className:"mt-3 text-xs text-bambu-gray font-mono truncate",children:[s.os.os,s.os.kernel,s.os.arch,s.os.python&&`Python ${s.os.python}`].filter(Boolean).join(" · ")})]})]}),d&&r.jsx(vn,{variant:d==="shutdown"||d==="reboot"?"danger":"default",title:w[d],message:g[d],confirmText:a("settings.spoolbuddy.commandConfirm"),isLoading:m!==null,onConfirm:()=>f(d),onCancel:()=>u(null)})]})}function eat(){const{t}=kt(),e=en(),{showToast:n}=rn(),[a,i]=y.useState(null),{data:s=[],isLoading:o}=Ve({queryKey:["spoolbuddy-devices"],queryFn:()=>Xr.getDevices(),refetchInterval:15e3}),l=it({mutationFn:d=>Xr.deleteDevice(d),onSuccess:()=>{e.invalidateQueries({queryKey:["spoolbuddy-devices"]}),n(t("settings.spoolbuddy.unregisterSuccess"),"success"),i(null)},onError:d=>{n(d.message||t("settings.spoolbuddy.unregisterError"),"error")}});if(o)return r.jsx(Ct,{children:r.jsx(At,{className:"py-8 flex justify-center",children:r.jsx(pt,{className:"w-6 h-6 animate-spin text-bambu-green"})})});const c=s.length>1;return r.jsxs("div",{className:"space-y-4",children:[r.jsx(Ct,{children:r.jsx(At,{className:"py-3 px-4",children:r.jsxs("div",{className:"flex items-start gap-2 text-xs",children:[r.jsx(Ci,{className:"w-4 h-4 text-blue-400 flex-shrink-0 mt-0.5"}),r.jsxs("div",{className:"text-bambu-gray",children:[r.jsx("p",{className:"text-white font-medium mb-1",children:t("settings.spoolbuddy.infoTitle")}),r.jsx("p",{children:t("settings.spoolbuddy.infoBody")})]})]})})}),c&&r.jsx(Ct,{className:"border-l-4 border-l-yellow-500",children:r.jsx(At,{className:"py-3 px-4",children:r.jsxs("div",{className:"flex items-start gap-2 text-xs",children:[r.jsx(Nn,{className:"w-4 h-4 text-yellow-500 flex-shrink-0 mt-0.5"}),r.jsxs("div",{className:"text-bambu-gray",children:[r.jsx("p",{className:"text-white font-medium mb-1",children:t("settings.spoolbuddy.duplicatesTitle",{count:s.length})}),r.jsx("p",{children:t("settings.spoolbuddy.duplicatesBody")})]})]})})}),s.length===0?r.jsx(Ct,{children:r.jsx(At,{className:"py-8 text-center text-bambu-gray text-sm",children:t("settings.spoolbuddy.empty")})}):r.jsx("div",{className:"space-y-3",children:s.map(d=>r.jsx(Jrt,{device:d,onUnregister:i,isDeleting:l.isPending&&l.variables===d.device_id},d.id))}),a&&r.jsx(vn,{variant:"danger",title:t("settings.spoolbuddy.confirmTitle"),message:t("settings.spoolbuddy.confirmBody",{hostname:a.hostname,deviceId:a.device_id}),confirmText:t("settings.spoolbuddy.unregister"),isLoading:l.isPending,onConfirm:()=>l.mutate(a.device_id),onCancel:()=>i(null)})]})}function sF(t){if(!t)return"-";const e=Xn(t);return e?e.toLocaleString():"-"}function oF({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:r.jsx(wr,{className:"w-3 h-3"}),failed:r.jsx(Da,{className:"w-3 h-3"}),skipped:r.jsx(NT,{className:"w-3 h-3"}),running:r.jsx(pt,{className:"w-3 h-3 animate-spin"})};return r.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)]})}const tat={github:"backup.repoUrlPlaceholderGitHub",gitea:"backup.repoUrlPlaceholderGitea",forgejo:"backup.repoUrlPlaceholderForgejo",gitlab:"backup.repoUrlPlaceholderGitLab"},nat={github:"ghp_xxxxxxxxxxxx",gitea:"your_access_token",forgejo:"your_access_token",gitlab:"glpat-xxxxxxxxxxxx"};function lQ(t){return JSON.stringify(t)}function rat(t,e){if(!e)return t;const n={};for(const a of Object.keys(t))t[a]!==e[a]&&(n[a]=t[a]);return n}function aat(){const t=en(),{showToast:e}=rn(),{t:n}=kt(),[a,i]=y.useState(""),[s,o]=y.useState(""),[l,c]=y.useState("main"),[d,u]=y.useState("github"),[m,p]=y.useState(!1),[f,b]=y.useState("daily"),[w,g]=y.useState(!0),[x,_]=y.useState(!0),[N,C]=y.useState(!1),[P,T]=y.useState(!1),[A,F]=y.useState(!1),[S,E]=y.useState(!1),[U,I]=y.useState(!0),[H,R]=y.useState(!1),[Q,re]=y.useState(!1),[J,de]=y.useState(""),[pe,ue]=y.useState(!1),[X,ae]=y.useState(null),[me,be]=y.useState(null),Ce=y.useRef(null),[$,W]=y.useState(null),[D,j]=y.useState(null),[B,Y]=y.useState(""),{data:O,refetch:ie}=Ve({queryKey:["local-backup-status"],queryFn:se.getLocalBackupStatus,refetchInterval:rt=>rt.state.data?.is_running?1e3:1e4}),{data:z,refetch:G}=Ve({queryKey:["local-backup-files"],queryFn:se.getLocalBackups,refetchInterval:3e4});y.useEffect(()=>{O?.path!==void 0&&Y(O.path)},[O?.path]);const K=it({mutationFn:se.triggerLocalBackup,onSuccess:rt=>{rt.success?e(n("backup.scheduledBackupComplete")):e(rt.message,"error"),ie(),G()},onError:()=>e(n("backup.scheduledBackupFailed"),"error")}),Z=it({mutationFn:rt=>se.deleteLocalBackup(rt),onSuccess:()=>{G(),W(null)}}),oe=it({mutationFn:async rt=>(j(null),re(!0),be(null),de(n("backup.restoring")),se.restoreLocalBackup(rt)),onSuccess:rt=>{re(!1),de(""),rt.success?(be({success:!0,message:rt.message}),e(n("backup.backupRestoredRestart"),"success")):(be({success:!1,message:rt.message}),e(rt.message,"error"))},onError:rt=>{re(!1),de("");const Ot=rt instanceof Error?rt.message:n("backup.failedToRestore");be({success:!1,message:Ot}),e(Ot,"error")}});y.useEffect(()=>{if(H||Q){const Ot=Wt=>(Wt.preventDefault(),Wt.returnValue="A backup operation is in progress. Are you sure you want to leave?",Wt.returnValue);return window.addEventListener("beforeunload",Ot),()=>window.removeEventListener("beforeunload",Ot)}},[H,Q]);const[ee,ge]=y.useState(!1),[ce,le]=y.useState(null),q=y.useRef(null),L=y.useRef(null),ne=y.useRef(null),ye=y.useRef(null),we=y.useRef(""),[Ne,ve]=y.useState(!1),xe=y.useMemo(()=>({repository_url:a,branch:l,provider:d,allow_insecure_http:S,schedule_enabled:m,schedule_type:f,backup_kprofiles:w,backup_cloud_profiles:x,backup_settings:N,backup_spools:P,backup_archives:A,enabled:U}),[a,l,d,S,m,f,w,x,N,P,A,U]),Ee=y.useMemo(()=>lQ(xe),[xe]),{data:ze,isLoading:_e}=Ve({queryKey:["github-backup-config"],queryFn:se.getGitHubBackupConfig}),{data:Oe}=Ve({queryKey:["github-backup-status"],queryFn:se.getGitHubBackupStatus,refetchInterval:rt=>rt.state.data?.is_running?500:1e4}),{data:Ie}=Ve({queryKey:["github-backup-logs"],queryFn:()=>se.getGitHubBackupLogs(20)}),{data:We}=Ve({queryKey:["cloud-status"],queryFn:se.getCloudStatus}),{data:at}=Ve({queryKey:["printers"],queryFn:se.getPrinters}),lt=ef({queries:(at??[]).map(rt=>({queryKey:["printerStatus",rt.id],queryFn:()=>se.getPrinterStatus(rt.id),staleTime:1e4,refetchInterval:3e4}))}),Fe=(at??[]).map((rt,Ot)=>({printer:rt,connected:lt[Ot]?.data?.connected??!1})),tt=Fe.length,Pe=Fe.filter(rt=>rt.connected).length,Ye=tt>0&&Pe===0,Ue=Pe>0&&Pe(ne.current&&clearTimeout(ne.current),ze?(ve(!1),ye.current={repository_url:ze.repository_url,branch:ze.branch,provider:ze.provider??"github",allow_insecure_http:ze.allow_insecure_http??!1,schedule_enabled:ze.schedule_enabled,schedule_type:ze.schedule_type,backup_kprofiles:ze.backup_kprofiles,backup_cloud_profiles:ze.backup_cloud_profiles,backup_settings:ze.backup_settings,backup_spools:ze.backup_spools,backup_archives:ze.backup_archives,enabled:ze.enabled},i(ze.repository_url),c(ze.branch),u(ze.provider??"github"),p(ze.schedule_enabled),b(ze.schedule_type),g(ze.backup_kprofiles),_(ze.backup_cloud_profiles),C(ze.backup_settings),T(ze.backup_spools),F(ze.backup_archives),E(ze.allow_insecure_http??!1),I(ze.enabled),o(""),ne.current=setTimeout(()=>{ve(!0)},100)):(ve(!1),ye.current=null,o("")),()=>{ne.current&&clearTimeout(ne.current)}),[ze]);const fe=y.useCallback(async(rt=!1)=>{if(ze)try{rt&&s?(await se.saveGitHubBackupConfig({...xe,access_token:s}),o(""),e(n("backup.tokenUpdated")),we.current=""):(await se.updateGitHubBackupConfig(rat(xe,ye.current)),e(n("backup.settingsSaved"))),ye.current=xe,t.invalidateQueries({queryKey:["github-backup-config"]}),t.invalidateQueries({queryKey:["github-backup-status"]})}catch(Ot){e(n("backup.failedToSave",{message:Ot.message}),"error")}},[ze,s,xe,t,e,n]),Ae=y.useRef(fe);y.useEffect(()=>{Ae.current=fe},[fe]),y.useEffect(()=>{if(!(!Ne||!ze)&&!(ye.current&&Ee===lQ(ye.current)))return q.current&&clearTimeout(q.current),q.current=setTimeout(()=>{fe(!1)},500),()=>{q.current&&clearTimeout(q.current)}},[Ne,ze,Ee,fe]),y.useEffect(()=>{if(!(!Ne||!ze||!s)&&s!==we.current)return we.current=s,L.current&&clearTimeout(L.current),L.current=setTimeout(()=>{Ae.current(!0)},1e3),()=>{L.current&&clearTimeout(L.current)}},[Ne,s,ze]);const qe=it({mutationFn:rt=>se.saveGitHubBackupConfig(rt),onSuccess:()=>{t.invalidateQueries({queryKey:["github-backup-config"]}),t.invalidateQueries({queryKey:["github-backup-status"]}),e(n("backup.githubBackupEnabled")),o(""),ve(!0)},onError:rt=>{e(n("backup.failedToSave",{message:rt.message}),"error")}}),nt=it({mutationFn:se.triggerGitHubBackup,onSuccess:rt=>{t.invalidateQueries({queryKey:["github-backup-status"]}),t.invalidateQueries({queryKey:["github-backup-logs"]}),rt.success?rt.files_changed>0?e(n("backup.backupCompleteFiles",{count:rt.files_changed})):e(n("backup.backupSkippedNoChanges")):e(n("backup.backupFailed2",{message:rt.message}),"error")},onError:rt=>{e(n("backup.backupFailed2",{message:rt.message}),"error")}}),Qe=it({mutationFn:()=>se.clearGitHubBackupLogs(0),onSuccess:rt=>{t.invalidateQueries({queryKey:["github-backup-logs"]}),e(n("backup.clearedLogs",{count:rt.deleted}))},onError:rt=>{e(n("backup.failedToClearLogs",{message:rt.message}),"error")}}),gt=async()=>{ge(!0),le(null);try{let rt;if(s){if(!a){e(n("backup.enterRepoUrl"),"error"),ge(!1);return}rt=await se.testGitHubConnection(a,s,d)}else if(ze?.has_token)rt=await se.testGitHubStoredConnection();else{e(n("backup.enterRepoAndToken"),"error"),ge(!1);return}le({success:rt.success,message:rt.message})}catch(rt){le({success:!1,message:rt.message})}finally{ge(!1)}},ct=()=>{if(!a){e(n("backup.repoRequired"),"error");return}if(!s){e(n("backup.tokenRequired"),"error");return}qe.mutate({repository_url:a,access_token:s,branch:l,provider:d,allow_insecure_http:S,schedule_enabled:m,schedule_type:f,backup_kprofiles:w,backup_cloud_profiles:x,backup_settings:N,backup_spools:P,backup_archives:A,enabled:U})};return _e?r.jsx("div",{className:"flex items-center justify-center py-12",children:r.jsx(pt,{className:"w-8 h-8 animate-spin text-bambu-green"})}):r.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[r.jsxs("div",{className:"space-y-6",children:[r.jsxs(Ct,{id:"card-backup-github",children:[r.jsx(pn,{children:r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(BF,{className:"w-5 h-5 text-gray-400"}),r.jsx("h2",{className:"text-lg font-semibold text-white",children:n("backup.githubBackup")})]}),ze&&r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:"text-sm text-bambu-gray",children:n("backup.enabled")}),r.jsx(En,{checked:U,onChange:I})]})]})}),r.jsxs(At,{className:"space-y-4",children:[r.jsx("p",{className:"text-sm text-bambu-gray",children:n("backup.githubDescription")}),r.jsxs("div",{children:[r.jsx("label",{htmlFor:"git-provider-select",className:"block text-sm text-bambu-gray mb-1",children:n("backup.provider")}),r.jsxs("select",{id:"git-provider-select",value:d,onChange:rt=>{u(rt.target.value),le(null)},className:"w-full h-10 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[r.jsx("option",{value:"github",children:n("backup.providerGitHub")}),r.jsx("option",{value:"gitlab",children:n("backup.providerGitLab")}),r.jsx("option",{value:"gitea",children:n("backup.providerGitea")}),r.jsx("option",{value:"forgejo",children:n("backup.providerForgejo")})]})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("backup.repositoryUrl")}),r.jsx("input",{type:"text",value:a,onChange:rt=>{i(rt.target.value),le(null)},placeholder:n(tat[d]),className:"w-full h-10 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"}),r.jsxs("label",{className:"flex items-start gap-2 mt-2 cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:S,onChange:rt=>{E(rt.target.checked),le(null)},className:"w-4 h-4 mt-0.5 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),r.jsxs("div",{children:[r.jsx("span",{className:"text-sm text-white",children:n("backup.allowInsecureHttp")}),r.jsx("p",{className:"text-xs text-bambu-gray",children:n("backup.allowInsecureHttpHint")})]})]})]}),r.jsxs("div",{children:[r.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[n("backup.personalAccessToken")," ",ze?.has_token&&r.jsx("span",{className:"text-green-400",children:n("backup.tokenSaved")})]}),r.jsx("input",{type:"password",value:s,onChange:rt=>{o(rt.target.value),le(null)},placeholder:ze?.has_token?n("backup.enterNewToken"):nat[d],className:"w-full h-10 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"}),r.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:n("backup.tokenHint")})]}),r.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("backup.branch")}),r.jsx("input",{type:"text",value:l,onChange:rt=>c(rt.target.value),placeholder:"main",className:"w-full h-10 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("backup.autoBackup")}),r.jsxs("select",{value:m?f:"disabled",onChange:rt=>{rt.target.value==="disabled"?p(!1):(p(!0),b(rt.target.value))},className:"w-full h-10 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[r.jsx("option",{value:"disabled",children:n("backup.manualOnly")}),r.jsx("option",{value:"hourly",children:n("backup.hourly")}),r.jsx("option",{value:"daily",children:n("backup.daily")}),r.jsx("option",{value:"weekly",children:n("backup.weekly")})]})]})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-2",children:n("backup.includeInBackup")}),r.jsxs("div",{className:"space-y-2",children:[r.jsxs("label",{className:`flex items-start gap-2 ${Ye?"cursor-not-allowed opacity-60":"cursor-pointer"}`,children:[r.jsx("input",{type:"checkbox",checked:w,onChange:rt=>g(rt.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:Ye}),r.jsxs("div",{className:"flex-1",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:`text-sm ${Ye?"text-bambu-gray":"text-white"}`,children:n("backup.kProfiles")}),Ye&&r.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:[r.jsx(Nn,{className:"w-3 h-3"}),n("backup.noPrintersConnected")]}),Ue&&r.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:[r.jsx(Nn,{className:"w-3 h-3"}),n("backup.printersConnected",{connected:Pe,total:tt})]})]}),r.jsx("p",{className:"text-xs text-bambu-gray",children:n("backup.kProfilesDescription")})]})]}),r.jsxs("label",{className:`flex items-start gap-2 ${We?.is_authenticated?"cursor-pointer":"cursor-not-allowed opacity-60"}`,children:[r.jsx("input",{type:"checkbox",checked:x,onChange:rt=>_(rt.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:!We?.is_authenticated}),r.jsxs("div",{children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:`text-sm ${We?.is_authenticated?"text-white":"text-bambu-gray"}`,children:n("backup.cloudProfiles")}),!We?.is_authenticated&&r.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:[r.jsx(Nn,{className:"w-3 h-3"}),n("backup.cloudLoginRequiredShort")]})]}),r.jsx("p",{className:"text-xs text-bambu-gray",children:n("backup.cloudProfilesDescription")})]})]}),r.jsxs("label",{className:"flex items-start gap-2 cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:N,onChange:rt=>C(rt.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"}),r.jsxs("div",{children:[r.jsx("span",{className:"text-white text-sm",children:n("backup.appSettings")}),r.jsx("p",{className:"text-xs text-bambu-gray",children:n("backup.appSettingsDescription")})]})]}),r.jsxs("label",{className:"flex items-start gap-2 cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:P,onChange:rt=>T(rt.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"}),r.jsxs("div",{children:[r.jsx("span",{className:"text-white text-sm",children:n("backup.spoolInventory")}),r.jsx("p",{className:"text-xs text-bambu-gray",children:n("backup.spoolInventoryDescription")})]})]}),r.jsxs("label",{className:"flex items-start gap-2 cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:A,onChange:rt=>F(rt.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"}),r.jsxs("div",{children:[r.jsx("span",{className:"text-white text-sm",children:n("backup.printArchives")}),r.jsx("p",{className:"text-xs text-bambu-gray",children:n("backup.printArchivesDescription")})]})]})]})]}),r.jsxs("div",{className:"border-t border-bambu-dark-tertiary pt-4 space-y-3",children:[Oe?.configured&&r.jsxs("div",{className:"flex items-center justify-between text-sm",children:[r.jsx("div",{className:"flex items-center gap-2 text-bambu-gray",children:Oe.last_backup_at?r.jsxs(r.Fragment,{children:[r.jsxs("span",{children:[n("backup.lastBackupAt")," ",jh(Oe.last_backup_at,"system",n)]}),r.jsx(oF,{status:Oe.last_backup_status})]}):r.jsx("span",{children:n("backup.noBackupsYet")})}),Oe.next_scheduled_run&&r.jsxs("span",{className:"text-bambu-gray",children:[r.jsx(Zn,{className:"w-3 h-3 inline mr-1"}),n("backup.next")," ",jh(Oe.next_scheduled_run,"system",n)]})]}),ce&&r.jsxs("div",{className:`text-sm flex items-center gap-1 ${ce.success?"text-green-400":"text-red-400"}`,children:[ce.success?r.jsx(wr,{className:"w-4 h-4"}):r.jsx(Da,{className:"w-4 h-4"}),ce.message]}),r.jsx("div",{className:"flex flex-wrap items-center gap-2",children:Oe?.configured?r.jsx(r.Fragment,{children:nt.isPending||Oe.is_running?r.jsxs("div",{className:"flex items-center gap-2 text-bambu-green",children:[r.jsx(pt,{className:"w-4 h-4 animate-spin"}),r.jsx("span",{className:"text-sm",children:Oe.progress||n("backup.startingBackup")})]}):r.jsxs(r.Fragment,{children:[r.jsxs(Me,{variant:"primary",size:"sm",onClick:()=>nt.mutate(),disabled:!ze?.enabled,children:[r.jsx(fs,{className:"w-4 h-4"}),n("backup.backupNow")]}),r.jsxs(Me,{variant:"secondary",size:"sm",onClick:gt,disabled:ee,children:[ee?r.jsx(pt,{className:"w-4 h-4 animate-spin"}):r.jsx(sr,{className:"w-4 h-4"}),n("backup.test")]})]})}):r.jsxs(r.Fragment,{children:[r.jsxs(Me,{variant:"primary",size:"sm",onClick:ct,disabled:qe.isPending||!a||!s,children:[qe.isPending?r.jsx(pt,{className:"w-4 h-4 animate-spin"}):r.jsx(wr,{className:"w-4 h-4"}),n("backup.enableBackup")]}),r.jsxs(Me,{variant:"secondary",size:"sm",onClick:gt,disabled:ee||!a||!s,children:[ee?r.jsx(pt,{className:"w-4 h-4 animate-spin"}):r.jsx(sr,{className:"w-4 h-4"}),n("backup.testConnection")]})]})})]})]})]}),Ie&&Ie.length>0&&r.jsxs(Ct,{id:"card-backup-history",children:[r.jsx(pn,{children:r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(Aw,{className:"w-5 h-5 text-gray-400"}),r.jsx("h2",{className:"text-lg font-semibold text-white",children:n("backup.history")})]}),r.jsxs(Me,{variant:"ghost",size:"sm",onClick:()=>Qe.mutate(),disabled:Qe.isPending,children:[r.jsx(Jt,{className:"w-4 h-4"}),n("backup.clear")]})]})}),r.jsx(At,{children:r.jsx("div",{className:"overflow-x-auto",children:r.jsxs("table",{className:"w-full text-sm",children:[r.jsx("thead",{children:r.jsxs("tr",{className:"text-bambu-gray border-b border-bambu-dark-tertiary",children:[r.jsx("th",{className:"text-left py-2 px-2",children:n("backup.date")}),r.jsx("th",{className:"text-left py-2 px-2",children:n("backup.status")}),r.jsx("th",{className:"text-left py-2 px-2",children:n("backup.commit")})]})}),r.jsx("tbody",{children:Ie.slice(0,10).map(rt=>r.jsxs("tr",{className:"border-b border-bambu-dark-tertiary/50 hover:bg-bambu-dark-secondary",children:[r.jsx("td",{className:"py-2 px-2 text-white",children:sF(rt.started_at)}),r.jsx("td",{className:"py-2 px-2",children:r.jsx(oF,{status:rt.status})}),r.jsx("td",{className:"py-2 px-2",children:rt.commit_sha?r.jsxs("a",{href:`${ze?.repository_url}/commit/${rt.commit_sha}`,target:"_blank",rel:"noopener noreferrer",className:"text-bambu-green hover:underline inline-flex items-center gap-1",children:[rt.commit_sha.substring(0,7),r.jsx(Rr,{className:"w-3 h-3"})]}):r.jsx("span",{className:"text-bambu-gray",children:"-"})})]},rt.id))})]})})})]})]}),r.jsxs("div",{className:"space-y-6",children:[r.jsxs(Ct,{id:"card-backup-local",children:[r.jsx(pn,{children:r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(hc,{className:"w-5 h-5 text-gray-400"}),r.jsx("h2",{className:"text-lg font-semibold text-white",children:n("backup.localBackup")})]})}),r.jsxs(At,{className:"space-y-4",children:[r.jsx("p",{className:"text-sm text-bambu-gray",children:n("backup.localBackupDescription")}),r.jsxs("div",{className:"flex items-center justify-between py-3 border-b border-bambu-dark-tertiary",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-white",children:n("backup.downloadBackupLabel")}),r.jsx("p",{className:"text-sm text-bambu-gray",children:n("backup.completeBackupZip")})]}),r.jsxs(Me,{variant:"secondary",size:"sm",disabled:H||Q,onClick:async()=>{R(!0),de(n("backup.preparingBackup"));try{de(n("backup.creatingArchive"));const{blob:rt,filename:Ot}=await se.exportBackup();de(n("backup.downloadingFile"));const Wt=URL.createObjectURL(rt),Zt=document.createElement("a");Zt.href=Wt,Zt.download=Ot,Zt.click(),URL.revokeObjectURL(Wt),e(n("backup.backupDownloaded"))}catch(rt){e(n("backup.failedToCreateBackup",{message:rt instanceof Error?rt.message:"Unknown error"}),"error")}finally{R(!1),de("")}},children:[r.jsx(Yr,{className:"w-4 h-4"}),n("backup.download")]})]}),r.jsxs("div",{className:"flex items-center justify-between py-3 border-b border-bambu-dark-tertiary",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-white",children:n("backup.restoreBackup")}),r.jsx("p",{className:"text-sm text-bambu-gray",children:n("backup.restoreDescription")}),r.jsx("p",{className:"text-xs text-bambu-gray-light mt-1",children:n("backup.restoreNote")})]}),r.jsx("input",{ref:Ce,type:"file",accept:".zip",className:"hidden",onChange:rt=>{const Ot=rt.target.files?.[0];Ot&&(ae(Ot),ue(!0)),rt.target.value=""}}),r.jsxs(Me,{variant:"secondary",size:"sm",disabled:Q||H,onClick:()=>Ce.current?.click(),children:[r.jsx(ka,{className:"w-4 h-4"}),n("backup.restore")]})]}),me&&r.jsx("div",{className:`p-3 rounded-lg ${me.success?"bg-green-500/10 border border-green-500/30":"bg-red-500/10 border border-red-500/30"}`,children:r.jsxs("div",{className:"flex items-start gap-2 text-sm",children:[me.success?r.jsx(wr,{className:"w-4 h-4 text-green-400 mt-0.5 flex-shrink-0"}):r.jsx(Da,{className:"w-4 h-4 text-red-400 mt-0.5 flex-shrink-0"}),r.jsxs("div",{className:me.success?"text-green-200":"text-red-200",children:[me.message,me.success&&r.jsx("div",{className:"mt-2",children:r.jsxs(Me,{size:"sm",onClick:()=>window.location.reload(),children:[r.jsx(gs,{className:"w-3 h-3"}),n("backup.reloadNow")]})})]})]})}),r.jsx("div",{className:"p-3 rounded-lg bg-yellow-500/10 border border-yellow-500/30",children:r.jsxs("div",{className:"flex items-start gap-2 text-sm",children:[r.jsx(Nn,{className:"w-4 h-4 text-yellow-400 mt-0.5 flex-shrink-0"}),r.jsxs("div",{className:"text-yellow-200",children:[r.jsx("span",{className:"font-medium",children:n("backup.restoreReplacesAll")})," ",r.jsx("span",{className:"text-yellow-200/70",children:n("backup.restoreReplacesAllDetail")})]})]})})]})]}),r.jsxs(Ct,{id:"card-backup-scheduled",children:[r.jsx(pn,{children:r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(lbe,{className:"w-5 h-5 text-gray-400"}),r.jsx("h2",{className:"text-lg font-semibold text-white",children:n("backup.scheduledBackup")})]}),r.jsx(En,{checked:O?.enabled??!1,onChange:async rt=>{try{await se.updateSettings({local_backup_enabled:rt}),t.invalidateQueries({queryKey:["settings"]}),e(n("backup.settingsSaved"))}catch(Ot){e(n("backup.failedToSave",{message:Ot instanceof Error?Ot.message:"Unknown error"}),"error")}ie()}})]})}),r.jsxs(At,{className:"space-y-4",children:[r.jsx("p",{className:"text-sm text-bambu-gray",children:n("backup.scheduledBackupDescription")}),O?.enabled&&r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("backup.frequency")}),r.jsxs("select",{value:O?.schedule??"daily",className:"w-full h-10 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",onChange:async rt=>{try{await se.updateSettings({local_backup_schedule:rt.target.value}),e(n("backup.settingsSaved"))}catch(Ot){e(n("backup.failedToSave",{message:Ot instanceof Error?Ot.message:"Unknown error"}),"error")}ie()},children:[r.jsx("option",{value:"hourly",children:n("backup.hourly")}),r.jsx("option",{value:"daily",children:n("backup.daily")}),r.jsx("option",{value:"weekly",children:n("backup.weekly")})]})]}),(O?.schedule??"daily")!=="hourly"&&r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("backup.backupTime")}),r.jsx("input",{type:"time",value:O?.time??"03:00",className:"w-full h-10 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none [color-scheme:dark]",onChange:async rt=>{try{await se.updateSettings({local_backup_time:rt.target.value}),e(n("backup.settingsSaved"))}catch(Ot){e(n("backup.failedToSave",{message:Ot instanceof Error?Ot.message:"Unknown error"}),"error")}ie()}}),r.jsx("p",{className:"text-xs text-bambu-gray-light mt-1",children:n("backup.utc")})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("backup.retention")}),r.jsx("input",{type:"number",min:1,max:100,value:O?.retention??5,className:"w-full h-10 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",onChange:async rt=>{const Ot=Math.max(1,Math.min(100,parseInt(rt.target.value)||5));try{await se.updateSettings({local_backup_retention:Ot}),e(n("backup.settingsSaved"))}catch(Wt){e(n("backup.failedToSave",{message:Wt instanceof Error?Wt.message:"Unknown error"}),"error")}ie()}}),r.jsx("p",{className:"text-xs text-bambu-gray-light mt-1",children:n("backup.retentionDescription")})]})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:n("backup.outputPath")}),r.jsx("input",{type:"text",value:B,onChange:rt=>Y(rt.target.value),className:"w-full h-10 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",onBlur:async()=>{try{await se.updateSettings({local_backup_path:B}),e(n("backup.settingsSaved"))}catch(rt){e(n("backup.failedToSave",{message:rt instanceof Error?rt.message:"Unknown error"}),"error")}ie(),G()},onKeyDown:rt=>{rt.key==="Enter"&&rt.target.blur()}}),r.jsx("p",{className:"text-xs text-bambu-gray-light mt-1",children:B?n("backup.outputPathDescription"):r.jsxs(r.Fragment,{children:[n("backup.defaultPathLabel")," ",r.jsx("code",{className:"text-bambu-gray",children:O?.default_path||"..."})]})})]}),r.jsxs("div",{className:"flex items-center justify-between py-3 border-t border-bambu-dark-tertiary",children:[r.jsxs("div",{className:"text-sm",children:[O?.last_backup_at&&r.jsxs("div",{className:"flex items-center gap-2 text-bambu-gray",children:[r.jsxs("span",{children:[n("backup.lastBackup"),":"]}),r.jsx(oF,{status:O.last_status}),r.jsx("span",{children:jh(O.last_backup_at)})]}),O?.next_run&&r.jsxs("div",{className:"text-bambu-gray mt-1",children:[r.jsxs("span",{children:[n("backup.nextBackup"),": "]}),r.jsx("span",{children:sF(O.next_run)})]})]}),r.jsxs(Me,{variant:"secondary",size:"sm",disabled:O?.is_running||K.isPending,onClick:()=>K.mutate(),children:[O?.is_running||K.isPending?r.jsx(pt,{className:"w-4 h-4 animate-spin"}):r.jsx(fs,{className:"w-4 h-4"}),O?.is_running?n("backup.backupRunning"):n("backup.runNow")]})]}),z&&z.length>0&&r.jsxs("div",{className:"border-t border-bambu-dark-tertiary pt-3",children:[r.jsx("h3",{className:"text-sm font-medium text-white mb-2",children:n("backup.backupFiles")}),r.jsx("div",{className:"space-y-1",children:z.map(rt=>r.jsxs("div",{className:"flex items-center justify-between py-1.5 px-2 rounded hover:bg-bambu-dark-tertiary/50 text-sm",children:[r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("span",{className:"text-white truncate block",children:rt.filename}),r.jsxs("span",{className:"text-bambu-gray text-xs",children:[(rt.size/1024/1024).toFixed(1)," MB · ",sF(rt.created_at)]})]}),r.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[r.jsx("button",{className:"text-bambu-gray hover:text-bambu-green p-1",title:n("backup.download"),onClick:async()=>{try{const{blob:Ot,filename:Wt}=await se.downloadLocalBackup(rt.filename),Zt=URL.createObjectURL(Ot),Yt=document.createElement("a");Yt.href=Zt,Yt.download=Wt,Yt.click(),URL.revokeObjectURL(Zt)}catch{e(n("backup.scheduledBackupFailed"),"error")}},children:r.jsx(Yr,{className:"w-3.5 h-3.5"})}),r.jsx("button",{className:"text-bambu-gray hover:text-yellow-400 p-1",title:n("backup.restore"),onClick:()=>j(rt.filename),children:r.jsx(gs,{className:"w-3.5 h-3.5"})}),r.jsx("button",{className:"text-bambu-gray hover:text-red-400 p-1",onClick:()=>W(rt.filename),title:n("backup.deleteBackup"),children:r.jsx(Jt,{className:"w-3.5 h-3.5"})})]})]},rt.filename))})]}),z&&z.length===0&&r.jsx("p",{className:"text-sm text-bambu-gray text-center py-3 border-t border-bambu-dark-tertiary",children:n("backup.noScheduledBackups")})]})]})]})]}),$&&r.jsx(vn,{title:n("backup.deleteBackup"),message:n("backup.deleteBackupConfirm"),confirmText:n("backup.deleteBackup"),variant:"danger",onConfirm:()=>Z.mutate($),onCancel:()=>W(null)}),D&&r.jsx(vn,{title:n("backup.restoreConfirmTitle"),message:n("backup.restoreConfirmMessage",{filename:D}),confirmText:n("backup.restoreConfirmButton"),variant:"danger",onConfirm:()=>oe.mutate(D),onCancel:()=>j(null)}),pe&&X&&r.jsx(vn,{title:n("backup.restoreConfirmTitle"),message:n("backup.restoreConfirmMessage",{filename:X.name}),confirmText:n("backup.restoreConfirmButton"),variant:"danger",onConfirm:async()=>{ue(!1),re(!0),be(null);try{de(n("backup.uploadingFile"));const rt=await se.importBackup(X);be(rt),rt.success?e(n("backup.backupRestoredRestart"),"success"):e(rt.message,"error")}catch(rt){const Ot=rt instanceof Error?rt.message:n("backup.failedToRestore");be({success:!1,message:Ot}),e(Ot,"error")}finally{re(!1),de(""),ae(null)}},onCancel:()=>{ue(!1),ae(null)}}),(H||Q)&&r.jsx("div",{className:"fixed inset-0 bg-black/80 flex items-center justify-center z-[100]",children:r.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:[r.jsx("div",{className:"flex justify-center mb-4",children:r.jsxs("div",{className:"relative",children:[r.jsx("div",{className:"w-16 h-16 border-4 border-bambu-dark-tertiary rounded-full"}),r.jsx("div",{className:"w-16 h-16 border-4 border-bambu-green border-t-transparent rounded-full absolute inset-0 animate-spin"})]})}),r.jsx("h3",{className:"text-xl font-semibold text-white mb-2",children:n(H?"backup.creatingBackup":"backup.restoringBackup")}),r.jsx("p",{className:"text-bambu-gray mb-4",children:J||n(H?"backup.preparing":"backup.processing")}),r.jsx("div",{className:"p-3 rounded-lg bg-yellow-500/10 border border-yellow-500/30",children:r.jsxs("div",{className:"flex items-start gap-2 text-sm",children:[r.jsx(Nn,{className:"w-4 h-4 text-yellow-400 mt-0.5 flex-shrink-0"}),r.jsx("p",{className:"text-yellow-200 text-left",children:n("backup.doNotClosePage")})]})})]})})]})}function iat(){const{t}=kt(),e=en(),{showToast:n}=rn(),[a,i]=y.useState(!1),[s,o]=y.useState(""),[l,c]=y.useState("medium"),[d,u]=y.useState("notify"),[m,p]=y.useState(10),[f,b]=y.useState(null),[w,g]=y.useState(null),[x,_]=y.useState(!1),{data:N}=Ve({queryKey:["settings"],queryFn:se.getSettings}),{data:C,refetch:P}=Ve({queryKey:["obico-status"],queryFn:se.getObicoStatus,refetchInterval:1e4}),{data:T}=Ve({queryKey:["printers"],queryFn:se.getPrinters});y.useEffect(()=>{if(N){i(N.obico_enabled??!1),o(N.obico_ml_url??""),c(N.obico_sensitivity??"medium"),u(N.obico_action??"notify"),p(N.obico_poll_interval??10);try{const E=N.obico_enabled_printers?JSON.parse(N.obico_enabled_printers):null;b(Array.isArray(E)?E:null)}catch{b(null)}_(!0)}},[N]);const A=it({mutationFn:()=>se.updateSettings({obico_enabled:a,obico_ml_url:s,obico_sensitivity:l,obico_action:d,obico_poll_interval:m,obico_enabled_printers:f===null?"":JSON.stringify(f)}),onSuccess:()=>{e.invalidateQueries({queryKey:["settings"]}),e.invalidateQueries({queryKey:["obico-status"]}),n(t("settings.toast.settingsSaved"))}});y.useEffect(()=>{if(!x||!N||!(N.obico_enabled!==a||N.obico_ml_url!==s||N.obico_sensitivity!==l||N.obico_action!==d||N.obico_poll_interval!==m||N.obico_enabled_printers!==(f===null?"":JSON.stringify(f))))return;const U=setTimeout(()=>A.mutate(),500);return()=>clearTimeout(U)},[a,s,l,d,m,f,x]);const F=async()=>{g(null);try{const E=await se.testObicoConnection(s);E.ok?g({ok:!0,message:t("failureDetection.testSuccess")}):g({ok:!1,message:E.error||`HTTP ${E.status_code??"?"} — ${E.body??t("failureDetection.testFailed")}`})}catch(E){g({ok:!1,message:E instanceof Error?E.message:String(E)})}},S=(E,U)=>{if(f===null){const I=T?.map(R=>R.id)??[],H=U?I:I.filter(R=>R!==E);b(H);return}b(U?[...f,E]:f.filter(I=>I!==E))};return r.jsxs("div",{className:"flex flex-col lg:flex-row gap-4 lg:gap-6",children:[r.jsxs("div",{className:"space-y-3 flex-1 lg:max-w-xl",children:[r.jsxs(Ct,{id:"card-fd-ml",children:[r.jsxs(pn,{children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(LZ,{className:"w-5 h-5 text-bambu-green"}),r.jsx("h2",{className:"text-lg font-semibold text-white",children:t("failureDetection.title")})]}),r.jsx(En,{checked:a,onChange:i})]}),r.jsx("p",{className:"text-sm text-bambu-gray mt-2",children:t("failureDetection.description")})]}),r.jsxs(At,{className:"space-y-4",children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:t("failureDetection.mlUrl")}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx("input",{type:"text",value:s,onChange:E=>o(E.target.value),placeholder:"http://192.168.1.10:3333",className:"flex-1 bg-gray-800 border border-gray-700 rounded px-3 py-2 text-white text-sm",disabled:!a}),r.jsx(Me,{onClick:F,disabled:!s||A.isPending,variant:"secondary",children:t("failureDetection.test")})]}),r.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:t("failureDetection.mlUrlHint")}),w&&r.jsxs("div",{className:`flex items-start gap-2 mt-2 text-sm ${w.ok?"text-green-400":"text-red-400"}`,children:[w.ok?r.jsx(_r,{className:"w-4 h-4 mt-0.5"}):r.jsx(Ht,{className:"w-4 h-4 mt-0.5"}),r.jsx("span",{children:w.message})]})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:t("failureDetection.sensitivity")}),r.jsxs("select",{value:l,onChange:E=>c(E.target.value),disabled:!a,className:"w-full bg-gray-800 border border-gray-700 rounded px-3 py-2 text-white text-sm",children:[r.jsx("option",{value:"low",children:t("failureDetection.sensitivityLow")}),r.jsx("option",{value:"medium",children:t("failureDetection.sensitivityMedium")}),r.jsx("option",{value:"high",children:t("failureDetection.sensitivityHigh")})]}),r.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:t("failureDetection.sensitivityHint")})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:t("failureDetection.action")}),r.jsxs("select",{value:d,onChange:E=>u(E.target.value),disabled:!a,className:"w-full bg-gray-800 border border-gray-700 rounded px-3 py-2 text-white text-sm",children:[r.jsx("option",{value:"notify",children:t("failureDetection.actionNotify")}),r.jsx("option",{value:"pause",children:t("failureDetection.actionPause")}),r.jsx("option",{value:"pause_and_off",children:t("failureDetection.actionPauseOff")})]})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:t("failureDetection.pollInterval")}),r.jsx("input",{type:"number",value:m,onChange:E=>p(Math.max(5,Math.min(120,Number(E.target.value)||10))),min:5,max:120,disabled:!a,className:"w-full bg-gray-800 border border-gray-700 rounded px-3 py-2 text-white text-sm"}),r.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:t("failureDetection.pollIntervalHint")})]}),C&&!C.external_url_configured&&a&&r.jsxs("div",{className:"flex items-start gap-2 p-3 bg-amber-900/30 border border-amber-700 rounded text-sm text-amber-200",children:[r.jsx(Nn,{className:"w-4 h-4 mt-0.5 flex-shrink-0"}),r.jsxs("div",{children:[r.jsx("div",{className:"font-medium",children:t("failureDetection.externalUrlMissing")}),r.jsx("div",{className:"text-xs mt-1",children:t("failureDetection.externalUrlHint")})]})]})]})]}),r.jsxs(Ct,{id:"card-fd-perprinter",children:[r.jsxs(pn,{children:[r.jsx("h2",{className:"text-lg font-semibold text-white",children:t("failureDetection.perPrinterTitle")}),r.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:t("failureDetection.perPrinterHint")})]}),r.jsxs(At,{className:"space-y-2",children:[r.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[r.jsx("input",{type:"checkbox",checked:f===null,onChange:E=>b(E.target.checked?null:T?.map(U=>U.id)??[]),disabled:!a}),r.jsx("span",{className:"text-white",children:t("failureDetection.monitorAll")})]}),f!==null&&T&&r.jsx("div",{className:"pl-5 space-y-1 border-l border-gray-700",children:T.map(E=>r.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[r.jsx("input",{type:"checkbox",checked:f.includes(E.id),onChange:U=>S(E.id,U.target.checked),disabled:!a}),r.jsx("span",{className:"text-white",children:E.name})]},E.id))})]})]})]}),r.jsxs("div",{className:"space-y-3 flex-1 lg:max-w-xl",children:[r.jsxs(Ct,{id:"card-fd-status",children:[r.jsx(pn,{children:r.jsx("h2",{className:"text-lg font-semibold text-white",children:t("failureDetection.statusTitle")})}),r.jsx(At,{children:C?r.jsxs("div",{className:"space-y-3 text-sm",children:[r.jsxs("div",{className:"flex justify-between",children:[r.jsx("span",{className:"text-bambu-gray",children:t("failureDetection.serviceRunning")}),r.jsx("span",{className:C.is_running?"text-green-400":"text-red-400",children:C.is_running?t("common.yes"):t("common.no")})]}),r.jsxs("div",{className:"flex justify-between",children:[r.jsx("span",{className:"text-bambu-gray",children:t("failureDetection.thresholds")}),r.jsxs("span",{className:"text-white font-mono",children:[C.thresholds.low.toFixed(2)," / ",C.thresholds.high.toFixed(2)]})]}),C.last_error&&r.jsxs("div",{className:"flex items-start gap-2 text-red-400",children:[r.jsx(Ht,{className:"w-4 h-4 mt-0.5 flex-shrink-0"}),r.jsx("span",{className:"break-words",children:C.last_error})]}),r.jsxs("div",{children:[r.jsx("div",{className:"text-bambu-gray mb-1",children:t("failureDetection.activePrinters")}),Object.keys(C.per_printer).length===0?r.jsx("div",{className:"text-bambu-gray italic text-xs",children:t("failureDetection.noActivePrints")}):r.jsx("div",{className:"space-y-1",children:Object.entries(C.per_printer).map(([E,U])=>{const I=T?.find(R=>String(R.id)===E),H=U.class==="failure"?"text-red-400":U.class==="warning"?"text-amber-400":"text-green-400";return r.jsxs("div",{className:"flex justify-between",children:[r.jsx("span",{className:"text-white",children:I?.name??`Printer ${E}`}),r.jsxs("span",{className:`font-mono ${H}`,children:[U.class," (",U.score.toFixed(3),", ",U.frame_count,"f)"]})]},E)})})]})]}):r.jsxs("div",{className:"flex items-center gap-2 text-bambu-gray",children:[r.jsx(pt,{className:"w-4 h-4 animate-spin"}),r.jsx("span",{children:t("common.loading")})]})})]}),r.jsxs(Ct,{id:"card-fd-history",children:[r.jsx(pn,{children:r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsx("h2",{className:"text-lg font-semibold text-white",children:t("failureDetection.historyTitle")}),r.jsx("button",{onClick:()=>P(),className:"text-xs text-bambu-gray hover:text-white",children:t("common.refresh")})]})}),r.jsx(At,{children:!C||C.history.length===0?r.jsxs("div",{className:"flex items-center gap-2 text-bambu-gray text-sm",children:[r.jsx(Ci,{className:"w-4 h-4"}),r.jsx("span",{children:t("failureDetection.noHistory")})]}):r.jsx("div",{className:"space-y-1 max-h-96 overflow-y-auto text-xs font-mono",children:C.history.map((E,U)=>{const I=T?.find(R=>R.id===E.printer_id),H=E.class==="failure"?"text-red-400":E.class==="warning"?"text-amber-400":"text-bambu-gray";return r.jsxs("div",{className:"flex justify-between gap-2 py-1 border-b border-gray-800",children:[r.jsx("span",{className:"text-bambu-gray",children:new Date(E.timestamp).toLocaleTimeString()}),r.jsx("span",{className:"text-white truncate",children:I?.name??`#${E.printer_id}`}),r.jsxs("span",{className:H,children:[E.class," ",E.score.toFixed(3)]})]},U)})})})]})]})]})}const sat={starttls:587,ssl:465,none:25},oat={587:"starttls",465:"ssl",25:"none"};function lat(){const{t}=kt(),{showToast:e}=rn(),n=en(),[a,i]=y.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]=y.useState(""),{data:l,isLoading:c}=Ve({queryKey:["smtpSettings"],queryFn:()=>se.getSMTPSettings()}),{authEnabled:d}=cr(),{data:u}=Ve({queryKey:["advancedAuthStatus"],queryFn:()=>se.getAdvancedAuthStatus()});y.useEffect(()=>{l&&i({...l,smtp_password:""})},[l]);const m=A=>{i({...a,smtp_security:A,smtp_port:sat[A]})},p=A=>{const F=oat[A];i({...a,smtp_port:A,...F?{smtp_security:F}:{}})},f=A=>{i({...a,smtp_auth_enabled:A,...A?{}:{smtp_username:"",smtp_password:""}})},b=it({mutationFn:A=>se.saveSMTPSettings(A),onSuccess:()=>{n.invalidateQueries({queryKey:["smtpSettings"]}),n.invalidateQueries({queryKey:["advancedAuthStatus"]}),e(t("settings.email.success.settingsSaved"),"success")},onError:A=>{e(A.message,"error")}}),w=it({mutationFn:A=>se.testSMTP(A),onSuccess:A=>{e(A.message,A.success?"success":"error")},onError:A=>{e(A.message,"error")}}),g=it({mutationFn:A=>A?se.enableAdvancedAuth():se.disableAdvancedAuth(),onSuccess:A=>{n.invalidateQueries({queryKey:["advancedAuthStatus"]}),e(A.message,"success")},onError:A=>{e(A.message,"error")}}),x=()=>{if(!a.smtp_host||!a.smtp_from_email){e(t("settings.email.errors.requiredFields"),"error");return}if(a.smtp_auth_enabled&&!a.smtp_username){e(t("settings.email.errors.usernameRequired"),"error");return}b.mutate(a)},_=()=>{if(!s){e(t("settings.email.errors.enterTestEmail"),"error");return}w.mutate({test_recipient:s})},N=()=>{if(!d){e(t("settings.email.errors.enableAuthFirst"),"error");return}if(!u?.advanced_auth_enabled&&!u?.smtp_configured){e(t("settings.email.errors.configureSmtpFirst"),"error");return}g.mutate(!u?.advanced_auth_enabled)};if(c)return r.jsx("div",{className:"flex items-center justify-center p-12",children:r.jsx(pt,{className:"w-8 h-8 animate-spin text-bambu-green"})});const C=u?.advanced_auth_enabled??!1,P="w-full px-3 py-2 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-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white/40 placeholder-bambu-gray/40 cursor-not-allowed";return r.jsxs("div",{className:"space-y-3",children:[r.jsxs(Ct,{id:"card-email-advanced-auth",children:[r.jsx(pn,{children:r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(qm,{className:"w-5 h-5 text-bambu-green"}),r.jsx("h2",{className:"text-lg font-semibold text-white",children:t("settings.email.advancedAuth")||"Advanced Authentication"})]}),r.jsx(Me,{onClick:N,disabled:g.isPending,variant:C?"danger":"primary",children:C?r.jsxs(r.Fragment,{children:[r.jsx(K0,{className:"w-4 h-4"}),t("settings.email.disable")||"Disable"]}):r.jsxs(r.Fragment,{children:[r.jsx(lc,{className:"w-4 h-4"}),t("settings.email.enable")||"Enable"]})})]})}),r.jsx(At,{children:r.jsx("div",{className:"space-y-3",children:C?r.jsx("div",{className:"bg-green-500/10 border border-green-500/30 rounded-lg p-4",children:r.jsxs("div",{className:"flex items-start gap-3",children:[r.jsx(wr,{className:"w-5 h-5 text-green-400 mt-0.5 flex-shrink-0"}),r.jsxs("div",{className:"space-y-2",children:[r.jsx("p",{className:"text-white font-medium",children:t("settings.email.advancedAuthEnabled")||"Advanced Authentication is enabled"}),r.jsxs("ul",{className:"text-sm text-green-300 space-y-1 list-disc list-inside",children:[r.jsx("li",{children:t("settings.email.feature1")||"Passwords are auto-generated and emailed to new users"}),r.jsx("li",{children:t("settings.email.feature2")||"Users can login with username or email"}),r.jsx("li",{children:t("settings.email.feature3")||"Forgot password feature is available"}),r.jsx("li",{children:t("settings.email.feature4")||"Admins can reset user passwords via email"})]})]})]})}):r.jsx("div",{className:"bg-yellow-500/10 border border-yellow-500/30 rounded-lg p-4",children:r.jsxs("div",{className:"flex items-start gap-3",children:[r.jsx(Nn,{className:"w-5 h-5 text-yellow-400 mt-0.5 flex-shrink-0"}),r.jsxs("div",{className:"space-y-2",children:[r.jsx("p",{className:"text-white font-medium",children:t("settings.email.advancedAuthDisabled")||"Advanced Authentication is disabled"}),r.jsx("p",{className:"text-sm text-yellow-300",children:t("settings.email.advancedAuthDisabledDesc")||"Enable advanced authentication to activate email-based features for user management."})]})]})})})})]}),r.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-4",children:[r.jsx("div",{className:"lg:col-span-2",children:r.jsxs(Ct,{id:"card-smtp-config",children:[r.jsx(pn,{children:r.jsx("h2",{className:"text-lg font-semibold text-white",children:t("settings.email.smtpSettings")||"SMTP Configuration"})}),r.jsx(At,{children:r.jsxs("div",{className:"space-y-3",children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm font-medium text-white mb-1",children:t("settings.email.authentication")||"Authentication"}),r.jsxs("select",{value:a.smtp_auth_enabled?"true":"false",onChange:A=>f(A.target.value==="true"),className:P,children:[r.jsx("option",{value:"true",children:t("settings.email.authOptions.enabled")}),r.jsx("option",{value:"false",children:t("settings.email.authOptions.disabled")})]})]}),r.jsxs("div",{className:`grid grid-cols-1 md:grid-cols-2 gap-4 transition-opacity ${a.smtp_auth_enabled?"":"opacity-40 pointer-events-none"}`,children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm font-medium text-white mb-1",children:t("settings.email.username")||"Username"}),r.jsx("input",{type:"text",value:a.smtp_username||"",onChange:A=>i({...a,smtp_username:A.target.value}),placeholder:"your.email@gmail.com",disabled:!a.smtp_auth_enabled,className:a.smtp_auth_enabled?P:T})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm font-medium text-white mb-1",children:t("settings.email.password")||"Password"}),r.jsx("input",{type:"password",value:a.smtp_password||"",onChange:A=>i({...a,smtp_password:A.target.value}),placeholder:l?"••••••••":"App password",disabled:!a.smtp_auth_enabled,className:a.smtp_auth_enabled?P:T})]})]}),r.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[r.jsxs("div",{children:[r.jsxs("label",{className:"block text-sm font-medium text-white mb-1",children:[t("settings.email.smtpHost")||"SMTP Server"," *"]}),r.jsx("input",{type:"text",value:a.smtp_host,onChange:A=>i({...a,smtp_host:A.target.value}),placeholder:"smtp.gmail.com",className:P})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm font-medium text-white mb-1",children:t("settings.email.smtpPort")||"SMTP Port"}),r.jsx("input",{type:"number",value:a.smtp_port,onChange:A=>p(parseInt(A.target.value)||587),placeholder:"587",className:P})]})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm font-medium text-white mb-1",children:t("settings.email.security")||"Security"}),r.jsxs("select",{value:a.smtp_security,onChange:A=>m(A.target.value),className:P,children:[r.jsx("option",{value:"starttls",children:t("settings.email.securityOptions.starttls")}),r.jsx("option",{value:"ssl",children:t("settings.email.securityOptions.ssl")}),r.jsx("option",{value:"none",children:t("settings.email.securityOptions.none")})]})]}),r.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[r.jsxs("div",{children:[r.jsxs("label",{className:"block text-sm font-medium text-white mb-1",children:[t("settings.email.fromEmail")||"From Email"," *"]}),r.jsx("input",{type:"email",value:a.smtp_from_email,onChange:A=>i({...a,smtp_from_email:A.target.value}),placeholder:"your@email.com",className:P})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm font-medium text-white mb-1",children:t("settings.email.fromName")||"From Name"}),r.jsx("input",{type:"text",value:a.smtp_from_name,onChange:A=>i({...a,smtp_from_name:A.target.value}),placeholder:"BamBuddy",className:P})]})]}),r.jsx("div",{className:"flex gap-2",children:r.jsx(Me,{onClick:x,disabled:b.isPending,className:"flex-1",children:b.isPending?r.jsxs(r.Fragment,{children:[r.jsx(pt,{className:"w-4 h-4 animate-spin"}),t("settings.email.saving")||"Saving..."]}):t("settings.email.save")||"Save Settings"})})]})})]})}),r.jsx("div",{children:r.jsxs(Ct,{id:"card-email-test",children:[r.jsx(pn,{children:r.jsx("h2",{className:"text-lg font-semibold text-white",children:t("settings.email.testConnection")||"Test SMTP Connection"})}),r.jsx(At,{children:r.jsxs("div",{className:"space-y-3",children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm font-medium text-white mb-1",children:t("settings.email.testRecipient")||"Test Recipient Email"}),r.jsx("input",{type:"email",value:s,onChange:A=>o(A.target.value),placeholder:"test@example.com",className:P})]}),r.jsx(Me,{onClick:_,disabled:w.isPending,variant:"secondary",children:w.isPending?r.jsxs(r.Fragment,{children:[r.jsx(pt,{className:"w-4 h-4 animate-spin"}),t("settings.email.sending")||"Sending..."]}):r.jsxs(r.Fragment,{children:[r.jsx(DS,{className:"w-4 h-4"}),t("settings.email.sendTest")||"Send Test Email"]})})]})})]})})]})]})}const cat={starttls:"389",ldaps:"636"};function dat(){const{t}=kt(),{showToast:e}=rn(),n=en(),{authEnabled:a}=cr(),[i,s]=y.useState({ldap_server_url:"",ldap_bind_dn:"",ldap_bind_password:"",ldap_search_base:"",ldap_user_filter:"(sAMAccountName={username})",ldap_security:"starttls",ldap_group_mapping:"",ldap_auto_provision:!1,ldap_default_group:""}),{data:o,isLoading:l}=Ve({queryKey:["settings"],queryFn:()=>se.getSettings()}),{data:c}=Ve({queryKey:["ldapStatus"],queryFn:()=>se.getLDAPStatus()}),{data:d=[]}=Ve({queryKey:["groups"],queryFn:()=>se.getGroups()});y.useEffect(()=>{o&&s({ldap_server_url:o.ldap_server_url||"",ldap_bind_dn:o.ldap_bind_dn||"",ldap_bind_password:"",ldap_search_base:o.ldap_search_base||"",ldap_user_filter:o.ldap_user_filter||"(sAMAccountName={username})",ldap_security:o.ldap_security||"starttls",ldap_group_mapping:o.ldap_group_mapping||"",ldap_auto_provision:o.ldap_auto_provision??!1,ldap_default_group:o.ldap_default_group||""})},[o]);const u=it({mutationFn:x=>se.updateSettings(x),onSuccess:()=>{n.invalidateQueries({queryKey:["settings"]}),n.invalidateQueries({queryKey:["ldapStatus"]}),e(t("settings.ldap.settingsSaved")||"LDAP settings saved","success")},onError:x=>{e(x.message,"error")}}),m=it({mutationFn:x=>se.updateSettings({ldap_enabled:x}),onSuccess:()=>{n.invalidateQueries({queryKey:["settings"]}),n.invalidateQueries({queryKey:["ldapStatus"]}),e(c?.ldap_enabled?t("settings.ldap.disabled")||"LDAP authentication disabled":t("settings.ldap.enabled")||"LDAP authentication enabled","success")},onError:x=>{e(x.message,"error")}}),p=it({mutationFn:()=>se.testLDAP(),onSuccess:x=>{e(x.message,x.success?"success":"error")},onError:x=>{e(x.message,"error")}}),f=()=>{if(!i.ldap_server_url){e(t("settings.ldap.errors.serverRequired")||"LDAP server URL is required","error");return}if(!i.ldap_search_base){e(t("settings.ldap.errors.searchBaseRequired")||"Search base DN is required","error");return}const x={ldap_server_url:i.ldap_server_url,ldap_bind_dn:i.ldap_bind_dn,ldap_search_base:i.ldap_search_base,ldap_user_filter:i.ldap_user_filter,ldap_security:i.ldap_security,ldap_group_mapping:i.ldap_group_mapping,ldap_auto_provision:i.ldap_auto_provision,ldap_default_group:i.ldap_default_group};i.ldap_bind_password&&(x.ldap_bind_password=i.ldap_bind_password),u.mutate(x)},b=()=>{if(!a){e(t("settings.ldap.errors.enableAuthFirst")||"Enable authentication first","error");return}if(!c?.ldap_enabled&&!c?.ldap_configured){e(t("settings.ldap.errors.configureLdapFirst")||"Save LDAP settings first","error");return}m.mutate(!c?.ldap_enabled)};if(l)return r.jsx("div",{className:"flex items-center justify-center p-12",children:r.jsx(pt,{className:"w-8 h-8 animate-spin text-bambu-green"})});const w=c?.ldap_enabled??!1,g="w-full px-3 py-2 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";return r.jsxs("div",{className:"space-y-3",children:[r.jsxs(Ct,{id:"card-ldap-toggle",children:[r.jsx(pn,{children:r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(Sl,{className:"w-5 h-5 text-bambu-green"}),r.jsx("h2",{className:"text-lg font-semibold text-white",children:t("settings.ldap.title")||"LDAP Authentication"})]}),r.jsx(Me,{onClick:b,disabled:m.isPending,variant:w?"danger":"primary",children:w?r.jsxs(r.Fragment,{children:[r.jsx(K0,{className:"w-4 h-4"}),t("common.disable")||"Disable"]}):r.jsxs(r.Fragment,{children:[r.jsx(lc,{className:"w-4 h-4"}),t("common.enable")||"Enable"]})})]})}),r.jsx(At,{children:w?r.jsx("div",{className:"bg-green-500/10 border border-green-500/30 rounded-lg p-4",children:r.jsxs("div",{className:"flex items-start gap-3",children:[r.jsx(wr,{className:"w-5 h-5 text-green-400 mt-0.5 flex-shrink-0"}),r.jsxs("div",{className:"space-y-2",children:[r.jsx("p",{className:"text-white font-medium",children:t("settings.ldap.enabledDesc")||"LDAP authentication is enabled"}),r.jsxs("ul",{className:"text-sm text-green-300 space-y-1 list-disc list-inside",children:[r.jsx("li",{children:t("settings.ldap.feature1")||"Users can login with LDAP credentials"}),r.jsx("li",{children:t("settings.ldap.feature2")||"Local admin account remains as fallback"}),r.jsx("li",{children:t("settings.ldap.feature3")||"LDAP groups are mapped to BamBuddy groups on login"})]})]})]})}):r.jsx("div",{className:"bg-yellow-500/10 border border-yellow-500/30 rounded-lg p-4",children:r.jsxs("div",{className:"flex items-start gap-3",children:[r.jsx(Nn,{className:"w-5 h-5 text-yellow-400 mt-0.5 flex-shrink-0"}),r.jsxs("div",{children:[r.jsx("p",{className:"text-white font-medium",children:t("settings.ldap.disabledDesc")||"LDAP authentication is disabled"}),r.jsx("p",{className:"text-sm text-yellow-300 mt-1",children:t("settings.ldap.disabledHint")||"Configure and save LDAP settings below, then enable."})]})]})})})]}),r.jsxs(Ct,{id:"card-ldap-server",children:[r.jsx(pn,{children:r.jsx("h2",{className:"text-lg font-semibold text-white",children:t("settings.ldap.serverConfig")||"LDAP Server Configuration"})}),r.jsx(At,{children:r.jsxs("div",{className:"space-y-3",children:[r.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-3",children:[r.jsxs("div",{className:"md:col-span-2",children:[r.jsx("label",{className:"block text-sm font-medium text-bambu-gray mb-1",children:t("settings.ldap.serverUrl")||"Server URL"}),r.jsx("input",{type:"text",className:g,placeholder:"ldaps://ldap.example.com:636",value:i.ldap_server_url,onChange:x=>s({...i,ldap_server_url:x.target.value})}),r.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:t("settings.ldap.serverUrlHint")||"Use ldaps:// for SSL or ldap:// with StartTLS"})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm font-medium text-bambu-gray mb-1",children:t("settings.ldap.security")||"Security"}),r.jsx("div",{className:"flex gap-2",children:["starttls","ldaps"].map(x=>r.jsx("button",{onClick:()=>s({...i,ldap_security:x}),className:`flex-1 px-2 py-2 rounded-lg text-sm font-medium transition-colors ${i.ldap_security===x?"bg-bambu-green text-black":"bg-bambu-dark-secondary text-bambu-gray hover:text-white border border-bambu-dark-tertiary"}`,children:x==="starttls"?"StartTLS":"LDAPS"},x))}),r.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:t("settings.ldap.securityHint")||`Default port: ${cat[i.ldap_security]}`})]})]}),r.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm font-medium text-bambu-gray mb-1",children:t("settings.ldap.bindDn")||"Bind DN (Service Account)"}),r.jsx("input",{type:"text",className:g,placeholder:"cn=service-account,ou=service,dc=example,dc=com",value:i.ldap_bind_dn,onChange:x=>s({...i,ldap_bind_dn:x.target.value})})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm font-medium text-bambu-gray mb-1",children:t("settings.ldap.bindPassword")||"Bind Password"}),r.jsx("input",{type:"password",className:g,placeholder:o?.ldap_bind_dn?"••••••••":"",value:i.ldap_bind_password,onChange:x=>s({...i,ldap_bind_password:x.target.value})})]})]}),r.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm font-medium text-bambu-gray mb-1",children:t("settings.ldap.searchBase")||"Search Base DN"}),r.jsx("input",{type:"text",className:g,placeholder:"ou=users,dc=example,dc=com",value:i.ldap_search_base,onChange:x=>s({...i,ldap_search_base:x.target.value})})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm font-medium text-bambu-gray mb-1",children:t("settings.ldap.userFilter")||"User Search Filter"}),r.jsx("input",{type:"text",className:g,placeholder:"(sAMAccountName={username})",value:i.ldap_user_filter,onChange:x=>s({...i,ldap_user_filter:x.target.value})})]})]}),r.jsx(o5,{summary:r.jsx("span",{className:"text-sm font-medium text-bambu-gray",children:t("settings.ldap.advanced")||"Advanced"}),className:"border-t border-bambu-dark-tertiary pt-3",summaryClassName:"py-1",children:r.jsxs("div",{className:"space-y-3",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm font-medium text-white",children:t("settings.ldap.autoProvision")||"Auto-provision users"}),r.jsx("p",{className:"text-xs text-bambu-gray mt-0.5",children:t("settings.ldap.autoProvisionHint")||"Automatically create a BamBuddy account on first LDAP login"})]}),r.jsx("button",{onClick:()=>s({...i,ldap_auto_provision:!i.ldap_auto_provision}),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors flex-shrink-0 ${i.ldap_auto_provision?"bg-bambu-green":"bg-bambu-dark-tertiary"}`,children:r.jsx("span",{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${i.ldap_auto_provision?"translate-x-6":"translate-x-1"}`})})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm font-medium text-bambu-gray mb-1",children:t("settings.ldap.defaultGroup")||"Default group"}),r.jsxs("select",{className:g,value:i.ldap_default_group,onChange:x=>s({...i,ldap_default_group:x.target.value}),children:[r.jsx("option",{value:"",children:t("settings.ldap.defaultGroupNone")||"— None (reject login) —"}),d.map(x=>r.jsx("option",{value:x.name,children:x.name},x.id))]}),r.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:t("settings.ldap.defaultGroupHint")||"Fallback group assigned when an LDAP user authenticates but is not listed in any mapped group. Leave empty to leave unmapped users without permissions."})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm font-medium text-bambu-gray mb-1",children:t("settings.ldap.groupMapping")||"Group Mapping (JSON)"}),r.jsx("textarea",{className:`${g} font-mono text-sm`,rows:4,placeholder:`{ "CN=PrintFarm_Admins,OU=Groups,DC=example,DC=com": "Administrators", "CN=PrintFarm_Users,OU=Groups,DC=example,DC=com": "Operators" }`,value:i.ldap_group_mapping,onChange:x=>s({...i,ldap_group_mapping:x.target.value})}),r.jsxs("p",{className:"text-xs text-bambu-gray mt-1",children:[t("settings.ldap.groupMappingHint")||"Map LDAP group DNs to BamBuddy groups. Available groups: ",d.map(x=>x.name).join(", ")]})]})]})}),r.jsxs("div",{className:"flex gap-3 pt-2",children:[r.jsxs(Me,{onClick:f,disabled:u.isPending,children:[u.isPending?r.jsx(pt,{className:"w-4 h-4 animate-spin"}):r.jsx(wr,{className:"w-4 h-4"}),t("common.save")||"Save"]}),r.jsxs(Me,{variant:"secondary",onClick:()=>p.mutate(),disabled:p.isPending,children:[p.isPending?r.jsx(pt,{className:"w-4 h-4 animate-spin"}):r.jsx(DS,{className:"w-4 h-4"}),t("settings.ldap.testConnection")||"Test Connection"]})]})]})})]})]})}function BN({value:t,onChange:e,placeholder:n,maxLength:a=6}){return r.jsx("input",{type:"text",value:t,onChange:i=>e(i.target.value.toUpperCase().replace(/\s/g,"")),maxLength:a,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 font-mono tracking-widest text-center",placeholder:n,autoComplete:"one-time-code"})}function Pce({codes:t,onDone:e}){const{t:n}=kt(),[a,i]=y.useState(!1),s=()=>{navigator.clipboard.writeText(t.join(` -`)),i(!0),setTimeout(()=>i(!1),2e3)};return r.jsxs("div",{className:"space-y-4",children:[r.jsx("div",{className:"bg-amber-500/10 border border-amber-500/30 rounded-lg p-4",children:r.jsx("p",{className:"text-amber-400 text-sm font-medium",children:n("settings.twoFa.backupCodesWarning")})}),r.jsx("div",{className:"grid grid-cols-2 gap-2",children:t.map((o,l)=>r.jsx("code",{className:"bg-bambu-dark-secondary rounded px-3 py-2 text-center font-mono text-sm text-white tracking-widest",children:o},l))}),r.jsxs("div",{className:"flex gap-3",children:[r.jsxs(Me,{variant:"secondary",size:"sm",onClick:s,className:"flex items-center gap-2",children:[r.jsx(Mi,{className:"w-4 h-4"}),n(a?"common.copied":"common.copy")]}),r.jsx(Me,{variant:"primary",size:"sm",onClick:e,className:"flex-1",children:n("settings.twoFa.savedCodes")})]})]})}function uat({onDone:t}){const{t:e}=kt(),n=en(),{showToast:a}=rn(),[i,s]=y.useState("qr"),[o,l]=y.useState(""),[c,d]=y.useState([]),[u,m]=y.useState(!1),{data:p,isLoading:f}=Ve({queryKey:["totp-setup"],queryFn:()=>se.setupTOTP(),staleTime:1/0}),b=it({mutationFn:w=>se.enableTOTP(w),onSuccess:w=>{d(w.backup_codes),s("backup"),n.invalidateQueries({queryKey:["2fa-status"]})},onError:()=>a(e("settings.twoFa.invalidCode"),"error")});return f||!p?r.jsx("div",{className:"flex items-center justify-center py-8",children:r.jsx(sr,{className:"w-6 h-6 animate-spin text-bambu-green"})}):i==="qr"?r.jsxs("div",{className:"space-y-4",children:[r.jsx("p",{className:"text-bambu-gray-light text-sm",children:e("settings.twoFa.setupInstructions")}),r.jsx("div",{className:"flex justify-center",children:r.jsx("img",{src:`data:image/png;base64,${p.qr_code_b64}`,alt:"TOTP QR Code",className:"w-48 h-48 rounded-lg"})}),r.jsxs("div",{children:[r.jsx("p",{className:"text-xs text-bambu-gray mb-1",children:e("settings.twoFa.manualEntry")}),r.jsxs("div",{className:"flex items-center gap-2 bg-bambu-dark-secondary rounded-lg px-3 py-2",children:[r.jsx("code",{className:"text-white text-xs font-mono flex-1 break-all",children:u?p.secret:"••••••••••••••••"}),r.jsx("button",{onClick:()=>m(!u),className:"text-bambu-gray hover:text-white",children:u?r.jsx(sb,{className:"w-4 h-4"}):r.jsx(Dl,{className:"w-4 h-4"})}),r.jsx("button",{onClick:()=>{navigator.clipboard.writeText(p.secret)},className:"text-bambu-gray hover:text-white",children:r.jsx(Mi,{className:"w-4 h-4"})})]})]}),r.jsx(Me,{variant:"primary",className:"w-full",onClick:()=>s("confirm"),children:e("settings.twoFa.scannedContinue")})]}):i==="confirm"?r.jsxs("div",{className:"space-y-4",children:[r.jsx("p",{className:"text-bambu-gray-light text-sm",children:e("settings.twoFa.enterCodeToConfirm")}),r.jsx(BN,{value:o,onChange:l,placeholder:"000000"}),r.jsxs("div",{className:"flex gap-3",children:[r.jsx(Me,{variant:"secondary",onClick:()=>s("qr"),className:"flex-1",children:e("common.back")}),r.jsx(Me,{variant:"primary",className:"flex-1",disabled:o.length!==6||b.isPending,onClick:()=>b.mutate(o),children:b.isPending?e("common.saving"):e("settings.twoFa.activate")})]})]}):r.jsxs("div",{className:"space-y-4",children:[r.jsx("h3",{className:"text-white font-medium",children:e("settings.twoFa.backupCodesTitle")}),r.jsx(Pce,{codes:c,onDone:t})]})}function mat(){const{t}=kt(),e=en(),{showToast:n}=rn(),{user:a}=cr(),[i,s]=y.useState(!1),[o,l]=y.useState(!1),[c,d]=y.useState(!1),[u,m]=y.useState(""),[p,f]=y.useState(""),[b,w]=y.useState(null),[g,x]=y.useState(null),[_,N]=y.useState(""),[C,P]=y.useState(!1),[T,A]=y.useState(""),[F,S]=y.useState(!1),{data:E,isLoading:U}=Ve({queryKey:["2fa-status"],queryFn:()=>se.get2FAStatus()}),{data:I}=Ve({queryKey:["oidc-links"],queryFn:()=>se.getOIDCLinks()}),H=it({mutationFn:()=>se.enableEmailOTP(),onSuccess:ue=>{x(ue.setup_token),n(ue.message,"success")},onError:ue=>{const X=ue.message??"";X.toLowerCase().includes("smtp")?n(t("settings.twoFa.smtpRequired"),"error"):n(X,"error")}}),R=it({mutationFn:()=>se.confirmEnableEmailOTP(g,_),onSuccess:()=>{e.invalidateQueries({queryKey:["2fa-status"]}),x(null),N(""),n(t("settings.twoFa.emailOtpEnabled"),"success")},onError:ue=>n(ue.message,"error")}),Q=it({mutationFn:ue=>se.disableEmailOTP(ue),onSuccess:()=>{e.invalidateQueries({queryKey:["2fa-status"]}),P(!1),A(""),n(t("settings.twoFa.emailOtpDisabled"),"success")},onError:ue=>n(ue.message,"error")}),re=it({mutationFn:ue=>se.disableTOTP(ue),onSuccess:()=>{e.invalidateQueries({queryKey:["2fa-status"]}),l(!1),m(""),n(t("settings.twoFa.totpDisabled"),"success")},onError:()=>n(t("settings.twoFa.invalidCode"),"error")}),J=it({mutationFn:ue=>se.regenerateBackupCodes(ue),onSuccess:ue=>{e.invalidateQueries({queryKey:["2fa-status"]}),d(!1),f(""),w(ue.backup_codes)},onError:()=>n(t("settings.twoFa.invalidCode"),"error")}),de=it({mutationFn:ue=>se.deleteOIDCLink(ue),onSuccess:()=>{e.invalidateQueries({queryKey:["oidc-links"]}),n(t("settings.twoFa.oidcUnlinked"),"success")},onError:ue=>n(ue.message,"error")});if(U)return r.jsx("div",{className:"flex items-center justify-center py-12",children:r.jsx(sr,{className:"w-6 h-6 animate-spin text-bambu-green"})});const pe=!!a?.email;return r.jsxs("div",{className:"space-y-6",children:[r.jsxs(Ct,{id:"card-2fa-totp",children:[r.jsx(pn,{children:r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx("div",{className:`w-10 h-10 rounded-full flex items-center justify-center ${E?.totp_enabled?"bg-green-500/20":"bg-gray-500/20"}`,children:r.jsx(GF,{className:`w-5 h-5 ${E?.totp_enabled?"text-green-400":"text-gray-400"}`})}),r.jsxs("div",{children:[r.jsx("h3",{className:"text-white font-semibold",children:t("settings.twoFa.totpTitle")}),r.jsx("p",{className:"text-bambu-gray text-sm",children:t("settings.twoFa.totpDesc")})]}),r.jsx("div",{className:"ml-auto",children:E?.totp_enabled?r.jsxs("span",{className:"flex items-center gap-1 text-green-400 text-sm font-medium",children:[r.jsx(Ew,{className:"w-4 h-4"})," ",t("common.enabled")]}):r.jsxs("span",{className:"flex items-center gap-1 text-bambu-gray text-sm",children:[r.jsx(VF,{className:"w-4 h-4"})," ",t("common.disabled")]})})]})}),r.jsx(At,{children:i?r.jsxs("div",{className:"space-y-4",children:[r.jsxs("div",{className:"flex items-center justify-between mb-2",children:[r.jsx("h4",{className:"text-white font-medium",children:t("settings.twoFa.setupAuthApp")}),r.jsx("button",{onClick:()=>{s(!1),e.removeQueries({queryKey:["totp-setup"]})},className:"text-bambu-gray hover:text-white",children:r.jsx(Ht,{className:"w-5 h-5"})})]}),r.jsx(uat,{onDone:()=>{s(!1),e.removeQueries({queryKey:["totp-setup"]})}})]}):o?r.jsxs("div",{className:"space-y-4",children:[r.jsx("p",{className:"text-bambu-gray-light text-sm",children:t("settings.twoFa.disableConfirmHint")}),r.jsx(BN,{value:u,onChange:m,placeholder:"000000 or XXXXXXXX",maxLength:8}),r.jsxs("div",{className:"flex gap-3",children:[r.jsx(Me,{variant:"secondary",onClick:()=>{l(!1),m("")},className:"flex-1",children:t("common.cancel")}),r.jsx(Me,{variant:"danger",className:"flex-1",disabled:u.length<6||re.isPending,onClick:()=>re.mutate(u),children:re.isPending?t("common.saving"):t("settings.twoFa.disableTotp")})]})]}):c?r.jsxs("div",{className:"space-y-4",children:[r.jsx("p",{className:"text-bambu-gray-light text-sm",children:t("settings.twoFa.regenBackupHint")}),r.jsx(BN,{value:p,onChange:f,placeholder:"000000 or XXXXXXXX",maxLength:8}),r.jsxs("div",{className:"flex gap-3",children:[r.jsx(Me,{variant:"secondary",onClick:()=>{d(!1),f("")},className:"flex-1",children:t("common.cancel")}),r.jsx(Me,{variant:"primary",className:"flex-1",disabled:p.length<6||J.isPending,onClick:()=>J.mutate(p),children:J.isPending?t("common.saving"):t("settings.twoFa.regenBackup")})]})]}):b?r.jsxs("div",{className:"space-y-4",children:[r.jsx("h4",{className:"text-white font-medium",children:t("settings.twoFa.newBackupCodes")}),r.jsx(Pce,{codes:b,onDone:()=>w(null)})]}):r.jsx("div",{className:"space-y-3",children:E?.totp_enabled?r.jsxs("div",{className:"flex flex-wrap gap-3",children:[r.jsxs("div",{className:"flex items-center gap-2 text-sm text-bambu-gray-light",children:[r.jsx(vo,{className:"w-4 h-4"}),t("settings.twoFa.backupCodesRemaining",{count:E.backup_codes_remaining})]}),r.jsxs(Me,{variant:"secondary",size:"sm",onClick:()=>d(!0),className:"flex items-center gap-2",children:[r.jsx(sr,{className:"w-4 h-4"}),t("settings.twoFa.regenBackup")]}),r.jsxs(Me,{variant:"danger",size:"sm",onClick:()=>l(!0),className:"flex items-center gap-2",children:[r.jsx(Jt,{className:"w-4 h-4"}),t("settings.twoFa.disableTotp")]})]}):r.jsxs(Me,{variant:"primary",onClick:()=>s(!0),className:"flex items-center gap-2",children:[r.jsx(GF,{className:"w-4 h-4"}),t("settings.twoFa.setupTotp")]})})})]}),r.jsxs(Ct,{id:"card-2fa-emailotp",children:[r.jsx(pn,{children:r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx("div",{className:`w-10 h-10 rounded-full flex items-center justify-center ${E?.email_otp_enabled?"bg-green-500/20":"bg-gray-500/20"}`,children:r.jsx(qm,{className:`w-5 h-5 ${E?.email_otp_enabled?"text-green-400":"text-gray-400"}`})}),r.jsxs("div",{className:"flex-1",children:[r.jsx("h3",{className:"text-white font-semibold",children:t("settings.twoFa.emailOtpTitle")}),r.jsx("p",{className:"text-bambu-gray text-sm",children:pe?t("settings.twoFa.emailOtpDesc",{email:a?.email}):t("settings.twoFa.emailOtpNoEmail")})]}),r.jsx("div",{className:"ml-auto",children:E?.email_otp_enabled?r.jsxs("span",{className:"flex items-center gap-1 text-green-400 text-sm font-medium",children:[r.jsx(Ew,{className:"w-4 h-4"})," ",t("common.enabled")]}):r.jsxs("span",{className:"flex items-center gap-1 text-bambu-gray text-sm",children:[r.jsx(VF,{className:"w-4 h-4"})," ",t("common.disabled")]})})]})}),r.jsx(At,{children:pe?g?r.jsxs("div",{className:"space-y-4",children:[r.jsx("p",{className:"text-bambu-gray-light text-sm",children:t("settings.twoFa.emailSetupEnterCode")}),r.jsx(BN,{value:_,onChange:N,placeholder:"000000"}),r.jsxs("div",{className:"flex gap-3",children:[r.jsx(Me,{variant:"secondary",onClick:()=>{x(null),N("")},className:"flex-1",children:t("common.cancel")}),r.jsx(Me,{variant:"primary",className:"flex-1",disabled:_.length!==6||R.isPending,onClick:()=>R.mutate(),children:R.isPending?t("common.saving"):t("settings.twoFa.verifyAndEnable")})]})]}):C?r.jsxs("div",{className:"space-y-4",children:[r.jsx("p",{className:"text-bambu-gray-light text-sm",children:t("settings.twoFa.emailDisablePasswordHint")}),r.jsxs("div",{className:"relative",children:[r.jsx("input",{type:F?"text":"password",value:T,onChange:ue=>A(ue.target.value),placeholder:t("settings.twoFa.passwordPlaceholder"),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"}),r.jsx("button",{type:"button",onClick:()=>S(!F),className:"absolute right-3 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white",children:F?r.jsx(sb,{className:"w-5 h-5"}):r.jsx(Dl,{className:"w-5 h-5"})})]}),r.jsxs("div",{className:"flex gap-3",children:[r.jsx(Me,{variant:"secondary",onClick:()=>{P(!1),A("")},className:"flex-1",children:t("common.cancel")}),r.jsx(Me,{variant:"danger",className:"flex-1",disabled:!T||Q.isPending,onClick:()=>Q.mutate(T),children:Q.isPending?t("common.saving"):t("settings.twoFa.disableEmailOtp")})]})]}):r.jsx("div",{className:"flex gap-3",children:E?.email_otp_enabled?r.jsxs(Me,{variant:"danger",size:"sm",onClick:()=>P(!0),className:"flex items-center gap-2",children:[r.jsx(Jt,{className:"w-4 h-4"}),t("settings.twoFa.disableEmailOtp")]}):r.jsxs(Me,{variant:"primary",disabled:!pe||H.isPending,onClick:()=>H.mutate(),className:"flex items-center gap-2",children:[r.jsx(qm,{className:"w-4 h-4"}),H.isPending?t("common.saving"):t("settings.twoFa.enableEmailOtp")]})}):r.jsx("p",{className:"text-amber-400 text-sm",children:t("settings.twoFa.addEmailFirst")})})]}),I&&I.length>0&&r.jsxs(Ct,{id:"card-2fa-linked",children:[r.jsxs(pn,{children:[r.jsx("h3",{className:"text-white font-semibold",children:t("settings.twoFa.linkedAccounts")}),r.jsx("p",{className:"text-bambu-gray text-sm",children:t("settings.twoFa.linkedAccountsDesc")})]}),r.jsx(At,{children:r.jsx("div",{className:"space-y-3",children:I.map(ue=>r.jsxs("div",{className:"flex items-center justify-between py-2 border-b border-bambu-dark-tertiary last:border-0",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-white text-sm font-medium",children:ue.provider_name}),ue.provider_email&&r.jsx("p",{className:"text-bambu-gray text-xs",children:ue.provider_email})]}),r.jsx(Me,{variant:"danger",size:"sm",onClick:()=>de.mutate(ue.provider_id),disabled:de.isPending,children:r.jsx(Jt,{className:"w-4 h-4"})})]},ue.id))})})]})]})}const pat={name:"",issuer_url:"",client_id:"",client_secret:"",scopes:"openid email profile",is_enabled:!0,auto_create_users:!1,auto_link_existing_accounts:!1,email_claim:"email",require_email_verified:!0,icon_url:void 0,default_group_id:null};function cQ({initial:t,isEdit:e=!1,groups:n=[],onSave:a,onCancel:i,isPending:s}){const{t:o}=kt(),[l,c]=y.useState(t),[d,u]=y.useState(!1),m=(_,N)=>c(C=>({...C,[_]:N})),p="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 text-sm",f="block text-sm font-medium text-white mb-1",b=()=>{const _={...l};e&&!d&&delete _.client_secret,a(_)},w=l.auto_link_existing_accounts===!0,g=l.require_email_verified??!0;let x;return w?x=o("settings.oidc.form.requireEmailVerifiedAutoLink"):g?x=o("settings.oidc.form.requireEmailVerifiedDesc"):x=r.jsx("span",{className:"text-red-400",children:o("settings.oidc.form.requireEmailVerifiedWarning")}),r.jsxs("div",{className:"space-y-4",children:[r.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[r.jsxs("div",{children:[r.jsxs("label",{className:f,children:[o("settings.oidc.form.name")," ",r.jsx("span",{className:"text-red-400",children:"*"})]}),r.jsx("input",{className:p,value:l.name,onChange:_=>m("name",_.target.value),placeholder:"Google"})]}),r.jsxs("div",{children:[r.jsxs("label",{className:f,children:[o("settings.oidc.form.issuerUrl")," ",r.jsx("span",{className:"text-red-400",children:"*"})]}),r.jsx("input",{className:p,value:l.issuer_url,onChange:_=>m("issuer_url",_.target.value),placeholder:"https://accounts.google.com"})]}),r.jsxs("div",{children:[r.jsxs("label",{className:f,children:[o("settings.oidc.form.clientId")," ",r.jsx("span",{className:"text-red-400",children:"*"})]}),r.jsx("input",{className:p,value:l.client_id,onChange:_=>m("client_id",_.target.value),placeholder:"your-client-id"})]}),r.jsxs("div",{children:[r.jsxs("label",{className:f,children:[o("settings.oidc.form.clientSecret"),!e&&r.jsx("span",{className:"text-red-400",children:" *"}),e&&r.jsxs("span",{className:"text-bambu-gray text-xs ml-1",children:["(",o("settings.oidc.form.secretHint"),")"]})]}),r.jsx("input",{className:p,type:"password",value:d?l.client_secret:"",placeholder:e&&!d?"••••••••":o("settings.oidc.form.secretPlaceholder"),onChange:_=>{u(!0),m("client_secret",_.target.value)}})]}),r.jsxs("div",{children:[r.jsx("label",{className:f,children:o("settings.oidc.form.scopes")}),r.jsx("input",{className:p,value:l.scopes,onChange:_=>m("scopes",_.target.value),placeholder:"openid email profile"})]}),r.jsxs("div",{children:[r.jsx("label",{className:f,children:o("settings.oidc.form.iconUrl")}),r.jsx("input",{className:p,value:l.icon_url??"",onChange:_=>m("icon_url",_.target.value||void 0),placeholder:"https://..."})]})]}),r.jsxs("div",{className:"flex flex-wrap gap-6 pt-2",children:[r.jsxs("label",{className:"flex items-center gap-3 cursor-pointer",children:[r.jsx(En,{checked:l.is_enabled??!0,onChange:_=>m("is_enabled",_)}),r.jsx("span",{className:"text-white text-sm",children:o("settings.oidc.form.enabled")})]}),r.jsxs("label",{className:"flex items-center gap-3 cursor-pointer",children:[r.jsx(En,{checked:l.auto_create_users??!1,onChange:_=>m("auto_create_users",_)}),r.jsxs("div",{children:[r.jsx("p",{className:"text-white text-sm",children:o("settings.oidc.form.autoCreate")}),r.jsx("p",{className:"text-bambu-gray text-xs",children:o("settings.oidc.form.autoCreateDesc")})]})]}),r.jsxs("label",{className:"flex items-center gap-3 cursor-pointer w-full",children:[r.jsx(En,{checked:l.auto_link_existing_accounts??!1,onChange:_=>m("auto_link_existing_accounts",_)}),r.jsxs("div",{children:[r.jsx("p",{className:"text-white text-sm",children:o("settings.oidc.form.autoLink")}),r.jsx("p",{className:"text-bambu-gray text-xs",children:o("settings.oidc.form.autoLinkDesc")})]})]}),r.jsxs("label",{className:"flex items-center gap-3 cursor-pointer w-full",children:[r.jsx(En,{checked:g,onChange:_=>m("require_email_verified",_),disabled:w}),r.jsxs("div",{children:[r.jsx("p",{className:"text-white text-sm",children:o("settings.oidc.form.requireEmailVerified")}),r.jsx("p",{className:"text-bambu-gray text-xs",children:x})]})]})]}),r.jsxs("div",{children:[r.jsx("label",{className:f,children:o("settings.oidc.form.emailClaim")}),r.jsx("input",{className:p,value:l.email_claim,onChange:_=>m("email_claim",_.target.value||"email"),placeholder:o("settings.oidc.form.emailClaimPlaceholder")}),r.jsx("p",{className:"text-bambu-gray text-xs mt-1",children:o("settings.oidc.form.emailClaimDesc")}),w&&l.email_claim!=="email"&&r.jsx("p",{className:"text-yellow-400 text-xs mt-1",children:o("settings.oidc.form.emailClaimCustomClaimAutoLinkWarning")})]}),r.jsxs("div",{children:[r.jsx("label",{className:f,children:o("settings.oidc.form.defaultGroup")}),r.jsxs("select",{className:p,value:l.default_group_id??"",onChange:_=>m("default_group_id",_.target.value?Number(_.target.value):null),children:[r.jsx("option",{value:"",children:o("settings.oidc.form.defaultGroupViewersFallback")}),n.map(_=>r.jsx("option",{value:_.id,children:_.name},_.id))]}),r.jsx("p",{className:"text-bambu-gray text-xs mt-1",children:o("settings.oidc.form.defaultGroupDesc")})]}),r.jsxs("div",{className:"flex gap-3 pt-2",children:[r.jsx(Me,{variant:"secondary",onClick:i,className:"flex-1",children:o("common.cancel")}),r.jsx(Me,{variant:"primary",className:"flex-1",disabled:!l.name||!l.issuer_url||!l.client_id||!e&&!l.client_secret||e&&d&&!l.client_secret||s,onClick:b,children:o(s?"common.saving":"common.save")})]})]})}function hat(){const{t}=kt(),e=en(),{showToast:n}=rn(),[a,i]=y.useState(!1),[s,o]=y.useState(null),[l,c]=y.useState(null),{data:d,isLoading:u}=Ve({queryKey:["oidc-providers-all"],queryFn:()=>se.getOIDCProvidersAll()}),{data:m=[]}=Ve({queryKey:["groups"],queryFn:()=>se.getGroups()}),p=it({mutationFn:g=>se.createOIDCProvider(g),onSuccess:()=>{e.invalidateQueries({queryKey:["oidc-providers-all"]}),i(!1),n(t("settings.oidc.created"),"success")},onError:g=>n(g.message,"error")}),f=it({mutationFn:({id:g,data:x})=>se.updateOIDCProvider(g,x),onSuccess:()=>{e.invalidateQueries({queryKey:["oidc-providers-all"]}),o(null),n(t("settings.oidc.updated"),"success")},onError:g=>n(g.message,"error")}),b=it({mutationFn:g=>se.deleteOIDCProvider(g),onSuccess:()=>{e.invalidateQueries({queryKey:["oidc-providers-all"]}),c(null),n(t("settings.oidc.deleted"),"success")},onError:g=>n(g.message,"error")}),w=g=>f.mutate({id:g.id,data:{is_enabled:!g.is_enabled}});return u?r.jsx("div",{className:"flex items-center justify-center py-12",children:r.jsx(sr,{className:"w-6 h-6 animate-spin text-bambu-green"})}):r.jsxs("div",{className:"space-y-6",children:[r.jsxs(Ct,{id:"card-oidc",children:[r.jsx(pn,{children:r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("h3",{className:"text-white font-semibold",children:t("settings.oidc.title")}),r.jsx("p",{className:"text-bambu-gray text-sm",children:t("settings.oidc.desc")})]}),!a&&r.jsxs(Me,{variant:"primary",size:"sm",onClick:()=>i(!0),className:"flex items-center gap-2",children:[r.jsx(ar,{className:"w-4 h-4"}),t("settings.oidc.addProvider")]})]})}),a&&r.jsx(At,{children:r.jsxs("div",{className:"border-t border-bambu-dark-tertiary pt-4",children:[r.jsx("h4",{className:"text-white font-medium mb-4",children:t("settings.oidc.newProvider")}),r.jsx(cQ,{initial:pat,groups:m,onSave:g=>p.mutate(g),onCancel:()=>i(!1),isPending:p.isPending})]})})]}),d&&d.length===0&&!a&&r.jsx(Ct,{id:"card-oidc-empty",children:r.jsx(At,{children:r.jsxs("div",{className:"text-center py-8 space-y-3",children:[r.jsx(no,{className:"w-12 h-12 text-bambu-gray mx-auto"}),r.jsx("p",{className:"text-bambu-gray",children:t("settings.oidc.empty")}),r.jsxs(Me,{variant:"primary",size:"sm",onClick:()=>i(!0),className:"inline-flex items-center gap-2",children:[r.jsx(ar,{className:"w-4 h-4"}),t("settings.oidc.addProvider")]})]})})}),d?.map(g=>r.jsxs(Ct,{children:[r.jsx(pn,{children:r.jsxs("div",{className:"flex items-center gap-3",children:[g.icon_url?r.jsx("img",{src:g.icon_url,alt:g.name,className:"w-8 h-8 rounded object-contain",onError:x=>{x.target.style.display="none"}}):r.jsx("div",{className:"w-8 h-8 rounded-full bg-bambu-dark-tertiary flex items-center justify-center",children:r.jsx(no,{className:"w-4 h-4 text-bambu-gray"})}),r.jsxs("div",{className:"flex-1",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("h4",{className:"text-white font-medium",children:g.name}),g.is_enabled?r.jsxs("span",{className:"flex items-center gap-1 text-xs text-green-400 bg-green-400/10 px-2 py-0.5 rounded-full",children:[r.jsx(_r,{className:"w-3 h-3"})," ",t("common.enabled")]}):r.jsxs("span",{className:"flex items-center gap-1 text-xs text-bambu-gray bg-bambu-dark-tertiary px-2 py-0.5 rounded-full",children:[r.jsx(Ht,{className:"w-3 h-3"})," ",t("common.disabled")]})]}),r.jsxs("div",{className:"flex items-center gap-1 text-bambu-gray text-xs mt-0.5",children:[r.jsx(Rr,{className:"w-3 h-3"}),r.jsx("span",{children:g.issuer_url})]})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(En,{checked:g.is_enabled,onChange:()=>w(g),disabled:f.isPending}),r.jsx(Me,{variant:"secondary",size:"sm",onClick:()=>o(s===g.id?null:g.id),children:r.jsx(fc,{className:"w-4 h-4"})}),r.jsx(Me,{variant:"danger",size:"sm",onClick:()=>c(g),children:r.jsx(Jt,{className:"w-4 h-4"})})]})]})}),s===g.id&&r.jsx(At,{children:r.jsx("div",{className:"border-t border-bambu-dark-tertiary pt-4",children:r.jsx(cQ,{isEdit:!0,groups:m,initial:{name:g.name,issuer_url:g.issuer_url,client_id:g.client_id,client_secret:"",scopes:g.scopes,is_enabled:g.is_enabled,auto_create_users:g.auto_create_users,auto_link_existing_accounts:g.auto_link_existing_accounts,email_claim:g.email_claim,require_email_verified:g.require_email_verified,icon_url:g.icon_url??void 0,default_group_id:g.default_group_id??null},onSave:x=>f.mutate({id:g.id,data:x}),onCancel:()=>o(null),isPending:f.isPending})})}),s!==g.id&&r.jsx(At,{children:r.jsxs("dl",{className:"grid grid-cols-2 sm:grid-cols-3 gap-x-6 gap-y-2 text-sm",children:[r.jsxs("div",{children:[r.jsx("dt",{className:"text-bambu-gray",children:t("settings.oidc.form.clientId")}),r.jsx("dd",{className:"text-white font-mono truncate",children:g.client_id})]}),r.jsxs("div",{children:[r.jsx("dt",{className:"text-bambu-gray",children:t("settings.oidc.form.scopes")}),r.jsx("dd",{className:"text-white",children:g.scopes})]}),r.jsxs("div",{children:[r.jsx("dt",{className:"text-bambu-gray",children:t("settings.oidc.form.autoCreate")}),r.jsx("dd",{className:g.auto_create_users?"text-green-400":"text-bambu-gray",children:g.auto_create_users?t("common.yes"):t("common.no")})]}),r.jsxs("div",{children:[r.jsx("dt",{className:"text-bambu-gray",children:t("settings.oidc.form.autoLink")}),r.jsx("dd",{className:g.auto_link_existing_accounts?"text-green-400":"text-bambu-gray",children:g.auto_link_existing_accounts?t("common.yes"):t("common.no")})]}),r.jsxs("div",{children:[r.jsx("dt",{className:"text-bambu-gray",children:t("settings.oidc.form.emailClaim")}),r.jsx("dd",{className:"text-white font-mono",children:g.email_claim})]}),r.jsxs("div",{children:[r.jsx("dt",{className:"text-bambu-gray",children:t("settings.oidc.form.requireEmailVerified")}),r.jsx("dd",{className:g.require_email_verified?"text-green-400":"text-red-400",children:g.require_email_verified?t("common.yes"):t("common.no")})]}),r.jsxs("div",{children:[r.jsx("dt",{className:"text-bambu-gray",children:t("settings.oidc.form.defaultGroup")}),r.jsx("dd",{className:"text-white",children:g.default_group_id?m.find(x=>x.id===g.default_group_id)?.name??t("settings.oidc.form.defaultGroupViewersFallback"):t("settings.oidc.form.defaultGroupViewersFallback")})]})]})})]},g.id)),l&&r.jsx(vn,{title:t("settings.oidc.deleteTitle"),message:t("settings.oidc.deleteMessage",{name:l.name}),confirmText:t("common.delete"),variant:"danger",onConfirm:()=>b.mutate(l.id),onCancel:()=>c(null)})]})}const Tce=new Map;function jn(t){Tce.set(t.anchor,t)}function fat(){return Array.from(Tce.values())}jn({labelKey:"settings.encryption.title",labelFallback:"MFA Encryption Status",tab:"users",subTab:"security",keywords:"mfa encryption status security backup totp oidc fernet",anchor:"card-mfa-encryption"});function gat(){const{t}=kt(),{data:e,isLoading:n,isError:a,refetch:i}=Ve({queryKey:["encryptionStatus"],queryFn:()=>se.getEncryptionStatus(),refetchInterval:p=>{if(!p.state.error)return 3e4;const f=p.state.fetchFailureCount??0;return f<=3?Math.min(5e3*Math.max(1,f),3e4):!1}});if(n)return r.jsxs(Ct,{id:"card-mfa-encryption","data-testid":"encryption-status-card",children:[r.jsx(pn,{children:r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(Sl,{className:"text-bambu-gray",size:20}),r.jsx("h2",{className:"text-lg font-semibold",children:t("settings.encryption.title")})]})}),r.jsx(At,{children:r.jsxs("div",{className:"flex items-center gap-2 text-bambu-gray","data-testid":"encryption-loading",children:[r.jsx(pt,{className:"animate-spin",size:16}),r.jsx("span",{children:t("common.loading")})]})})]});if(a||!e)return r.jsxs(Ct,{id:"card-mfa-encryption","data-testid":"encryption-status-card",children:[r.jsx(pn,{children:r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(Sl,{className:"text-bambu-gray",size:20}),r.jsx("h2",{className:"text-lg font-semibold",children:t("settings.encryption.title")})]})}),r.jsxs(At,{children:[r.jsx("div",{className:"text-red-400","data-testid":"encryption-error",children:t("common.errorLoading")}),r.jsx("button",{type:"button",onClick:()=>i(),className:"mt-2 text-sm text-blue-400 underline hover:text-blue-300","data-testid":"encryption-retry-button",children:t("common.retry")})]})]});const s=e.legacy_plaintext_rows.oidc_providers+e.legacy_plaintext_rows.user_totp,o=e.encrypted_rows.oidc_providers+e.encrypted_rows.user_totp;let l,c,d,u;e.decryption_broken?(l="bg-red-500/20 border-red-500/50 text-red-400",c=r.jsx(Da,{className:"text-red-400",size:20}),d=t("settings.encryption.decryptionBrokenTitle"),u=t("settings.encryption.decryptionBrokenError",{count:o})):e.key_source==="generated"?(l="bg-amber-500/10 border-amber-500/30 text-amber-400",c=r.jsx(Ew,{className:"text-amber-400",size:20}),d=t("settings.encryption.enabledGenerated"),u=t("settings.encryption.backupHint")):s>0?(l="bg-amber-500/10 border-amber-500/30 text-amber-400",c=r.jsx(Nn,{className:"text-amber-400",size:20}),d=e.key_source==="env"?t("settings.encryption.enabledFromEnv"):t("settings.encryption.enabledFromFile"),u=t("settings.encryption.legacyRowsWarning",{count:s})):e.key_configured?(l="bg-green-500/20 border-green-500/30 text-green-400",c=r.jsx(Ew,{className:"text-green-400",size:20}),d=e.key_source==="env"?t("settings.encryption.enabledFromEnv"):t("settings.encryption.enabledFromFile"),u=t("settings.encryption.allEncrypted")):(l="bg-gray-500/20 border-gray-500/30 text-gray-400",c=r.jsx(VF,{className:"text-gray-400",size:20}),d=t("settings.encryption.notConfigured"),u=t("settings.encryption.notConfiguredDesc"));const m=e.key_source==="generated"&&s>0;return r.jsxs(Ct,{id:"card-mfa-encryption","data-testid":"encryption-status-card",children:[r.jsx(pn,{children:r.jsxs("div",{className:"flex items-center gap-2",children:[c,r.jsx("h2",{className:"text-lg font-semibold",children:t("settings.encryption.title")})]})}),r.jsxs(At,{children:[r.jsxs("div",{className:`p-3 border rounded-lg ${l}`,"data-testid":"encryption-status",children:[r.jsx("p",{className:"font-medium mb-1",children:d}),r.jsx("p",{className:"text-sm",children:u})]}),m&&r.jsx("div",{className:"mt-2 p-3 border rounded-lg bg-amber-500/10 border-amber-500/30 text-amber-400","data-testid":"encryption-legacy-warning",children:r.jsx("p",{className:"text-sm",children:t("settings.encryption.legacyRowsWarning",{count:s})})}),e.migration_error_count>0&&r.jsx("div",{className:"mt-2 p-3 border rounded-lg bg-amber-500/10 border-amber-500/30 text-amber-400","data-testid":"encryption-migration-warning",children:r.jsx("p",{className:"text-sm",children:t("settings.encryption.migrationErrorWarning",{count:e.migration_error_count})})}),r.jsxs("div",{className:"mt-4 grid grid-cols-2 gap-4 text-sm",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-bambu-gray",children:t("settings.encryption.encryptedRowsLabel")}),r.jsxs("p",{className:"font-medium",children:["OIDC: ",e.encrypted_rows.oidc_providers," · TOTP: ",e.encrypted_rows.user_totp]})]}),r.jsxs("div",{children:[r.jsx("p",{className:"text-bambu-gray",children:t("settings.encryption.legacyRowsLabel")}),r.jsxs("p",{className:"font-medium",children:["OIDC: ",e.legacy_plaintext_rows.oidc_providers," · TOTP: ",e.legacy_plaintext_rows.user_totp]})]})]})]})]})}const bat={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 xat(t,e){const n=e.replace("#/","").split("/");let a=t;for(const i of n)a=a[i];return a}function $0(t,e,n=0){if(n>5)return"...";if(e.$ref)return $0(t,xat(t,e.$ref),n+1);if(e.allOf){const a={};for(const i of e.allOf){const s=$0(t,i,n+1);typeof s=="object"&&s!==null&&Object.assign(a,s)}return a}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?[$0(t,e.items,n+1)]:[];case"object":if(e.properties){const a={};for(const[i,s]of Object.entries(e.properties))a[i]=$0(t,s,n+1);return a}return{};default:return null}}function yat({path:t,method:e,spec:n,schema:a,apiKey:i}){const[s,o]=y.useState(!1),[l,c]=y.useState({}),[d,u]=y.useState(""),[m,p]=y.useState(null),[f,b]=y.useState(!1),[w,g]=y.useState(!1);y.useEffect(()=>{if(s&&n.parameters){const F={};for(const S of n.parameters)S.schema?.default!==void 0&&(F[S.name]=String(S.schema.default));c(S=>({...F,...S}))}},[s,n.parameters]),y.useEffect(()=>{if(s&&n.requestBody?.content?.["application/json"]?.schema&&!d){const F=n.requestBody.content["application/json"].schema,S=$0(a,F);u(JSON.stringify(S,null,2))}},[s,n.requestBody,a,d]);const _=(()=>{const F=[];for(const S of n.parameters||[])if(S.in==="path"||S.required){const E=l[S.name];(E===void 0||E==="")&&F.push(S.name)}return F})(),N=async()=>{if(_.length>0){p({status:0,statusText:"Validation Error",headers:{},body:`Missing required parameters: ${_.join(", ")}`,duration:0});return}b(!0),p(null);try{let F=t;const S=new URLSearchParams;for(const ue of n.parameters||[]){const X=l[ue.name];X!==void 0&&X!==""&&(ue.in==="path"?F=F.replace(`{${ue.name}}`,encodeURIComponent(X)):ue.in==="query"&&S.append(ue.name,X))}const E=S.toString(),U=`${F}${E?`?${E}`:""}`,I={"Content-Type":"application/json"};i&&(I["X-API-Key"]=i);const H={method:e.toUpperCase(),headers:I};["post","put","patch"].includes(e)&&d&&(H.body=d);const R=performance.now(),Q=await fetch(U,H),re=Math.round(performance.now()-R),J={};Q.headers.forEach((ue,X)=>{J[X]=ue});let de;Q.headers.get("content-type")?.includes("application/json")?de=await Q.json():de=await Q.text(),p({status:Q.status,statusText:Q.statusText,headers:J,body:de,duration:re})}catch(F){p({status:0,statusText:"Network Error",headers:{},body:F instanceof Error?F.message:"Unknown error",duration:0})}finally{b(!1)}},C=async()=>{if(m){const F=typeof m.body=="string"?m.body:JSON.stringify(m.body,null,2);try{await navigator.clipboard.writeText(F),g(!0),setTimeout(()=>g(!1),2e3)}catch{const S=document.createElement("textarea");S.value=F,S.style.position="fixed",S.style.left="-999999px",document.body.appendChild(S),S.select(),document.execCommand("copy"),document.body.removeChild(S),g(!0),setTimeout(()=>g(!1),2e3)}}},P=(n.parameters||[]).filter(F=>F.in==="path"),T=(n.parameters||[]).filter(F=>F.in==="query"),A=["post","put","patch"].includes(e)&&n.requestBody;return r.jsxs("div",{className:"border border-bambu-dark-tertiary rounded-lg overflow-hidden",children:[r.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?r.jsx(Ln,{className:"w-4 h-4 text-bambu-gray flex-shrink-0"}):r.jsx(Va,{className:"w-4 h-4 text-bambu-gray flex-shrink-0"}),r.jsx("span",{className:`px-2 py-0.5 text-xs font-mono font-semibold uppercase rounded border ${bat[e]||"bg-gray-500/20 text-gray-400"}`,children:e}),r.jsx("code",{className:"text-sm text-white font-mono flex-1 truncate",children:t}),n.summary&&r.jsx("span",{className:"text-sm text-bambu-gray truncate max-w-[40%]",children:n.summary})]}),s&&r.jsxs("div",{className:"border-t border-bambu-dark-tertiary p-4 space-y-4 bg-bambu-dark/50",children:[n.description&&r.jsx("p",{className:"text-sm text-bambu-gray",children:n.description}),P.length>0&&r.jsxs("div",{className:"space-y-2",children:[r.jsx("h4",{className:"text-sm font-medium text-white",children:"Path Parameters"}),r.jsx("div",{className:"space-y-2",children:P.map(F=>r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsxs("label",{className:"text-sm text-bambu-gray w-32 flex-shrink-0",children:[F.name,F.required&&r.jsx("span",{className:"text-red-400 ml-1",children:"*"})]}),r.jsx("input",{type:"text",value:l[F.name]||"",onChange:S=>c(E=>({...E,[F.name]:S.target.value})),placeholder:F.description||F.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"})]},F.name))})]}),T.length>0&&r.jsxs("div",{className:"space-y-2",children:[r.jsx("h4",{className:"text-sm font-medium text-white",children:"Query Parameters"}),r.jsx("div",{className:"space-y-2",children:T.map(F=>r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsxs("label",{className:"text-sm text-bambu-gray w-32 flex-shrink-0",children:[F.name,F.required&&r.jsx("span",{className:"text-red-400 ml-1",children:"*"})]}),F.schema?.enum?r.jsxs("select",{value:l[F.name]||"",onChange:S=>c(E=>({...E,[F.name]:S.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:[r.jsx("option",{value:"",children:"-- Select --"}),F.schema.enum.map(S=>r.jsx("option",{value:S,children:S},S))]}):r.jsx("input",{type:"text",value:l[F.name]||"",onChange:S=>c(E=>({...E,[F.name]:S.target.value})),placeholder:F.description||F.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"})]},F.name))})]}),A&&r.jsxs("div",{className:"space-y-2",children:[r.jsx("h4",{className:"text-sm font-medium text-white",children:"Request Body"}),r.jsx("textarea",{value:d,onChange:F=>u(F.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..."})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsxs(Me,{onClick:N,disabled:f,children:[f?r.jsx(pt,{className:"w-4 h-4 animate-spin"}):r.jsx(fs,{className:"w-4 h-4"}),"Execute"]}),_.length>0&&r.jsxs("span",{className:"text-xs text-yellow-400 flex items-center gap-1",children:[r.jsx($a,{className:"w-3 h-3"}),"Fill in: ",_.join(", ")]})]}),m&&r.jsxs("div",{className:"space-y-2",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("h4",{className:"text-sm font-medium text-white flex items-center gap-2",children:["Response",r.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]}),r.jsxs("span",{className:"text-xs text-bambu-gray",children:[m.duration,"ms"]})]}),r.jsx(Me,{variant:"secondary",size:"sm",onClick:C,children:w?r.jsx(wr,{className:"w-3 h-3 text-green-400"}):r.jsx(Mi,{className:"w-3 h-3"})})]}),r.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 vat({apiKey:t=""}){const[e,n]=y.useState(null),[a,i]=y.useState(!0),[s,o]=y.useState(null),[l,c]=y.useState(new Set),[d,u]=y.useState("");if(y.useEffect(()=>{async function g(){try{const x=await fetch("/openapi.json");if(!x.ok)throw new Error("Failed to fetch OpenAPI schema");const _=await x.json();n(_)}catch(x){o(x instanceof Error?x.message:"Unknown error")}finally{i(!1)}}g()},[]),a)return r.jsx("div",{className:"flex justify-center py-12",children:r.jsx(pt,{className:"w-8 h-8 text-bambu-green animate-spin"})});if(s||!e)return r.jsx(Ct,{children:r.jsx(At,{className:"py-8",children:r.jsxs("div",{className:"text-center text-red-400",children:[r.jsx($a,{className:"w-12 h-12 mx-auto mb-3 opacity-50"}),r.jsx("p",{children:"Failed to load API schema"}),r.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:s})]})})});const m={};for(const[g,x]of Object.entries(e.paths))for(const[_,N]of Object.entries(x)){if(_==="parameters")continue;const C=N.tags||["Other"];for(const P of C)m[P]||(m[P]=[]),m[P].push({path:g,method:_,spec:N})}const p=Object.entries(m).map(([g,x])=>{if(!d)return{tag:g,endpoints:x};const _=x.filter(({path:N,method:C,spec:P})=>{const T=d.toLowerCase();return N.toLowerCase().includes(T)||C.toLowerCase().includes(T)||(P.summary?.toLowerCase()||"").includes(T)||(P.description?.toLowerCase()||"").includes(T)});return{tag:g,endpoints:_}}).filter(({endpoints:g})=>g.length>0).sort((g,x)=>g.tag.localeCompare(x.tag)),f=g=>{c(x=>{const _=new Set(x);return _.has(g)?_.delete(g):_.add(g),_})},b=()=>{c(new Set(p.map(g=>g.tag)))},w=()=>{c(new Set)};return r.jsxs("div",{className:"space-y-4",children:[r.jsxs("div",{className:"flex items-center justify-between gap-4",children:[r.jsx("div",{className:"flex-1",children:r.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"})}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(Me,{variant:"secondary",size:"sm",onClick:b,children:"Expand All"}),r.jsx(Me,{variant:"secondary",size:"sm",onClick:w,children:"Collapse All"}),r.jsxs("a",{href:"/docs",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1 text-sm text-bambu-green hover:underline",children:[r.jsx(Rr,{className:"w-4 h-4"}),"Swagger UI"]})]})]}),r.jsxs("p",{className:"text-sm text-bambu-gray",children:[p.reduce((g,x)=>g+x.endpoints.length,0)," endpoints in ",p.length," categories"]}),r.jsx("div",{className:"space-y-3",children:p.map(({tag:g,endpoints:x})=>r.jsxs(Ct,{children:[r.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:r.jsxs("div",{className:"flex items-center gap-2",children:[l.has(g)?r.jsx(Ln,{className:"w-5 h-5 text-bambu-gray"}):r.jsx(Va,{className:"w-5 h-5 text-bambu-gray"}),r.jsx("h3",{className:"text-base font-semibold text-white capitalize",children:g.replace(/-/g," ")}),r.jsx("span",{className:"text-xs bg-bambu-dark-tertiary px-2 py-0.5 rounded-full text-bambu-gray",children:x.length})]})}),l.has(g)&&r.jsx(At,{className:"pt-0 space-y-2",children:x.map(({path:_,method:N,spec:C})=>r.jsx(yat,{path:_,method:N,spec:C,schema:e,apiKey:t},`${N}-${_}`))})]},g))})]})}const wat=["general","plugs","notifications","queue","filament","network","apikeys","virtual-printer","spoolbuddy","failure-detection","users","backup"];jn({labelKey:"settings.general",tab:"general",keywords:"language date time format printer model printers cards",anchor:"card-general"});jn({labelKey:"settings.appearance",tab:"general",keywords:"theme dark light mode colors",anchor:"card-appearance"});jn({labelKey:"settings.archiveSettings",tab:"general",keywords:"archive auto save thumbnails captures",anchor:"card-archive"});jn({labelKey:"settings.camera",tab:"general",keywords:"camera external video stream",anchor:"card-camera"});jn({labelKey:"settings.costTracking",tab:"general",keywords:"currency filament cost energy kwh price",anchor:"card-cost"});jn({labelKey:"settings.fileManager",tab:"general",keywords:"file manager archive mode disk warning storage",anchor:"card-filemanager"});jn({labelKey:"settings.updates",tab:"general",keywords:"updates version firmware beta check",anchor:"card-updates"});jn({labelKey:"settings.dataManagement",tab:"general",keywords:"data reset clear logs notifications preferences",anchor:"card-data"});jn({labelKey:"settings.smartPlugs",tab:"plugs",keywords:"smart plug energy power automation tapo kasa tplink shelly",anchor:"card-plugs"});jn({labelKey:"settings.providers",tab:"notifications",keywords:"telegram discord email notification providers webhook",anchor:"card-providers"});jn({labelKey:"settings.messageTemplates",tab:"notifications",keywords:"message templates notification text edit",anchor:"card-templates"});jn({labelKey:"settings.defaultPrintOptions",labelFallback:"Default Print Options",tab:"queue",keywords:"print bed leveling flow calibration vibration first layer timelapse",anchor:"card-print-options"});jn({labelKey:"settings.staggeredStart",labelFallback:"Staggered Start",tab:"queue",keywords:"staggered batch delay start queue group",anchor:"card-staggered"});jn({labelKey:"settings.plateClear",labelFallback:"Plate-Clear Confirmation",tab:"queue",keywords:"plate clear confirm auto queue",anchor:"card-plate"});jn({labelKey:"settings.gcodeInjection",labelFallback:"G-code Injection",tab:"queue",keywords:"gcode injection start end autoprint farmloop swapmod autoclear printflow",anchor:"card-gcode"});jn({labelKey:"settings.slicerCard",labelFallback:"Slicer",tab:"queue",keywords:"slicer orcaslicer bambustudio orca bambu api sidecar url docker preferred",anchor:"card-slicer"});jn({labelKey:"settings.queueDrying",tab:"queue",keywords:"drying presets temperature time humidity ams",anchor:"card-drying"});jn({labelKey:"settings.filamentChecks",tab:"filament",keywords:"filament check warning runout remaining",anchor:"card-filamentchecks"});jn({labelKey:"settings.printModal",tab:"filament",keywords:"print modal custom mapping",anchor:"card-printmodal"});jn({labelKey:"settings.amsDisplayThresholds",tab:"filament",keywords:"ams humidity temperature threshold history retention",anchor:"card-amsthresholds"});jn({labelKey:"settings.externalUrl",tab:"network",keywords:"external url reverse proxy public notification link",anchor:"card-externalurl"});jn({labelKey:"settings.ftpRetry",tab:"network",keywords:"ftp retry upload retries backoff",anchor:"card-ftpretry"});jn({labelKey:"settings.homeAssistant",tab:"network",keywords:"home assistant ha hass mqtt integration",anchor:"card-ha"});jn({labelKey:"settings.mqttPublishing",tab:"network",keywords:"mqtt publish broker topic",anchor:"card-mqtt"});jn({labelKey:"settings.prometheusMetrics",tab:"network",keywords:"prometheus metrics grafana monitoring bearer token",anchor:"card-prometheus"});jn({labelKey:"settings.createNewApiKey",tab:"apikeys",keywords:"api key create permission scope",anchor:"card-createapi"});jn({labelKey:"settings.webhookEndpoints",tab:"apikeys",keywords:"webhook endpoint post http",anchor:"card-webhooks"});jn({labelKey:"settings.apiBrowser",tab:"apikeys",keywords:"api browser endpoint documentation test",anchor:"card-apibrowser"});jn({labelKey:"cameraTokens.title",tab:"apikeys",keywords:"camera token long-lived home assistant frigate kiosk stream",anchor:"card-camera-tokens"});jn({labelKey:"settings.tabs.virtualPrinter",tab:"virtual-printer",keywords:"virtual printer proxy archive slicer bambustudio orcaslicer ip bind",anchor:"card-vp"});jn({labelKey:"settings.tabs.spoolbuddy",tab:"spoolbuddy",keywords:"spoolbuddy device scale nfc rfid kiosk unregister",anchor:"card-spoolbuddy"});jn({labelKey:"settings.currentUser",tab:"users",subTab:"users",keywords:"current user profile password change",anchor:"card-currentuser"});jn({labelKey:"settings.users",tab:"users",subTab:"users",keywords:"users accounts list",anchor:"card-users"});jn({labelKey:"settings.groups",tab:"users",subTab:"users",keywords:"groups roles permissions administrators operators viewers",anchor:"card-groups"});jn({labelKey:"settings.email.smtpSettings",labelFallback:"SMTP Configuration",tab:"users",subTab:"email",keywords:"smtp email send server port password auth starttls ssl",anchor:"card-smtp"});jn({labelKey:"settings.ldap.title",labelFallback:"LDAP Authentication",tab:"users",subTab:"ldap",keywords:"ldap active directory ad authentication bind dn search base group mapping",anchor:"card-ldap"});jn({labelKey:"settings.tabs.backup",tab:"backup",keywords:"backup github restore download cloud sync profiles archives",anchor:"card-backup"});jn({labelKey:"externalLinks.title",labelFallback:"Sidebar Links",tab:"general",keywords:"sidebar links external custom navigation url add",anchor:"card-sidebar-links"});jn({labelKey:"settings.filamentTracking",tab:"filament",keywords:"spoolman filament tracking inventory sync remote integration",anchor:"card-spoolman"});jn({labelKey:"settings.catalog.spoolCatalog",labelFallback:"Spool Catalog",tab:"filament",keywords:"spool catalog entries brand material reset import export",anchor:"card-spool-catalog"});jn({labelKey:"settings.colorCatalog.title",labelFallback:"Color Catalog",tab:"filament",keywords:"color catalog hex swatch palette sync reset",anchor:"card-color-catalog"});jn({labelKey:"settings.tabs.failureDetection",labelFallback:"Failure Detection",tab:"failure-detection",keywords:"failure detection ai ml obico spaghetti detect monitoring",anchor:"card-fd-ml"});jn({labelKey:"failureDetection.perPrinterTitle",labelFallback:"Per-Printer Settings",tab:"failure-detection",keywords:"failure detection per printer enable per-printer sensitivity",anchor:"card-fd-perprinter"});jn({labelKey:"failureDetection.statusTitle",labelFallback:"Detection Status",tab:"failure-detection",keywords:"failure detection status running connection",anchor:"card-fd-status"});jn({labelKey:"failureDetection.historyTitle",labelFallback:"Detection History",tab:"failure-detection",keywords:"failure detection history log events",anchor:"card-fd-history"});jn({labelKey:"settings.email.advancedAuth",labelFallback:"Advanced Email Authentication",tab:"users",subTab:"email",keywords:"email authentication advanced password reset self-service forgot",anchor:"card-email-advanced-auth"});jn({labelKey:"settings.email.testConnection",labelFallback:"Test SMTP Connection",tab:"users",subTab:"email",keywords:"email smtp test connection send check",anchor:"card-email-test"});jn({labelKey:"settings.twoFa.totpTitle",labelFallback:"Authenticator App (TOTP)",tab:"users",subTab:"twofa",keywords:"two factor 2fa totp authenticator app google authy otp",anchor:"card-2fa-totp"});jn({labelKey:"settings.twoFa.emailOtpTitle",labelFallback:"Email One-Time Codes",tab:"users",subTab:"twofa",keywords:"two factor 2fa email otp one time code",anchor:"card-2fa-emailotp"});jn({labelKey:"settings.twoFa.linkedAccounts",labelFallback:"Linked Accounts",tab:"users",subTab:"twofa",keywords:"two factor 2fa linked accounts sso oidc provider google github",anchor:"card-2fa-linked"});jn({labelKey:"settings.oidc.title",labelFallback:"Single Sign-On (OIDC)",tab:"users",subTab:"oidc",keywords:"sso oidc openid single sign-on pocketid authentik keycloak google okta azure provider",anchor:"card-oidc"});jn({labelKey:"settings.ldap.serverConfig",labelFallback:"LDAP Server Configuration",tab:"users",subTab:"ldap",keywords:"ldap server url bind dn user search base group filter tls",anchor:"card-ldap-server"});jn({labelKey:"backup.githubBackup",labelFallback:"GitHub Backup",tab:"backup",keywords:"github backup cloud remote sync profiles token",anchor:"card-backup-github"});jn({labelKey:"backup.history",labelFallback:"Backup History",tab:"backup",keywords:"backup history log runs github commits",anchor:"card-backup-history"});jn({labelKey:"backup.localBackup",labelFallback:"Local Backup",tab:"backup",keywords:"local backup download zip manual export",anchor:"card-backup-local"});jn({labelKey:"backup.scheduledBackup",labelFallback:"Scheduled Backups",tab:"backup",keywords:"scheduled backup automatic hourly daily weekly retention local path",anchor:"card-backup-scheduled"});const Sat={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"},dQ=["bg-blue-500","bg-green-500","bg-yellow-500","bg-red-500","bg-orange-500","bg-teal-500","bg-cyan-500","bg-purple-500"],uQ=(t,e)=>Sat[t]||dQ[e%dQ.length];function _at(){const t=en(),e=Di(),[n,a]=ab(),{t:i,i18n:s}=kt(),{showToast:o}=rn(),{authEnabled:l,user:c,isAdmin:d,refreshAuth:u,hasPermission:m}=cr(),{mode:p,darkStyle:f,darkBackground:b,darkAccent:w,lightStyle:g,lightBackground:x,lightAccent:_,setDarkStyle:N,setDarkBackground:C,setDarkAccent:P,setLightStyle:T,setLightBackground:A,setLightAccent:F}=cb(),[S,E]=y.useState(null),[U,I]=y.useState(!1),[H,R]=y.useState(null),[Q,re]=y.useState(!1),[J,de]=y.useState(null),[pe,ue]=y.useState(null),[X,ae]=y.useState(""),[me,be]=y.useState(""),[Ce,$]=y.useState(!1),[W,D]=y.useState(JZ()),j=n.get("tab"),B=j==="email",Y=B?"users":j&&wat.includes(j)?j:"general",[O,ie]=y.useState(Y),[z,G]=y.useState(B?"email":"users"),K=Se=>{ie(Se),Se==="users"&&G("users"),Se==="general"?n.delete("tab"):n.set("tab",Se),a(n,{replace:!0})},[Z,oe]=y.useState(!1),[ee,ge]=y.useState(""),[ce,le]=y.useState({can_queue:!0,can_control_printer:!1,can_read_status:!0,can_access_cloud:!1}),[q,L]=y.useState(null),[ne,ye]=y.useState(null),[we,Ne]=y.useState(""),[ve,xe]=y.useState(!1),[Ee,ze]=y.useState(!1),[_e,Oe]=y.useState(null),[Ie,We]=y.useState(!1),[at,lt]=y.useState(!1),[Fe,tt]=y.useState(!1),[Pe,Ye]=y.useState({currentPassword:"",newPassword:"",confirmPassword:""}),[Ue,fe]=y.useState(!1),[Ae,qe]=y.useState(!1),[nt,Qe]=y.useState(!1),[gt,ct]=y.useState(!1),[rt,Ot]=y.useState(null),[Wt,Zt]=y.useState(null),[Yt,un]=y.useState(null),[bn,dt]=y.useState(!1),[st,vt]=y.useState({username:"",password:"",email:"",confirmPassword:"",role:"user",group_ids:[]}),[_t,Dt]=y.useState(null),[De,je]=y.useState(null),[$e,Je]=y.useState(!1),[Re,mt]=y.useState({}),[he,Le]=y.useState({}),Xe=Se=>{D(Se),Bve(Se),o(i("settings.toast.settingsSaved"),"success")},Ze=()=>{localStorage.removeItem("sidebarOrder"),window.location.reload()},Ke=!!S?.default_sidebar_order,bt=async Se=>{try{if(Se){let Rt;const an=localStorage.getItem("sidebarOrder");try{Rt=an?JSON.parse(an):vm.map(Bn=>Bn.id)}catch{Rt=vm.map(Bn=>Bn.id)}(!Array.isArray(Rt)||Rt.length===0)&&(Rt=vm.map(Bn=>Bn.id));const An=JSON.stringify({order:Rt});await se.updateSettings({default_sidebar_order:An}),E(Bn=>Bn&&{...Bn,default_sidebar_order:An}),o(i("settings.sidebarDefaultSet"),"success")}else await se.updateSettings({default_sidebar_order:""}),E(Rt=>Rt&&{...Rt,default_sidebar_order:""}),o(i("settings.sidebarDefaultCleared"),"success");t.invalidateQueries({queryKey:["settings"]}),t.invalidateQueries({queryKey:["default-sidebar-order"]})}catch{o(i("settings.sidebarDefaultFailed"),"error")}},{data:et,isLoading:jt}=Ve({queryKey:["settings"],queryFn:se.getSettings}),{data:St,isLoading:It,isFetching:zt}=Ve({queryKey:["storage-usage"],queryFn:()=>se.getStorageUsage(),enabled:O==="general",staleTime:1/0,refetchInterval:!1,refetchOnWindowFocus:!1,refetchOnReconnect:!1}),He=async()=>{qe(!0);try{const Se=await se.getStorageUsage({refresh:!0});t.setQueryData(["storage-usage"],Se)}catch(Se){const Rt=Se instanceof Error?Se.message:"Failed to refresh storage usage";o(Rt,"error")}finally{qe(!1)}},{data:Ge,isLoading:Vt}=Ve({queryKey:["smart-plugs"],queryFn:se.getSmartPlugs}),{data:Qt,isLoading:mn}=Ve({queryKey:["smart-plugs-energy",Ge?.map(Se=>Se.id)],queryFn:async()=>{if(!Ge||Ge.length===0)return null;const Se=await Promise.all(Ge.filter(Na=>Na.enabled).map(async Na=>{try{const ot=await se.getSmartPlugStatus(Na.id);return{plug:Na,status:ot}}catch{return{plug:Na,status:null}}}));let Rt=0,an=0,An=0,Bn=0,ba=0;for(const{plug:Na,status:ot}of Se){const $t=Na.plug_type==="mqtt"&&ot?.energy?.power!=null;(ot?.reachable||$t)&&ot?.energy&&(ba++,ot.energy?.power!=null&&(Rt+=ot.energy.power),ot.energy?.today!=null&&(an+=ot.energy.today),ot.energy?.yesterday!=null&&(An+=ot.energy.yesterday),ot.energy?.total!=null&&(Bn+=ot.energy.total))}return{totalPower:Rt,totalToday:an,totalYesterday:An,totalLifetime:Bn,reachableCount:ba,totalPlugs:Ge.filter(Na=>Na.enabled).length}},enabled:O==="plugs"&&!!Ge&&Ge.length>0,refetchInterval:O==="plugs"?1e4:!1}),{data:wn,isLoading:gn}=Ve({queryKey:["notification-providers"],queryFn:se.getNotificationProviders}),{data:Cn,isLoading:Mn}=Ve({queryKey:["api-keys"],queryFn:se.getAPIKeys}),xr=it({mutationFn:Se=>se.createAPIKey(Se),onSuccess:Se=>{L(Se.key||null),oe(!1),ge(""),t.invalidateQueries({queryKey:["api-keys"]}),o(i("settings.toast.apiKeyCreated"))},onError:Se=>{o(`Failed to create API key: ${Se.message}`,"error")}}),Er=it({mutationFn:Se=>se.deleteAPIKey(Se),onSuccess:(Se,Rt)=>{t.setQueryData(["api-keys"],an=>(an??[]).filter(An=>An.id!==Rt)),o(i("settings.toast.apiKeyDeleted"))},onError:Se=>{o(`Failed to delete API key: ${Se.message}`,"error")}}),{data:zn}=Ve({queryKey:["printers"],queryFn:se.getPrinters}),{data:Xa,isLoading:Kn}=Ve({queryKey:["notification-templates"],queryFn:se.getNotificationTemplates}),{data:Ar}=Ve({queryKey:["virtual-printer-settings"],queryFn:WF.getSettings,refetchInterval:1e4}),ca=Ar?.status?.running??!1,{data:jr}=Ve({queryKey:["spoolbuddy-devices"],queryFn:()=>Xr.getDevices(),refetchInterval:15e3}),da=jr?.length??0,Ki=jr?.some(Se=>Se.online)??!1,{data:Yi}=Ve({queryKey:["obico-status"],queryFn:se.getObicoStatus,refetchInterval:15e3}),bd=!!(Yi?.is_running&&Yi?.enabled),{data:Lc}=Ve({queryKey:["ffmpeg-status"],queryFn:se.checkFfmpeg}),{data:$s}=Ve({queryKey:["version"],queryFn:se.getVersion}),Ft=!l||m("library:purge"),{data:cn}=Ve({queryKey:["library-trash-settings"],queryFn:()=>se.getLibraryTrashSettings(),enabled:Ft}),hr=it({mutationFn:Se=>se.updateLibraryTrashSettings(Se),onSuccess:()=>{t.invalidateQueries({queryKey:["library-trash-settings"]}),o(i("settings.toast.settingsSaved"),"success")},onError:Se=>o(Se.message||i("libraryAutoPurge.saveFailed"),"error")}),Gt=Se=>{cn&&hr.mutate({retention_days:cn.retention_days,auto_purge_enabled:cn.auto_purge_enabled,auto_purge_days:cn.auto_purge_days,auto_purge_include_never_printed:cn.auto_purge_include_never_printed,...Se})},Ol=!l||m("archives:purge"),{data:mo}=Ve({queryKey:["archive-purge-settings"],queryFn:()=>se.getArchivePurgeSettings(),enabled:Ol}),xd=it({mutationFn:Se=>se.updateArchivePurgeSettings(Se),onSuccess:()=>{t.invalidateQueries({queryKey:["archive-purge-settings"]}),o(i("settings.toast.settingsSaved"),"success")},onError:Se=>o(Se.message||i("archiveAutoPurge.saveFailed"),"error")}),Rc=Se=>{mo&&xd.mutate({enabled:mo.enabled,days:mo.days,...Se})},{data:Or,refetch:mf,isRefetching:il}=Ve({queryKey:["updateCheck"],queryFn:se.checkForUpdates,enabled:et?.check_updates!==!1,staleTime:300*1e3}),{data:Xi,refetch:sl}=Ve({queryKey:["updateStatus"],queryFn:se.getUpdateStatus,refetchInterval:Se=>{const Rt=Se.state.data;return Rt?.status==="downloading"||Rt?.status==="installing"?1e3:!1}}),{data:vs}=Ve({queryKey:["mqtt-status"],queryFn:se.getMQTTStatus,refetchInterval:O==="network"?5e3:!1}),{data:zl}=Ve({queryKey:["github-backup-status"],queryFn:se.getGitHubBackupStatus}),{data:po}=Ve({queryKey:["cloud-status"],queryFn:se.getCloudStatus}),{data:di={advanced_auth_enabled:!1,smtp_configured:!1}}=Ve({queryKey:["advancedAuthStatus"],queryFn:()=>se.getAdvancedAuthStatus()}),{data:lp}=Ve({queryKey:["ldapStatus"],queryFn:()=>se.getLDAPStatus()}),{data:pf}=Ve({queryKey:["twoFAStatus"],queryFn:()=>se.get2FAStatus()}),{data:yd=[]}=Ve({queryKey:["oidcProvidersAll"],queryFn:()=>se.getOIDCProvidersAll(),enabled:d}),{data:Ic=[],isLoading:cp}=Ve({queryKey:["users"],queryFn:()=>se.getUsers(),enabled:l&&m("users:read")}),{data:Qr=[],isLoading:Do}=Ve({queryKey:["groups"],queryFn:()=>se.getGroups(),enabled:l&&m("groups:read")}),ol=it({mutationFn:Se=>se.createUser(Se),onSuccess:()=>{t.invalidateQueries({queryKey:["users"]}),t.invalidateQueries({queryKey:["groups"]}),Qe(!1),vt({username:"",password:"",email:"",confirmPassword:"",role:"user",group_ids:[]}),o(i("settings.toast.userCreated"))},onError:Se=>{o(Se.message,"error")}}),ll=it({mutationFn:({id:Se,data:Rt})=>se.updateUser(Se,Rt),onSuccess:()=>{t.invalidateQueries({queryKey:["users"]}),t.invalidateQueries({queryKey:["groups"]}),ct(!1),Ot(null),vt({username:"",password:"",email:"",confirmPassword:"",role:"user",group_ids:[]}),o(i("settings.toast.userUpdated"))},onError:Se=>{o(Se.message,"error")}}),cl=it({mutationFn:({id:Se,deleteItems:Rt})=>se.deleteUser(Se,Rt),onSuccess:()=>{t.invalidateQueries({queryKey:["users"]}),o(i("settings.toast.userDeleted")),Zt(null),un(null)},onError:Se=>{o(Se.message,"error")}}),vd=it({mutationFn:Se=>se.resetUserPassword({user_id:Se}),onSuccess:Se=>{o(Se.message,"success")},onError:Se=>{o(Se.message,"error")}}),dp=async Se=>{Zt(Se),dt(!0);try{const Rt=await se.getUserItemsCount(Se);un(Rt)}catch{un({archives:0,queue_items:0,library_files:0})}finally{dt(!1)}},Fo=it({mutationFn:Se=>se.deleteGroup(Se),onSuccess:()=>{t.invalidateQueries({queryKey:["groups"]}),o(i("settings.toast.groupDeleted"))},onError:Se=>{o(Se.message,"error")}}),wd=()=>{const Se=di?.advanced_auth_enabled||!1;if(!st.username){o(i("settings.toast.fillRequiredFields"),"error");return}if(Se&&!st.email){o("Email is required when advanced authentication is enabled","error");return}if(!Se){if(!st.password){o(i("settings.toast.fillRequiredFields"),"error");return}if(st.password!==st.confirmPassword){o(i("settings.toast.passwordsDoNotMatch"),"error");return}const Rt=cN(st.password);if(Rt){o(i({tooShort:"settings.toast.passwordTooShort",needsUppercase:"settings.toast.passwordNeedsUppercase",needsLowercase:"settings.toast.passwordNeedsLowercase",needsDigit:"settings.toast.passwordNeedsDigit",needsSpecial:"settings.toast.passwordNeedsSpecial"}[Rt]),"error");return}}ol.mutate({username:st.username,password:Se?void 0:st.password,email:st.email||void 0,role:st.role,group_ids:st.group_ids.length>0?st.group_ids:void 0})},gb=Se=>{if(st.password){if(st.password!==st.confirmPassword){o(i("settings.toast.passwordsDoNotMatch"),"error");return}const an=cN(st.password);if(an){o(i({tooShort:"settings.toast.passwordTooShort",needsUppercase:"settings.toast.passwordNeedsUppercase",needsLowercase:"settings.toast.passwordNeedsLowercase",needsDigit:"settings.toast.passwordNeedsDigit",needsSpecial:"settings.toast.passwordNeedsSpecial"}[an]),"error");return}}const Rt={username:st.username||void 0,password:st.password||void 0,email:st.email||void 0,role:st.role,group_ids:st.group_ids};Rt.password||delete Rt.password,ll.mutate({id:Se,data:Rt})},hv=Se=>{Ot(Se.id),vt({username:Se.username,password:"",email:Se.email||"",confirmPassword:"",role:Se.role,group_ids:Se.groups?.map(Rt=>Rt.id)||[]}),ct(!0)},hf=Se=>{vt(Rt=>({...Rt,group_ids:Rt.group_ids.includes(Se)?Rt.group_ids.filter(an=>an!==Se):[...Rt.group_ids,Se]}))},ff=it({mutationFn:se.applyUpdate,onSuccess:Se=>{Se.is_ha_addon||Se.is_docker?o(Se.message,"error"):sl()}}),[ho,up]=y.useState(null),Cu=it({mutationFn:se.testAllNotificationProviders,onSuccess:Se=>{up(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")}}),Lo=it({mutationFn:async Se=>{if(!Ge)return{success:0,failed:0};const Rt=Ge.filter(An=>An.enabled),an=await Promise.all(Rt.map(async An=>{try{return await se.controlSmartPlug(An.id,Se),{success:!0}}catch{return{success:!1}}}));return{success:an.filter(An=>An.success).length,failed:an.filter(An=>!An.success).length}},onSuccess:(Se,Rt)=>{t.invalidateQueries({queryKey:["smart-plugs"]}),t.invalidateQueries({queryKey:["smart-plugs-energy"]}),Se.failed===0?o(`All ${Se.success} plugs turned ${Rt}`,"success"):o(`${Se.success} plugs turned ${Rt}, ${Se.failed} failed`,"error")},onError:Se=>{o(`Failed: ${Se.message}`,"error")}}),dl=y.useRef(null),Sd=y.useRef(null),ws=y.useRef(!1),mp=y.useRef(!0);y.useEffect(()=>{if(et&&!S){const Se={...et,external_url:et.external_url||window.location.origin};E(Se),setTimeout(()=>{mp.current=!1},100)}},[et,S]);const Pu=it({mutationFn:se.updateSettings,onSuccess:Se=>{t.setQueryData(["settings"],Se),t.invalidateQueries({queryKey:["archiveStats"]}),o(i("settings.toast.settingsSaved"),"success")},onError:Se=>{o(`Failed to save: ${Se.message}`,"error")},onSettled:()=>{ws.current=!1}}),Tu=it({mutationFn:({id:Se,data:Rt})=>se.updatePrinter(Se,Rt),onSuccess:()=>{t.invalidateQueries({queryKey:["printers"]}),o(i("settings.toast.cameraSettingsSaved"),"success")},onError:Se=>{o(`Failed to update printer: ${Se.message}`,"error")}});y.useEffect(()=>{if(!(mp.current||!S||!et||l&&!m("settings:update")||!(et.auto_archive!==S.auto_archive||et.save_thumbnails!==S.save_thumbnails||et.capture_finish_photo!==S.capture_finish_photo||et.default_filament_cost!==S.default_filament_cost||et.currency!==S.currency||et.energy_cost_per_kwh!==S.energy_cost_per_kwh||et.energy_tracking_mode!==S.energy_tracking_mode||et.check_updates!==S.check_updates||(et.check_printer_firmware??!0)!==(S.check_printer_firmware??!0)||(et.include_beta_updates??!1)!==(S.include_beta_updates??!1)||et.notification_language!==S.notification_language||(et.bed_cooled_threshold??35)!==(S.bed_cooled_threshold??35)||et.ams_humidity_good!==S.ams_humidity_good||et.ams_humidity_fair!==S.ams_humidity_fair||et.ams_temp_good!==S.ams_temp_good||et.ams_temp_fair!==S.ams_temp_fair||et.ams_history_retention_days!==S.ams_history_retention_days||et.disable_filament_warnings!==S.disable_filament_warnings||et.prefer_lowest_filament!==S.prefer_lowest_filament||(et.queue_drying_enabled??!1)!==(S.queue_drying_enabled??!1)||(et.queue_drying_block??!1)!==(S.queue_drying_block??!1)||(et.ambient_drying_enabled??!1)!==(S.ambient_drying_enabled??!1)||(et.drying_presets??"")!==(S.drying_presets??"")||et.per_printer_mapping_expanded!==S.per_printer_mapping_expanded||et.date_format!==S.date_format||et.time_format!==S.time_format||et.default_printer_id!==S.default_printer_id||et.ftp_retry_enabled!==S.ftp_retry_enabled||et.ftp_retry_count!==S.ftp_retry_count||et.ftp_retry_delay!==S.ftp_retry_delay||et.ftp_timeout!==S.ftp_timeout||et.mqtt_enabled!==S.mqtt_enabled||et.mqtt_broker!==S.mqtt_broker||et.mqtt_port!==S.mqtt_port||et.mqtt_username!==S.mqtt_username||et.mqtt_password!==S.mqtt_password||et.mqtt_topic_prefix!==S.mqtt_topic_prefix||et.mqtt_use_tls!==S.mqtt_use_tls||et.external_url!==S.external_url||et.ha_enabled!==S.ha_enabled||et.ha_url!==S.ha_url||et.ha_token!==S.ha_token||(et.library_archive_mode??"ask")!==(S.library_archive_mode??"ask")||Number(et.library_disk_warning_gb??5)!==Number(S.library_disk_warning_gb??5)||(et.camera_view_mode??"window")!==(S.camera_view_mode??"window")||(et.preferred_slicer??"bambu_studio")!==(S.preferred_slicer??"bambu_studio")||(et.use_slicer_api??!1)!==(S.use_slicer_api??!1)||(et.orcaslicer_api_url??"")!==(S.orcaslicer_api_url??"")||(et.bambu_studio_api_url??"")!==(S.bambu_studio_api_url??"")||et.prometheus_enabled!==S.prometheus_enabled||et.prometheus_token!==S.prometheus_token||(et.user_notifications_enabled??!0)!==(S.user_notifications_enabled??!0)||(et.default_bed_levelling??!0)!==(S.default_bed_levelling??!0)||(et.default_flow_cali??!1)!==(S.default_flow_cali??!1)||(et.default_vibration_cali??!0)!==(S.default_vibration_cali??!0)||(et.default_layer_inspect??!1)!==(S.default_layer_inspect??!1)||(et.default_timelapse??!1)!==(S.default_timelapse??!1)||(et.stagger_group_size??2)!==(S.stagger_group_size??2)||(et.stagger_interval_minutes??5)!==(S.stagger_interval_minutes??5)||(et.require_plate_clear??!1)!==(S.require_plate_clear??!1)))&&!ws.current)return dl.current&&clearTimeout(dl.current),dl.current=setTimeout(()=>{if(ws.current)return;ws.current=!0;const Rt={auto_archive:S.auto_archive,save_thumbnails:S.save_thumbnails,capture_finish_photo:S.capture_finish_photo,default_filament_cost:S.default_filament_cost,currency:S.currency,energy_cost_per_kwh:S.energy_cost_per_kwh,energy_tracking_mode:S.energy_tracking_mode,check_updates:S.check_updates,check_printer_firmware:S.check_printer_firmware,include_beta_updates:S.include_beta_updates,notification_language:S.notification_language,bed_cooled_threshold:S.bed_cooled_threshold,ams_humidity_good:S.ams_humidity_good,ams_humidity_fair:S.ams_humidity_fair,ams_temp_good:S.ams_temp_good,ams_temp_fair:S.ams_temp_fair,ams_history_retention_days:S.ams_history_retention_days,disable_filament_warnings:S.disable_filament_warnings,prefer_lowest_filament:S.prefer_lowest_filament,queue_drying_enabled:S.queue_drying_enabled,queue_drying_block:S.queue_drying_block,ambient_drying_enabled:S.ambient_drying_enabled,drying_presets:S.drying_presets,per_printer_mapping_expanded:S.per_printer_mapping_expanded,date_format:S.date_format,time_format:S.time_format,default_printer_id:S.default_printer_id,ftp_retry_enabled:S.ftp_retry_enabled,ftp_retry_count:S.ftp_retry_count,ftp_retry_delay:S.ftp_retry_delay,ftp_timeout:S.ftp_timeout,mqtt_enabled:S.mqtt_enabled,mqtt_broker:S.mqtt_broker,mqtt_port:S.mqtt_port,mqtt_username:S.mqtt_username,mqtt_password:S.mqtt_password,mqtt_topic_prefix:S.mqtt_topic_prefix,mqtt_use_tls:S.mqtt_use_tls,external_url:S.external_url,ha_enabled:S.ha_enabled,ha_url:S.ha_url,ha_token:S.ha_token,library_archive_mode:S.library_archive_mode,library_disk_warning_gb:S.library_disk_warning_gb,camera_view_mode:S.camera_view_mode,preferred_slicer:S.preferred_slicer,use_slicer_api:S.use_slicer_api,orcaslicer_api_url:S.orcaslicer_api_url,bambu_studio_api_url:S.bambu_studio_api_url,prometheus_enabled:S.prometheus_enabled,prometheus_token:S.prometheus_token,user_notifications_enabled:S.user_notifications_enabled,default_bed_levelling:S.default_bed_levelling,default_flow_cali:S.default_flow_cali,default_vibration_cali:S.default_vibration_cali,default_layer_inspect:S.default_layer_inspect,default_timelapse:S.default_timelapse,stagger_group_size:S.stagger_group_size,stagger_interval_minutes:S.stagger_interval_minutes,require_plate_clear:S.require_plate_clear};Pu.mutate(Rt)},500),()=>{dl.current&&clearTimeout(dl.current)}},[S,et,Pu,l,m,o,i]);const _n=y.useCallback((Se,Rt)=>{if(l&&!m("settings:update")){o(i("settings.toast.noPermissionUpdate"),"error");return}E(an=>an?{...an,[Se]:Rt}:null)},[l,m,o,i]),Ro=async(Se,Rt,an)=>{if(!Rt){o(i("settings.toast.enterCameraUrl"),"error");return}Le(An=>({...An,[Se]:!0})),mt(An=>({...An,[Se]:null}));try{const An=await se.testExternalCamera(Se,Rt,an);mt(Bn=>({...Bn,[Se]:An})),An.success?o(i("settings.toast.cameraConnected",{resolution:An.resolution||""}),"success"):o(An.error||i("settings.toast.connectionFailed"),"error")}catch(An){const Bn=An instanceof Error?An.message:i("settings.toast.testFailed");mt(ba=>({...ba,[Se]:{success:!1,error:Bn}})),o(Bn,"error")}finally{Le(An=>({...An,[Se]:!1}))}},[gf,_d]=y.useState({}),kd=y.useRef({}),Nd=y.useRef(new Set),[bf,bb]=y.useState({}),Ul=y.useRef({}),xf=y.useRef(new Set);y.useEffect(()=>{if(zn){const Se={},Rt={};zn.forEach(an=>{an.external_camera_url&&!Nd.current.has(an.id)&&(Se[an.id]=an.external_camera_url,Nd.current.add(an.id)),an.external_camera_snapshot_url&&!xf.current.has(an.id)&&(Rt[an.id]=an.external_camera_snapshot_url,xf.current.add(an.id))}),Object.keys(Se).length>0&&_d(an=>({...an,...Se})),Object.keys(Rt).length>0&&bb(an=>({...an,...Rt}))}},[zn]);const xb=(Se,Rt)=>{_d(an=>({...an,[Se]:Rt})),kd.current[Se]&&clearTimeout(kd.current[Se]),kd.current[Se]=setTimeout(()=>{Tu.mutate({id:Se,data:{external_camera_url:Rt||null}})},800)},fv=(Se,Rt)=>{bb(an=>({...an,[Se]:Rt})),Ul.current[Se]&&clearTimeout(Ul.current[Se]),Ul.current[Se]=setTimeout(()=>{Tu.mutate({id:Se,data:{external_camera_snapshot_url:Rt||null}})},800)},yf=(Se,Rt)=>{const an={};Rt.type!==void 0&&(an.external_camera_type=Rt.type||null),Rt.enabled!==void 0&&(an.external_camera_enabled=Rt.enabled),Rt.rotation!==void 0&&(an.camera_rotation=Rt.rotation),Tu.mutate({id:Se,data:an})};if(jt||!S)return r.jsx("div",{className:"p-4 md:p-8 flex justify-center",children:r.jsx(pt,{className:"w-8 h-8 text-bambu-green animate-spin"})});const Oc=fat().map(Se=>({...Se,label:i(Se.labelKey,Se.labelFallback??Se.labelKey)})),Qi=me.trim().toLowerCase(),fi=Qi?Oc.filter(Se=>Se.label.toLowerCase().includes(Qi)||Se.keywords.toLowerCase().includes(Qi)).slice(0,8):[],Au=Se=>{K(Se.tab),Se.subTab&&G(Se.subTab),be(""),setTimeout(()=>{const Rt=document.getElementById(Se.anchor);Rt&&(Rt.scrollIntoView({behavior:"smooth",block:"start"}),Rt.classList.add("ring-2","ring-bambu-green"),setTimeout(()=>Rt.classList.remove("ring-2","ring-bambu-green"),1500))},50)};return r.jsx(xve,{density:"dense",children:r.jsxs("div",{className:"p-4 md:p-8",children:[r.jsxs("div",{className:"mb-4 flex flex-col sm:flex-row sm:items-center sm:justify-between gap-3",children:[r.jsxs("div",{children:[r.jsxs("h1",{className:"text-2xl font-bold text-white flex items-center gap-3",children:[r.jsx(gy,{className:"w-7 h-7 text-bambu-green"}),i("settings.title")]}),r.jsx("p",{className:"text-bambu-gray mt-1",children:i("settings.configureBambuddy")})]}),r.jsxs("div",{className:"relative sm:w-72",children:[r.jsx(Sr,{className:"w-4 h-4 text-bambu-gray absolute left-3 top-1/2 -translate-y-1/2 pointer-events-none"}),r.jsx("input",{type:"text",value:me,onChange:Se=>be(Se.target.value),placeholder:i("settings.searchPlaceholder","Search settings…"),className:"w-full pl-9 pr-8 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green"}),me&&r.jsx("button",{onClick:()=>be(""),className:"absolute right-2 top-1/2 -translate-y-1/2 p-1 text-bambu-gray hover:text-white","aria-label":"Clear",children:r.jsx(Ht,{className:"w-3.5 h-3.5"})}),fi.length>0&&r.jsx("div",{className:"absolute top-full left-0 right-0 mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl z-30 overflow-hidden",children:fi.map(Se=>r.jsxs("button",{onClick:()=>Au(Se),className:"w-full px-3 py-2 text-left hover:bg-bambu-dark-tertiary transition-colors border-b border-bambu-dark-tertiary last:border-b-0",children:[r.jsx("p",{className:"text-sm text-white",children:Se.label}),r.jsxs("p",{className:"text-xs text-bambu-gray",children:[i(`settings.tabs.${Se.tab==="virtual-printer"?"virtualPrinter":Se.tab==="failure-detection"?"failureDetection":Se.tab}`),Se.subTab?` › ${i(`settings.tabs.${Se.subTab}`,Se.subTab)}`:""]})]},Se.anchor))}),Qi&&fi.length===0&&r.jsx("div",{className:"absolute top-full left-0 right-0 mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl z-30 p-3",children:r.jsx("p",{className:"text-xs text-bambu-gray italic",children:i("settings.noSearchResults","No matching settings.")})})]})]}),r.jsxs("div",{className:"flex flex-col lg:flex-row gap-4 lg:gap-6",children:[r.jsxs("nav",{className:"flex flex-wrap gap-1 border-b border-bambu-dark-tertiary lg:flex-col lg:flex-nowrap lg:gap-0 lg:border-b-0 lg:border-r lg:w-48 lg:flex-shrink-0 lg:self-start lg:sticky lg:top-4",children:[r.jsxs("button",{onClick:()=>K("general"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${O==="general"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[r.jsx(gy,{className:"w-4 h-4"}),i("settings.tabs.general")]}),r.jsxs("button",{onClick:()=>K("plugs"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${O==="plugs"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[r.jsx(xc,{className:"w-4 h-4"}),i("settings.tabs.smartPlugs"),Ge&&Ge.length>0&&r.jsx("span",{className:"text-xs bg-bambu-dark-tertiary px-1.5 py-0.5 rounded-full",children:Ge.length})]}),r.jsxs("button",{onClick:()=>K("notifications"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${O==="notifications"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[r.jsx(kh,{className:"w-4 h-4"}),i("settings.tabs.notifications"),wn&&wn.length>0&&r.jsx("span",{className:"text-xs bg-bambu-dark-tertiary px-1.5 py-0.5 rounded-full",children:wn.length})]}),r.jsxs("button",{onClick:()=>K("queue"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${O==="queue"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[r.jsx(jw,{className:"w-4 h-4"}),i("settings.tabs.queue","Workflow")]}),r.jsxs("button",{onClick:()=>K("filament"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${O==="filament"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[r.jsx(jge,{className:"w-4 h-4"}),i("settings.tabs.filament")]}),r.jsxs("button",{onClick:()=>K("network"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${O==="network"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[r.jsx(Ah,{className:"w-4 h-4"}),i("settings.tabs.network"),r.jsx("span",{className:`w-2 h-2 rounded-full ${vs?.enabled?"bg-green-400":"bg-gray-500"}`})]}),r.jsxs("button",{onClick:()=>K("apikeys"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${O==="apikeys"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[r.jsx(vo,{className:"w-4 h-4"}),i("settings.tabs.apiKeys"),Cn&&Cn.length>0&&r.jsx("span",{className:"text-xs bg-bambu-dark-tertiary px-1.5 py-0.5 rounded-full",children:Cn.length})]}),r.jsxs("button",{onClick:()=>K("virtual-printer"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${O==="virtual-printer"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[r.jsx(pr,{className:"w-4 h-4"}),i("settings.tabs.virtualPrinter"),r.jsx("span",{className:`w-2 h-2 rounded-full ${ca?"bg-green-400":"bg-gray-500"}`})]}),r.jsxs("button",{onClick:()=>K("spoolbuddy"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${O==="spoolbuddy"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[r.jsx(FZ,{className:"w-4 h-4"}),i("settings.tabs.spoolbuddy"),da>0&&r.jsx("span",{className:"text-xs bg-bambu-dark-tertiary px-1.5 py-0.5 rounded-full",children:da}),r.jsx("span",{className:`w-2 h-2 rounded-full ${Ki?"bg-green-400":"bg-gray-500"}`})]}),r.jsxs("button",{onClick:()=>K("failure-detection"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${O==="failure-detection"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[r.jsx(LZ,{className:"w-4 h-4"}),i("settings.tabs.failureDetection"),r.jsx("span",{className:`w-2 h-2 rounded-full ${bd?"bg-green-400":"bg-gray-500"}`})]}),r.jsxs("button",{onClick:()=>K("users"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${O==="users"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[r.jsx(gm,{className:"w-4 h-4"}),i("settings.tabs.users"),l&&r.jsx("span",{className:"w-2 h-2 rounded-full bg-green-400"})]}),r.jsxs("button",{onClick:()=>K("backup"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${O==="backup"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[r.jsx(hc,{className:"w-4 h-4"}),i("settings.tabs.backup"),r.jsx("span",{className:`w-2 h-2 rounded-full ${po?.is_authenticated&&zl?.configured&&zl?.enabled?"bg-green-400":"bg-gray-500"}`})]})]}),r.jsxs("div",{className:"flex-1 min-w-0",children:[O==="general"&&r.jsxs("div",{className:"flex flex-col lg:flex-row gap-4 lg:gap-6",children:[r.jsxs("div",{className:"space-y-3 flex-1 lg:max-w-xl",children:[r.jsxs(Ct,{id:"card-general",children:[r.jsx(pn,{children:r.jsx("h2",{className:"text-lg font-semibold text-white",children:i("settings.general")})}),r.jsxs(At,{className:"space-y-3",children:[r.jsxs("div",{children:[r.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[r.jsx(no,{className:"w-4 h-4 inline mr-1"}),i("settings.language")]}),r.jsxs("div",{className:"relative",children:[r.jsx("select",{value:s.language,onChange:Se=>{const Rt=Se.target.value;if(l&&!m("settings:update")){o(i("settings.toast.noPermissionUpdate"),"error");return}s.changeLanguage(Rt),Pu.mutate({language:Rt})},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:$H.map(Se=>r.jsxs("option",{value:Se.code,children:[Se.nativeName," (",Se.name,")"]},Se.code))}),r.jsx(Ln,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}),r.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:i("settings.languageDescription")})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:i("settings.defaultView")}),r.jsxs("div",{className:"relative",children:[r.jsx("select",{value:W,onChange:Se=>Xe(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:vm.map(Se=>r.jsx("option",{value:Se.to,children:i(Se.labelKey)},Se.id))}),r.jsx(Ln,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}),r.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:i("settings.defaultViewDescription")})]}),r.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:i("settings.dateFormat")}),r.jsxs("div",{className:"relative",children:[r.jsxs("select",{value:S.date_format||"system",onChange:Se=>_n("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:[r.jsx("option",{value:"system",children:i("settings.systemDefault")}),r.jsx("option",{value:"us",children:i("settings.dateFormatUs")}),r.jsx("option",{value:"eu",children:i("settings.dateFormatEu")}),r.jsx("option",{value:"iso",children:i("settings.dateFormatIso")})]}),r.jsx(Ln,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:i("settings.timeFormat")}),r.jsxs("div",{className:"relative",children:[r.jsxs("select",{value:S.time_format||"system",onChange:Se=>_n("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:[r.jsx("option",{value:"system",children:i("settings.systemDefault")}),r.jsx("option",{value:"12h",children:i("settings.timeFormat12")}),r.jsx("option",{value:"24h",children:i("settings.timeFormat24")})]}),r.jsx(Ln,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]})]})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:i("settings.defaultPrinter")}),r.jsxs("div",{className:"relative",children:[r.jsxs("select",{value:S.default_printer_id??"",onChange:Se=>_n("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:[r.jsx("option",{value:"",children:i("settings.noDefaultPrinter")}),zn?.map(Se=>r.jsx("option",{value:Se.id,children:Se.name},Se.id))]}),r.jsx(Ln,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}),r.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:i("settings.defaultPrinterDescription")})]}),r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-white",children:i("settings.sidebarOrder")}),r.jsxs("p",{className:"text-sm text-bambu-gray",children:[i("settings.sidebarOrderDescription"),l&&m("settings:update")&&` ${i("settings.sidebarOrderSetDefaultHint")}`]})]}),r.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[r.jsxs(Me,{variant:"secondary",size:"sm",onClick:Ze,children:[r.jsx(gs,{className:"w-4 h-4"}),i("settings.reset")]}),l&&m("settings:update")&&r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:"text-sm text-bambu-gray whitespace-nowrap",children:i("settings.setDefault")}),r.jsx(En,{checked:Ke,onChange:bt,disabled:jt})]})]})]})]})]}),r.jsxs(Ct,{id:"card-appearance",children:[r.jsx(pn,{children:r.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[r.jsx(jS,{className:"w-5 h-5"}),i("settings.appearance")]})}),r.jsxs(At,{className:"space-y-3",children:[r.jsxs("div",{className:`space-y-3 p-4 rounded-lg border ${p==="dark"?"border-bambu-green bg-bambu-green/5":"border-bambu-dark-tertiary"}`,children:[r.jsxs("h3",{className:"text-sm font-medium text-white flex items-center gap-2",children:[i("settings.darkMode"),p==="dark"&&r.jsx("span",{className:"text-xs text-bambu-green",children:i("settings.active")})]}),r.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:i("settings.background")}),r.jsxs("select",{value:b,onChange:Se=>{C(Se.target.value),o(i("settings.toast.settingsSaved"),"success")},className:"w-full px-2 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[r.jsx("option",{value:"neutral",children:i("settings.bgNeutral")}),r.jsx("option",{value:"warm",children:i("settings.bgWarm")}),r.jsx("option",{value:"cool",children:i("settings.bgCool")}),r.jsx("option",{value:"oled",children:i("settings.bgOled")}),r.jsx("option",{value:"slate",children:i("settings.bgSlate")}),r.jsx("option",{value:"forest",children:i("settings.bgForest")})]})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:i("settings.accent")}),r.jsxs("select",{value:w,onChange:Se=>{P(Se.target.value),o(i("settings.toast.settingsSaved"),"success")},className:"w-full px-2 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[r.jsx("option",{value:"green",children:i("settings.accentGreen")}),r.jsx("option",{value:"teal",children:i("settings.accentTeal")}),r.jsx("option",{value:"blue",children:i("settings.accentBlue")}),r.jsx("option",{value:"orange",children:i("settings.accentOrange")}),r.jsx("option",{value:"purple",children:i("settings.accentPurple")}),r.jsx("option",{value:"red",children:i("settings.accentRed")})]})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:i("settings.style")}),r.jsxs("select",{value:f,onChange:Se=>{N(Se.target.value),o(i("settings.toast.settingsSaved"),"success")},className:"w-full px-2 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[r.jsx("option",{value:"classic",children:i("settings.styleClassic")}),r.jsx("option",{value:"glow",children:i("settings.styleGlow")}),r.jsx("option",{value:"vibrant",children:i("settings.styleVibrant")})]})]})]})]}),r.jsxs("div",{className:`space-y-3 p-4 rounded-lg border ${p==="light"?"border-bambu-green bg-bambu-green/5":"border-bambu-dark-tertiary"}`,children:[r.jsxs("h3",{className:"text-sm font-medium text-white flex items-center gap-2",children:[i("settings.lightMode"),p==="light"&&r.jsx("span",{className:"text-xs text-bambu-green",children:i("settings.active")})]}),r.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:i("settings.background")}),r.jsxs("select",{value:x,onChange:Se=>{A(Se.target.value),o(i("settings.toast.settingsSaved"),"success")},className:"w-full px-2 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[r.jsx("option",{value:"neutral",children:i("settings.bgNeutral")}),r.jsx("option",{value:"warm",children:i("settings.bgWarm")}),r.jsx("option",{value:"cool",children:i("settings.bgCool")})]})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:i("settings.accent")}),r.jsxs("select",{value:_,onChange:Se=>{F(Se.target.value),o(i("settings.toast.settingsSaved"),"success")},className:"w-full px-2 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[r.jsx("option",{value:"green",children:i("settings.accentGreen")}),r.jsx("option",{value:"teal",children:i("settings.accentTeal")}),r.jsx("option",{value:"blue",children:i("settings.accentBlue")}),r.jsx("option",{value:"orange",children:i("settings.accentOrange")}),r.jsx("option",{value:"purple",children:i("settings.accentPurple")}),r.jsx("option",{value:"red",children:i("settings.accentRed")})]})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:i("settings.style")}),r.jsxs("select",{value:g,onChange:Se=>{T(Se.target.value),o(i("settings.toast.settingsSaved"),"success")},className:"w-full px-2 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[r.jsx("option",{value:"classic",children:i("settings.styleClassic")}),r.jsx("option",{value:"glow",children:i("settings.styleGlow")}),r.jsx("option",{value:"vibrant",children:i("settings.styleVibrant")})]})]})]})]}),r.jsx("p",{className:"text-xs text-bambu-gray",children:i("settings.themeToggleHint")})]})]}),r.jsxs(Ct,{id:"card-archive",children:[r.jsx(pn,{children:r.jsx("h2",{className:"text-lg font-semibold text-white",children:i("settings.archiveSettings")})}),r.jsxs(At,{className:"space-y-3",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-white",children:i("settings.autoArchivePrints")}),r.jsx("p",{className:"text-sm text-bambu-gray",children:i("settings.autoArchiveDescription")})]}),r.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:S.auto_archive,onChange:Se=>_n("auto_archive",Se.target.checked),className:"sr-only peer"}),r.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"})]})]}),r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-white",children:i("settings.saveThumbnails")}),r.jsx("p",{className:"text-sm text-bambu-gray",children:i("settings.saveThumbnailsDescription")})]}),r.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:S.save_thumbnails,onChange:Se=>_n("save_thumbnails",Se.target.checked),className:"sr-only peer"}),r.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"})]})]}),r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-white",children:i("settings.captureFinishPhoto")}),r.jsx("p",{className:"text-sm text-bambu-gray",children:i("settings.captureFinishPhotoDescription")})]}),r.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:S.capture_finish_photo,onChange:Se=>_n("capture_finish_photo",Se.target.checked),className:"sr-only peer"}),r.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.capture_finish_photo&&Lc&&!Lc.installed&&r.jsxs("div",{className:"flex items-start gap-2 p-3 bg-yellow-500/10 border border-yellow-500/30 rounded-lg",children:[r.jsx(Nn,{className:"w-5 h-5 text-yellow-500 flex-shrink-0 mt-0.5"}),r.jsxs("div",{className:"text-sm",children:[r.jsx("p",{className:"text-yellow-500 font-medium",children:i("settings.ffmpegNotInstalled")}),r.jsx("p",{className:"text-bambu-gray mt-1",children:i("settings.ffmpegRequired")})]})]}),Ol&&mo&&r.jsxs("div",{className:"border-t border-bambu-dark-tertiary pt-3 mt-3 space-y-3",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-white",children:i("archiveAutoPurge.enableLabel")}),r.jsx("p",{className:"text-sm text-bambu-gray",children:i("archiveAutoPurge.enableDescription")})]}),r.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:mo.enabled,onChange:Se=>Rc({enabled:Se.target.checked}),className:"sr-only peer"}),r.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"})]})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:i("archiveAutoPurge.ageLabel")}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("input",{type:"number",min:7,max:3650,disabled:!mo.enabled,value:mo.days,onChange:Se=>Rc({days:Math.max(7,Math.min(3650,parseInt(Se.target.value||"0",10)||0))}),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 disabled:opacity-50"}),r.jsx("span",{className:"text-bambu-gray",children:i("archiveAutoPurge.days")})]}),r.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:i("archiveAutoPurge.ageDescription")})]})]})]})]})]}),r.jsxs("div",{className:"space-y-3 flex-1 lg:max-w-md",children:[r.jsxs(Ct,{id:"card-camera",children:[r.jsx(pn,{children:r.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[r.jsx(iC,{className:"w-5 h-5 text-bambu-green"}),i("settings.camera")]})}),r.jsxs(At,{className:"space-y-3",children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:i("settings.cameraViewMode")}),r.jsxs("select",{value:S.camera_view_mode??"window",onChange:Se=>_n("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:[r.jsx("option",{value:"window",children:i("settings.newWindow")}),r.jsx("option",{value:"embedded",children:i("settings.embeddedOverlay")})]}),r.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:S.camera_view_mode==="embedded"?i("settings.cameraOverlayDescription"):i("settings.cameraWindowDescription")})]}),r.jsxs("div",{className:"border-t border-bambu-dark-tertiary pt-4 mt-4",children:[r.jsx("h3",{className:"text-sm font-medium text-white mb-2",children:i("settings.externalCameras")}),r.jsx("p",{className:"text-xs text-bambu-gray mb-3",children:i("settings.externalCamerasDescription")}),zn&&zn.length>0?r.jsx("div",{className:"space-y-3",children:zn.map(Se=>r.jsxs("div",{className:"p-3 bg-bambu-dark rounded-lg",children:[r.jsxs("div",{className:"flex items-center justify-between mb-2",children:[r.jsx("span",{className:"text-white font-medium text-sm",children:Se.name}),r.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:Se.external_camera_enabled,onChange:Rt=>yf(Se.id,{enabled:Rt.target.checked}),className:"sr-only peer"}),r.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&&r.jsxs("div",{className:"space-y-2 mt-2",children:[r.jsx("input",{type:"text",placeholder:Se.external_camera_type==="usb"?i("settings.cameraPlaceholderUsb"):i("settings.cameraPlaceholderUrl"),value:gf[Se.id]??Se.external_camera_url??"",onChange:Rt=>xb(Se.id,Rt.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"}),r.jsxs("div",{className:"flex gap-2",children:[r.jsxs("select",{value:Se.external_camera_type||"mjpeg",onChange:Rt=>yf(Se.id,{type:Rt.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:[r.jsx("option",{value:"mjpeg",children:i("settings.cameraTypeMjpeg")}),r.jsx("option",{value:"rtsp",children:i("settings.cameraTypeRtsp")}),r.jsx("option",{value:"snapshot",children:i("settings.cameraTypeSnapshot")}),r.jsx("option",{value:"usb",children:i("settings.cameraTypeUsb")})]}),r.jsx(Me,{size:"sm",variant:"secondary",onClick:()=>Ro(Se.id,gf[Se.id]??Se.external_camera_url??"",Se.external_camera_type||"mjpeg"),disabled:he[Se.id]||!(gf[Se.id]??Se.external_camera_url),children:he[Se.id]?r.jsx(pt,{className:"w-4 h-4 animate-spin"}):i("settings.test")})]}),Re[Se.id]&&r.jsx("div",{className:`text-xs flex items-center gap-1 ${Re[Se.id]?.success?"text-green-500":"text-red-500"}`,children:Re[Se.id]?.success?r.jsxs(r.Fragment,{children:[r.jsx(wr,{className:"w-3 h-3"}),i("settings.connected"),Re[Se.id]?.resolution&&` (${Re[Se.id]?.resolution})`]}):r.jsxs(r.Fragment,{children:[r.jsx(Da,{className:"w-3 h-3"}),Re[Se.id]?.error||i("settings.toast.connectionFailed")]})}),(Se.external_camera_type==="mjpeg"||Se.external_camera_type==="rtsp"||Se.external_camera_type==="usb")&&r.jsxs("div",{className:"space-y-1",children:[r.jsx("label",{className:"text-xs text-bambu-gray",children:i("settings.cameraSnapshotUrl","Snapshot URL (optional)")}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx("input",{type:"text",placeholder:i("settings.cameraSnapshotUrlPlaceholder","http://192.168.1.61:1984/api/frame.jpeg?src=printer"),value:bf[Se.id]??Se.external_camera_snapshot_url??"",onChange:Rt=>fv(Se.id,Rt.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"}),r.jsx(Me,{size:"sm",variant:"secondary",onClick:()=>Ro(Se.id,bf[Se.id]??Se.external_camera_snapshot_url??"","snapshot"),disabled:he[Se.id]||!(bf[Se.id]??Se.external_camera_snapshot_url),children:he[Se.id]?r.jsx(pt,{className:"w-4 h-4 animate-spin"}):i("settings.test")})]}),r.jsx("p",{className:"text-xs text-bambu-gray opacity-75",children:i("settings.cameraSnapshotUrlHelp","Single-frame URL used for notification thumbnails, finish photos, timelapse and plate detection. Leave blank to capture from the live stream above. Useful for go2rtc (/api/frame.jpeg) and IP cameras with a dedicated snapshot endpoint.")})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("label",{className:"text-xs text-bambu-gray",children:i("settings.cameraRotation")}),r.jsxs("select",{value:Se.camera_rotation||0,onChange:Rt=>yf(Se.id,{rotation:parseInt(Rt.target.value)}),className:"px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-xs focus:border-bambu-green focus:outline-none",children:[r.jsx("option",{value:0,children:"0°"}),r.jsx("option",{value:90,children:"90°"}),r.jsx("option",{value:180,children:"180°"}),r.jsx("option",{value:270,children:"270°"})]})]})]})]},Se.id))}):r.jsx("p",{className:"text-xs text-bambu-gray italic",children:i("settings.noPrintersConfigured")})]})]})]}),r.jsxs(Ct,{id:"card-cost",children:[r.jsx(pn,{children:r.jsx("h2",{className:"text-lg font-semibold text-white",children:i("settings.costTracking")})}),r.jsxs(At,{className:"space-y-3",children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:i("settings.currency")}),r.jsx("select",{value:S.currency,onChange:Se=>_n("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:b7e.map(Se=>r.jsx("option",{value:Se.code,children:Se.label},Se.code))})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:i("settings.defaultFilamentCost")}),r.jsxs("div",{className:"relative",children:[r.jsx("span",{className:"absolute left-3 top-1/2 -translate-y-1/2 text-bambu-gray text-sm pointer-events-none",children:Vo(S.currency)}),r.jsx("input",{type:"number",step:"0.01",min:"0",value:S.default_filament_cost,onChange:Se=>_n("default_filament_cost",parseFloat(Se.target.value)||0),style:{paddingLeft:`${Math.max(2,Vo(S.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"})]})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:i("settings.electricityCost")}),r.jsxs("div",{className:"relative",children:[r.jsx("span",{className:"absolute left-3 top-1/2 -translate-y-1/2 text-bambu-gray text-sm pointer-events-none",children:Vo(S.currency)}),r.jsx("input",{type:"number",step:"0.001",min:"0",value:S.energy_cost_per_kwh,onChange:Se=>_n("energy_cost_per_kwh",parseFloat(Se.target.value)||0),style:{paddingLeft:`${Math.max(2,Vo(S.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"})]})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:i("settings.energyDisplayMode")}),r.jsxs("select",{value:S.energy_tracking_mode||"total",onChange:Se=>_n("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:[r.jsx("option",{value:"print",children:i("settings.printsOnly")}),r.jsx("option",{value:"total",children:i("settings.totalConsumption")})]}),r.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:S.energy_tracking_mode==="print"?i("settings.energyModePrintDescription"):i("settings.energyModeTotalDescription")})]})]})]}),r.jsxs(Ct,{id:"card-filemanager",children:[r.jsx(pn,{children:r.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[r.jsx(Bs,{className:"w-5 h-5 text-bambu-green"}),i("settings.fileManager")]})}),r.jsxs(At,{className:"space-y-3",children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:i("settings.createArchiveEntry")}),r.jsxs("select",{value:S.library_archive_mode??"ask",onChange:Se=>_n("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:[r.jsx("option",{value:"always",children:i("settings.archiveMode.always")}),r.jsx("option",{value:"never",children:i("settings.archiveMode.never")}),r.jsx("option",{value:"ask",children:i("settings.archiveMode.ask")})]}),r.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:i("settings.createArchiveEntryDescription")})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:i("settings.lowDiskSpaceWarning")}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("input",{type:"number",min:"0.5",max:"100",step:"0.5",value:S.library_disk_warning_gb??5,onChange:Se=>_n("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"}),r.jsx("span",{className:"text-bambu-gray",children:"GB"})]}),r.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:i("settings.lowDiskSpaceDescription")})]}),Ft&&cn&&r.jsxs("div",{className:"border-t border-bambu-dark-tertiary pt-3 mt-3 space-y-3",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-white",children:i("libraryAutoPurge.enableLabel")}),r.jsx("p",{className:"text-sm text-bambu-gray",children:i("libraryAutoPurge.enableDescription")})]}),r.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:cn.auto_purge_enabled,onChange:Se=>Gt({auto_purge_enabled:Se.target.checked}),className:"sr-only peer"}),r.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"})]})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:i("libraryAutoPurge.ageLabel")}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("input",{type:"number",min:7,max:3650,disabled:!cn.auto_purge_enabled,value:cn.auto_purge_days,onChange:Se=>Gt({auto_purge_days:Math.max(7,Math.min(3650,parseInt(Se.target.value||"0",10)||0))}),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 disabled:opacity-50"}),r.jsx("span",{className:"text-bambu-gray",children:i("libraryAutoPurge.days")})]}),r.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:i("libraryAutoPurge.ageDescription")})]}),r.jsxs("label",{className:"flex items-center gap-2 text-sm text-white cursor-pointer",children:[r.jsx("input",{type:"checkbox",disabled:!cn.auto_purge_enabled,checked:cn.auto_purge_include_never_printed,onChange:Se=>Gt({auto_purge_include_never_printed:Se.target.checked}),className:"rounded border-gray-300 disabled:opacity-50"}),i("libraryAutoPurge.includeNeverPrinted")]})]})]})]})]}),r.jsxs("div",{className:"space-y-3 flex-1 lg:max-w-sm",children:[r.jsx(Yrt,{}),r.jsxs(Ct,{id:"card-updates",children:[r.jsx(pn,{children:r.jsx("h2",{className:"text-lg font-semibold text-white",children:i("settings.updates")})}),r.jsxs(At,{className:"space-y-3",children:[r.jsx("p",{className:"text-xs font-medium text-bambu-gray uppercase tracking-wider",children:i("settings.printerFirmware")}),r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-white",children:i("settings.checkPrinterFirmware")}),r.jsx("p",{className:"text-sm text-bambu-gray",children:i("settings.checkFirmwareDescription")})]}),r.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:S.check_printer_firmware??!0,onChange:Se=>_n("check_printer_firmware",Se.target.checked),className:"sr-only peer"}),r.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"})]})]}),r.jsx("div",{className:"border-t border-bambu-dark-tertiary pt-4",children:r.jsx("p",{className:"text-xs font-medium text-bambu-gray uppercase tracking-wider mb-4",children:i("settings.bambuddySoftware")})}),r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-white",children:i("settings.checkForUpdatesLabel")}),r.jsx("p",{className:"text-sm text-bambu-gray",children:i("settings.autoCheckDescription")})]}),r.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:S.check_updates,onChange:Se=>_n("check_updates",Se.target.checked),className:"sr-only peer"}),r.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"})]})]}),r.jsxs("div",{className:`flex items-center justify-between ${S.check_updates?"":"opacity-50"}`,children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-white",children:i("settings.includeBetaUpdates")}),r.jsx("p",{className:"text-sm text-bambu-gray",children:i("settings.includeBetaUpdatesDesc")})]}),r.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:S.include_beta_updates??!1,onChange:Se=>_n("include_beta_updates",Se.target.checked),disabled:!S.check_updates,className:"sr-only peer"}),r.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"})]})]}),r.jsxs("div",{children:[r.jsxs("div",{className:"flex items-center justify-between mb-2",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-white",children:i("settings.currentVersion")}),r.jsxs("p",{className:"text-sm text-bambu-gray",children:["v",$s?.version||"..."]})]}),r.jsxs(Me,{variant:"secondary",size:"sm",onClick:()=>mf(),disabled:il,children:[il?r.jsx(pt,{className:"w-4 h-4 animate-spin"}):r.jsx(sr,{className:"w-4 h-4"}),i("settings.checkNow")]})]}),Or?.update_available?r.jsxs("div",{className:"mt-4 p-3 bg-bambu-green/10 border border-bambu-green/30 rounded-lg",children:[r.jsxs("div",{className:"flex items-start justify-between",children:[r.jsxs("div",{children:[r.jsxs("p",{className:"text-bambu-green font-medium",children:["Update available: v",Or.latest_version]}),Or.release_name&&Or.release_name!==Or.latest_version&&r.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:Or.release_name})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[Or.release_notes&&r.jsx("button",{onClick:()=>We(!0),className:"text-bambu-gray hover:text-white transition-colors text-sm underline",children:i("settings.releaseNotes")}),Or.release_url&&r.jsx("a",{href:Or.release_url,target:"_blank",rel:"noopener noreferrer",className:"text-bambu-gray hover:text-white transition-colors",title:i("settings.viewReleaseOnGitHub"),children:r.jsx(Rr,{className:"w-4 h-4"})})]})]}),Xi?.status==="downloading"||Xi?.status==="installing"?r.jsxs("div",{className:"mt-3",children:[r.jsxs("div",{className:"flex items-center gap-2 text-sm text-bambu-gray",children:[r.jsx(pt,{className:"w-4 h-4 animate-spin"}),r.jsx("span",{children:Xi.message})]}),r.jsx("div",{className:"mt-2 w-full bg-bambu-dark-tertiary rounded-full h-2",children:r.jsx("div",{className:"bg-bambu-green h-2 rounded-full transition-all duration-300",style:{width:`${Xi.progress}%`}})})]}):Xi?.status==="complete"?r.jsx("div",{className:"mt-3 p-2 bg-bambu-green/20 rounded text-sm text-bambu-green",children:Xi.message}):Xi?.status==="error"?r.jsx("div",{className:"mt-3 p-2 bg-red-500/20 rounded text-sm text-red-400",children:Xi.error||Xi.message}):Or?.is_ha_addon?r.jsx("div",{className:"mt-3 p-3 bg-bambu-dark-tertiary rounded-lg",children:r.jsx("p",{className:"text-sm text-bambu-gray",children:i("settings.updateViaHomeAssistant")})}):Or?.is_docker?r.jsxs("div",{className:"mt-3 p-3 bg-bambu-dark-tertiary rounded-lg",children:[r.jsx("p",{className:"text-sm text-bambu-gray mb-2",children:i("settings.updateViaDocker")}),r.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"})]}):r.jsxs(Me,{className:"mt-3",onClick:()=>ff.mutate(),disabled:ff.isPending,children:[ff.isPending?r.jsx(pt,{className:"w-4 h-4 animate-spin"}):r.jsx(Yr,{className:"w-4 h-4"}),i("settings.installUpdate")]})]}):Or?.error?r.jsx("div",{className:"mt-2 p-2 bg-red-500/10 border border-red-500/30 rounded text-sm text-red-400",children:i("settings.failedToCheckUpdates",{error:Or.error})}):Or&&!Or.update_available?r.jsx("p",{className:"mt-2 text-sm text-bambu-gray",children:i("settings.latestVersionRunning")}):null]})]})]}),r.jsxs(Ct,{id:"card-data",children:[r.jsx(pn,{children:r.jsx("h2",{className:"text-lg font-semibold text-white",children:i("settings.dataManagement")})}),r.jsxs(At,{className:"space-y-3",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-white",children:i("settings.clearNotificationLogs")}),r.jsx("p",{className:"text-sm text-bambu-gray",children:i("settings.clearNotificationLogsDescription")})]}),r.jsxs(Me,{variant:"secondary",size:"sm",onClick:()=>xe(!0),children:[r.jsx(Jt,{className:"w-4 h-4"}),i("common.clear")]})]}),r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-white",children:i("settings.resetUiPreferences")}),r.jsx("p",{className:"text-sm text-bambu-gray",children:i("settings.resetUiPreferencesDescription")})]}),r.jsxs(Me,{variant:"secondary",size:"sm",onClick:()=>ze(!0),children:[r.jsx(Jt,{className:"w-4 h-4"}),i("settings.reset")]})]}),r.jsxs("div",{className:"pt-4 border-t border-bambu-dark-tertiary",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-white",children:i("settings.storageUsage","Storage Usage")}),r.jsx("p",{className:"text-sm text-bambu-gray",children:i("settings.storageUsageDescription","Breakdown of data usage by category")})]}),r.jsxs(Me,{variant:"secondary",size:"sm",onClick:He,disabled:zt||Ae,children:[r.jsx(sr,{className:`w-4 h-4 ${zt||Ae?"animate-spin":""}`}),i("common.refresh","Refresh")]})]}),r.jsx("div",{className:"mt-3",children:It?r.jsxs("div",{className:"flex items-center gap-2 text-sm text-bambu-gray",children:[r.jsx(pt,{className:"w-4 h-4 animate-spin"}),i("common.loading","Loading")]}):St?r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"w-full h-3 bg-bambu-dark rounded-full overflow-hidden flex",children:St.categories.filter(Se=>Se.bytes>0).map((Se,Rt)=>r.jsx("div",{className:`${uQ(Se.key,Rt)} h-full`,style:{width:`${Se.percent_of_total}%`},title:`${Se.label}: ${Se.formatted}`},Se.key))}),r.jsx("div",{className:"mt-3 flex flex-wrap gap-3",children:St.categories.filter(Se=>Se.bytes>0).map((Se,Rt)=>r.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[r.jsx("span",{className:`w-3 h-3 rounded-full ${uQ(Se.key,Rt)}`}),r.jsx("span",{className:"text-bambu-gray",children:Se.label}),r.jsx("span",{className:"text-white",children:Se.formatted}),r.jsxs("span",{className:"text-bambu-gray",children:["(",Se.percent_of_total.toFixed(1),"%)"]})]},Se.key))}),r.jsxs("div",{className:"mt-2 text-xs text-bambu-gray",children:[i("settings.storageUsageTotal","Total"),": ",r.jsx("span",{className:"text-white",children:St.total_formatted}),St.scan_errors>0&&r.jsxs("span",{className:"ml-2 text-amber-400",children:[i("settings.storageUsageErrors","Scan errors"),": ",St.scan_errors]})]}),St.other_breakdown?.length>0&&r.jsxs("div",{className:"mt-4",children:[r.jsx("p",{className:"text-xs text-bambu-gray mb-2",children:i("settings.storageUsageOtherBreakdown","Other breakdown")}),r.jsx("div",{className:"space-y-2",children:St.other_breakdown.map(Se=>r.jsxs("div",{className:"flex items-center justify-between text-xs",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:"text-white",children:Se.label}),r.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"?i("settings.storageUsageSystem","System"):i("settings.storageUsageData","Data")})]}),r.jsxs("div",{className:"flex items-center gap-2 text-bambu-gray",children:[r.jsx("span",{className:"text-white",children:Se.formatted}),r.jsxs("span",{children:["(",Se.percent_of_total.toFixed(1),"%)"]})]})]},`${Se.bucket}-${Se.kind}`))})]})]}):r.jsx("p",{className:"text-sm text-bambu-gray",children:i("settings.storageUsageUnavailable","Storage usage data is unavailable")})})]}),r.jsxs("div",{className:"flex items-center justify-between pt-4 border-t border-bambu-dark-tertiary",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-white",children:i("settings.backupRestore")}),r.jsx("p",{className:"text-sm text-bambu-gray",children:i("settings.backupRestoreDescription")})]}),r.jsxs(Me,{variant:"secondary",size:"sm",onClick:()=>K("backup"),children:[r.jsx(hc,{className:"w-4 h-4"}),i("settings.goToBackup")]})]})]})]})]})]}),O==="network"&&S&&r.jsxs("div",{className:"flex flex-col lg:flex-row gap-6",children:[r.jsxs("div",{className:"flex-1 lg:max-w-xl space-y-3",children:[r.jsxs(Ct,{id:"card-externalurl",children:[r.jsx(pn,{children:r.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[r.jsx(no,{className:"w-5 h-5 text-blue-400"}),i("settings.externalUrl")]})}),r.jsxs(At,{className:"space-y-3",children:[r.jsx("p",{className:"text-sm text-bambu-gray",children:i("settings.externalUrlDescription")}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:i("settings.bambuddyUrl")}),r.jsx("input",{type:"text",value:S.external_url??"",onChange:Se=>_n("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"}),r.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:i("settings.externalUrlHint")})]})]})]}),r.jsxs(Ct,{id:"card-ftpretry",children:[r.jsx(pn,{children:r.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[r.jsx(sr,{className:"w-5 h-5 text-blue-400"}),i("settings.ftpRetry")]})}),r.jsxs(At,{className:"space-y-3",children:[r.jsx("p",{className:"text-sm text-bambu-gray",children:i("settings.ftpRetryDescription")}),r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-white",children:i("settings.enableRetry")}),r.jsx("p",{className:"text-sm text-bambu-gray",children:i("settings.autoRetryDescription")})]}),r.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:S.ftp_retry_enabled??!0,onChange:Se=>_n("ftp_retry_enabled",Se.target.checked),className:"sr-only peer"}),r.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.ftp_retry_enabled&&r.jsxs("div",{className:"space-y-3 pt-2 border-t border-bambu-dark-tertiary",children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:i("settings.retryAttempts")}),r.jsxs("div",{className:"relative w-44",children:[r.jsx("select",{value:S.ftp_retry_count??3,onChange:Se=>_n("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=>r.jsx("option",{value:Se,children:i("settings.time",{count:Se})},Se))}),r.jsx(Ln,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:i("settings.retryDelay")}),r.jsxs("div",{className:"relative w-44",children:[r.jsx("select",{value:S.ftp_retry_delay??2,onChange:Se=>_n("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=>r.jsx("option",{value:Se,children:i("settings.second",{count:Se})},Se))}),r.jsx(Ln,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:i("settings.connectionTimeout")}),r.jsxs("div",{className:"relative w-44",children:[r.jsx("select",{value:S.ftp_timeout??30,onChange:Se=>_n("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,180,300].map(Se=>r.jsx("option",{value:Se,children:i("settings.nSeconds",{count:Se})},Se))}),r.jsx(Ln,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}),r.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:i("settings.increaseForWeakWifi")})]})]})]})]})]}),r.jsxs("div",{className:"flex-1 lg:max-w-xl space-y-3",children:[r.jsxs(Ct,{id:"card-ha",children:[r.jsx(pn,{children:r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[r.jsx(PS,{className:"w-5 h-5 text-bambu-green"}),i("settings.homeAssistant")]}),S.ha_enabled&&De&&r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:`w-2.5 h-2.5 rounded-full ${De.success?"bg-green-400":"bg-red-400"}`}),r.jsx("span",{className:`text-sm ${De.success?"text-green-400":"text-red-400"}`,children:De.success?i("settings.connected"):i("settings.disconnected")})]})]})}),r.jsxs(At,{className:"space-y-3",children:[r.jsx("p",{className:"text-sm text-bambu-gray",children:i("settings.homeAssistantFullDescription")}),r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{className:"flex-1",children:[r.jsx("p",{className:"text-white",children:i("settings.enableHomeAssistant")}),r.jsx("p",{className:"text-xs text-bambu-gray",children:i("settings.homeAssistantDescription")}),S.ha_env_managed&&r.jsxs("div",{className:"flex items-center gap-1 mt-1",children:[r.jsx(lc,{className:"w-3 h-3 text-bambu-green"}),r.jsx("span",{className:"text-xs text-bambu-green",children:i("settings.autoEnabledViaEnv")})]})]}),r.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:S.ha_enabled??!1,onChange:Se=>_n("ha_enabled",Se.target.checked),disabled:S.ha_env_managed,className:"sr-only peer"}),r.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.ha_env_managed?"opacity-60 cursor-not-allowed":""}`})]})]}),S.ha_enabled&&r.jsxs(r.Fragment,{children:[r.jsxs("div",{children:[r.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[i("settings.homeAssistantUrl"),S.ha_url_from_env&&r.jsx("span",{className:"ml-2 text-xs text-bambu-green",children:i("settings.environmentManagedLabel")})]}),r.jsxs("div",{className:"relative",children:[r.jsx("input",{type:"text",value:S.ha_url??"",onChange:Se=>_n("ha_url",Se.target.value),placeholder:"http://192.168.1.100:8123",disabled:S.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 ${S.ha_url_from_env?"opacity-60 cursor-not-allowed":""}`}),S.ha_url_from_env&&r.jsx(lc,{className:"absolute right-3 top-2.5 w-4 h-4 text-bambu-gray"})]}),S.ha_url_from_env&&r.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:i("settings.urlFromEnvReadOnly")})]}),r.jsxs("div",{children:[r.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[i("settings.longLivedAccessToken"),S.ha_token_from_env&&r.jsx("span",{className:"ml-2 text-xs text-bambu-green",children:i("settings.environmentManagedLabel")})]}),r.jsxs("div",{className:"relative",children:[r.jsx("input",{type:"password",value:S.ha_token??"",onChange:Se=>_n("ha_token",Se.target.value),placeholder:"eyJ0eXAiOiJKV1QiLC...",disabled:S.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 ${S.ha_token_from_env?"opacity-60 cursor-not-allowed":""}`}),S.ha_token_from_env&&r.jsx(lc,{className:"absolute right-3 top-2.5 w-4 h-4 text-bambu-gray"})]}),S.ha_token_from_env?r.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:i("settings.tokenFromEnvReadOnly")}):r.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:i("settings.haTokenHint")})]}),S.ha_url&&S.ha_token&&r.jsx("div",{className:"pt-2 border-t border-bambu-dark-tertiary",children:r.jsxs(Me,{variant:"secondary",size:"sm",disabled:$e,onClick:async()=>{Je(!0),je(null);try{const Se=await se.testHAConnection(S.ha_url,S.ha_token);je(Se)}catch(Se){je({success:!1,message:null,error:Se instanceof Error?Se.message:i("common.unknownError")})}finally{Je(!1)}},children:[$e?r.jsx(pt,{className:"w-4 h-4 animate-spin"}):r.jsx(Ah,{className:"w-4 h-4"}),i("settings.testConnection")]})})]})]})]}),r.jsxs(Ct,{id:"card-mqtt",children:[r.jsx(pn,{children:r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[r.jsx(Ah,{className:"w-5 h-5 text-blue-400"}),i("settings.mqttPublishing")]}),vs?.enabled&&r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:`w-2.5 h-2.5 rounded-full ${vs.connected?"bg-green-400":"bg-red-400"}`}),r.jsx("span",{className:`text-sm ${vs.connected?"text-green-400":"text-red-400"}`,children:vs.connected?i("settings.connected"):i("settings.disconnected")})]})]})}),r.jsxs(At,{className:"space-y-3",children:[r.jsx("p",{className:"text-sm text-bambu-gray",children:i("settings.mqttDescription")}),r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-white",children:i("settings.enableMqtt")}),r.jsx("p",{className:"text-sm text-bambu-gray",children:i("settings.mqttEnableDescription")})]}),r.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:S.mqtt_enabled??!1,onChange:Se=>_n("mqtt_enabled",Se.target.checked),className:"sr-only peer"}),r.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.mqtt_enabled&&r.jsxs("div",{className:"space-y-3 pt-2 border-t border-bambu-dark-tertiary",children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:i("settings.brokerHostname")}),r.jsx("input",{type:"text",value:S.mqtt_broker??"",onChange:Se=>_n("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"})]}),r.jsxs("div",{className:"flex items-end gap-4",children:[r.jsxs("div",{className:"flex-1",children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:i("settings.port")}),r.jsx("input",{type:"number",min:"1",max:"65535",value:S.mqtt_port??1883,onChange:Se=>_n("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"})]}),r.jsxs("div",{className:"flex items-center gap-3 pb-2",children:[r.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:S.mqtt_use_tls??!1,onChange:Se=>{const Rt=Se.target.checked;_n("mqtt_use_tls",Rt);const an=S.mqtt_port??1883;Rt&&an===1883?_n("mqtt_port",8883):!Rt&&an===8883&&_n("mqtt_port",1883)},className:"sr-only peer"}),r.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"})]}),r.jsx("span",{className:"text-white text-sm",children:i("settings.useTls")})]})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:i("settings.usernameOptional")}),r.jsx("input",{type:"text",value:S.mqtt_username??"",onChange:Se=>_n("mqtt_username",Se.target.value),placeholder:i("settings.leaveEmptyForAnonymous"),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:i("settings.passwordOptional")}),r.jsx("input",{type:"password",value:S.mqtt_password??"",onChange:Se=>_n("mqtt_password",Se.target.value),placeholder:i("settings.leaveEmptyForAnonymous"),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:i("settings.topicPrefix")}),r.jsx("input",{type:"text",value:S.mqtt_topic_prefix??"bambuddy",onChange:Se=>_n("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"}),r.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:i("settings.topicPrefixHint",{prefix:S.mqtt_topic_prefix||"bambuddy"})})]}),vs&&r.jsx("div",{className:"pt-3 mt-3 border-t border-bambu-dark-tertiary",children:r.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[r.jsx("span",{className:`w-2 h-2 rounded-full ${vs.connected?"bg-green-400":"bg-red-400"}`}),r.jsx("span",{className:"text-bambu-gray",children:vs.connected?r.jsxs(r.Fragment,{children:[i("settings.mqttConnectedTo")," ",r.jsxs("span",{className:"text-white",children:[vs.broker,":",vs.port]})]}):i("settings.spoolmanDisconnected")})]})})]})]})]})]}),r.jsx("div",{className:"flex-1 lg:max-w-md space-y-3",children:r.jsxs(Ct,{id:"card-prometheus",children:[r.jsx(pn,{children:r.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[r.jsx(aC,{className:"w-5 h-5 text-orange-400"}),i("settings.prometheusMetrics")]})}),r.jsxs(At,{className:"space-y-3",children:[r.jsx("p",{className:"text-sm text-bambu-gray",children:i("settings.prometheusEndpointDescription")}),r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-white",children:i("settings.enableMetricsEndpoint")}),r.jsx("p",{className:"text-xs text-bambu-gray",children:i("settings.prometheusDescription")})]}),r.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:S.prometheus_enabled??!1,onChange:Se=>_n("prometheus_enabled",Se.target.checked),className:"sr-only peer"}),r.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.prometheus_enabled&&r.jsxs("div",{className:"space-y-3 pt-2 border-t border-bambu-dark-tertiary",children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:i("settings.bearerTokenOptional")}),r.jsx("input",{type:"password",value:S.prometheus_token??"",onChange:Se=>_n("prometheus_token",Se.target.value),placeholder:i("settings.leaveEmptyForNoAuth"),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"}),r.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:i("settings.bearerTokenHint")})]}),r.jsxs("div",{className:"pt-2 border-t border-bambu-dark-tertiary",children:[r.jsx("p",{className:"text-sm text-white mb-2",children:i("settings.availableMetrics")}),r.jsxs("div",{className:"text-xs text-bambu-gray space-y-1",children:[r.jsxs("p",{children:[r.jsx("code",{className:"text-orange-400",children:"bambuddy_printer_connected"})," - ",i("settings.metricsConnectionStatus")]}),r.jsxs("p",{children:[r.jsx("code",{className:"text-orange-400",children:"bambuddy_printer_state"})," - ",i("settings.metricsPrinterState")]}),r.jsxs("p",{children:[r.jsx("code",{className:"text-orange-400",children:"bambuddy_print_progress"})," - ",i("settings.metricsPrintProgress")]}),r.jsxs("p",{children:[r.jsx("code",{className:"text-orange-400",children:"bambuddy_bed_temp_celsius"})," - ",i("settings.metricsBedTemp")]}),r.jsxs("p",{children:[r.jsx("code",{className:"text-orange-400",children:"bambuddy_nozzle_temp_celsius"})," - ",i("settings.metricsNozzleTemp")]}),r.jsxs("p",{children:[r.jsx("code",{className:"text-orange-400",children:"bambuddy_prints_total"})," - ",i("settings.metricsPrintsTotal")]}),r.jsx("p",{className:"text-bambu-gray/70 italic",children:i("settings.metricsMore")})]})]})]})]})]})})]}),De&&r.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50",children:r.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg p-6 max-w-md w-full mx-4",children:[r.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[De.success?r.jsx(wr,{className:"w-8 h-8 text-green-400"}):r.jsx(Da,{className:"w-8 h-8 text-red-400"}),r.jsx("h3",{className:"text-lg font-medium text-white",children:De.success?i("settings.connectionSuccessful"):i("settings.connectionFailed")})]}),r.jsx("p",{className:"text-bambu-gray mb-6",children:De.success?De.message||i("settings.haConnectionSuccess"):De.error||i("settings.haConnectionFailed")}),r.jsx("div",{className:"flex justify-end",children:r.jsx(Me,{variant:"primary",onClick:()=>je(null),children:i("settings.ok")})})]})}),O==="plugs"&&r.jsxs("div",{id:"card-plugs",children:[r.jsxs("div",{className:"flex items-start justify-between mb-6",children:[r.jsxs("div",{children:[r.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[r.jsx(xc,{className:"w-5 h-5 text-bambu-green"}),i("settings.smartPlugs")]}),r.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:i("settings.smartPlugsDescription")})]}),r.jsxs("div",{className:"flex items-center gap-2 pt-1 shrink-0",children:[Ge&&Ge.filter(Se=>Se.enabled).length>1&&r.jsxs(r.Fragment,{children:[r.jsxs(Me,{variant:"secondary",size:"sm",className:"whitespace-nowrap",onClick:()=>Oe("on"),disabled:Lo.isPending,title:i("settings.turnAllPlugsOn"),children:[Lo.isPending?r.jsx(pt,{className:"w-4 h-4 animate-spin"}):r.jsx(wu,{className:"w-4 h-4 text-bambu-green"}),i("settings.allOn")]}),r.jsxs(Me,{variant:"secondary",size:"sm",className:"whitespace-nowrap",onClick:()=>Oe("off"),disabled:Lo.isPending,title:i("settings.turnAllPlugsOff"),children:[Lo.isPending?r.jsx(pt,{className:"w-4 h-4 animate-spin"}):r.jsx(ES,{className:"w-4 h-4 text-red-400"}),i("settings.allOff")]})]}),r.jsxs(Me,{className:"whitespace-nowrap",onClick:()=>{R(null),I(!0)},children:[r.jsx(ar,{className:"w-4 h-4"}),i("settings.addSmartPlug")]})]})]}),Ge&&Ge.length>0&&r.jsxs(Ct,{className:"mb-6",children:[r.jsx(pn,{children:r.jsxs("h3",{className:"text-base font-semibold text-white flex items-center gap-2",children:[r.jsx(Nc,{className:"w-4 h-4 text-yellow-400"}),i("settings.energySummary"),mn&&r.jsx(pt,{className:"w-4 h-4 animate-spin text-bambu-gray ml-2"})]})}),r.jsx(At,{children:Qt?r.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[r.jsxs("div",{className:"bg-bambu-dark rounded-lg p-3",children:[r.jsxs("div",{className:"flex items-center gap-2 text-bambu-gray text-xs mb-1",children:[r.jsx(Nc,{className:"w-3 h-3"}),i("settings.currentPower")]}),r.jsxs("div",{className:"text-xl font-bold text-white",children:[Qt.totalPower.toFixed(1),r.jsx("span",{className:"text-sm font-normal text-bambu-gray ml-1",children:"W"})]}),r.jsx("div",{className:"text-xs text-bambu-gray mt-1",children:i("settings.plugsOnline",{reachable:Qt.reachableCount,total:Qt.totalPlugs})})]}),r.jsxs("div",{className:"bg-bambu-dark rounded-lg p-3",children:[r.jsxs("div",{className:"flex items-center gap-2 text-bambu-gray text-xs mb-1",children:[r.jsx(Sa,{className:"w-3 h-3"}),i("settings.today")]}),r.jsxs("div",{className:"text-xl font-bold text-white",children:[Qt.totalToday.toFixed(3),r.jsx("span",{className:"text-sm font-normal text-bambu-gray ml-1",children:"kWh"})]}),(S?.energy_cost_per_kwh??0)>0&&r.jsxs("div",{className:"text-xs text-bambu-gray mt-1",children:["~",(Qt.totalToday*(S?.energy_cost_per_kwh??0)).toFixed(2)," ",Vo(S?.currency||"USD")]})]}),r.jsxs("div",{className:"bg-bambu-dark rounded-lg p-3",children:[r.jsxs("div",{className:"flex items-center gap-2 text-bambu-gray text-xs mb-1",children:[r.jsx(aC,{className:"w-3 h-3"}),i("settings.yesterday")]}),r.jsxs("div",{className:"text-xl font-bold text-white",children:[Qt.totalYesterday.toFixed(3),r.jsx("span",{className:"text-sm font-normal text-bambu-gray ml-1",children:"kWh"})]}),(S?.energy_cost_per_kwh??0)>0&&r.jsxs("div",{className:"text-xs text-bambu-gray mt-1",children:["~",(Qt.totalYesterday*(S?.energy_cost_per_kwh??0)).toFixed(2)," ",Vo(S?.currency||"USD")]})]}),r.jsxs("div",{className:"bg-bambu-dark rounded-lg p-3",children:[r.jsxs("div",{className:"flex items-center gap-2 text-bambu-gray text-xs mb-1",children:[r.jsx(QN,{className:"w-3 h-3"}),i("settings.total")]}),r.jsxs("div",{className:"text-xl font-bold text-white",children:[Qt.totalLifetime.toFixed(1),r.jsx("span",{className:"text-sm font-normal text-bambu-gray ml-1",children:"kWh"})]}),(S?.energy_cost_per_kwh??0)>0&&r.jsxs("div",{className:"text-xs text-bambu-gray mt-1",children:["~",(Qt.totalLifetime*(S?.energy_cost_per_kwh??0)).toFixed(2)," ",Vo(S?.currency||"USD")]})]})]}):mn?null:r.jsx("p",{className:"text-sm text-bambu-gray",children:i("settings.enablePlugsForSummary")})})]}),Vt?r.jsx("div",{className:"flex justify-center py-12",children:r.jsx(pt,{className:"w-8 h-8 text-bambu-green animate-spin"})}):Ge&&Ge.length>0?r.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4",children:Ge.map(Se=>r.jsx(Nrt,{plug:Se,onEdit:Rt=>{R(Rt),I(!0)}},Se.id))}):r.jsx(Ct,{children:r.jsx(At,{className:"py-12",children:r.jsxs("div",{className:"text-center text-bambu-gray",children:[r.jsx(xc,{className:"w-16 h-16 mx-auto mb-4 opacity-30"}),r.jsx("p",{className:"text-lg font-medium text-white mb-2",children:i("settings.noSmartPlugsTitle")}),r.jsx("p",{className:"text-sm mb-4",children:i("settings.noSmartPlugsDescription")}),r.jsxs(Me,{onClick:()=>{R(null),I(!0)},children:[r.jsx(ar,{className:"w-4 h-4"}),i("settings.addFirstSmartPlug")]})]})})})]}),O==="notifications"&&r.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-4",children:[r.jsxs("div",{children:[r.jsxs("div",{className:"flex items-center justify-between mb-4",children:[r.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",id:"card-providers",children:[r.jsx(kh,{className:"w-5 h-5 text-bambu-green"}),i("settings.providers")]}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsxs(Me,{size:"sm",variant:"secondary",onClick:()=>$(!0),children:[r.jsx(Aw,{className:"w-4 h-4"}),i("settings.log")]}),wn&&wn.length>0&&r.jsxs(Me,{size:"sm",variant:"secondary",onClick:()=>{up(null),Cu.mutate()},disabled:Cu.isPending,children:[Cu.isPending?r.jsx(pt,{className:"w-4 h-4 animate-spin"}):r.jsx(DS,{className:"w-4 h-4"}),i("settings.testAll")]}),r.jsxs(Me,{size:"sm",onClick:()=>{de(null),re(!0)},children:[r.jsx(ar,{className:"w-4 h-4"}),i("settings.addNotificationProvider")]})]})]}),r.jsx(Ct,{className:"mb-4",children:r.jsx(At,{className:"py-3",children:r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-white text-sm font-medium",children:i("settings.notificationLanguage")}),r.jsx("p",{className:"text-xs text-bambu-gray",children:i("settings.notificationLanguageDescription")})]}),r.jsx("select",{value:S.notification_language||"en",onChange:Se=>_n("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:$H.map(Se=>r.jsx("option",{value:Se.code,children:Se.nativeName},Se.code))})]})})}),r.jsx(Ct,{className:"mb-4",children:r.jsx(At,{className:"py-3",children:r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-white text-sm font-medium",children:i("settings.bedCooledThreshold")}),r.jsx("p",{className:"text-xs text-bambu-gray",children:i("settings.bedCooledThresholdDescription")})]}),r.jsxs("div",{className:"flex items-center gap-1",children:[r.jsx("input",{type:"number",min:20,max:80,step:1,value:S.bed_cooled_threshold??35,onChange:Se=>_n("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"}),r.jsx("span",{className:"text-sm text-bambu-gray",children:"°C"})]})]})})}),r.jsx(Ct,{className:"mb-4",children:r.jsx(At,{className:"py-3",children:r.jsxs("div",{className:`flex items-center justify-between ${di?.advanced_auth_enabled?"":"opacity-50"}`,children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-white text-sm font-medium",children:i("settings.userNotificationsEnabled")}),r.jsx("p",{className:"text-xs text-bambu-gray",children:di?.advanced_auth_enabled?i("settings.userNotificationsEnabledDescription"):i("settings.userNotificationsDisabledHint")})]}),r.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[r.jsx("input",{type:"checkbox",className:"sr-only peer",checked:S.user_notifications_enabled??!0,disabled:!di?.advanced_auth_enabled,onChange:Se=>_n("user_notifications_enabled",Se.target.checked)}),r.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 peer-disabled:cursor-not-allowed"})]})]})})}),ho&&r.jsx(Ct,{className:"mb-4",children:r.jsxs(At,{className:"py-3",children:[r.jsxs("div",{className:"flex items-center justify-between mb-2",children:[r.jsx("span",{className:"text-sm font-medium text-white",children:i("settings.testResults")}),r.jsx("button",{onClick:()=>up(null),className:"text-bambu-gray hover:text-white text-xs",children:i("common.dismiss")})]}),r.jsxs("div",{className:"flex items-center gap-4 text-sm mb-2",children:[r.jsxs("span",{className:"flex items-center gap-1 text-bambu-green",children:[r.jsx(wr,{className:"w-4 h-4"}),i("settings.testPassedCount",{count:ho.success})]}),ho.failed>0&&r.jsxs("span",{className:"flex items-center gap-1 text-red-400",children:[r.jsx(Da,{className:"w-4 h-4"}),i("settings.testFailedCount",{count:ho.failed})]})]}),ho.results.filter(Se=>!Se.success).length>0&&r.jsx("div",{className:"space-y-1 mt-2 pt-2 border-t border-bambu-dark-tertiary",children:ho.results.filter(Se=>!Se.success).map(Se=>r.jsxs("div",{className:"text-xs text-red-400",children:[r.jsxs("span",{className:"font-medium",children:[Se.provider_name,":"]})," ",Se.message]},Se.provider_id))})]})}),gn?r.jsx("div",{className:"flex justify-center py-12",children:r.jsx(pt,{className:"w-6 h-6 text-bambu-green animate-spin"})}):wn&&wn.length>0?r.jsx("div",{className:"space-y-3",children:wn.map(Se=>r.jsx(Prt,{provider:Se,onEdit:Rt=>{de(Rt),re(!0)}},Se.id))}):r.jsx(Ct,{children:r.jsx(At,{className:"py-8",children:r.jsxs("div",{className:"text-center text-bambu-gray",children:[r.jsx(kh,{className:"w-12 h-12 mx-auto mb-3 opacity-30"}),r.jsx("p",{className:"text-sm font-medium text-white mb-2",children:i("settings.noProvidersTitle")}),r.jsx("p",{className:"text-xs mb-3",children:i("settings.noProvidersDescription")}),r.jsxs(Me,{size:"sm",onClick:()=>{de(null),re(!0)},children:[r.jsx(ar,{className:"w-4 h-4"}),i("settings.addProvider")]})]})})})]}),r.jsxs("div",{children:[r.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2 mb-2",id:"card-templates",children:[r.jsx(Bs,{className:"w-5 h-5 text-bambu-green"}),i("settings.messageTemplates")]}),r.jsx("p",{className:"text-sm text-bambu-gray mb-3",children:i("settings.messageTemplatesDescription")}),r.jsxs("div",{className:"relative mb-3",children:[r.jsx(Sr,{className:"w-4 h-4 text-bambu-gray absolute left-3 top-1/2 -translate-y-1/2 pointer-events-none"}),r.jsx("input",{type:"text",value:X,onChange:Se=>ae(Se.target.value),placeholder:i("settings.filterTemplates","Filter templates…"),className:"w-full pl-9 pr-8 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green"}),X&&r.jsx("button",{onClick:()=>ae(""),className:"absolute right-2 top-1/2 -translate-y-1/2 p-1 text-bambu-gray hover:text-white","aria-label":"Clear filter",children:r.jsx(Ht,{className:"w-3.5 h-3.5"})})]}),Kn?r.jsx("div",{className:"flex justify-center py-8",children:r.jsx(pt,{className:"w-6 h-6 text-bambu-green animate-spin"})}):Xa&&Xa.length>0?(()=>{const Se=X.trim().toLowerCase(),Rt=[...Xa].sort((an,An)=>an.name.localeCompare(An.name)).filter(an=>!Se||an.name.toLowerCase().includes(Se)||(an.title_template||"").toLowerCase().includes(Se));return Rt.length===0?r.jsx("p",{className:"text-sm text-bambu-gray italic text-center py-6",children:i("settings.noTemplatesMatch","No templates match your filter.")}):r.jsx("div",{className:"space-y-2",children:Rt.map(an=>r.jsx(Ct,{className:"cursor-pointer hover:border-bambu-green/50 transition-colors",onClick:()=>ue(an),children:r.jsx(At,{className:"py-2.5 px-3",children:r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{className:"min-w-0 flex-1",children:[r.jsx("p",{className:"text-white font-medium text-sm truncate",children:an.name}),r.jsx("p",{className:"text-bambu-gray text-xs truncate mt-0.5",children:an.title_template})]}),r.jsx("button",{className:"p-1.5 hover:bg-bambu-dark-tertiary rounded transition-colors shrink-0 ml-2",onClick:An=>{An.stopPropagation(),ue(an)},children:r.jsx(fc,{className:"w-4 h-4 text-bambu-gray"})})]})})},an.id))})})():r.jsx(Ct,{children:r.jsx(At,{className:"py-8",children:r.jsxs("div",{className:"text-center text-bambu-gray",children:[r.jsx(Bs,{className:"w-12 h-12 mx-auto mb-3 opacity-30"}),r.jsx("p",{className:"text-sm",children:i("settings.noTemplatesAvailable")})]})})})]})]}),O==="apikeys"&&r.jsxs("div",{className:m("api_keys:read")?"grid grid-cols-1 xl:grid-cols-2 gap-4":"grid grid-cols-1 gap-4",children:[r.jsxs("div",{children:[m("api_keys:read")&&r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"flex items-start justify-between gap-4 mb-6",children:[r.jsxs("div",{className:"flex-1",children:[r.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",id:"card-createapi",children:[r.jsx(vo,{className:"w-5 h-5 text-bambu-green"}),i("settings.apiKeys")]}),r.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:i("settings.apiKeysDescription")})]}),r.jsxs(Me,{size:"sm",onClick:()=>oe(!0),className:"flex-shrink-0",children:[r.jsx(ar,{className:"w-4 h-4"}),i("settings.createKey")]})]}),q&&r.jsx(Ct,{className:"mb-6 border-bambu-green",children:r.jsx(At,{className:"py-4",children:r.jsxs("div",{className:"flex items-start gap-3",children:[r.jsx(wr,{className:"w-5 h-5 text-bambu-green flex-shrink-0 mt-0.5"}),r.jsxs("div",{className:"flex-1",children:[r.jsx("p",{className:"text-white font-medium mb-1",children:i("settings.apiKeyCreated")}),r.jsx("p",{className:"text-sm text-bambu-gray mb-2",children:i("settings.apiKeyCopyWarning")}),r.jsxs("div",{className:"flex items-center gap-2 bg-bambu-dark rounded-lg p-2",children:[r.jsx("code",{className:"flex-1 text-sm text-bambu-green font-mono break-all",children:q}),r.jsx(Me,{variant:"secondary",size:"sm",onClick:async()=>{try{if(navigator.clipboard&&navigator.clipboard.writeText)await navigator.clipboard.writeText(q);else{const Se=document.createElement("textarea");Se.value=q,Se.style.position="fixed",Se.style.left="-999999px",document.body.appendChild(Se),Se.select(),document.execCommand("copy"),document.body.removeChild(Se)}o(i("settings.toast.keyCopied"))}catch{o(i("settings.toast.copyFailed"),"error")}},children:r.jsx(Mi,{className:"w-4 h-4"})})]}),r.jsxs("div",{className:"flex gap-2 mt-3",children:[r.jsx(Me,{variant:"secondary",size:"sm",onClick:()=>{Ne(q),o(i("settings.toast.keyAddedToBrowser"))},children:i("settings.useInApiBrowser")}),r.jsx(Me,{variant:"secondary",size:"sm",onClick:()=>L(null),children:i("common.dismiss")})]})]})]})})}),Z&&r.jsxs(Ct,{className:"mb-6",children:[r.jsx(pn,{children:r.jsx("h3",{className:"text-base font-semibold text-white",children:i("settings.createNewApiKey")})}),r.jsxs(At,{className:"space-y-3",children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:i("settings.keyName")}),r.jsx("input",{type:"text",value:ee,onChange:Se=>ge(Se.target.value),placeholder:i("settings.keyNamePlaceholder"),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-2",children:i("common.permissions")}),r.jsxs("div",{className:"space-y-2",children:[r.jsxs("label",{className:"flex items-center gap-3 cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:ce.can_read_status,onChange:Se=>le(Rt=>({...Rt,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"}),r.jsxs("div",{children:[r.jsx("span",{className:"text-white",children:i("settings.readStatus")}),r.jsx("p",{className:"text-xs text-bambu-gray",children:i("settings.readStatusDescription")})]})]}),r.jsxs("label",{className:"flex items-center gap-3 cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:ce.can_queue,onChange:Se=>le(Rt=>({...Rt,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"}),r.jsxs("div",{children:[r.jsx("span",{className:"text-white",children:i("settings.manageQueue")}),r.jsx("p",{className:"text-xs text-bambu-gray",children:i("settings.manageQueueDescription")})]})]}),r.jsxs("label",{className:"flex items-center gap-3 cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:ce.can_control_printer,onChange:Se=>le(Rt=>({...Rt,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"}),r.jsxs("div",{children:[r.jsx("span",{className:"text-white",children:i("settings.controlPrinter")}),r.jsx("p",{className:"text-xs text-bambu-gray",children:i("settings.controlPrinterDescription")})]})]}),r.jsxs("label",{className:"flex items-center gap-3 cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:ce.can_access_cloud,onChange:Se=>le(Rt=>({...Rt,can_access_cloud:Se.target.checked})),className:"w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green"}),r.jsxs("div",{children:[r.jsx("span",{className:"text-white",children:i("settings.cloudAccess","Allow cloud access")}),r.jsx("p",{className:"text-xs text-bambu-gray",children:i("settings.cloudAccessDescription","Read Bambu Cloud presets and filaments on your behalf. Requires you to be signed into Bambu Cloud.")})]})]})]})]}),r.jsxs("div",{className:"flex items-center gap-2 pt-2",children:[r.jsxs(Me,{onClick:()=>xr.mutate({name:ee||i("settings.unnamedKey"),...ce}),disabled:xr.isPending,children:[xr.isPending?r.jsx(pt,{className:"w-4 h-4 animate-spin"}):r.jsx(ar,{className:"w-4 h-4"}),i("settings.createKey")]}),r.jsx(Me,{variant:"secondary",onClick:()=>oe(!1),children:i("common.cancel")})]})]})]}),Mn?r.jsx("div",{className:"flex justify-center py-12",children:r.jsx(pt,{className:"w-8 h-8 text-bambu-green animate-spin"})}):Cn&&Cn.length>0?r.jsx("div",{className:"space-y-3",children:Cn.map(Se=>r.jsx(Ct,{children:r.jsx(At,{className:"py-3",children:r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx(vo,{className:`w-5 h-5 ${Se.enabled?"text-bambu-green":"text-bambu-gray"}`}),r.jsxs("div",{children:[r.jsx("p",{className:"text-white font-medium",children:Se.name}),r.jsxs("p",{className:"text-xs text-bambu-gray",children:[Se.key_prefix,"••••••••",Se.last_used&&` · ${i("settings.lastUsed")}: ${Lg(Se.last_used)}`]})]})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsxs("div",{className:"flex gap-1 text-xs flex-wrap justify-end",children:[Se.can_read_status&&r.jsx("span",{className:"px-1.5 py-0.5 bg-blue-500/20 text-blue-400 rounded",children:i("settings.read")}),Se.can_queue&&r.jsx("span",{className:"px-1.5 py-0.5 bg-green-500/20 text-green-400 rounded",children:i("queue.title")}),Se.can_control_printer&&r.jsx("span",{className:"px-1.5 py-0.5 bg-orange-500/20 text-orange-400 rounded",children:i("settings.control")}),Se.can_access_cloud&&r.jsx("span",{className:"px-1.5 py-0.5 bg-purple-500/20 text-purple-400 rounded",children:i("settings.cloudBadge","Cloud")}),Se.user_id===null&&r.jsx("span",{className:"px-1.5 py-0.5 bg-yellow-500/20 text-yellow-400 rounded",title:i("settings.legacyKeyTooltip","Created before per-user ownership; recreate to use cloud access"),children:i("settings.legacyKey","Legacy")})]}),r.jsx(Me,{variant:"secondary",size:"sm",onClick:()=>ye(Se.id),children:r.jsx(Jt,{className:"w-4 h-4 text-red-400"})})]})]})})},Se.id))}):r.jsx(Ct,{children:r.jsx(At,{className:"py-12",children:r.jsxs("div",{className:"text-center text-bambu-gray",children:[r.jsx(vo,{className:"w-16 h-16 mx-auto mb-4 opacity-30"}),r.jsx("p",{className:"text-lg font-medium text-white mb-2",children:i("settings.apiKeysEmptyTitle")}),r.jsx("p",{className:"text-sm mb-4",children:i("settings.apiKeysEmptyDescription")}),r.jsxs(Me,{onClick:()=>oe(!0),children:[r.jsx(ar,{className:"w-4 h-4"}),i("settings.createFirstKey")]})]})})}),r.jsxs(Ct,{className:"mt-6",children:[r.jsx(pn,{children:r.jsx("h3",{className:"text-base font-semibold text-white",id:"card-webhooks",children:i("settings.webhookEndpoints")})}),r.jsxs(At,{className:"space-y-3 text-sm",children:[r.jsx("p",{className:"text-bambu-gray",children:i("settings.webhookApiKeyHint")}),r.jsxs("div",{className:"space-y-2 font-mono text-xs",children:[r.jsxs("div",{className:"p-2 bg-bambu-dark rounded",children:[r.jsx("span",{className:"text-blue-400",children:"GET"})," ",r.jsx("span",{className:"text-white",children:"/api/v1/webhook/status"}),r.jsxs("span",{className:"text-bambu-gray",children:[" - ",i("settings.webhook.getAllStatus")]})]}),r.jsxs("div",{className:"p-2 bg-bambu-dark rounded",children:[r.jsx("span",{className:"text-blue-400",children:"GET"})," ",r.jsx("span",{className:"text-white",children:"/api/v1/webhook/status/:id"}),r.jsxs("span",{className:"text-bambu-gray",children:[" - ",i("settings.webhook.getSpecificStatus")]})]}),r.jsxs("div",{className:"p-2 bg-bambu-dark rounded",children:[r.jsx("span",{className:"text-green-400",children:"POST"})," ",r.jsx("span",{className:"text-white",children:"/api/v1/webhook/queue"}),r.jsxs("span",{className:"text-bambu-gray",children:[" - ",i("settings.webhook.addToQueue")]})]}),r.jsxs("div",{className:"p-2 bg-bambu-dark rounded",children:[r.jsx("span",{className:"text-orange-400",children:"POST"})," ",r.jsx("span",{className:"text-white",children:"/api/v1/webhook/printer/:id/pause"}),r.jsxs("span",{className:"text-bambu-gray",children:[" - ",i("settings.webhook.pausePrint")]})]}),r.jsxs("div",{className:"p-2 bg-bambu-dark rounded",children:[r.jsx("span",{className:"text-orange-400",children:"POST"})," ",r.jsx("span",{className:"text-white",children:"/api/v1/webhook/printer/:id/resume"}),r.jsxs("span",{className:"text-bambu-gray",children:[" - ",i("settings.webhook.resumePrint")]})]}),r.jsxs("div",{className:"p-2 bg-bambu-dark rounded",children:[r.jsx("span",{className:"text-red-400",children:"POST"})," ",r.jsx("span",{className:"text-white",children:"/api/v1/webhook/printer/:id/stop"}),r.jsxs("span",{className:"text-bambu-gray",children:[" - ",i("settings.webhook.stopPrint")]})]})]})]})]})]}),r.jsxs(Ct,{className:"mt-6",children:[r.jsx(pn,{children:r.jsxs("h3",{className:"text-base font-semibold text-white flex items-center gap-2",id:"card-camera-tokens",children:[r.jsx(iC,{className:"w-4 h-4 text-bambu-green"}),i("cameraTokens.title","Camera API Tokens")]})}),r.jsx(At,{children:r.jsx(krt,{})})]})]}),m("api_keys:read")&&r.jsxs("div",{children:[r.jsxs("div",{className:"mb-6",children:[r.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",id:"card-apibrowser",children:[r.jsx(no,{className:"w-5 h-5 text-bambu-green"}),i("settings.apiBrowser")]}),r.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:i("settings.apiBrowserDescription")})]}),r.jsx(Ct,{className:"mb-4",children:r.jsxs(At,{className:"py-3",children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-2",children:i("settings.apiKeyForTesting")}),r.jsx("input",{type:"text",value:we,onChange:Se=>Ne(Se.target.value),placeholder:i("settings.apiKeyPlaceholder"),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white font-mono text-sm focus:border-bambu-green focus:outline-none"}),r.jsx("p",{className:"text-xs text-bambu-gray mt-2",children:i("settings.apiKeyHint")})]})}),r.jsx(vat,{apiKey:we})]})]}),O==="virtual-printer"&&r.jsx("div",{id:"card-vp",children:r.jsx(Zrt,{})}),O==="spoolbuddy"&&r.jsx("div",{id:"card-spoolbuddy",children:r.jsx(eat,{})}),O==="queue"&&S&&r.jsxs("div",{className:"flex flex-col lg:flex-row gap-4 lg:gap-6",children:[r.jsxs("div",{className:"lg:w-1/2 space-y-3",children:[r.jsxs(Ct,{id:"card-print-options",children:[r.jsx(pn,{children:r.jsxs("h3",{className:"text-base font-semibold text-white flex items-center gap-2",children:[r.jsx(jw,{className:"w-4 h-4 text-bambu-green"}),i("settings.defaultPrintOptions","Default Print Options")]})}),r.jsxs(At,{className:"space-y-3",children:[r.jsx("p",{className:"text-xs text-bambu-gray",children:i("settings.defaultPrintOptionsDescription","Set default values for print options when starting new prints. These can be overridden per print in the print dialog.")}),[{key:"default_bed_levelling",label:i("settings.defaultBedLevelling","Bed Levelling"),desc:i("settings.defaultBedLevellingDesc","Auto-level bed before print"),fallback:!0},{key:"default_flow_cali",label:i("settings.defaultFlowCali","Flow Calibration"),desc:i("settings.defaultFlowCaliDesc","Calibrate extrusion flow"),fallback:!1},{key:"default_vibration_cali",label:i("settings.defaultVibrationCali","Vibration Calibration"),desc:i("settings.defaultVibrationCaliDesc","Reduce ringing artifacts"),fallback:!0},{key:"default_layer_inspect",label:i("settings.defaultLayerInspect","First Layer Inspection"),desc:i("settings.defaultLayerInspectDesc","AI inspection of first layer"),fallback:!1},{key:"default_timelapse",label:i("settings.defaultTimelapse","Timelapse"),desc:i("settings.defaultTimelapseDesc","Record timelapse video"),fallback:!1}].map(({key:Se,label:Rt,desc:an,fallback:An})=>r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{className:"flex-1 mr-4",children:[r.jsx("p",{className:"text-sm text-white",children:Rt}),r.jsx("p",{className:"text-xs text-bambu-gray mt-0.5",children:an})]}),r.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:S[Se]??An,onChange:Bn=>_n(Se,Bn.target.checked),className:"sr-only peer"}),r.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"})]})]},Se))]})]}),r.jsxs(Ct,{id:"card-staggered",children:[r.jsx(pn,{children:r.jsxs("h3",{className:"text-base font-semibold text-white flex items-center gap-2",children:[r.jsx(oa,{className:"w-4 h-4 text-bambu-green"}),i("settings.staggeredStart","Staggered Start")]})}),r.jsxs(At,{className:"space-y-3",children:[r.jsx("p",{className:"text-xs text-bambu-gray",children:i("settings.staggeredStartDescription","Default group size and interval when staggering multi-printer batch starts. Can be overridden per batch in the print modal.")}),r.jsxs("div",{className:"flex gap-4",children:[r.jsxs("div",{className:"flex-1",children:[r.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:i("settings.staggerGroupSize","Group size")}),r.jsx("input",{type:"number",min:1,max:50,value:S.stagger_group_size??2,onChange:Se=>_n("stagger_group_size",Math.max(1,Math.min(50,parseInt(Se.target.value)||1))),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green"}),r.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:i("settings.staggerGroupSizeHelp","Printers to start simultaneously per group")})]}),r.jsxs("div",{className:"flex-1",children:[r.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:i("settings.staggerInterval","Interval (minutes)")}),r.jsx("input",{type:"number",min:1,max:60,value:S.stagger_interval_minutes??5,onChange:Se=>_n("stagger_interval_minutes",Math.max(1,Math.min(60,parseInt(Se.target.value)||1))),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green"}),r.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:i("settings.staggerIntervalHelp","Delay between each group starting")})]})]})]})]}),r.jsxs(Ct,{id:"card-plate",children:[r.jsx(pn,{children:r.jsxs("h3",{className:"text-base font-semibold text-white flex items-center gap-2",children:[r.jsx(Sl,{className:"w-4 h-4 text-bambu-green"}),i("settings.plateClear","Plate-Clear Confirmation")]})}),r.jsx(At,{className:"space-y-3",children:r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{className:"flex-1 mr-4",children:[r.jsx("p",{className:"text-sm text-white",children:i("settings.requirePlateClear","Require plate-clear confirmation")}),r.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:i("settings.requirePlateClearDescription",'When enabled, the scheduler waits for per-printer plate-clear confirmation before starting queued prints on printers with finished jobs. Disabling this also hides the plate status badge and the "Mark plate as cleared" button on printer cards.')})]}),r.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:S.require_plate_clear??!1,onChange:Se=>_n("require_plate_clear",Se.target.checked),className:"sr-only peer"}),r.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"})]})]})})]}),r.jsxs(Ct,{id:"card-gcode",children:[r.jsx(pn,{children:r.jsxs("h3",{className:"text-base font-semibold text-white flex items-center gap-2",children:[r.jsx(Gy,{className:"w-4 h-4 text-bambu-green"}),i("settings.gcodeInjection","G-code Injection")]})}),r.jsxs(At,{className:"space-y-3",children:[r.jsx("p",{className:"text-xs text-bambu-gray",children:i("settings.gcodeInjectionDescription",'Configure custom G-code to inject at the start and/or end of prints for auto-print systems like Farmloop, SwapMod, AutoClear, and Printflow 3D. Snippets are configured per printer model and applied when "Inject G-code" is enabled on a queue item.')}),(()=>{const Se=(()=>{try{return S.gcode_snippets?JSON.parse(S.gcode_snippets):{}}catch{return{}}})(),Rt=[...new Set((zn||[]).filter(Bn=>Bn.model).map(Bn=>Bn.model))].sort(),an=(Bn,ba,Na)=>{const ot={...Se};ot[Bn]||(ot[Bn]={start_gcode:"",end_gcode:""}),ot[Bn][ba]=Na,!ot[Bn].start_gcode&&!ot[Bn].end_gcode&&delete ot[Bn];const $t=Object.keys(ot).length>0?JSON.stringify(ot):"";E(sn=>sn?{...sn,gcode_snippets:$t}:null),Sd.current=$t},An=()=>{Sd.current!==null&&(Pu.mutate({gcode_snippets:Sd.current}),Sd.current=null)};return Rt.length===0?r.jsx("p",{className:"text-sm text-bambu-gray italic",children:i("settings.gcodeInjectionNoPrinters","No printers found. Add printers to configure G-code snippets.")}):Rt.map(Bn=>{const ba=Se[Bn]||{start_gcode:"",end_gcode:""},Na=!!(ba.start_gcode||ba.end_gcode);return r.jsx(o5,{defaultOpen:Na,className:"border border-bambu-dark-tertiary rounded-lg px-3 py-2",summary:r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("h4",{className:"text-sm font-medium text-white",children:Bn}),Na&&r.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-bambu-green/20 text-bambu-green",children:i("settings.gcodeConfigured","Configured")})]}),children:r.jsxs("div",{className:"space-y-2",children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:i("settings.gcodeStartLabel","Start G-code")}),r.jsx("textarea",{value:ba.start_gcode,onChange:ot=>an(Bn,"start_gcode",ot.target.value),onBlur:An,placeholder:i("settings.gcodeStartPlaceholder","G-code prepended before the print starts..."),rows:3,className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-xs font-mono focus:outline-none focus:border-bambu-green resize-y"})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:i("settings.gcodeEndLabel","End G-code")}),r.jsx("textarea",{value:ba.end_gcode,onChange:ot=>an(Bn,"end_gcode",ot.target.value),onBlur:An,placeholder:i("settings.gcodeEndPlaceholder","G-code appended after the print ends..."),rows:3,className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-xs font-mono focus:outline-none focus:border-bambu-green resize-y"})]})]})},Bn)})})()]})]})]}),r.jsxs("div",{className:"lg:w-1/2 space-y-3",children:[r.jsxs(Ct,{id:"card-slicer",children:[r.jsx(pn,{children:r.jsxs("h3",{className:"text-base font-semibold text-white flex items-center gap-2",children:[r.jsx(cu,{className:"w-4 h-4 text-bambu-green"}),i("settings.slicerCard","Slicer")]})}),r.jsxs(At,{className:"space-y-3",children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:i("settings.preferredSlicer")}),r.jsxs("div",{className:"relative",children:[r.jsxs("select",{value:S.preferred_slicer??"bambu_studio",onChange:Se=>_n("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:[r.jsx("option",{value:"bambu_studio",children:i("settings.slicerBambuStudio")}),r.jsx("option",{value:"orcaslicer",children:i("settings.slicerOrcaSlicer")})]}),r.jsx(Ln,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}),r.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:i("settings.preferredSlicerDescription")}),(S.preferred_slicer??"bambu_studio")==="orcaslicer"&&r.jsx("div",{role:"alert",className:"text-xs text-amber-200 bg-amber-900/20 border border-amber-700/40 rounded p-2 mt-2",children:i("settings.orcaslicerKnownIssuesWarning","OrcaSlicer 2.3.2 / 2.4.0-dev have known CLI bugs that block slicing many Bambu-authored 3MFs — see upstream issues #12426 (segfault on painted multi-extruder files) and #13386 (parameter-range strict-validation reject). Bambu Studio is recommended until the upstream fixes land.")})]}),r.jsxs("div",{className:"flex items-center justify-between gap-3",children:[r.jsxs("div",{className:"min-w-0",children:[r.jsx("p",{className:"text-white",children:i("settings.useSlicerApi")}),r.jsx("p",{className:"text-sm text-bambu-gray",children:i("settings.useSlicerApiDescription")})]}),r.jsxs("label",{className:"flex items-center cursor-pointer shrink-0",children:[r.jsx("input",{type:"checkbox",checked:S.use_slicer_api??!1,onChange:Se=>_n("use_slicer_api",Se.target.checked),className:"sr-only peer"}),r.jsx("div",{className:"relative w-11 h-6 bg-bambu-dark-tertiary rounded-full peer peer-checked:bg-bambu-green peer-focus:outline-none peer-focus:ring-2 peer-focus:ring-bambu-green/50 transition-colors after:content-[''] after:absolute after:top-0.5 after:left-0.5 after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-transform peer-checked:after:translate-x-5"})]})]}),(S.use_slicer_api??!1)&&r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:(S.preferred_slicer??"bambu_studio")==="orcaslicer"?i("settings.orcaslicerApiUrl","OrcaSlicer sidecar URL"):i("settings.bambuStudioApiUrl","Bambu Studio sidecar URL")}),r.jsx("input",{type:"text",value:((S.preferred_slicer??"bambu_studio")==="orcaslicer"?S.orcaslicer_api_url:S.bambu_studio_api_url)??"",onChange:Se=>_n((S.preferred_slicer??"bambu_studio")==="orcaslicer"?"orcaslicer_api_url":"bambu_studio_api_url",Se.target.value),placeholder:(S.preferred_slicer??"bambu_studio")==="orcaslicer"?"http://localhost:3003":"http://localhost:3001",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none placeholder:text-bambu-gray/40"}),r.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:i("settings.slicerApiUrlDescription","URL of the slicer-API sidecar container. Leave blank to use the SLICER_API_URL / BAMBU_STUDIO_API_URL env var defaults.")})]})]})]}),(S.use_slicer_api??!1)&&r.jsx(xrt,{}),r.jsxs(Ct,{children:[r.jsx(pn,{children:r.jsxs("h3",{className:"text-base font-semibold text-white flex items-center gap-2",id:"card-drying",children:[r.jsx(mm,{className:"w-4 h-4 text-amber-400"}),i("settings.queueDrying")]})}),r.jsxs(At,{className:"space-y-3",children:[r.jsx("p",{className:"text-xs text-bambu-gray",children:i("settings.queueDryingDescription")}),r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-white",children:i("settings.queueDryingEnabled")}),r.jsx("p",{className:"text-xs text-bambu-gray mt-0.5",children:i("settings.queueDryingEnabledDescription")})]}),r.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:S.queue_drying_enabled??!1,onChange:Se=>_n("queue_drying_enabled",Se.target.checked),className:"sr-only peer"}),r.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.queue_drying_enabled&&r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-white",children:i("settings.queueDryingBlock")}),r.jsx("p",{className:"text-xs text-bambu-gray mt-0.5",children:i("settings.queueDryingBlockDescription")})]}),r.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:S.queue_drying_block??!1,onChange:Se=>_n("queue_drying_block",Se.target.checked),className:"sr-only peer"}),r.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-amber-500"})]})]}),r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-white",children:i("settings.ambientDryingEnabled")}),r.jsx("p",{className:"text-xs text-bambu-gray mt-0.5",children:i("settings.ambientDryingEnabledDescription")})]}),r.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:S.ambient_drying_enabled??!1,onChange:Se=>_n("ambient_drying_enabled",Se.target.checked),className:"sr-only peer"}),r.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"})]})]}),r.jsxs("div",{className:"space-y-2",children:[r.jsx("p",{className:"text-sm text-white font-medium",children:i("settings.dryingPresets")}),r.jsx("p",{className:"text-xs text-bambu-gray",children:i("settings.dryingPresetsDescription")}),r.jsx("div",{className:"overflow-x-auto",children:r.jsxs("table",{className:"w-full text-xs",children:[r.jsx("thead",{children:r.jsxs("tr",{className:"text-bambu-gray border-b border-bambu-dark-tertiary",children:[r.jsx("th",{className:"text-left py-1.5",children:i("settings.dryingFilament")}),r.jsx("th",{className:"text-center py-1.5",colSpan:2,children:"AMS 2 Pro"}),r.jsx("th",{className:"text-center py-1.5",colSpan:2,children:"AMS-HT"})]})}),r.jsx("tbody",{children:(()=>{const Se={PLA:{n3f:45,n3s:45,n3f_hours:12,n3s_hours:12},PETG:{n3f:65,n3s:65,n3f_hours:12,n3s_hours:12},TPU:{n3f:65,n3s:75,n3f_hours:12,n3s_hours:18},ABS:{n3f:65,n3s:80,n3f_hours:12,n3s_hours:8},ASA:{n3f:65,n3s:80,n3f_hours:12,n3s_hours:8},PA:{n3f:65,n3s:85,n3f_hours:12,n3s_hours:12},PC:{n3f:65,n3s:80,n3f_hours:12,n3s_hours:8},PVA:{n3f:65,n3s:85,n3f_hours:12,n3s_hours:18}};let Rt={...Se};try{if(S.drying_presets){const An=JSON.parse(S.drying_presets);typeof An=="object"&&An!==null&&(Rt={...Se,...An})}}catch{}const an=(An,Bn,ba)=>{const Na={...Rt,[An]:{...Rt[An],[Bn]:ba}};_n("drying_presets",JSON.stringify(Na))};return Object.entries(Rt).map(([An,Bn])=>r.jsxs("tr",{className:"border-b border-bambu-dark-tertiary/50",children:[r.jsx("td",{className:"py-1.5 pr-2 text-white font-medium",children:An}),r.jsx("td",{className:"py-1 px-1",children:r.jsxs("div",{className:"flex items-center justify-end gap-1",children:[r.jsx("input",{type:"number",min:30,max:65,value:Bn.n3f,onChange:ba=>an(An,"n3f",Math.max(1,parseInt(ba.target.value)||0)),className:"w-14 px-1.5 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-center text-xs focus:border-amber-500/50 focus:outline-none [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none"}),r.jsx("span",{className:"text-bambu-gray",children:"°C"})]})}),r.jsx("td",{className:"py-1 px-1",children:r.jsxs("div",{className:"flex items-center gap-1",children:[r.jsx("input",{type:"number",min:1,max:24,value:Bn.n3f_hours,onChange:ba=>an(An,"n3f_hours",Math.max(1,parseInt(ba.target.value)||0)),className:"w-14 px-1.5 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-center text-xs focus:border-amber-500/50 focus:outline-none [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none"}),r.jsx("span",{className:"text-bambu-gray",children:"h"})]})}),r.jsx("td",{className:"py-1 px-1",children:r.jsxs("div",{className:"flex items-center justify-end gap-1",children:[r.jsx("input",{type:"number",min:30,max:85,value:Bn.n3s,onChange:ba=>an(An,"n3s",Math.max(1,parseInt(ba.target.value)||0)),className:"w-14 px-1.5 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-center text-xs focus:border-amber-500/50 focus:outline-none [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none"}),r.jsx("span",{className:"text-bambu-gray",children:"°C"})]})}),r.jsx("td",{className:"py-1 px-1",children:r.jsxs("div",{className:"flex items-center gap-1",children:[r.jsx("input",{type:"number",min:1,max:24,value:Bn.n3s_hours,onChange:ba=>an(An,"n3s_hours",Math.max(1,parseInt(ba.target.value)||0)),className:"w-14 px-1.5 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-center text-xs focus:border-amber-500/50 focus:outline-none [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none"}),r.jsx("span",{className:"text-bambu-gray",children:"h"})]})})]},An))})()})]})})]})]})]})]})]}),O==="filament"&&S&&r.jsx(r.Fragment,{children:r.jsxs("div",{className:"flex flex-col lg:flex-row gap-4 lg:gap-6",children:[r.jsxs("div",{className:"lg:w-1/3 space-y-3",children:[r.jsx(Lrt,{}),r.jsxs(Ct,{id:"card-filamentchecks",children:[r.jsx(pn,{children:r.jsx("h2",{className:"text-lg font-semibold text-white",children:i("settings.filamentChecks")})}),r.jsxs(At,{className:"space-y-3",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-white",children:i("settings.disableFilamentWarnings")}),r.jsx("p",{className:"text-sm text-bambu-gray",children:i("settings.disableFilamentWarningsDesc")})]}),r.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:S.disable_filament_warnings,onChange:Se=>_n("disable_filament_warnings",Se.target.checked),className:"sr-only peer"}),r.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"})]})]}),r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-white",children:i("settings.preferLowestFilament")}),r.jsx("p",{className:"text-sm text-bambu-gray",children:i("settings.preferLowestFilamentDesc")})]}),r.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:S.prefer_lowest_filament,onChange:Se=>_n("prefer_lowest_filament",Se.target.checked),className:"sr-only peer"}),r.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"})]})]})]})]}),r.jsxs(Ct,{id:"card-printmodal",children:[r.jsx(pn,{children:r.jsx("h2",{className:"text-lg font-semibold text-white",children:i("settings.printModal")})}),r.jsx(At,{className:"space-y-3",children:r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-white",children:i("settings.expandCustomMapping")}),r.jsx("p",{className:"text-sm text-bambu-gray",children:i("settings.expandCustomMappingDescription")})]}),r.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:S.per_printer_mapping_expanded??!1,onChange:Se=>_n("per_printer_mapping_expanded",Se.target.checked),className:"sr-only peer"}),r.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"})]})]})})]}),r.jsxs(Ct,{id:"card-amsthresholds",children:[r.jsx(pn,{children:r.jsx("h2",{className:"text-lg font-semibold text-white",children:i("settings.amsDisplayThresholds")})}),r.jsxs(At,{className:"space-y-3",children:[r.jsx("p",{className:"text-sm text-bambu-gray",children:i("settings.amsThresholdsDescription")}),r.jsxs("div",{className:"space-y-3",children:[r.jsxs("div",{className:"flex items-center gap-2 text-white",children:[r.jsx(bO,{className:"w-4 h-4 text-blue-400"}),r.jsx("span",{className:"font-medium",children:i("settings.humidity")})]}),r.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[r.jsxs("div",{children:[r.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[i("settings.goodGreen")," ≤"]}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("input",{type:"number",min:"0",max:"100",value:S.ams_humidity_good??40,onChange:Se=>_n("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"}),r.jsx("span",{className:"text-bambu-gray",children:"%"})]})]}),r.jsxs("div",{children:[r.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[i("settings.fairOrange")," ≤"]}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("input",{type:"number",min:"0",max:"100",value:S.ams_humidity_fair??60,onChange:Se=>_n("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"}),r.jsx("span",{className:"text-bambu-gray",children:"%"})]})]})]}),r.jsx("p",{className:"text-xs text-bambu-gray",children:i("settings.aboveFairBad")}),r.jsx("p",{className:"text-xs text-amber-400/70",children:i("settings.fairAlsoDryingThreshold")})]}),r.jsxs("div",{className:"space-y-3 pt-2 border-t border-bambu-dark-tertiary",children:[r.jsxs("div",{className:"flex items-center gap-2 text-white",children:[r.jsx(FS,{className:"w-4 h-4 text-orange-400"}),r.jsx("span",{className:"font-medium",children:i("settings.temperature")})]}),r.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[r.jsxs("div",{children:[r.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[i("settings.goodBlue")," ≤"]}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("input",{type:"number",step:"0.5",min:"0",max:"60",value:S.ams_temp_good??28,onChange:Se=>_n("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"}),r.jsx("span",{className:"text-bambu-gray",children:"°C"})]})]}),r.jsxs("div",{children:[r.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[i("settings.fairOrange")," ≤"]}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("input",{type:"number",step:"0.5",min:"0",max:"60",value:S.ams_temp_fair??35,onChange:Se=>_n("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"}),r.jsx("span",{className:"text-bambu-gray",children:"°C"})]})]})]}),r.jsx("p",{className:"text-xs text-bambu-gray",children:i("settings.aboveFairHot")})]}),r.jsxs("div",{className:"space-y-3 pt-4 border-t border-bambu-dark-tertiary",children:[r.jsxs("div",{className:"flex items-center gap-2 text-white",children:[r.jsx(hc,{className:"w-4 h-4 text-purple-400"}),r.jsx("span",{className:"font-medium",children:i("settings.historyRetention")})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:i("settings.keepSensorHistory")}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("input",{type:"number",min:"1",max:"365",value:S.ams_history_retention_days??30,onChange:Se=>_n("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"}),r.jsx("span",{className:"text-bambu-gray",children:i("common.days")})]})]}),r.jsx("p",{className:"text-xs text-bambu-gray",children:i("settings.historyRetentionDescription")})]})]})]})]}),r.jsxs("div",{className:"lg:w-2/3 space-y-3",children:[r.jsx(Irt,{}),r.jsx(Wrt,{})]})]})}),ne!==null&&r.jsx(vn,{title:i("settings.deleteApiKeyTitle"),message:i("settings.deleteApiKeyMessage"),confirmText:i("settings.deleteKey"),variant:"danger",onConfirm:()=>{Er.mutate(ne),ye(null)},onCancel:()=>ye(null)}),U&&r.jsx(Crt,{plug:H,onClose:()=>{I(!1),R(null)}}),Q&&r.jsx(Art,{provider:J,onClose:()=>{re(!1),de(null)}}),pe&&r.jsx(jrt,{template:pe,onClose:()=>ue(null)}),Ce&&r.jsx(Ert,{onClose:()=>$(!1)}),ve&&r.jsx(vn,{title:i("settings.clearNotificationLogs"),message:i("settings.clearLogsMessage"),confirmText:i("settings.clearLogs"),variant:"warning",onConfirm:async()=>{xe(!1);try{const Se=await se.clearNotificationLogs(30);o(Se.message,"success")}catch{o(i("settings.toast.clearLogsFailed"),"error")}},onCancel:()=>xe(!1)}),Ee&&r.jsx(vn,{title:i("settings.resetUiPreferences"),message:i("settings.resetUiPreferencesMessage"),confirmText:i("settings.resetPreferences"),variant:"default",onConfirm:()=>{ze(!1),localStorage.clear(),o(i("settings.toast.uiPreferencesReset"),"success"),setTimeout(()=>window.location.reload(),1e3)},onCancel:()=>ze(!1)}),_e&&r.jsx(vn,{title:`Turn All Plugs ${_e==="on"?"On":"Off"}`,message:`This will turn ${_e==="on"?"ON":"OFF"} all ${Ge?.filter(Se=>Se.enabled).length||0} enabled smart plugs. ${_e==="off"?"Any running printers may be affected!":""}`,confirmText:`Turn All ${_e==="on"?"On":"Off"}`,variant:_e==="off"?"danger":"warning",onConfirm:()=>{const Se=_e;Oe(null),Lo.mutate(Se)},onCancel:()=>Oe(null)}),Ie&&Or?.release_notes&&r.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",onClick:()=>We(!1),children:r.jsxs(Ct,{className:"w-full max-w-2xl max-h-[80vh] flex flex-col",onClick:Se=>Se.stopPropagation(),children:[r.jsxs(pn,{className:"flex flex-row items-center justify-between shrink-0",children:[r.jsxs("div",{children:[r.jsxs("h2",{className:"text-lg font-semibold text-white",children:["Release Notes - v",Or.latest_version]}),Or.release_name&&Or.release_name!==Or.latest_version&&r.jsx("p",{className:"text-sm text-bambu-gray",children:Or.release_name})]}),r.jsx("button",{onClick:()=>We(!1),className:"p-1 rounded hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white",children:r.jsx(Ht,{className:"w-5 h-5"})})]}),r.jsx(At,{className:"overflow-y-auto flex-1",children:r.jsx("pre",{className:"text-sm text-bambu-gray whitespace-pre-wrap font-sans",children:Or.release_notes})}),r.jsxs("div",{className:"p-4 border-t border-bambu-dark-tertiary shrink-0 flex gap-2",children:[Or.release_url&&r.jsx("a",{href:Or.release_url,target:"_blank",rel:"noopener noreferrer",className:"flex-1",children:r.jsxs(Me,{variant:"secondary",className:"w-full",children:[r.jsx(Rr,{className:"w-4 h-4"}),"View on GitHub"]})}),r.jsx(Me,{onClick:()=>We(!1),className:"flex-1",children:"Close"})]})]})}),O==="users"&&r.jsxs("div",{className:"space-y-3",children:[r.jsxs("div",{className:"flex gap-1 border-b border-bambu-dark-tertiary",children:[r.jsxs("button",{onClick:()=>G("users"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${z==="users"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[r.jsx(gm,{className:"w-4 h-4"}),i("settings.tabs.users")]}),r.jsxs("button",{onClick:()=>G("email"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${z==="email"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[r.jsx(qm,{className:"w-4 h-4"}),i("settings.tabs.emailAuth")||"Email Authentication",di?.advanced_auth_enabled&&r.jsx("span",{className:"w-2 h-2 rounded-full bg-green-400"})]}),r.jsxs("button",{onClick:()=>G("ldap"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${z==="ldap"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[r.jsx(Sl,{className:"w-4 h-4"}),i("settings.tabs.ldap")||"LDAP",lp?.ldap_enabled&&r.jsx("span",{className:"w-2 h-2 rounded-full bg-green-400"})]}),r.jsxs("button",{onClick:()=>G("twofa"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${z==="twofa"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[r.jsx(Sl,{className:"w-4 h-4"}),i("settings.tabs.twoFa"),r.jsx("span",{className:`w-2 h-2 rounded-full ${pf?.totp_enabled||pf?.email_otp_enabled?"bg-green-400":"bg-bambu-gray/40"}`})]}),d&&r.jsxs("button",{onClick:()=>G("oidc"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${z==="oidc"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[r.jsx(no,{className:"w-4 h-4"}),i("settings.tabs.oidc"),r.jsx("span",{className:`w-2 h-2 rounded-full ${yd.some(Se=>Se.is_enabled)?"bg-green-400":"bg-bambu-gray/40"}`})]}),d&&r.jsxs("button",{onClick:()=>G("security"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${z==="security"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[r.jsx(Sl,{className:"w-4 h-4"}),i("settings.tabs.security")]})]}),z==="users"&&r.jsxs(r.Fragment,{children:[r.jsx(Ct,{children:r.jsx(At,{className:"py-4",children:r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{className:"flex items-center gap-3",children:[r.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?r.jsx(lc,{className:"w-5 h-5 text-green-400"}):r.jsx(K0,{className:"w-5 h-5 text-gray-400"})}),r.jsxs("div",{children:[r.jsx("h3",{className:"text-white font-medium",children:i("settings.authentication")}),r.jsx("p",{className:"text-sm text-bambu-gray",children:i(l?"settings.authEnabledDescription":"settings.authDisabledDescription")})]})]}),l?c?.is_admin&&r.jsxs(Me,{variant:"secondary",onClick:()=>lt(!0),children:[r.jsx(K0,{className:"w-4 h-4"}),i("common.disable")]}):r.jsxs(Me,{onClick:()=>e("/setup"),children:[r.jsx(lc,{className:"w-4 h-4"}),i("common.enable")]})]})})}),di?.advanced_auth_enabled&&r.jsx(Ct,{className:"border-blue-500/30 bg-blue-500/5",children:r.jsx(At,{className:"py-4",children:r.jsxs("div",{className:"flex items-start gap-3",children:[r.jsx("div",{className:"w-10 h-10 rounded-full flex items-center justify-center bg-blue-500/20 flex-shrink-0",children:r.jsx(qm,{className:"w-5 h-5 text-blue-400"})}),r.jsxs("div",{children:[r.jsx("h3",{className:"text-white font-medium",children:i("settings.email.advancedAuthEnabled")}),r.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:i("settings.email.advancedAuthEnabledDesc")})]})]})})}),l&&r.jsxs("div",{className:"grid grid-cols-1 xl:grid-cols-2 gap-6",children:[r.jsxs("div",{className:"space-y-3",children:[c&&r.jsxs(Ct,{children:[r.jsx(pn,{children:r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("h3",{className:"text-lg font-semibold text-white flex items-center gap-2",id:"card-currentuser",children:[r.jsx(gm,{className:"w-5 h-5 text-bambu-green"}),i("settings.currentUser")]}),c.auth_source!=="ldap"&&r.jsxs(Me,{size:"sm",variant:"ghost",onClick:()=>tt(!0),children:[r.jsx(vo,{className:"w-4 h-4"}),i("settings.changePassword")]})]})}),r.jsx(At,{children:r.jsx("div",{className:"flex items-center justify-between",children:r.jsxs("div",{children:[r.jsx("p",{className:"text-white font-medium text-lg",children:c.username}),r.jsxs("div",{className:"flex flex-wrap gap-1 mt-2",children:[c.is_admin&&r.jsx("span",{className:"px-2 py-0.5 rounded-full text-xs font-medium bg-purple-500/20 text-purple-300",children:i("settings.admin")}),c.groups?.map(Se=>r.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))]})]})})})]}),r.jsxs(Ct,{children:[r.jsx(pn,{children:r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("h3",{className:"text-lg font-semibold text-white flex items-center gap-2",id:"card-users",children:[r.jsx(gm,{className:"w-5 h-5 text-bambu-green"}),i("settings.users")]}),m("users:create")&&r.jsxs(Me,{size:"sm",onClick:()=>{Qe(!0),vt({username:"",password:"",email:"",confirmPassword:"",role:"user",group_ids:[]})},children:[r.jsx(ar,{className:"w-4 h-4"}),i("settings.addUser")]})]})}),r.jsx(At,{children:cp?r.jsx("div",{className:"flex items-center justify-center py-8",children:r.jsx(pt,{className:"w-6 h-6 text-bambu-green animate-spin"})}):Ic.length===0?r.jsx("p",{className:"text-center text-bambu-gray py-8",children:i("settings.noUsersFound")}):r.jsx("div",{className:"divide-y divide-bambu-dark-tertiary",children:Ic.map(Se=>r.jsxs("div",{className:"py-3 flex items-center justify-between",children:[r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("p",{className:"text-white font-medium truncate",children:Se.username}),r.jsxs("div",{className:"flex flex-wrap gap-1 mt-1",children:[Se.auth_source==="ldap"&&r.jsx("span",{className:"px-2 py-0.5 rounded-full text-xs font-medium bg-cyan-500/20 text-cyan-300",children:"LDAP"}),Se.is_admin&&r.jsx("span",{className:"px-2 py-0.5 rounded-full text-xs font-medium bg-purple-500/20 text-purple-300",children:i("settings.admin")}),Se.groups?.map(Rt=>r.jsx("span",{className:`px-2 py-0.5 rounded-full text-xs font-medium ${Rt.name==="Administrators"?"bg-purple-500/20 text-purple-300":Rt.name==="Operators"?"bg-blue-500/20 text-blue-300":Rt.name==="Viewers"?"bg-green-500/20 text-green-300":"bg-gray-500/20 text-gray-300"}`,children:Rt.name},Rt.id))]})]}),r.jsxs("div",{className:"flex items-center gap-1 ml-4",children:[m("users:update")&&r.jsx(Me,{size:"sm",variant:"ghost",onClick:()=>hv(Se),children:r.jsx(fc,{className:"w-4 h-4"})}),m("users:delete")&&Se.id!==c?.id&&r.jsx(Me,{size:"sm",variant:"ghost",onClick:()=>dp(Se.id),children:r.jsx(Jt,{className:"w-4 h-4"})})]})]},Se.id))})})]})]}),r.jsx("div",{children:r.jsxs(Ct,{children:[r.jsx(pn,{children:r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("h3",{className:"text-lg font-semibold text-white flex items-center gap-2",id:"card-groups",children:[r.jsx(Sl,{className:"w-5 h-5 text-bambu-green"}),i("settings.groups")]}),m("groups:create")&&r.jsxs(Me,{size:"sm",onClick:()=>e("/groups/new"),children:[r.jsx(ar,{className:"w-4 h-4"}),i("settings.addGroup")]})]})}),r.jsx(At,{children:Do?r.jsx("div",{className:"flex items-center justify-center py-8",children:r.jsx(pt,{className:"w-6 h-6 text-bambu-green animate-spin"})}):Qr.length===0?r.jsx("p",{className:"text-center text-bambu-gray py-8",children:i("settings.noGroupsFound")}):r.jsx("div",{className:"divide-y divide-bambu-dark-tertiary",children:Qr.map(Se=>r.jsxs("div",{className:"py-3",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(Sl,{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"}`}),r.jsx("span",{className:"text-white font-medium",children:Se.name}),Se.is_system&&r.jsx("span",{className:"px-2 py-0.5 rounded text-xs bg-yellow-500/20 text-yellow-400",children:i("settings.system")})]}),r.jsxs("div",{className:"flex items-center gap-1",children:[m("groups:update")&&r.jsx(Me,{size:"sm",variant:"ghost",onClick:()=>e(`/groups/${Se.id}/edit`),children:r.jsx(fc,{className:"w-4 h-4"})}),m("groups:delete")&&!Se.is_system&&r.jsx(Me,{size:"sm",variant:"ghost",onClick:()=>Dt(Se.id),children:r.jsx(Jt,{className:"w-4 h-4"})})]})]}),r.jsx("p",{className:"text-sm text-bambu-gray mt-1 ml-6",children:Se.description||i("settings.noDescription")}),r.jsxs("div",{className:"flex items-center gap-4 mt-2 ml-6 text-xs text-bambu-gray",children:[r.jsx("span",{children:i("settings.userCount",{count:Se.user_count})}),r.jsx("span",{children:i("settings.permissionCount",{count:Se.permissions.length})})]})]},Se.id))})})]})})]}),!l&&r.jsx(Ct,{children:r.jsx(At,{className:"py-6",children:r.jsxs("div",{className:"text-center",children:[r.jsx(K0,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),r.jsx("h3",{className:"text-lg font-medium text-white mb-2",children:i("settings.authDisabledTitle")}),r.jsx("p",{className:"text-sm text-bambu-gray mb-4 max-w-md mx-auto",children:i("settings.authDisabledMessage")}),r.jsxs("ul",{className:"space-y-2 text-sm text-bambu-gray mb-6 text-left max-w-xs mx-auto",children:[r.jsxs("li",{className:"flex items-start gap-2",children:[r.jsx(wr,{className:"w-4 h-4 text-bambu-green mt-0.5 flex-shrink-0"}),r.jsx("span",{children:i("settings.authDisabledFeature1")})]}),r.jsxs("li",{className:"flex items-start gap-2",children:[r.jsx(wr,{className:"w-4 h-4 text-bambu-green mt-0.5 flex-shrink-0"}),r.jsx("span",{children:i("settings.authDisabledFeature2")})]}),r.jsxs("li",{className:"flex items-start gap-2",children:[r.jsx(wr,{className:"w-4 h-4 text-bambu-green mt-0.5 flex-shrink-0"}),r.jsx("span",{children:i("settings.authDisabledFeature3")})]})]}),r.jsxs(Me,{onClick:()=>e("/setup"),children:[r.jsx(lc,{className:"w-4 h-4"}),i("settings.enableAuthentication")]})]})})})]}),z==="email"&&r.jsx("div",{className:"max-w-5xl",id:"card-smtp",children:r.jsx(lat,{})}),z==="ldap"&&r.jsx("div",{className:"max-w-5xl",id:"card-ldap",children:r.jsx(dat,{})}),z==="twofa"&&r.jsx("div",{className:"max-w-2xl",children:r.jsx(mat,{})}),z==="oidc"&&d&&r.jsx("div",{className:"max-w-3xl",children:r.jsx(hat,{})}),z==="security"&&d&&r.jsx("div",{className:"max-w-3xl",children:r.jsx(gat,{})})]}),nt&&!di?.advanced_auth_enabled&&r.jsx("div",{className:"fixed inset-0 bg-black flex items-center justify-center z-50 p-4",onClick:()=>{Qe(!1),vt({username:"",password:"",email:"",confirmPassword:"",role:"user",group_ids:[]})},children:r.jsxs(Ct,{className:"w-full max-w-md",onClick:Se=>Se.stopPropagation(),children:[r.jsx(pn,{children:r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(gm,{className:"w-5 h-5 text-bambu-green"}),r.jsx("h2",{className:"text-lg font-semibold text-white",children:i("settings.createUser")})]}),r.jsx(Me,{variant:"ghost",size:"sm",onClick:()=>{Qe(!1),vt({username:"",password:"",email:"",confirmPassword:"",role:"user",group_ids:[]})},children:r.jsx(Ht,{className:"w-5 h-5"})})]})}),r.jsxs(At,{children:[r.jsxs("div",{className:"space-y-3",children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:i("settings.username")}),r.jsx("input",{type:"text",value:st.username,onChange:Se=>vt({...st,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:i("settings.enterUsername"),autoComplete:"username"})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:i("settings.password")}),r.jsx("input",{type:"password",value:st.password,onChange:Se=>vt({...st,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:i("settings.enterPassword"),autoComplete:"new-password",minLength:8}),r.jsx("p",{className:"text-bambu-gray text-xs mt-1",children:i("settings.passwordRequirements")})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:i("settings.confirmPassword")}),r.jsx("input",{type:"password",value:st.confirmPassword,onChange:Se=>vt({...st,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 ${st.confirmPassword&&st.password!==st.confirmPassword?"border-red-500":"border-bambu-dark-tertiary"}`,placeholder:i("settings.confirmPasswordPlaceholder"),autoComplete:"new-password",minLength:6}),st.confirmPassword&&st.password!==st.confirmPassword&&r.jsx("p",{className:"text-red-400 text-xs mt-1",children:i("settings.passwordsDoNotMatch")})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:i("settings.groups")}),r.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:[Qr.map(Se=>r.jsxs("label",{className:"flex items-center gap-3 px-2 py-1.5 rounded hover:bg-bambu-dark-tertiary cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:st.group_ids.includes(Se.id),onChange:()=>hf(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"}),r.jsx("span",{className:"text-sm text-white",children:Se.name}),Se.is_system&&r.jsx("span",{className:"text-xs text-yellow-400",children:i("settings.systemBadge")})]},Se.id)),Qr.length===0&&r.jsx("p",{className:"text-sm text-bambu-gray",children:i("settings.noGroupsAvailable")})]})]})]}),r.jsxs("div",{className:"mt-6 flex justify-end gap-3",children:[r.jsx(Me,{variant:"secondary",onClick:()=>{Qe(!1),vt({username:"",password:"",email:"",confirmPassword:"",role:"user",group_ids:[]})},children:i("common.cancel")}),r.jsx(Me,{onClick:wd,disabled:ol.isPending||!st.username||!st.password||st.password!==st.confirmPassword||cN(st.password)!==null,children:ol.isPending?r.jsxs(r.Fragment,{children:[r.jsx(pt,{className:"w-4 h-4 animate-spin"}),i("settings.creating")]}):r.jsxs(r.Fragment,{children:[r.jsx(ar,{className:"w-4 h-4"}),i("settings.createUser")]})})]})]})]})}),nt&&di?.advanced_auth_enabled&&r.jsx(Frt,{formData:st,setFormData:vt,groups:Qr,onClose:()=>{Qe(!1),vt({username:"",password:"",email:"",confirmPassword:"",role:"user",group_ids:[]})},onCreate:wd,isCreating:ol.isPending,isCreateButtonDisabled:ol.isPending||!st.username||!st.email}),gt&&rt!==null&&r.jsx("div",{className:"fixed inset-0 bg-black flex items-center justify-center z-50 p-4",onClick:()=>{ct(!1),Ot(null),vt({username:"",password:"",email:"",confirmPassword:"",role:"user",group_ids:[]})},children:r.jsxs(Ct,{className:"w-full max-w-md",onClick:Se=>Se.stopPropagation(),children:[r.jsx(pn,{children:r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(fc,{className:"w-5 h-5 text-bambu-green"}),r.jsx("h2",{className:"text-lg font-semibold text-white",children:i("settings.editUser")})]}),r.jsx(Me,{variant:"ghost",size:"sm",onClick:()=>{ct(!1),Ot(null),vt({username:"",password:"",email:"",confirmPassword:"",role:"user",group_ids:[]})},children:r.jsx(Ht,{className:"w-5 h-5"})})]})}),r.jsxs(At,{children:[r.jsxs("div",{className:"space-y-3",children:[r.jsxs("div",{children:[r.jsxs("label",{className:"block text-sm font-medium text-white mb-2",children:[i("settings.username")," ",di?.advanced_auth_enabled&&r.jsx("span",{className:"text-red-400",children:"*"})]}),r.jsx("input",{type:"text",value:st.username,onChange:Se=>vt({...st,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:i("settings.enterUsername"),autoComplete:"username"})]}),r.jsxs("div",{children:[r.jsxs("label",{className:"block text-sm font-medium text-white mb-2",children:[i("users.form.email")||"Email"," ",di?.advanced_auth_enabled?r.jsx("span",{className:"text-red-400",children:"*"}):r.jsxs("span",{className:"text-bambu-gray font-normal",children:["(",i("users.form.optional")||"optional",")"]})]}),r.jsx("input",{type:"email",value:st.email,onChange:Se=>vt({...st,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:i("users.form.emailPlaceholder")||"user@example.com",required:di?.advanced_auth_enabled})]}),!di?.advanced_auth_enabled&&r.jsxs(r.Fragment,{children:[r.jsxs("div",{children:[r.jsxs("label",{className:"block text-sm font-medium text-white mb-2",children:[i("users.form.password")||"Password"," ",r.jsxs("span",{className:"text-bambu-gray font-normal",children:["(",i("users.form.leaveBlankToKeep")||"leave blank to keep current",")"]})]}),r.jsx("input",{type:"password",value:st.password,onChange:Se=>vt({...st,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:i("settings.enterNewPassword"),autoComplete:"new-password",minLength:8}),r.jsx("p",{className:"text-bambu-gray text-xs mt-1",children:i("settings.passwordRequirements")})]}),st.password&&r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:i("settings.confirmPassword")}),r.jsx("input",{type:"password",value:st.confirmPassword,onChange:Se=>vt({...st,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 ${st.confirmPassword&&st.password!==st.confirmPassword?"border-red-500":"border-bambu-dark-tertiary"}`,placeholder:i("settings.confirmNewPassword"),autoComplete:"new-password",minLength:6}),st.confirmPassword&&st.password!==st.confirmPassword&&r.jsx("p",{className:"text-red-400 text-xs mt-1",children:i("settings.passwordsDoNotMatch")})]})]}),di?.advanced_auth_enabled&&r.jsxs("div",{className:"bg-bambu-dark-secondary/50 border border-bambu-green/20 rounded-lg p-3 space-y-3",children:[r.jsx("p",{className:"text-sm text-bambu-gray",children:i("users.form.passwordManagedByAdvancedAuth")||'Password is managed by Advanced Authentication. Use "Reset Password" to send a new password to the user via email.'}),r.jsx(Me,{variant:"secondary",size:"sm",onClick:()=>rt&&vd.mutate(rt),disabled:vd.isPending||!st.email,className:"w-full",children:vd.isPending?r.jsxs(r.Fragment,{children:[r.jsx(pt,{className:"w-4 h-4 animate-spin"}),i("users.form.resettingPassword")||"Resetting Password..."]}):r.jsxs(r.Fragment,{children:[r.jsx(gs,{className:"w-4 h-4"}),i("users.form.resetPassword")||"Reset Password"]})})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:i("users.form.groups")||"Groups"}),r.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:Qr.map(Se=>r.jsxs("label",{className:"flex items-center gap-3 px-2 py-1.5 rounded hover:bg-bambu-dark-tertiary cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:st.group_ids.includes(Se.id),onChange:()=>hf(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"}),r.jsx("span",{className:"text-sm text-white",children:Se.name}),Se.is_system&&r.jsxs("span",{className:"text-xs text-yellow-400",children:["(",i("users.system")||"System",")"]})]},Se.id))})]})]}),r.jsxs("div",{className:"mt-6 flex justify-end gap-3",children:[r.jsx(Me,{variant:"secondary",onClick:()=>{ct(!1),Ot(null),vt({username:"",password:"",email:"",confirmPassword:"",role:"user",group_ids:[]})},children:i("users.modal.cancel")||"Cancel"}),r.jsx(Me,{onClick:()=>gb(rt),disabled:ll.isPending||!st.username||di?.advanced_auth_enabled&&!st.email||!!(!di?.advanced_auth_enabled&&st.password&&(st.password!==st.confirmPassword||cN(st.password)!==null)),children:ll.isPending?r.jsxs(r.Fragment,{children:[r.jsx(pt,{className:"w-4 h-4 animate-spin"}),i("users.modal.saving")||"Saving..."]}):r.jsxs(r.Fragment,{children:[r.jsx(us,{className:"w-4 h-4"}),i("users.modal.saveChanges")||"Save Changes"]})})]})]})]})}),Wt!==null&&r.jsx("div",{className:"fixed inset-0 bg-black/80 flex items-center justify-center z-50 p-4",onClick:()=>{Zt(null),un(null)},children:r.jsxs(Ct,{className:"w-full max-w-md",onClick:Se=>Se.stopPropagation(),children:[r.jsx(pn,{children:r.jsxs("div",{className:"flex items-center gap-2 text-red-400",children:[r.jsx(Jt,{className:"w-5 h-5"}),r.jsx("h3",{className:"text-lg font-semibold",children:i("settings.deleteUserTitle")})]})}),r.jsx(At,{className:"space-y-3",children:bn?r.jsx("div",{className:"flex items-center justify-center py-4",children:r.jsx("div",{className:"animate-spin rounded-full h-6 w-6 border-2 border-bambu-green border-t-transparent"})}):Yt&&Yt.archives+Yt.queue_items+Yt.library_files>0?r.jsxs(r.Fragment,{children:[r.jsx("p",{className:"text-white",children:i("settings.userHasCreated")}),r.jsxs("ul",{className:"list-disc list-inside text-bambu-gray space-y-1",children:[Yt.archives>0&&r.jsxs("li",{children:[Yt.archives," archive",Yt.archives!==1?"s":""]}),Yt.queue_items>0&&r.jsxs("li",{children:[Yt.queue_items," queue item",Yt.queue_items!==1?"s":""]}),Yt.library_files>0&&r.jsxs("li",{children:[Yt.library_files," library file",Yt.library_files!==1?"s":""]})]}),r.jsx("p",{className:"text-bambu-gray text-sm",children:i("settings.userItemsQuestion")}),r.jsxs("div",{className:"flex flex-col gap-2",children:[r.jsx(Me,{variant:"danger",onClick:()=>cl.mutate({id:Wt,deleteItems:!0}),disabled:cl.isPending,className:"justify-center",children:i("settings.deleteUserAndItems")}),r.jsx(Me,{variant:"secondary",onClick:()=>cl.mutate({id:Wt,deleteItems:!1}),disabled:cl.isPending,className:"justify-center",children:i("settings.deleteUserKeepItems")}),r.jsx(Me,{variant:"ghost",onClick:()=>{Zt(null),un(null)},disabled:cl.isPending,className:"justify-center",children:i("common.cancel")})]})]}):r.jsxs(r.Fragment,{children:[r.jsx("p",{className:"text-white",children:i("settings.deleteUserConfirm")}),r.jsx("p",{className:"text-bambu-gray text-sm",children:i("settings.actionCannotBeUndone")}),r.jsxs("div",{className:"flex gap-2 justify-end",children:[r.jsx(Me,{variant:"ghost",onClick:()=>{Zt(null),un(null)},disabled:cl.isPending,children:i("common.cancel")}),r.jsx(Me,{variant:"danger",onClick:()=>cl.mutate({id:Wt,deleteItems:!1}),disabled:cl.isPending,children:i("settings.deleteUserTitle")})]})]})})]})}),_t!==null&&r.jsx(vn,{title:i("settings.deleteGroupTitle"),message:i("settings.deleteGroupMessage"),confirmText:i("settings.deleteGroup"),variant:"danger",onConfirm:()=>{Fo.mutate(_t),Dt(null)},onCancel:()=>Dt(null)}),O==="failure-detection"&&r.jsx("div",{id:"card-failure-detection",children:r.jsx(iat,{})}),O==="backup"&&r.jsxs("div",{id:"card-backup",children:[r.jsxs("div",{className:"mb-4 p-3 bg-amber-500/10 border border-amber-500/30 rounded-lg flex items-start gap-2",children:[r.jsx(Sl,{className:"text-amber-400 flex-shrink-0 mt-0.5",size:16}),r.jsx("p",{className:"text-sm text-amber-400",children:i("backup.includesEncryptionKey")})]}),r.jsx(aat,{})]}),at&&r.jsx(vn,{title:i("settings.disableAuthenticationTitle"),message:i("settings.disableAuthenticationMessage"),confirmText:i("settings.disableAuthentication"),variant:"danger",onConfirm:async()=>{try{await se.disableAuth(),o(i("settings.toast.authDisabled"),"success"),await u(),lt(!1),window.location.href="/"}catch(Se){const Rt=Se instanceof Error?Se.message:i("settings.toast.authDisableFailed");o(Rt,"error")}},onCancel:()=>lt(!1)}),Fe&&r.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",onClick:()=>{tt(!1),Ye({currentPassword:"",newPassword:"",confirmPassword:""})},children:r.jsxs(Ct,{className:"w-full max-w-md",onClick:Se=>Se.stopPropagation(),children:[r.jsx(pn,{children:r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(vo,{className:"w-5 h-5 text-bambu-green"}),r.jsx("h2",{className:"text-lg font-semibold text-white",children:i("settings.changePassword")})]}),r.jsx(Me,{variant:"ghost",size:"sm",onClick:()=>{tt(!1),Ye({currentPassword:"",newPassword:"",confirmPassword:""})},children:r.jsx(Ht,{className:"w-5 h-5"})})]})}),r.jsxs(At,{children:[r.jsxs("div",{className:"space-y-3",children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:"Current Password"}),r.jsx("input",{type:"password",value:Pe.currentPassword,onChange:Se=>Ye({...Pe,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:i("settings.enterCurrentPassword"),autoComplete:"current-password"})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:"New Password"}),r.jsx("input",{type:"password",value:Pe.newPassword,onChange:Se=>Ye({...Pe,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:i("settings.enterNewPasswordMin6"),autoComplete:"new-password",minLength:6})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:"Confirm New Password"}),r.jsx("input",{type:"password",value:Pe.confirmPassword,onChange:Se=>Ye({...Pe,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 ${Pe.confirmPassword&&Pe.newPassword!==Pe.confirmPassword?"border-red-500":"border-bambu-dark-tertiary"}`,placeholder:i("settings.confirmNewPassword"),autoComplete:"new-password",minLength:6}),Pe.confirmPassword&&Pe.newPassword!==Pe.confirmPassword&&r.jsx("p",{className:"text-red-400 text-xs mt-1",children:i("settings.passwordsDoNotMatch")})]})]}),r.jsxs("div",{className:"mt-6 flex justify-end gap-3",children:[r.jsx(Me,{variant:"secondary",onClick:()=>{tt(!1),Ye({currentPassword:"",newPassword:"",confirmPassword:""})},children:i("common.cancel")}),r.jsx(Me,{onClick:async()=>{if(Pe.newPassword!==Pe.confirmPassword){o(i("settings.toast.passwordsDoNotMatch"),"error");return}if(Pe.newPassword.length<6){o(i("settings.toast.passwordTooShort"),"error");return}fe(!0);try{await se.changePassword(Pe.currentPassword,Pe.newPassword),o(i("settings.toast.passwordChanged"),"success"),tt(!1),Ye({currentPassword:"",newPassword:"",confirmPassword:""})}catch(Se){const Rt=Se instanceof Error?Se.message:"Failed to change password";o(Rt,"error")}finally{fe(!1)}},disabled:Ue||!Pe.currentPassword||!Pe.newPassword||Pe.newPassword!==Pe.confirmPassword||Pe.newPassword.length<6,children:Ue?r.jsxs(r.Fragment,{children:[r.jsx(pt,{className:"w-4 h-4 animate-spin"}),i("settings.changing")]}):r.jsxs(r.Fragment,{children:[r.jsx(vo,{className:"w-4 h-4"}),i("settings.changePassword")]})})]})]})]})})]})]})]})})}const Ace=t=>{const e=parseFloat(t);return(Math.trunc(e*1e3)/1e3).toFixed(3)},kat=t=>t.startsWith("HH")?"HF":"S",Nat=t=>{const e=t.match(/^([A-Z]{2}\d{2})/);return e?e[1]:"HH00"},jce=t=>{const e=["High Flow_","High Flow ","Standard_","Standard ","HF_","HF ","S_","S "];for(const a of e)if(t.startsWith(a))return t.slice(a.length);const n=t.indexOf("_");return n>0?t.slice(n+1):t};function lF({profile:t,onEdit:e,onCopy:n,selectionMode:a,isSelected:i,onToggleSelect:s,note:o}){const l=kat(t.nozzle_id),c=t.nozzle_diameter,d=()=>{a&&s?s():e()};return r.jsxs("div",{className:"flex items-center gap-2",children:[a&&r.jsx("button",{onClick:s,className:"text-bambu-gray hover:text-white transition-colors p-1",children:i?r.jsx(bs,{className:"w-4 h-4 text-bambu-green"}):r.jsx(so,{className:"w-4 h-4"})}),r.jsxs("button",{onClick:d,className:`flex-1 text-left px-3 py-2 bg-bambu-dark rounded hover:bg-bambu-dark-tertiary transition-colors ${i?"ring-1 ring-bambu-green":""}`,children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:"text-bambu-green font-mono text-sm font-bold whitespace-nowrap",children:Ace(t.k_value)}),r.jsx("span",{className:"text-white text-sm truncate flex-1",title:t.name,children:t.name||"Unnamed"}),o&&r.jsx("span",{title:"Has note",children:r.jsx(IZ,{className:"w-3 h-3 text-yellow-500"})}),r.jsxs("span",{className:"text-xs text-bambu-gray whitespace-nowrap",children:[l," ",c]})]}),o&&r.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]})]}),!a&&n&&r.jsx("button",{onClick:u=>{u.stopPropagation(),n()},className:"text-bambu-gray hover:text-white transition-colors p-1",title:"Copy profile",children:r.jsx(Mi,{className:"w-4 h-4"})})]})}function cF({profile:t,printerId:e,nozzleDiameter:n,existingProfiles:a=[],builtinFilaments:i=[],isDualNozzle:s=!1,initialNote:o="",initialNoteKey:l=null,onClose:c,onSave:d,onSaveNote:u,hasPermission:m}){const{t:p}=kt(),{showToast:f}=rn(),[b,w]=y.useState(t?.name||""),[g,x]=y.useState(t?.k_value?Ace(t.k_value):"0.020"),[_,N]=y.useState(t?.filament_id||""),[C,P]=y.useState(t?.nozzle_id?Nat(t.nozzle_id):"HH00"),[T,A]=y.useState(t?.nozzle_diameter||n),[F,S]=y.useState(t?[t.extruder_id]:s?[0,1]:[0]),[E,U]=y.useState(!1),[I,H]=y.useState({current:0,total:0}),[R,Q]=y.useState(o),re=pa.useMemo(()=>{const me=new Map;for(const Ce of i)me.set(Ce.filament_id,Ce.name);const be=new Map;for(const Ce of a)if(Ce.filament_id&&!be.has(Ce.filament_id)){const W=me.get(Ce.filament_id)||jce(Ce.name||"");be.set(Ce.filament_id,{id:Ce.filament_id,name:W||Ce.filament_id})}return Array.from(be.values()).sort((Ce,$)=>Ce.name.localeCompare($.name))},[a,i]),J=it({mutationFn:me=>(console.log("[KProfile] Calling API..."),se.setKProfile(e,me)),onSuccess:me=>{if(console.log("[KProfile] Save success:",me),f(p("kProfiles.toast.profileSaved")),u&&R!==o){let be;R===""&&l?be=l:t&&t.slot_id>0?be=t.setting_id||`slot_${t.slot_id}_${t.filament_id}_${t.extruder_id}`:be=`name_${b}_${_}`,u(be,R)}U(!0),setTimeout(()=>{U(!1),d()},2500)},onError:me=>{console.error("[KProfile] Save error:",me),f(me.message,"error"),U(!1)}}),de=it({mutationFn:me=>(console.log("[KProfile] Deleting profile..."),se.deleteKProfile(e,me)),onSuccess:me=>{console.log("[KProfile] Delete success:",me),f(p("kProfiles.toast.profileDeleted")),U(!0),setTimeout(()=>{U(!1),c()},4e3)},onError:me=>{console.error("[KProfile] Delete error:",me),f(me.message,"error"),U(!1)}}),[pe,ue]=y.useState(!1),X=()=>{t&&de.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})},ae=async me=>{if(me.preventDefault(),s&&!t&&F.length===0){f(p("kProfiles.toast.selectAtLeastOneExtruder"),"error");return}const be=parseFloat(g).toFixed(6),Ce=`${C}-${T}`;if(t||F.length===1){const W={name:b,k_value:be,filament_id:_,nozzle_id:Ce,nozzle_diameter:T,extruder_id:t?t.extruder_id:F[0],setting_id:t?.setting_id,slot_id:t?.slot_id??0};console.log("[KProfile] Saving profile:",W),J.mutate(W);return}U(!0),H({current:1,total:F.length});const $=F.map(W=>({name:b,k_value:be,filament_id:_,nozzle_id:Ce,nozzle_diameter:T,extruder_id:W,setting_id:void 0,slot_id:0}));console.log(`[KProfile] Saving ${$.length} profiles in batch:`,$);try{if(await se.setKProfilesBatch(e,$),f(p("kProfiles.toast.profilesSaved",{count:F.length})),u&&R){const W=`name_${b}_${_}`;u(W,R)}}catch(W){console.error("[KProfile] Failed to save batch:",W),f(p("kProfiles.toast.failedToSaveBatch"),"error"),U(!1),H({current:0,total:0});return}H({current:F.length,total:F.length}),setTimeout(()=>{U(!1),H({current:0,total:0}),d()},3e3)};return r.jsxs("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",children:[r.jsxs(Ct,{className:"w-full max-w-md relative",children:[E&&r.jsxs("div",{className:"absolute inset-0 bg-bambu-dark-secondary/90 flex flex-col items-center justify-center z-10 rounded-lg",children:[r.jsx(pt,{className:"w-8 h-8 text-bambu-green animate-spin mb-3"}),r.jsx("p",{className:"text-white font-medium",children:I.total>1?p("kProfiles.modal.savingExtruder",{current:I.current,total:I.total}):p("kProfiles.modal.syncing")}),r.jsx("p",{className:"text-bambu-gray text-sm mt-1",children:p("kProfiles.modal.pleaseWait")})]}),r.jsxs(At,{className:"p-0",children:[r.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[r.jsx("h2",{className:"text-xl font-semibold text-white",children:p(t?"kProfiles.modal.editTitle":"kProfiles.modal.addTitle")}),r.jsx("button",{onClick:c,className:"text-bambu-gray hover:text-white transition-colors",disabled:E,children:r.jsx(Ht,{className:"w-5 h-5"})})]}),r.jsxs("form",{onSubmit:ae,className:"p-4 space-y-4",children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:p("kProfiles.modal.profileName")}),r.jsx("input",{type:"text",value:b,onChange:me=>w(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})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:p("kProfiles.modal.kValue")}),r.jsx("input",{type:"text",inputMode:"decimal",value:g,onChange:me=>{const be=me.target.value;(be===""||/^\d*\.?\d*$/.test(be))&&x(be)},onBlur:me=>{const be=parseFloat(me.target.value);isNaN(be)||x((Math.trunc(be*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}),r.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:p("kProfiles.modal.kValueHelp")})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:p("kProfiles.modal.filament")}),r.jsxs("select",{value:_,onChange:me=>{const be=me.target.value;if(N(be),!t&&be&&!b){const Ce=re.find($=>$.id===be);Ce&&w(`${C==="HH00"?"HF":"S"} ${Ce.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:[r.jsx("option",{value:"",children:p("kProfiles.modal.selectFilament")}),t?.filament_id&&r.jsx("option",{value:t.filament_id,children:re.find(me=>me.id===t.filament_id)?.name||t.filament_id},t.filament_id),!t&&re.map(me=>r.jsx("option",{value:me.id,children:me.name},me.id))]}),!t&&re.length===0&&r.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:p("kProfiles.modal.noFilamentsHelp")})]}),r.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:p("kProfiles.modal.flowType")}),r.jsxs("select",{value:C,onChange:me=>{const be=me.target.value;if(P(be),!t&&_&&!b){const Ce=re.find($=>$.id===_);Ce&&w(`${be==="HS00"?"HF":"S"} ${Ce.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:[r.jsx("option",{value:"HH00",children:p("kProfiles.modal.highFlow")}),r.jsx("option",{value:"HS00",children:p("kProfiles.modal.standard")})]})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:p("kProfiles.modal.nozzleSize")}),r.jsxs("select",{value:T,onChange:me=>A(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:[r.jsx("option",{value:"0.2",children:"0.2mm"}),r.jsx("option",{value:"0.4",children:"0.4mm"}),r.jsx("option",{value:"0.6",children:"0.6mm"}),r.jsx("option",{value:"0.8",children:"0.8mm"})]})]})]}),s&&r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:p(t?"kProfiles.modal.extruder":"kProfiles.modal.extruders")}),t?r.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")}):r.jsxs("div",{className:"flex gap-4",children:[r.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:F.includes(1),onChange:me=>{me.target.checked?S([...F,1]):S(F.filter(be=>be!==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"}),r.jsx("span",{className:"text-white",children:p("kProfiles.modal.left")})]}),r.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:F.includes(0),onChange:me=>{me.target.checked?S([...F,0]):S(F.filter(be=>be!==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"}),r.jsx("span",{className:"text-white",children:p("kProfiles.modal.right")})]})]})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:p("kProfiles.modal.notes")}),r.jsx("textarea",{value:R,onChange:me=>Q(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"}),r.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:p("kProfiles.modal.notesHelp")})]}),r.jsxs("div",{className:"flex gap-2 pt-4",children:[t&&r.jsx(Me,{type:"button",variant:"secondary",onClick:()=>ue(!0),disabled:de.isPending||E||!m("kprofiles:delete"),title:m("kprofiles:delete")?void 0:p("kProfiles.permission.noDelete"),className:"text-red-500 hover:bg-red-500/10",children:de.isPending?r.jsx(pt,{className:"w-4 h-4 animate-spin"}):r.jsx(Jt,{className:"w-4 h-4"})}),r.jsx(Me,{type:"button",variant:"secondary",onClick:c,disabled:E,className:"flex-1",children:p("common.cancel")}),r.jsxs(Me,{type:"submit",disabled:J.isPending||E||!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:[J.isPending?r.jsx(pt,{className:"w-4 h-4 animate-spin"}):r.jsx(CS,{className:"w-4 h-4"}),p("common.save")]})]})]})]})]}),pe&&r.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-[60]",children:r.jsx(Ct,{className:"w-full max-w-sm",children:r.jsxs(At,{className:"p-6",children:[r.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[r.jsx("div",{className:"w-10 h-10 rounded-full bg-red-500/20 flex items-center justify-center",children:r.jsx(Jt,{className:"w-5 h-5 text-red-500"})}),r.jsxs("div",{children:[r.jsx("h3",{className:"text-lg font-semibold text-white",children:p("kProfiles.deleteConfirm.title")}),r.jsx("p",{className:"text-sm text-bambu-gray",children:p("kProfiles.deleteConfirm.cannotUndo")})]})]}),r.jsx("p",{className:"text-bambu-gray mb-6",children:p("kProfiles.deleteConfirm.message",{name:t?.name})}),r.jsxs("div",{className:"flex gap-3",children:[r.jsx(Me,{variant:"secondary",onClick:()=>ue(!1),className:"flex-1",children:p("common.cancel")}),r.jsxs(Me,{onClick:()=>{ue(!1),X()},disabled:de.isPending,className:"flex-1 bg-red-500 hover:bg-red-600 text-white",children:[de.isPending?r.jsx(pt,{className:"w-4 h-4 animate-spin"}):r.jsx(Jt,{className:"w-4 h-4"}),p("common.delete")]})]})]})})})]})}const dN={NOZZLE_DIAMETER:"bambusy_kprofiles_nozzle",SORT_OPTION:"bambusy_kprofiles_sort"};function Cat(){const{t}=kt(),{showToast:e}=rn(),{hasPermission:n}=cr(),[a,i]=y.useState(null),[s,o]=y.useState(()=>localStorage.getItem(dN.NOZZLE_DIAMETER)||"0.4"),[l,c]=y.useState(null),[d,u]=y.useState(!1),[m,p]=y.useState(null),[f,b]=y.useState(""),[w,g]=y.useState("all"),[x,_]=y.useState("all"),[N,C]=y.useState(()=>localStorage.getItem(dN.SORT_OPTION)||"name"),[P,T]=y.useState(!1),[A,F]=y.useState(new Set),[S,E]=y.useState(!1),[U,I]=y.useState(!1),H=y.useCallback(L=>`${L.slot_id}_${L.extruder_id}`,[]);y.useEffect(()=>{localStorage.setItem(dN.NOZZLE_DIAMETER,s)},[s]),y.useEffect(()=>{localStorage.setItem(dN.SORT_OPTION,N)},[N]);const{data:R,isLoading:Q}=Ve({queryKey:["printers"],queryFn:se.getPrinters}),{data:re,isLoading:J,isFetching:de,error:pe,refetch:ue}=Ve({queryKey:["kprofiles",a,s],queryFn:async()=>{console.log("[KProfiles] Fetching profiles for printer",a,"nozzle",s);const L=await se.getKProfiles(a,s);return console.log("[KProfiles] Received profiles:",L?.profiles?.length||0,"profiles"),L},enabled:!!a,retry:!1,staleTime:0,gcTime:0,refetchOnMount:"always"}),{data:X}=Ve({queryKey:["kprofiles",a,"0.4"],queryFn:()=>se.getKProfiles(a,"0.4"),enabled:!!a,staleTime:6e4}),{data:ae}=Ve({queryKey:["builtinFilaments"],queryFn:()=>se.getBuiltinFilaments(),staleTime:3e5}),{data:me}=Ve({queryKey:["filamentIdMap"],queryFn:()=>se.getFilamentIdMap(),staleTime:3e5}),{data:be,refetch:Ce}=Ve({queryKey:["kprofile-notes",a],queryFn:()=>se.getKProfileNotes(a),enabled:!!a,staleTime:3e4}),$=pe?.message?.includes("not connected");y.useEffect(()=>{if(!a&&R&&R.length>0){const L=R.find(ne=>ne.is_active);L&&i(L.id)}},[a,R]),y.useEffect(()=>{if(a){const L=setTimeout(()=>{ue()},150);return()=>clearTimeout(L)}},[a,s]);const W=R?.filter(L=>L.is_active)||[],D=pa.useMemo(()=>{const L=new Map;if(ae)for(const ne of ae)L.set(ne.filament_id,ne.name);if(me)for(const[ne,ye]of Object.entries(me))L.has(ne)||L.set(ne,ye);return L},[ae,me]),j=pa.useMemo(()=>Array.from(D.entries()).map(([L,ne])=>({filament_id:L,name:ne})),[D]),B=pa.useCallback(L=>D.get(L.filament_id)||jce(L.name),[D]),Y=pa.useMemo(()=>re?.profiles?re.profiles.filter(ne=>{const ye=f.toLowerCase(),we=!ye||ne.name.toLowerCase().includes(ye)||ne.filament_id.toLowerCase().includes(ye),Ne=w==="all"||w==="left"&&ne.extruder_id===1||w==="right"&&ne.extruder_id===0,ve=x==="all"||x==="hf"&&ne.nozzle_id.startsWith("HH")||x==="s"&&ne.nozzle_id.startsWith("HS");return we&&Ne&&ve}).sort((ne,ye)=>{switch(N){case"k_value":return parseFloat(ne.k_value)-parseFloat(ye.k_value);case"filament":return B(ne).localeCompare(B(ye));default:return ne.name.localeCompare(ye.name)}}):[],[re?.profiles,f,w,x,N,B]),O=R?.find(L=>L.id===a),ie=O?.nozzle_count===2;y.useEffect(()=>{const L=ne=>{ne.target instanceof HTMLInputElement||ne.target instanceof HTMLTextAreaElement||ne.target instanceof HTMLSelectElement||l||d||m||(ne.key==="r"||ne.key==="R"?(ne.preventDefault(),ue()):ne.key==="n"||ne.key==="N"?(ne.preventDefault(),u(!0)):ne.key==="Escape"&&P&&(ne.preventDefault(),T(!1),F(new Set)))};return window.addEventListener("keydown",L),()=>window.removeEventListener("keydown",L)},[l,d,m,P,ue]);const z=y.useCallback(()=>{if(!re?.profiles||re.profiles.length===0){e(t("kProfiles.toast.noProfilesToExport"),"error");return}const L={version:1,exported_at:new Date().toISOString(),printer:O?.name||"Unknown",nozzle_diameter:s,profiles:re.profiles.map(Ne=>({name:Ne.name,k_value:Ne.k_value,filament_id:Ne.filament_id,nozzle_id:Ne.nozzle_id,nozzle_diameter:Ne.nozzle_diameter,extruder_id:Ne.extruder_id}))},ne=new Blob([JSON.stringify(L,null,2)],{type:"application/json"}),ye=URL.createObjectURL(ne),we=document.createElement("a");we.href=ye,we.download=`kprofiles_${O?.name||"printer"}_${s}mm_${new Date().toISOString().split("T")[0]}.json`,document.body.appendChild(we),we.click(),document.body.removeChild(we),URL.revokeObjectURL(ye),e(t("kProfiles.toast.exportedProfiles",{count:re.profiles.length}))},[re?.profiles,O,s,e,t]),G=y.useCallback(()=>{const L=document.createElement("input");L.type="file",L.accept=".json",L.onchange=async ne=>{const ye=ne.target.files?.[0];if(ye)try{const we=await ye.text(),Ne=JSON.parse(we);if(!Ne.profiles||!Array.isArray(Ne.profiles)){e(t("kProfiles.toast.invalidFileFormat"),"error");return}let ve=0;for(const xe of Ne.profiles)if(!(!xe.name||!xe.k_value||!xe.filament_id))try{await se.setKProfile(a,{name:xe.name,k_value:parseFloat(xe.k_value).toFixed(6),filament_id:xe.filament_id,nozzle_id:xe.nozzle_id||`HH00-${s}`,nozzle_diameter:xe.nozzle_diameter||s,extruder_id:xe.extruder_id??0,slot_id:0}),ve++,await new Promise(Ee=>setTimeout(Ee,500))}catch(Ee){console.error("Failed to import profile:",xe.name,Ee)}e(t("kProfiles.toast.importedProfiles",{count:ve,total:Ne.profiles.length})),ue()}catch(we){console.error("Import error:",we),e(t("kProfiles.toast.failedToParseImport"),"error")}},L.click()},[a,s,e,ue,t]),K=y.useCallback(L=>{F(ne=>{const ye=new Set(ne);return ye.has(L)?ye.delete(L):ye.add(L),ye})},[]),Z=y.useCallback(()=>{F(new Set(Y.map(L=>H(L))))},[Y,H]),oe=y.useCallback(()=>{A.size!==0&&E(!0)},[A.size]),ee=y.useCallback(async()=>{const L=Y.filter(ye=>A.has(H(ye)));I(!0);let ne=0;for(const ye of L)try{await se.deleteKProfile(a,{slot_id:ye.slot_id,extruder_id:ye.extruder_id,nozzle_id:ye.nozzle_id,nozzle_diameter:ye.nozzle_diameter,filament_id:ye.filament_id,setting_id:ye.setting_id}),ne++,await new Promise(we=>setTimeout(we,300))}catch(we){console.error("Failed to delete profile:",ye.name,we)}e(t("kProfiles.toast.profilesDeleted",{count:ne})),I(!1),E(!1),T(!1),F(new Set),ue()},[a,A,Y,e,ue,H,t]),ge=y.useCallback(L=>{const ne=[];return L.setting_id&&ne.push(L.setting_id),ne.push(`slot_${L.slot_id}_${L.filament_id}_${L.extruder_id}`),ne.push(`name_${L.name}_${L.filament_id}`),ne},[]),ce=y.useCallback(async(L,ne)=>{if(a)try{await se.setKProfileNote(a,L,ne),Ce()}catch(ye){console.error("Failed to save note:",ye),e(t("kProfiles.toast.failedToSaveNote"),"error")}},[a,Ce,e,t]),le=y.useCallback(L=>{if(!be?.notes)return{note:"",key:null};const ne=ge(L);for(const ye of ne)if(be.notes[ye])return{note:be.notes[ye],key:ye};return{note:"",key:null}},[be,ge]),q=y.useCallback(L=>le(L).note,[le]);return Q?r.jsx("div",{className:"flex justify-center py-12",children:r.jsx(pt,{className:"w-8 h-8 text-bambu-green animate-spin"})}):!R||R.length===0?r.jsx(Ct,{children:r.jsxs(At,{className:"py-12 text-center",children:[r.jsx($a,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),r.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:t("kProfiles.noPrintersConfigured")}),r.jsx("p",{className:"text-bambu-gray",children:t("kProfiles.addPrinterInSettings")})]})}):W.length===0?r.jsx(Ct,{children:r.jsxs(At,{className:"py-12 text-center",children:[r.jsx(pr,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),r.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:t("kProfiles.noActivePrinters")}),r.jsx("p",{className:"text-bambu-gray",children:t("kProfiles.enablePrinterConnection")})]})}):r.jsxs(r.Fragment,{children:[de&&!J&&r.jsxs("div",{className:"fixed inset-0 bg-black/50 flex flex-col items-center justify-center z-40",children:[r.jsx(pt,{className:"w-10 h-10 text-bambu-green animate-spin mb-3"}),r.jsx("p",{className:"text-white font-medium",children:t("kProfiles.loadingProfiles")})]}),r.jsxs("div",{className:"flex flex-wrap gap-4 mb-6",children:[r.jsxs("div",{className:"flex-1 min-w-48",children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:t("kProfiles.printer")}),r.jsx("select",{value:a||"",onChange:L=>i(parseInt(L.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.map(L=>r.jsx("option",{value:L.id,children:L.name},L.id))})]}),r.jsxs("div",{className:"w-32",children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:t("kProfiles.nozzle")}),r.jsxs("select",{value:s,onChange:L=>o(L.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:[r.jsx("option",{value:"0.2",children:"0.2mm"}),r.jsx("option",{value:"0.4",children:"0.4mm"}),r.jsx("option",{value:"0.6",children:"0.6mm"}),r.jsx("option",{value:"0.8",children:"0.8mm"})]})]}),r.jsxs("div",{className:"flex items-end gap-2",children:[r.jsxs(Me,{variant:"secondary",onClick:()=>ue(),disabled:de||!n("kprofiles:read"),title:n("kprofiles:read")?void 0:t("kProfiles.permission.noRead"),children:[r.jsx(sr,{className:`w-4 h-4 ${de?"animate-spin":""}`}),t("kProfiles.refresh")]}),r.jsxs(Me,{onClick:()=>u(!0),disabled:!n("kprofiles:create"),title:n("kprofiles:create")?void 0:t("kProfiles.permission.noCreate"),children:[r.jsx(ar,{className:"w-4 h-4"}),t("kProfiles.addProfile")]})]})]}),r.jsxs("div",{className:"flex flex-wrap gap-4 mb-4",children:[r.jsxs("div",{className:"flex-1 min-w-48 relative",children:[r.jsx(Sr,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray"}),r.jsx("input",{type:"text",value:f,onChange:L=>b(L.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"})]}),ie&&r.jsx("div",{className:"w-36",children:r.jsxs("select",{value:w,onChange:L=>g(L.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:[r.jsx("option",{value:"all",children:t("kProfiles.allExtruders")}),r.jsx("option",{value:"left",children:t("kProfiles.leftOnly")}),r.jsx("option",{value:"right",children:t("kProfiles.rightOnly")})]})}),r.jsx("div",{className:"w-32",children:r.jsxs("select",{value:x,onChange:L=>_(L.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:[r.jsx("option",{value:"all",children:t("kProfiles.allFlow")}),r.jsx("option",{value:"hf",children:t("kProfiles.hfOnly")}),r.jsx("option",{value:"s",children:t("kProfiles.sOnly")})]})}),r.jsx("div",{className:"w-32",children:r.jsxs("select",{value:N,onChange:L=>C(L.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:[r.jsx("option",{value:"name",children:t("kProfiles.sortName")}),r.jsx("option",{value:"k_value",children:t("kProfiles.sortKValue")}),r.jsx("option",{value:"filament",children:t("kProfiles.sortFilament")})]})})]}),r.jsxs("div",{className:"flex flex-wrap gap-2 mb-6",children:[r.jsxs(Me,{variant:"secondary",onClick:z,disabled:!re?.profiles?.length||!n("kprofiles:read"),title:n("kprofiles:read")?void 0:t("kProfiles.permission.noExport"),children:[r.jsx(Yr,{className:"w-4 h-4"}),t("kProfiles.export")]}),r.jsxs(Me,{variant:"secondary",onClick:G,disabled:!n("kprofiles:create"),title:n("kprofiles:create")?void 0:t("kProfiles.permission.noImport"),children:[r.jsx(ka,{className:"w-4 h-4"}),t("kProfiles.import")]}),r.jsx("div",{className:"flex-1"}),P?r.jsxs(r.Fragment,{children:[r.jsxs(Me,{variant:"secondary",onClick:Z,children:[r.jsx(bs,{className:"w-4 h-4"}),t("kProfiles.selectAll")]}),r.jsxs(Me,{variant:"secondary",onClick:oe,disabled:A.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:[r.jsx(Jt,{className:"w-4 h-4"}),t("kProfiles.delete")," (",A.size,")"]}),r.jsxs(Me,{variant:"secondary",onClick:()=>{T(!1),F(new Set)},children:[r.jsx(Ht,{className:"w-4 h-4"}),t("common.cancel")]})]}):r.jsxs(Me,{variant:"secondary",onClick:()=>T(!0),disabled:!Y.length||!n("kprofiles:delete"),title:n("kprofiles:delete")?void 0:t("kProfiles.permission.noDelete"),children:[r.jsx(bs,{className:"w-4 h-4"}),t("kProfiles.select")]})]}),J?r.jsx("div",{className:"flex justify-center py-12",children:r.jsx(pt,{className:"w-8 h-8 text-bambu-green animate-spin"})}):$?r.jsx(Ct,{children:r.jsxs(At,{className:"py-12 text-center",children:[r.jsx(mu,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),r.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:t("kProfiles.printerOffline")}),r.jsx("p",{className:"text-bambu-gray mb-4",children:t("kProfiles.printerOfflineDesc")}),r.jsxs(Me,{variant:"secondary",onClick:()=>ue(),children:[r.jsx(sr,{className:"w-4 h-4"}),t("common.refresh")]})]})}):Y.length>0?ie?r.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[r.jsxs("div",{children:[r.jsx("h3",{className:"text-sm font-medium text-bambu-gray mb-2 px-1",children:t("kProfiles.leftExtruder")}),r.jsx("div",{className:"space-y-1",children:Y.filter(L=>L.extruder_id===1).map(L=>r.jsx(lF,{profile:L,onEdit:()=>c(L),onCopy:()=>p(L),selectionMode:P,isSelected:A.has(H(L)),onToggleSelect:()=>K(H(L)),note:q(L)},H(L)))})]}),r.jsxs("div",{children:[r.jsx("h3",{className:"text-sm font-medium text-bambu-gray mb-2 px-1",children:t("kProfiles.rightExtruder")}),r.jsx("div",{className:"space-y-1",children:Y.filter(L=>L.extruder_id===0).map(L=>r.jsx(lF,{profile:L,onEdit:()=>c(L),onCopy:()=>p(L),selectionMode:P,isSelected:A.has(H(L)),onToggleSelect:()=>K(H(L)),note:q(L)},H(L)))})]})]}):r.jsx("div",{className:"space-y-1",children:Y.map(L=>r.jsx(lF,{profile:L,onEdit:()=>c(L),onCopy:()=>p(L),selectionMode:P,isSelected:A.has(H(L)),onToggleSelect:()=>K(H(L)),note:q(L)},H(L)))}):f||w!=="all"||x!=="all"?r.jsx(Ct,{children:r.jsxs(At,{className:"py-12 text-center",children:[r.jsx(Sr,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),r.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:t("kProfiles.noMatchingProfiles")}),r.jsx("p",{className:"text-bambu-gray",children:t("kProfiles.noMatchingProfilesDesc")})]})}):r.jsx(Ct,{children:r.jsxs(At,{className:"py-12 text-center",children:[r.jsx(CS,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),r.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:t("kProfiles.noKProfiles")}),r.jsx("p",{className:"text-bambu-gray mb-4",children:t("kProfiles.noKProfilesDesc",{diameter:s})}),r.jsxs(Me,{onClick:()=>u(!0),children:[r.jsx(ar,{className:"w-4 h-4"}),t("kProfiles.createFirstProfile")]})]})}),l&&a&&(()=>{const{note:L,key:ne}=le(l);return r.jsx(cF,{profile:l,printerId:a,nozzleDiameter:s,existingProfiles:X?.profiles||re?.profiles,builtinFilaments:j,isDualNozzle:ie,initialNote:L,initialNoteKey:ne,onSaveNote:ce,hasPermission:n,onClose:()=>{console.log("[KProfiles] Edit modal onClose - refetching profiles..."),c(null),ue()},onSave:()=>{c(null),ue()}})})(),d&&a&&r.jsx(cF,{printerId:a,nozzleDiameter:s,existingProfiles:X?.profiles||re?.profiles,builtinFilaments:j,isDualNozzle:ie,onSaveNote:ce,hasPermission:n,onClose:()=>{u(!1),ue()},onSave:()=>{u(!1),ue()}}),m&&a&&r.jsx(cF,{printerId:a,nozzleDiameter:s,existingProfiles:X?.profiles||re?.profiles,builtinFilaments:j,isDualNozzle:ie,onSaveNote:ce,hasPermission:n,profile:{...m,slot_id:0,name:`${m.name} (Copy)`},onClose:()=>{p(null),ue()},onSave:()=>{p(null),ue()}}),S&&r.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",children:r.jsx(Ct,{className:"w-full max-w-sm",children:r.jsxs(At,{className:"p-6",children:[r.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[r.jsx("div",{className:"w-10 h-10 rounded-full bg-red-500/20 flex items-center justify-center",children:r.jsx(Jt,{className:"w-5 h-5 text-red-500"})}),r.jsxs("div",{children:[r.jsx("h3",{className:"text-lg font-semibold text-white",children:t("kProfiles.bulkDelete.title")}),r.jsx("p",{className:"text-sm text-bambu-gray",children:t("kProfiles.bulkDelete.cannotUndo")})]})]}),r.jsx("p",{className:"text-bambu-gray mb-6",children:t("kProfiles.bulkDelete.message",{count:A.size})}),r.jsxs("div",{className:"flex gap-3",children:[r.jsx(Me,{variant:"secondary",onClick:()=>E(!1),disabled:U,className:"flex-1",children:t("common.cancel")}),r.jsxs(Me,{onClick:ee,disabled:U,className:"flex-1 bg-red-500 hover:bg-red-600 text-white",children:[U?r.jsx(pt,{className:"w-4 h-4 animate-spin"}):r.jsx(Jt,{className:"w-4 h-4"}),t("common.delete")]})]})]})})})]})}const Mce=["PLA","PETG","PCTG","ABS","ASA","TPU","PC","PA","PVA","HIPS","PP","PET","NYLON"],Pat={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 Tat(t){const e=t.toUpperCase();for(const n of Mce)if(new RegExp(`\\b${n}\\b`).test(e))return n;return null}function Aat(t){const e=t.replace(/@.+$/,"").trim(),n=e.toUpperCase();for(const a of Mce){const i=n.indexOf(a);if(i>0){const s=e.slice(0,i).trim();if(s&&s.length>1)return s}}return null}function dF({preset:t,onDelete:e,onExpand:n,isExpanded:a}){const{t:i}=kt(),{hasPermission:s}=cr(),o=t.filament_type||Tat(t.name),l=t.filament_vendor||Aat(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=Pat[o.toUpperCase()]||null),r.jsx(Ct,{className:"bg-bambu-dark border-bambu-dark-tertiary hover:border-bambu-dark-tertiary/80 transition-colors",children:r.jsxs(At,{className:"p-3",children:[r.jsxs("div",{className:"flex items-start justify-between gap-2",children:[r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[t.preset_type==="filament"&&r.jsx("div",{className:`w-4 h-4 rounded-full border border-black/20 flex-shrink-0 ${!d&&!c?"opacity-25":d?"":"opacity-50"}`,style:{backgroundColor:c?`#${c}`:"#666"}}),r.jsx("span",{className:"text-sm font-medium text-white truncate",children:t.name})]}),r.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[o&&r.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-bambu-green/20 text-bambu-green",children:o}),l&&r.jsx("span",{className:"text-xs text-bambu-gray",children:l}),r.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-blue-500/20 text-blue-400",children:i("profiles.localProfiles.badge")})]})]}),r.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[s("settings:update")&&r.jsx("button",{onClick:()=>e(t.id),className:"p-1 text-bambu-gray hover:text-red-400 transition-colors",title:i("profiles.localProfiles.delete"),children:r.jsx(Jt,{className:"w-3.5 h-3.5"})}),r.jsx("button",{onClick:()=>n(a?null:t.id),className:"p-1 text-bambu-gray hover:text-white transition-colors",children:a?r.jsx(tl,{className:"w-3.5 h-3.5"}):r.jsx(Ln,{className:"w-3.5 h-3.5"})})]})]}),a&&r.jsxs("div",{className:"mt-3 pt-3 border-t border-bambu-dark-tertiary text-xs space-y-1.5",children:[o&&r.jsxs("div",{className:"flex justify-between",children:[r.jsx("span",{className:"text-bambu-gray",children:i("profiles.localProfiles.filamentType")}),r.jsx("span",{className:"text-white",children:o})]}),l&&r.jsxs("div",{className:"flex justify-between",children:[r.jsx("span",{className:"text-bambu-gray",children:i("profiles.localProfiles.vendor")}),r.jsx("span",{className:"text-white",children:l})]}),t.nozzle_temp_min!=null&&t.nozzle_temp_max!=null&&r.jsxs("div",{className:"flex justify-between",children:[r.jsx("span",{className:"text-bambu-gray",children:i("profiles.localProfiles.nozzleTemp")}),r.jsxs("span",{className:"text-white",children:[t.nozzle_temp_min,"–",t.nozzle_temp_max,"°C"]})]}),t.filament_cost&&r.jsxs("div",{className:"flex justify-between",children:[r.jsx("span",{className:"text-bambu-gray",children:i("profiles.localProfiles.cost")}),r.jsx("span",{className:"text-white",children:t.filament_cost})]}),t.filament_density&&r.jsxs("div",{className:"flex justify-between",children:[r.jsx("span",{className:"text-bambu-gray",children:i("profiles.localProfiles.density")}),r.jsxs("span",{className:"text-white",children:[t.filament_density," g/cm³"]})]}),t.pressure_advance&&r.jsxs("div",{className:"flex justify-between",children:[r.jsx("span",{className:"text-bambu-gray",children:i("profiles.localProfiles.pressureAdvance")}),r.jsx("span",{className:"text-white",children:t.pressure_advance})]}),t.compatible_printers&&r.jsxs("div",{className:"flex justify-between",children:[r.jsx("span",{className:"text-bambu-gray",children:i("profiles.localProfiles.compatiblePrinters")}),r.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&&r.jsxs("div",{className:"flex justify-between",children:[r.jsx("span",{className:"text-bambu-gray",children:i("profiles.localProfiles.inheritsFrom")}),r.jsx("span",{className:"text-white truncate ml-2",children:t.inherits})]}),r.jsxs("div",{className:"flex justify-between",children:[r.jsx("span",{className:"text-bambu-gray",children:i("profiles.localProfiles.source")}),r.jsx("span",{className:"text-white capitalize",children:t.source})]})]})]})})}function jat(){const{t}=kt(),{hasPermission:e}=cr(),n=en(),{showToast:a}=rn(),[i,s]=y.useState(""),[o,l]=y.useState(null),[c,d]=y.useState(!1),[u,m]=y.useState(null),{data:p,isLoading:f}=Ve({queryKey:["localPresets"],queryFn:()=>se.getLocalPresets()}),b=it({mutationFn:async A=>{const F=[];for(const S of Array.from(A)){const E=new FormData;E.append("file",S),F.push(await se.importLocalPresets(E))}return F},onSuccess:A=>{n.invalidateQueries({queryKey:["localPresets"]});let F=0,S=0,E=0;for(const U of A)F+=U.imported,S+=U.skipped,E+=U.errors.length;F>0&&a(t("profiles.localProfiles.toast.importSuccess",{count:F})),S>0&&a(t("profiles.localProfiles.toast.importSkipped",{count:S}),"warning"),E>0&&a(t("profiles.localProfiles.toast.importError",{count:E}),"error")},onError:A=>{a(A.message,"error")}}),w=it({mutationFn:A=>se.deleteLocalPreset(A),onSuccess:()=>{n.invalidateQueries({queryKey:["localPresets"]}),m(null),a(t("profiles.localProfiles.toast.deleted"))}}),g=y.useCallback(A=>{!A||A.length===0||b.mutate(A)},[b]),x=y.useCallback(A=>{A.preventDefault(),d(!1),g(A.dataTransfer.files)},[g]),_=y.useCallback(A=>{if(!i)return A;const F=i.toLowerCase();return A.filter(S=>S.name.toLowerCase().includes(F)||S.filament_type?.toLowerCase().includes(F)||S.filament_vendor?.toLowerCase().includes(F))},[i]),N=y.useMemo(()=>_(p?.filament||[]),[p?.filament,_]),C=y.useMemo(()=>_(p?.printer||[]),[p?.printer,_]),P=y.useMemo(()=>_(p?.process||[]),[p?.process,_]),T=N.length+C.length+P.length;return f?r.jsx("div",{className:"flex items-center justify-center py-16",children:r.jsx(pt,{className:"w-8 h-8 text-bambu-green animate-spin"})}):r.jsxs("div",{className:"space-y-6",children:[e("settings:update")&&r.jsxs("div",{onDragOver:A=>{A.preventDefault(),d(!0)},onDragLeave:()=>d(!1),onDrop:x,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:[r.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:A=>g(A.target.files)}),b.isPending?r.jsxs("div",{className:"flex items-center justify-center gap-2",children:[r.jsx(pt,{className:"w-5 h-5 text-bambu-green animate-spin"}),r.jsx("span",{className:"text-bambu-gray",children:t("profiles.localProfiles.importing")})]}):r.jsxs(r.Fragment,{children:[r.jsx(ka,{className:"w-8 h-8 text-bambu-gray mx-auto mb-2"}),r.jsx("p",{className:"text-sm text-white font-medium",children:t("profiles.localProfiles.import")}),r.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:t("profiles.localProfiles.importDesc")})]})]}),T>0&&r.jsxs("div",{className:"relative",children:[r.jsx(Sr,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray"}),r.jsx("input",{type:"text",value:i,onChange:A=>s(A.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"})]}),T===0&&!f&&r.jsxs("div",{className:"text-center py-12",children:[r.jsx(ob,{className:"w-12 h-12 text-bambu-gray mx-auto mb-3 opacity-50"}),r.jsx("p",{className:"text-bambu-gray",children:t("profiles.localProfiles.noPresets")}),r.jsx("p",{className:"text-xs text-bambu-gray/60 mt-1",children:t("profiles.localProfiles.importDesc")})]}),T>0&&r.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6",children:[N.length>0&&r.jsxs("div",{children:[r.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[r.jsx(ST,{className:"w-4 h-4 text-bambu-green"}),r.jsx("h3",{className:"text-sm font-medium text-white",children:t("profiles.localProfiles.filament")}),r.jsxs("span",{className:"text-xs text-bambu-gray",children:["(",N.length,")"]})]}),r.jsx("div",{className:"space-y-2",children:N.map(A=>r.jsx(dF,{preset:A,onDelete:F=>m(F),onExpand:l,isExpanded:o===A.id},A.id))})]}),P.length>0&&r.jsxs("div",{children:[r.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[r.jsx(oa,{className:"w-4 h-4 text-blue-400"}),r.jsx("h3",{className:"text-sm font-medium text-white",children:t("profiles.localProfiles.process")}),r.jsxs("span",{className:"text-xs text-bambu-gray",children:["(",P.length,")"]})]}),r.jsx("div",{className:"space-y-2",children:P.map(A=>r.jsx(dF,{preset:A,onDelete:F=>m(F),onExpand:l,isExpanded:o===A.id},A.id))})]}),C.length>0&&r.jsxs("div",{children:[r.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[r.jsx(uu,{className:"w-4 h-4 text-orange-400"}),r.jsx("h3",{className:"text-sm font-medium text-white",children:t("profiles.localProfiles.printer")}),r.jsxs("span",{className:"text-xs text-bambu-gray",children:["(",C.length,")"]})]}),r.jsx("div",{className:"space-y-2",children:C.map(A=>r.jsx(dF,{preset:A,onDelete:F=>m(F),onExpand:l,isExpanded:o===A.id},A.id))})]})]}),u!==null&&r.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50",children:r.jsxs("div",{className:"bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg p-6 max-w-sm mx-4",children:[r.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[r.jsx($a,{className:"w-5 h-5 text-red-400"}),r.jsx("h3",{className:"text-white font-medium",children:t("profiles.localProfiles.deleteConfirmTitle")})]}),r.jsx("p",{className:"text-sm text-bambu-gray mb-4",children:t("profiles.localProfiles.deleteConfirm")}),r.jsxs("div",{className:"flex justify-end gap-2",children:[r.jsx(Me,{variant:"secondary",size:"sm",onClick:()=>m(null),children:t("profiles.localProfiles.cancel")}),r.jsxs(Me,{variant:"danger",size:"sm",onClick:()=>w.mutate(u),disabled:w.isPending,children:[w.isPending?r.jsx(pt,{className:"w-4 h-4 animate-spin"}):r.jsx(Jt,{className:"w-4 h-4"}),t("profiles.localProfiles.delete")]})]})]})})]})}function aU(t,e){const n=`${t} ${e||""}`,a=n.match(/@?\s*(?:BBL\s+)?(?:Bambu\s+Lab\s+)?([XPAH][1-9][A-Z]?(?:\s*(?:Carbon|mini))?|H2D)/i),i=a?a[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:i,nozzle:o,layerHeight:c,filamentType:u}}function vS(t){return/^(P[FPM]US|PF\d|PP\d)/.test(t)}function Mat({onSuccess:t,t:e}){const{showToast:n}=rn(),[a,i]=y.useState("email"),[s,o]=y.useState(""),[l,c]=y.useState(""),[d,u]=y.useState(""),[m,p]=y.useState(""),[f,b]=y.useState("global"),[w,g]=y.useState(null),[x,_]=y.useState(null),N=it({mutationFn:()=>se.cloudLogin(s,l,f),onSuccess:F=>{F.success?(n(e("profiles.login.toast.loggedIn")),t()):F.needs_verification?(g(F.verification_type||"email"),_(F.tfa_key||null),F.verification_type==="totp"?n(e("profiles.login.toast.enterTotp")):n(e("profiles.login.toast.codeSent")),i("code")):n(F.message,"error")},onError:F=>n(F.message,"error")}),C=it({mutationFn:()=>se.cloudVerify(s,d,x||void 0,f),onSuccess:F=>{F.success?(n(e("profiles.login.toast.loggedIn")),t()):n(F.message,"error")},onError:F=>n(F.message,"error")}),P=it({mutationFn:()=>se.cloudSetToken(m,f),onSuccess:()=>{n(e("profiles.login.toast.tokenSet")),t()},onError:F=>n(F.message,"error")}),T=F=>{F.preventDefault(),a==="email"?N.mutate():a==="code"?C.mutate():a==="token"&&P.mutate()},A=N.isPending||C.isPending||P.isPending;return r.jsx(Ct,{className:"max-w-md mx-auto",children:r.jsxs(At,{children:[r.jsxs("div",{className:"text-center mb-6",children:[r.jsx("div",{className:"inline-flex items-center justify-center w-12 h-12 rounded-xl bg-bambu-green/20 mb-3",children:r.jsx(Hh,{className:"w-6 h-6 text-bambu-green"})}),r.jsx("h2",{className:"text-xl font-semibold text-white",children:e("profiles.login.title")}),r.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:e("profiles.login.subtitle")})]}),r.jsxs("form",{onSubmit:T,className:"space-y-4",children:[a==="email"&&r.jsxs(r.Fragment,{children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:e("profiles.login.email")}),r.jsx("input",{type:"email",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 placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none",placeholder:"your@email.com",required:!0})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:e("profiles.login.password")}),r.jsx("input",{type:"password",value:l,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 placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none",placeholder:"••••••••",required:!0})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:e("profiles.login.region")}),r.jsxs("select",{value:f,onChange:F=>b(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:[r.jsx("option",{value:"global",children:e("profiles.login.regionGlobal")}),r.jsx("option",{value:"china",children:e("profiles.login.regionChina")})]})]})]}),a==="code"&&r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:e(w==="totp"?"profiles.login.totpCode":"profiles.login.verificationCode")}),r.jsx("p",{className:"text-xs text-bambu-gray mb-2",children:w==="totp"?e("profiles.login.enterTotpHint"):e("profiles.login.checkEmail",{email:s})}),r.jsx("input",{type:"text",value:d,onChange:F=>u(F.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})]}),a==="token"&&r.jsxs(r.Fragment,{children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:e("profiles.login.accessToken")}),r.jsx("p",{className:"text-xs text-bambu-gray mb-2",children:e("profiles.login.accessTokenHint")}),r.jsx("textarea",{value:m,onChange:F=>p(F.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})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:e("profiles.login.region")}),r.jsxs("select",{value:f,onChange:F=>b(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:[r.jsx("option",{value:"global",children:e("profiles.login.regionGlobal")}),r.jsx("option",{value:"china",children:e("profiles.login.regionChina")})]})]})]}),r.jsxs("div",{className:"flex gap-2 max-[550px]:flex-wrap max-[550px]:items-center",children:[a==="code"&&r.jsx(Me,{type:"button",variant:"secondary",onClick:()=>i("email"),className:"flex-1",children:e("profiles.login.back")}),r.jsxs(Me,{type:"submit",disabled:A,className:"flex-1",children:[A?r.jsx(pt,{className:"w-4 h-4 animate-spin"}):r.jsx(Y0,{className:"w-4 h-4"}),e(a==="email"?"profiles.login.loginButton":a==="code"?"profiles.login.verifyButton":"profiles.login.setTokenButton")]})]}),a==="email"&&r.jsx("div",{className:"pt-4 border-t border-bambu-dark-tertiary",children:r.jsxs("button",{type:"button",onClick:()=>i("token"),className:"text-sm text-bambu-gray hover:text-white flex items-center gap-2 transition-colors",children:[r.jsx(vo,{className:"w-4 h-4"}),e("profiles.login.useToken")]})}),a==="token"&&r.jsx("div",{className:"pt-4 border-t border-bambu-dark-tertiary",children:r.jsxs("button",{type:"button",onClick:()=>i("email"),className:"text-sm text-bambu-gray hover:text-white flex items-center gap-2 transition-colors",children:[r.jsx(Y0,{className:"w-4 h-4"}),e("profiles.login.useEmail")]})})]})]})})}function Lx({label:t,value:e,options:n,onChange:a}){const[i,s]=y.useState(!1),o=n.find(l=>l.value===e);return r.jsxs("div",{className:"relative",children:[r.jsxs("button",{onClick:()=>s(!i),className:"flex items-center gap-2 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-sm text-white hover:border-bambu-gray-dark transition-colors",children:[r.jsxs("span",{className:"text-bambu-gray",children:[t,":"]}),r.jsx("span",{children:o?.label||"All"}),r.jsx(Ln,{className:`w-4 h-4 text-bambu-gray transition-transform ${i?"rotate-180":""}`})]}),i&&r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"fixed inset-0 z-10",onClick:()=>s(!1)}),r.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=>r.jsxs("button",{onClick:()=>{a(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:[r.jsx("span",{children:l.label}),l.count!==void 0&&r.jsx("span",{className:"text-bambu-gray text-xs",children:l.count})]},l.value))})]})]})}function Eat(){const[t,e]=y.useState(!1);y.useEffect(()=>{const a=()=>{e(window.scrollY>300)};return window.addEventListener("scroll",a),()=>window.removeEventListener("scroll",a)},[]);const n=()=>{window.scrollTo({top:0,behavior:"smooth"})};return t?r.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:r.jsx(Hm,{className:"w-5 h-5"})}):null}function uF({setting:t,onClick:e,onDuplicate:n,compareMode:a,isCompareSelected:i,compareIndex:s,compareDisabled:o,t:l}){const c=aU(t.name),d=vS(t.setting_id);return r.jsxs("div",{className:"flex items-center gap-2 group",children:[r.jsx("button",{onClick:e,disabled:o,className:`flex-1 text-left px-3 py-2 rounded transition-colors ${i?"bg-blue-500/20 border border-blue-500/50":o?"bg-bambu-dark/50 opacity-40 cursor-not-allowed":"bg-bambu-dark hover:bg-bambu-dark-tertiary"} ${a&&!o?"cursor-pointer":""}`,children:r.jsxs("div",{className:"flex items-center gap-2",children:[i&&s!==void 0&&r.jsx("span",{className:"flex-shrink-0 w-5 h-5 rounded-full bg-blue-500 text-white text-xs flex items-center justify-center font-medium",children:s+1}),!i&&d&&r.jsx("span",{className:"flex-shrink-0 w-1.5 h-1.5 rounded-full bg-bambu-green",title:l("profiles.presets.myPreset")}),r.jsx("span",{className:"text-white text-sm truncate flex-1",title:t.name,children:t.name}),c.filamentType&&t.type==="filament"&&r.jsx("span",{className:"text-xs text-bambu-gray whitespace-nowrap",children:c.filamentType}),c.layerHeight&&t.type==="process"&&r.jsx("span",{className:"text-xs text-bambu-gray whitespace-nowrap",children:c.layerHeight}),c.printer&&r.jsx("span",{className:"text-xs text-bambu-gray whitespace-nowrap",children:c.printer})]})}),r.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:r.jsx(Mi,{className:"w-4 h-4"})})]})}function KI(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(` +`)),i(!0),setTimeout(()=>i(!1),2e3)};return r.jsxs("div",{className:"space-y-4",children:[r.jsx("div",{className:"bg-amber-500/10 border border-amber-500/30 rounded-lg p-4",children:r.jsx("p",{className:"text-amber-400 text-sm font-medium",children:n("settings.twoFa.backupCodesWarning")})}),r.jsx("div",{className:"grid grid-cols-2 gap-2",children:t.map((o,l)=>r.jsx("code",{className:"bg-bambu-dark-secondary rounded px-3 py-2 text-center font-mono text-sm text-white tracking-widest",children:o},l))}),r.jsxs("div",{className:"flex gap-3",children:[r.jsxs(Me,{variant:"secondary",size:"sm",onClick:s,className:"flex items-center gap-2",children:[r.jsx(Mi,{className:"w-4 h-4"}),n(a?"common.copied":"common.copy")]}),r.jsx(Me,{variant:"primary",size:"sm",onClick:e,className:"flex-1",children:n("settings.twoFa.savedCodes")})]})]})}function uat({onDone:t}){const{t:e}=kt(),n=en(),{showToast:a}=rn(),[i,s]=y.useState("qr"),[o,l]=y.useState(""),[c,d]=y.useState([]),[u,m]=y.useState(!1),{data:p,isLoading:f}=Ve({queryKey:["totp-setup"],queryFn:()=>se.setupTOTP(),staleTime:1/0}),b=it({mutationFn:w=>se.enableTOTP(w),onSuccess:w=>{d(w.backup_codes),s("backup"),n.invalidateQueries({queryKey:["2fa-status"]})},onError:()=>a(e("settings.twoFa.invalidCode"),"error")});return f||!p?r.jsx("div",{className:"flex items-center justify-center py-8",children:r.jsx(sr,{className:"w-6 h-6 animate-spin text-bambu-green"})}):i==="qr"?r.jsxs("div",{className:"space-y-4",children:[r.jsx("p",{className:"text-bambu-gray-light text-sm",children:e("settings.twoFa.setupInstructions")}),r.jsx("div",{className:"flex justify-center",children:r.jsx("img",{src:`data:image/png;base64,${p.qr_code_b64}`,alt:"TOTP QR Code",className:"w-48 h-48 rounded-lg"})}),r.jsxs("div",{children:[r.jsx("p",{className:"text-xs text-bambu-gray mb-1",children:e("settings.twoFa.manualEntry")}),r.jsxs("div",{className:"flex items-center gap-2 bg-bambu-dark-secondary rounded-lg px-3 py-2",children:[r.jsx("code",{className:"text-white text-xs font-mono flex-1 break-all",children:u?p.secret:"••••••••••••••••"}),r.jsx("button",{onClick:()=>m(!u),className:"text-bambu-gray hover:text-white",children:u?r.jsx(sb,{className:"w-4 h-4"}):r.jsx(Dl,{className:"w-4 h-4"})}),r.jsx("button",{onClick:()=>{navigator.clipboard.writeText(p.secret)},className:"text-bambu-gray hover:text-white",children:r.jsx(Mi,{className:"w-4 h-4"})})]})]}),r.jsx(Me,{variant:"primary",className:"w-full",onClick:()=>s("confirm"),children:e("settings.twoFa.scannedContinue")})]}):i==="confirm"?r.jsxs("div",{className:"space-y-4",children:[r.jsx("p",{className:"text-bambu-gray-light text-sm",children:e("settings.twoFa.enterCodeToConfirm")}),r.jsx(BN,{value:o,onChange:l,placeholder:"000000"}),r.jsxs("div",{className:"flex gap-3",children:[r.jsx(Me,{variant:"secondary",onClick:()=>s("qr"),className:"flex-1",children:e("common.back")}),r.jsx(Me,{variant:"primary",className:"flex-1",disabled:o.length!==6||b.isPending,onClick:()=>b.mutate(o),children:b.isPending?e("common.saving"):e("settings.twoFa.activate")})]})]}):r.jsxs("div",{className:"space-y-4",children:[r.jsx("h3",{className:"text-white font-medium",children:e("settings.twoFa.backupCodesTitle")}),r.jsx(Pce,{codes:c,onDone:t})]})}function mat(){const{t}=kt(),e=en(),{showToast:n}=rn(),{user:a}=cr(),[i,s]=y.useState(!1),[o,l]=y.useState(!1),[c,d]=y.useState(!1),[u,m]=y.useState(""),[p,f]=y.useState(""),[b,w]=y.useState(null),[g,x]=y.useState(null),[_,N]=y.useState(""),[C,P]=y.useState(!1),[T,A]=y.useState(""),[F,S]=y.useState(!1),{data:E,isLoading:U}=Ve({queryKey:["2fa-status"],queryFn:()=>se.get2FAStatus()}),{data:I}=Ve({queryKey:["oidc-links"],queryFn:()=>se.getOIDCLinks()}),H=it({mutationFn:()=>se.enableEmailOTP(),onSuccess:ue=>{x(ue.setup_token),n(ue.message,"success")},onError:ue=>{const X=ue.message??"";X.toLowerCase().includes("smtp")?n(t("settings.twoFa.smtpRequired"),"error"):n(X,"error")}}),R=it({mutationFn:()=>se.confirmEnableEmailOTP(g,_),onSuccess:()=>{e.invalidateQueries({queryKey:["2fa-status"]}),x(null),N(""),n(t("settings.twoFa.emailOtpEnabled"),"success")},onError:ue=>n(ue.message,"error")}),Q=it({mutationFn:ue=>se.disableEmailOTP(ue),onSuccess:()=>{e.invalidateQueries({queryKey:["2fa-status"]}),P(!1),A(""),n(t("settings.twoFa.emailOtpDisabled"),"success")},onError:ue=>n(ue.message,"error")}),re=it({mutationFn:ue=>se.disableTOTP(ue),onSuccess:()=>{e.invalidateQueries({queryKey:["2fa-status"]}),l(!1),m(""),n(t("settings.twoFa.totpDisabled"),"success")},onError:()=>n(t("settings.twoFa.invalidCode"),"error")}),J=it({mutationFn:ue=>se.regenerateBackupCodes(ue),onSuccess:ue=>{e.invalidateQueries({queryKey:["2fa-status"]}),d(!1),f(""),w(ue.backup_codes)},onError:()=>n(t("settings.twoFa.invalidCode"),"error")}),de=it({mutationFn:ue=>se.deleteOIDCLink(ue),onSuccess:()=>{e.invalidateQueries({queryKey:["oidc-links"]}),n(t("settings.twoFa.oidcUnlinked"),"success")},onError:ue=>n(ue.message,"error")});if(U)return r.jsx("div",{className:"flex items-center justify-center py-12",children:r.jsx(sr,{className:"w-6 h-6 animate-spin text-bambu-green"})});const pe=!!a?.email;return r.jsxs("div",{className:"space-y-6",children:[r.jsxs(Ct,{id:"card-2fa-totp",children:[r.jsx(pn,{children:r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx("div",{className:`w-10 h-10 rounded-full flex items-center justify-center ${E?.totp_enabled?"bg-green-500/20":"bg-gray-500/20"}`,children:r.jsx(GF,{className:`w-5 h-5 ${E?.totp_enabled?"text-green-400":"text-gray-400"}`})}),r.jsxs("div",{children:[r.jsx("h3",{className:"text-white font-semibold",children:t("settings.twoFa.totpTitle")}),r.jsx("p",{className:"text-bambu-gray text-sm",children:t("settings.twoFa.totpDesc")})]}),r.jsx("div",{className:"ml-auto",children:E?.totp_enabled?r.jsxs("span",{className:"flex items-center gap-1 text-green-400 text-sm font-medium",children:[r.jsx(Ew,{className:"w-4 h-4"})," ",t("common.enabled")]}):r.jsxs("span",{className:"flex items-center gap-1 text-bambu-gray text-sm",children:[r.jsx(VF,{className:"w-4 h-4"})," ",t("common.disabled")]})})]})}),r.jsx(At,{children:i?r.jsxs("div",{className:"space-y-4",children:[r.jsxs("div",{className:"flex items-center justify-between mb-2",children:[r.jsx("h4",{className:"text-white font-medium",children:t("settings.twoFa.setupAuthApp")}),r.jsx("button",{onClick:()=>{s(!1),e.removeQueries({queryKey:["totp-setup"]})},className:"text-bambu-gray hover:text-white",children:r.jsx(Ht,{className:"w-5 h-5"})})]}),r.jsx(uat,{onDone:()=>{s(!1),e.removeQueries({queryKey:["totp-setup"]})}})]}):o?r.jsxs("div",{className:"space-y-4",children:[r.jsx("p",{className:"text-bambu-gray-light text-sm",children:t("settings.twoFa.disableConfirmHint")}),r.jsx(BN,{value:u,onChange:m,placeholder:"000000 or XXXXXXXX",maxLength:8}),r.jsxs("div",{className:"flex gap-3",children:[r.jsx(Me,{variant:"secondary",onClick:()=>{l(!1),m("")},className:"flex-1",children:t("common.cancel")}),r.jsx(Me,{variant:"danger",className:"flex-1",disabled:u.length<6||re.isPending,onClick:()=>re.mutate(u),children:re.isPending?t("common.saving"):t("settings.twoFa.disableTotp")})]})]}):c?r.jsxs("div",{className:"space-y-4",children:[r.jsx("p",{className:"text-bambu-gray-light text-sm",children:t("settings.twoFa.regenBackupHint")}),r.jsx(BN,{value:p,onChange:f,placeholder:"000000 or XXXXXXXX",maxLength:8}),r.jsxs("div",{className:"flex gap-3",children:[r.jsx(Me,{variant:"secondary",onClick:()=>{d(!1),f("")},className:"flex-1",children:t("common.cancel")}),r.jsx(Me,{variant:"primary",className:"flex-1",disabled:p.length<6||J.isPending,onClick:()=>J.mutate(p),children:J.isPending?t("common.saving"):t("settings.twoFa.regenBackup")})]})]}):b?r.jsxs("div",{className:"space-y-4",children:[r.jsx("h4",{className:"text-white font-medium",children:t("settings.twoFa.newBackupCodes")}),r.jsx(Pce,{codes:b,onDone:()=>w(null)})]}):r.jsx("div",{className:"space-y-3",children:E?.totp_enabled?r.jsxs("div",{className:"flex flex-wrap gap-3",children:[r.jsxs("div",{className:"flex items-center gap-2 text-sm text-bambu-gray-light",children:[r.jsx(vo,{className:"w-4 h-4"}),t("settings.twoFa.backupCodesRemaining",{count:E.backup_codes_remaining})]}),r.jsxs(Me,{variant:"secondary",size:"sm",onClick:()=>d(!0),className:"flex items-center gap-2",children:[r.jsx(sr,{className:"w-4 h-4"}),t("settings.twoFa.regenBackup")]}),r.jsxs(Me,{variant:"danger",size:"sm",onClick:()=>l(!0),className:"flex items-center gap-2",children:[r.jsx(Jt,{className:"w-4 h-4"}),t("settings.twoFa.disableTotp")]})]}):r.jsxs(Me,{variant:"primary",onClick:()=>s(!0),className:"flex items-center gap-2",children:[r.jsx(GF,{className:"w-4 h-4"}),t("settings.twoFa.setupTotp")]})})})]}),r.jsxs(Ct,{id:"card-2fa-emailotp",children:[r.jsx(pn,{children:r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx("div",{className:`w-10 h-10 rounded-full flex items-center justify-center ${E?.email_otp_enabled?"bg-green-500/20":"bg-gray-500/20"}`,children:r.jsx(qm,{className:`w-5 h-5 ${E?.email_otp_enabled?"text-green-400":"text-gray-400"}`})}),r.jsxs("div",{className:"flex-1",children:[r.jsx("h3",{className:"text-white font-semibold",children:t("settings.twoFa.emailOtpTitle")}),r.jsx("p",{className:"text-bambu-gray text-sm",children:pe?t("settings.twoFa.emailOtpDesc",{email:a?.email}):t("settings.twoFa.emailOtpNoEmail")})]}),r.jsx("div",{className:"ml-auto",children:E?.email_otp_enabled?r.jsxs("span",{className:"flex items-center gap-1 text-green-400 text-sm font-medium",children:[r.jsx(Ew,{className:"w-4 h-4"})," ",t("common.enabled")]}):r.jsxs("span",{className:"flex items-center gap-1 text-bambu-gray text-sm",children:[r.jsx(VF,{className:"w-4 h-4"})," ",t("common.disabled")]})})]})}),r.jsx(At,{children:pe?g?r.jsxs("div",{className:"space-y-4",children:[r.jsx("p",{className:"text-bambu-gray-light text-sm",children:t("settings.twoFa.emailSetupEnterCode")}),r.jsx(BN,{value:_,onChange:N,placeholder:"000000"}),r.jsxs("div",{className:"flex gap-3",children:[r.jsx(Me,{variant:"secondary",onClick:()=>{x(null),N("")},className:"flex-1",children:t("common.cancel")}),r.jsx(Me,{variant:"primary",className:"flex-1",disabled:_.length!==6||R.isPending,onClick:()=>R.mutate(),children:R.isPending?t("common.saving"):t("settings.twoFa.verifyAndEnable")})]})]}):C?r.jsxs("div",{className:"space-y-4",children:[r.jsx("p",{className:"text-bambu-gray-light text-sm",children:t("settings.twoFa.emailDisablePasswordHint")}),r.jsxs("div",{className:"relative",children:[r.jsx("input",{type:F?"text":"password",value:T,onChange:ue=>A(ue.target.value),placeholder:t("settings.twoFa.passwordPlaceholder"),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"}),r.jsx("button",{type:"button",onClick:()=>S(!F),className:"absolute right-3 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white",children:F?r.jsx(sb,{className:"w-5 h-5"}):r.jsx(Dl,{className:"w-5 h-5"})})]}),r.jsxs("div",{className:"flex gap-3",children:[r.jsx(Me,{variant:"secondary",onClick:()=>{P(!1),A("")},className:"flex-1",children:t("common.cancel")}),r.jsx(Me,{variant:"danger",className:"flex-1",disabled:!T||Q.isPending,onClick:()=>Q.mutate(T),children:Q.isPending?t("common.saving"):t("settings.twoFa.disableEmailOtp")})]})]}):r.jsx("div",{className:"flex gap-3",children:E?.email_otp_enabled?r.jsxs(Me,{variant:"danger",size:"sm",onClick:()=>P(!0),className:"flex items-center gap-2",children:[r.jsx(Jt,{className:"w-4 h-4"}),t("settings.twoFa.disableEmailOtp")]}):r.jsxs(Me,{variant:"primary",disabled:!pe||H.isPending,onClick:()=>H.mutate(),className:"flex items-center gap-2",children:[r.jsx(qm,{className:"w-4 h-4"}),H.isPending?t("common.saving"):t("settings.twoFa.enableEmailOtp")]})}):r.jsx("p",{className:"text-amber-400 text-sm",children:t("settings.twoFa.addEmailFirst")})})]}),I&&I.length>0&&r.jsxs(Ct,{id:"card-2fa-linked",children:[r.jsxs(pn,{children:[r.jsx("h3",{className:"text-white font-semibold",children:t("settings.twoFa.linkedAccounts")}),r.jsx("p",{className:"text-bambu-gray text-sm",children:t("settings.twoFa.linkedAccountsDesc")})]}),r.jsx(At,{children:r.jsx("div",{className:"space-y-3",children:I.map(ue=>r.jsxs("div",{className:"flex items-center justify-between py-2 border-b border-bambu-dark-tertiary last:border-0",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-white text-sm font-medium",children:ue.provider_name}),ue.provider_email&&r.jsx("p",{className:"text-bambu-gray text-xs",children:ue.provider_email})]}),r.jsx(Me,{variant:"danger",size:"sm",onClick:()=>de.mutate(ue.provider_id),disabled:de.isPending,children:r.jsx(Jt,{className:"w-4 h-4"})})]},ue.id))})})]})]})}const pat={name:"",issuer_url:"",client_id:"",client_secret:"",scopes:"openid email profile",is_enabled:!0,auto_create_users:!1,auto_link_existing_accounts:!1,email_claim:"email",require_email_verified:!0,icon_url:void 0,default_group_id:null};function cQ({initial:t,isEdit:e=!1,groups:n=[],onSave:a,onCancel:i,isPending:s}){const{t:o}=kt(),[l,c]=y.useState(t),[d,u]=y.useState(!1),m=(_,N)=>c(C=>({...C,[_]:N})),p="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 text-sm",f="block text-sm font-medium text-white mb-1",b=()=>{const _={...l};e&&!d&&delete _.client_secret,a(_)},w=l.auto_link_existing_accounts===!0,g=l.require_email_verified??!0;let x;return w?x=o("settings.oidc.form.requireEmailVerifiedAutoLink"):g?x=o("settings.oidc.form.requireEmailVerifiedDesc"):x=r.jsx("span",{className:"text-red-400",children:o("settings.oidc.form.requireEmailVerifiedWarning")}),r.jsxs("div",{className:"space-y-4",children:[r.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[r.jsxs("div",{children:[r.jsxs("label",{className:f,children:[o("settings.oidc.form.name")," ",r.jsx("span",{className:"text-red-400",children:"*"})]}),r.jsx("input",{className:p,value:l.name,onChange:_=>m("name",_.target.value),placeholder:"Google"})]}),r.jsxs("div",{children:[r.jsxs("label",{className:f,children:[o("settings.oidc.form.issuerUrl")," ",r.jsx("span",{className:"text-red-400",children:"*"})]}),r.jsx("input",{className:p,value:l.issuer_url,onChange:_=>m("issuer_url",_.target.value),placeholder:"https://accounts.google.com"})]}),r.jsxs("div",{children:[r.jsxs("label",{className:f,children:[o("settings.oidc.form.clientId")," ",r.jsx("span",{className:"text-red-400",children:"*"})]}),r.jsx("input",{className:p,value:l.client_id,onChange:_=>m("client_id",_.target.value),placeholder:"your-client-id"})]}),r.jsxs("div",{children:[r.jsxs("label",{className:f,children:[o("settings.oidc.form.clientSecret"),!e&&r.jsx("span",{className:"text-red-400",children:" *"}),e&&r.jsxs("span",{className:"text-bambu-gray text-xs ml-1",children:["(",o("settings.oidc.form.secretHint"),")"]})]}),r.jsx("input",{className:p,type:"password",value:d?l.client_secret:"",placeholder:e&&!d?"••••••••":o("settings.oidc.form.secretPlaceholder"),onChange:_=>{u(!0),m("client_secret",_.target.value)}})]}),r.jsxs("div",{children:[r.jsx("label",{className:f,children:o("settings.oidc.form.scopes")}),r.jsx("input",{className:p,value:l.scopes,onChange:_=>m("scopes",_.target.value),placeholder:"openid email profile"})]}),r.jsxs("div",{children:[r.jsx("label",{className:f,children:o("settings.oidc.form.iconUrl")}),r.jsx("input",{className:p,value:l.icon_url??"",onChange:_=>m("icon_url",_.target.value||void 0),placeholder:"https://..."})]})]}),r.jsxs("div",{className:"flex flex-wrap gap-6 pt-2",children:[r.jsxs("label",{className:"flex items-center gap-3 cursor-pointer",children:[r.jsx(En,{checked:l.is_enabled??!0,onChange:_=>m("is_enabled",_)}),r.jsx("span",{className:"text-white text-sm",children:o("settings.oidc.form.enabled")})]}),r.jsxs("label",{className:"flex items-center gap-3 cursor-pointer",children:[r.jsx(En,{checked:l.auto_create_users??!1,onChange:_=>m("auto_create_users",_)}),r.jsxs("div",{children:[r.jsx("p",{className:"text-white text-sm",children:o("settings.oidc.form.autoCreate")}),r.jsx("p",{className:"text-bambu-gray text-xs",children:o("settings.oidc.form.autoCreateDesc")})]})]}),r.jsxs("label",{className:"flex items-center gap-3 cursor-pointer w-full",children:[r.jsx(En,{checked:l.auto_link_existing_accounts??!1,onChange:_=>m("auto_link_existing_accounts",_)}),r.jsxs("div",{children:[r.jsx("p",{className:"text-white text-sm",children:o("settings.oidc.form.autoLink")}),r.jsx("p",{className:"text-bambu-gray text-xs",children:o("settings.oidc.form.autoLinkDesc")})]})]}),r.jsxs("label",{className:"flex items-center gap-3 cursor-pointer w-full",children:[r.jsx(En,{checked:g,onChange:_=>m("require_email_verified",_),disabled:w}),r.jsxs("div",{children:[r.jsx("p",{className:"text-white text-sm",children:o("settings.oidc.form.requireEmailVerified")}),r.jsx("p",{className:"text-bambu-gray text-xs",children:x})]})]})]}),r.jsxs("div",{children:[r.jsx("label",{className:f,children:o("settings.oidc.form.emailClaim")}),r.jsx("input",{className:p,value:l.email_claim,onChange:_=>m("email_claim",_.target.value||"email"),placeholder:o("settings.oidc.form.emailClaimPlaceholder")}),r.jsx("p",{className:"text-bambu-gray text-xs mt-1",children:o("settings.oidc.form.emailClaimDesc")}),w&&l.email_claim!=="email"&&r.jsx("p",{className:"text-yellow-400 text-xs mt-1",children:o("settings.oidc.form.emailClaimCustomClaimAutoLinkWarning")})]}),r.jsxs("div",{children:[r.jsx("label",{className:f,children:o("settings.oidc.form.defaultGroup")}),r.jsxs("select",{className:p,value:l.default_group_id??"",onChange:_=>m("default_group_id",_.target.value?Number(_.target.value):null),children:[r.jsx("option",{value:"",children:o("settings.oidc.form.defaultGroupViewersFallback")}),n.map(_=>r.jsx("option",{value:_.id,children:_.name},_.id))]}),r.jsx("p",{className:"text-bambu-gray text-xs mt-1",children:o("settings.oidc.form.defaultGroupDesc")})]}),r.jsxs("div",{className:"flex gap-3 pt-2",children:[r.jsx(Me,{variant:"secondary",onClick:i,className:"flex-1",children:o("common.cancel")}),r.jsx(Me,{variant:"primary",className:"flex-1",disabled:!l.name||!l.issuer_url||!l.client_id||!e&&!l.client_secret||e&&d&&!l.client_secret||s,onClick:b,children:o(s?"common.saving":"common.save")})]})]})}function hat(){const{t}=kt(),e=en(),{showToast:n}=rn(),[a,i]=y.useState(!1),[s,o]=y.useState(null),[l,c]=y.useState(null),{data:d,isLoading:u}=Ve({queryKey:["oidc-providers-all"],queryFn:()=>se.getOIDCProvidersAll()}),{data:m=[]}=Ve({queryKey:["groups"],queryFn:()=>se.getGroups()}),p=it({mutationFn:g=>se.createOIDCProvider(g),onSuccess:()=>{e.invalidateQueries({queryKey:["oidc-providers-all"]}),i(!1),n(t("settings.oidc.created"),"success")},onError:g=>n(g.message,"error")}),f=it({mutationFn:({id:g,data:x})=>se.updateOIDCProvider(g,x),onSuccess:()=>{e.invalidateQueries({queryKey:["oidc-providers-all"]}),o(null),n(t("settings.oidc.updated"),"success")},onError:g=>n(g.message,"error")}),b=it({mutationFn:g=>se.deleteOIDCProvider(g),onSuccess:()=>{e.invalidateQueries({queryKey:["oidc-providers-all"]}),c(null),n(t("settings.oidc.deleted"),"success")},onError:g=>n(g.message,"error")}),w=g=>f.mutate({id:g.id,data:{is_enabled:!g.is_enabled}});return u?r.jsx("div",{className:"flex items-center justify-center py-12",children:r.jsx(sr,{className:"w-6 h-6 animate-spin text-bambu-green"})}):r.jsxs("div",{className:"space-y-6",children:[r.jsxs(Ct,{id:"card-oidc",children:[r.jsx(pn,{children:r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("h3",{className:"text-white font-semibold",children:t("settings.oidc.title")}),r.jsx("p",{className:"text-bambu-gray text-sm",children:t("settings.oidc.desc")})]}),!a&&r.jsxs(Me,{variant:"primary",size:"sm",onClick:()=>i(!0),className:"flex items-center gap-2",children:[r.jsx(ar,{className:"w-4 h-4"}),t("settings.oidc.addProvider")]})]})}),a&&r.jsx(At,{children:r.jsxs("div",{className:"border-t border-bambu-dark-tertiary pt-4",children:[r.jsx("h4",{className:"text-white font-medium mb-4",children:t("settings.oidc.newProvider")}),r.jsx(cQ,{initial:pat,groups:m,onSave:g=>p.mutate(g),onCancel:()=>i(!1),isPending:p.isPending})]})})]}),d&&d.length===0&&!a&&r.jsx(Ct,{id:"card-oidc-empty",children:r.jsx(At,{children:r.jsxs("div",{className:"text-center py-8 space-y-3",children:[r.jsx(no,{className:"w-12 h-12 text-bambu-gray mx-auto"}),r.jsx("p",{className:"text-bambu-gray",children:t("settings.oidc.empty")}),r.jsxs(Me,{variant:"primary",size:"sm",onClick:()=>i(!0),className:"inline-flex items-center gap-2",children:[r.jsx(ar,{className:"w-4 h-4"}),t("settings.oidc.addProvider")]})]})})}),d?.map(g=>r.jsxs(Ct,{children:[r.jsx(pn,{children:r.jsxs("div",{className:"flex items-center gap-3",children:[g.icon_url?r.jsx("img",{src:g.icon_url,alt:g.name,className:"w-8 h-8 rounded object-contain",onError:x=>{x.target.style.display="none"}}):r.jsx("div",{className:"w-8 h-8 rounded-full bg-bambu-dark-tertiary flex items-center justify-center",children:r.jsx(no,{className:"w-4 h-4 text-bambu-gray"})}),r.jsxs("div",{className:"flex-1",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("h4",{className:"text-white font-medium",children:g.name}),g.is_enabled?r.jsxs("span",{className:"flex items-center gap-1 text-xs text-green-400 bg-green-400/10 px-2 py-0.5 rounded-full",children:[r.jsx(_r,{className:"w-3 h-3"})," ",t("common.enabled")]}):r.jsxs("span",{className:"flex items-center gap-1 text-xs text-bambu-gray bg-bambu-dark-tertiary px-2 py-0.5 rounded-full",children:[r.jsx(Ht,{className:"w-3 h-3"})," ",t("common.disabled")]})]}),r.jsxs("div",{className:"flex items-center gap-1 text-bambu-gray text-xs mt-0.5",children:[r.jsx(Rr,{className:"w-3 h-3"}),r.jsx("span",{children:g.issuer_url})]})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(En,{checked:g.is_enabled,onChange:()=>w(g),disabled:f.isPending}),r.jsx(Me,{variant:"secondary",size:"sm",onClick:()=>o(s===g.id?null:g.id),children:r.jsx(fc,{className:"w-4 h-4"})}),r.jsx(Me,{variant:"danger",size:"sm",onClick:()=>c(g),children:r.jsx(Jt,{className:"w-4 h-4"})})]})]})}),s===g.id&&r.jsx(At,{children:r.jsx("div",{className:"border-t border-bambu-dark-tertiary pt-4",children:r.jsx(cQ,{isEdit:!0,groups:m,initial:{name:g.name,issuer_url:g.issuer_url,client_id:g.client_id,client_secret:"",scopes:g.scopes,is_enabled:g.is_enabled,auto_create_users:g.auto_create_users,auto_link_existing_accounts:g.auto_link_existing_accounts,email_claim:g.email_claim,require_email_verified:g.require_email_verified,icon_url:g.icon_url??void 0,default_group_id:g.default_group_id??null},onSave:x=>f.mutate({id:g.id,data:x}),onCancel:()=>o(null),isPending:f.isPending})})}),s!==g.id&&r.jsx(At,{children:r.jsxs("dl",{className:"grid grid-cols-2 sm:grid-cols-3 gap-x-6 gap-y-2 text-sm",children:[r.jsxs("div",{children:[r.jsx("dt",{className:"text-bambu-gray",children:t("settings.oidc.form.clientId")}),r.jsx("dd",{className:"text-white font-mono truncate",children:g.client_id})]}),r.jsxs("div",{children:[r.jsx("dt",{className:"text-bambu-gray",children:t("settings.oidc.form.scopes")}),r.jsx("dd",{className:"text-white",children:g.scopes})]}),r.jsxs("div",{children:[r.jsx("dt",{className:"text-bambu-gray",children:t("settings.oidc.form.autoCreate")}),r.jsx("dd",{className:g.auto_create_users?"text-green-400":"text-bambu-gray",children:g.auto_create_users?t("common.yes"):t("common.no")})]}),r.jsxs("div",{children:[r.jsx("dt",{className:"text-bambu-gray",children:t("settings.oidc.form.autoLink")}),r.jsx("dd",{className:g.auto_link_existing_accounts?"text-green-400":"text-bambu-gray",children:g.auto_link_existing_accounts?t("common.yes"):t("common.no")})]}),r.jsxs("div",{children:[r.jsx("dt",{className:"text-bambu-gray",children:t("settings.oidc.form.emailClaim")}),r.jsx("dd",{className:"text-white font-mono",children:g.email_claim})]}),r.jsxs("div",{children:[r.jsx("dt",{className:"text-bambu-gray",children:t("settings.oidc.form.requireEmailVerified")}),r.jsx("dd",{className:g.require_email_verified?"text-green-400":"text-red-400",children:g.require_email_verified?t("common.yes"):t("common.no")})]}),r.jsxs("div",{children:[r.jsx("dt",{className:"text-bambu-gray",children:t("settings.oidc.form.defaultGroup")}),r.jsx("dd",{className:"text-white",children:g.default_group_id?m.find(x=>x.id===g.default_group_id)?.name??t("settings.oidc.form.defaultGroupViewersFallback"):t("settings.oidc.form.defaultGroupViewersFallback")})]})]})})]},g.id)),l&&r.jsx(vn,{title:t("settings.oidc.deleteTitle"),message:t("settings.oidc.deleteMessage",{name:l.name}),confirmText:t("common.delete"),variant:"danger",onConfirm:()=>b.mutate(l.id),onCancel:()=>c(null)})]})}const Tce=new Map;function jn(t){Tce.set(t.anchor,t)}function fat(){return Array.from(Tce.values())}jn({labelKey:"settings.encryption.title",labelFallback:"MFA Encryption Status",tab:"users",subTab:"security",keywords:"mfa encryption status security backup totp oidc fernet",anchor:"card-mfa-encryption"});function gat(){const{t}=kt(),{data:e,isLoading:n,isError:a,refetch:i}=Ve({queryKey:["encryptionStatus"],queryFn:()=>se.getEncryptionStatus(),refetchInterval:p=>{if(!p.state.error)return 3e4;const f=p.state.fetchFailureCount??0;return f<=3?Math.min(5e3*Math.max(1,f),3e4):!1}});if(n)return r.jsxs(Ct,{id:"card-mfa-encryption","data-testid":"encryption-status-card",children:[r.jsx(pn,{children:r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(Sl,{className:"text-bambu-gray",size:20}),r.jsx("h2",{className:"text-lg font-semibold",children:t("settings.encryption.title")})]})}),r.jsx(At,{children:r.jsxs("div",{className:"flex items-center gap-2 text-bambu-gray","data-testid":"encryption-loading",children:[r.jsx(pt,{className:"animate-spin",size:16}),r.jsx("span",{children:t("common.loading")})]})})]});if(a||!e)return r.jsxs(Ct,{id:"card-mfa-encryption","data-testid":"encryption-status-card",children:[r.jsx(pn,{children:r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(Sl,{className:"text-bambu-gray",size:20}),r.jsx("h2",{className:"text-lg font-semibold",children:t("settings.encryption.title")})]})}),r.jsxs(At,{children:[r.jsx("div",{className:"text-red-400","data-testid":"encryption-error",children:t("common.errorLoading")}),r.jsx("button",{type:"button",onClick:()=>i(),className:"mt-2 text-sm text-blue-400 underline hover:text-blue-300","data-testid":"encryption-retry-button",children:t("common.retry")})]})]});const s=e.legacy_plaintext_rows.oidc_providers+e.legacy_plaintext_rows.user_totp,o=e.encrypted_rows.oidc_providers+e.encrypted_rows.user_totp;let l,c,d,u;e.decryption_broken?(l="bg-red-500/20 border-red-500/50 text-red-400",c=r.jsx(Da,{className:"text-red-400",size:20}),d=t("settings.encryption.decryptionBrokenTitle"),u=t("settings.encryption.decryptionBrokenError",{count:o})):e.key_source==="generated"?(l="bg-amber-500/10 border-amber-500/30 text-amber-400",c=r.jsx(Ew,{className:"text-amber-400",size:20}),d=t("settings.encryption.enabledGenerated"),u=t("settings.encryption.backupHint")):s>0?(l="bg-amber-500/10 border-amber-500/30 text-amber-400",c=r.jsx(Nn,{className:"text-amber-400",size:20}),d=e.key_source==="env"?t("settings.encryption.enabledFromEnv"):t("settings.encryption.enabledFromFile"),u=t("settings.encryption.legacyRowsWarning",{count:s})):e.key_configured?(l="bg-green-500/20 border-green-500/30 text-green-400",c=r.jsx(Ew,{className:"text-green-400",size:20}),d=e.key_source==="env"?t("settings.encryption.enabledFromEnv"):t("settings.encryption.enabledFromFile"),u=t("settings.encryption.allEncrypted")):(l="bg-gray-500/20 border-gray-500/30 text-gray-400",c=r.jsx(VF,{className:"text-gray-400",size:20}),d=t("settings.encryption.notConfigured"),u=t("settings.encryption.notConfiguredDesc"));const m=e.key_source==="generated"&&s>0;return r.jsxs(Ct,{id:"card-mfa-encryption","data-testid":"encryption-status-card",children:[r.jsx(pn,{children:r.jsxs("div",{className:"flex items-center gap-2",children:[c,r.jsx("h2",{className:"text-lg font-semibold",children:t("settings.encryption.title")})]})}),r.jsxs(At,{children:[r.jsxs("div",{className:`p-3 border rounded-lg ${l}`,"data-testid":"encryption-status",children:[r.jsx("p",{className:"font-medium mb-1",children:d}),r.jsx("p",{className:"text-sm",children:u})]}),m&&r.jsx("div",{className:"mt-2 p-3 border rounded-lg bg-amber-500/10 border-amber-500/30 text-amber-400","data-testid":"encryption-legacy-warning",children:r.jsx("p",{className:"text-sm",children:t("settings.encryption.legacyRowsWarning",{count:s})})}),e.migration_error_count>0&&r.jsx("div",{className:"mt-2 p-3 border rounded-lg bg-amber-500/10 border-amber-500/30 text-amber-400","data-testid":"encryption-migration-warning",children:r.jsx("p",{className:"text-sm",children:t("settings.encryption.migrationErrorWarning",{count:e.migration_error_count})})}),r.jsxs("div",{className:"mt-4 grid grid-cols-2 gap-4 text-sm",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-bambu-gray",children:t("settings.encryption.encryptedRowsLabel")}),r.jsxs("p",{className:"font-medium",children:["OIDC: ",e.encrypted_rows.oidc_providers," · TOTP: ",e.encrypted_rows.user_totp]})]}),r.jsxs("div",{children:[r.jsx("p",{className:"text-bambu-gray",children:t("settings.encryption.legacyRowsLabel")}),r.jsxs("p",{className:"font-medium",children:["OIDC: ",e.legacy_plaintext_rows.oidc_providers," · TOTP: ",e.legacy_plaintext_rows.user_totp]})]})]})]})]})}const bat={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 xat(t,e){const n=e.replace("#/","").split("/");let a=t;for(const i of n)a=a[i];return a}function $0(t,e,n=0){if(n>5)return"...";if(e.$ref)return $0(t,xat(t,e.$ref),n+1);if(e.allOf){const a={};for(const i of e.allOf){const s=$0(t,i,n+1);typeof s=="object"&&s!==null&&Object.assign(a,s)}return a}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?[$0(t,e.items,n+1)]:[];case"object":if(e.properties){const a={};for(const[i,s]of Object.entries(e.properties))a[i]=$0(t,s,n+1);return a}return{};default:return null}}function yat({path:t,method:e,spec:n,schema:a,apiKey:i}){const[s,o]=y.useState(!1),[l,c]=y.useState({}),[d,u]=y.useState(""),[m,p]=y.useState(null),[f,b]=y.useState(!1),[w,g]=y.useState(!1);y.useEffect(()=>{if(s&&n.parameters){const F={};for(const S of n.parameters)S.schema?.default!==void 0&&(F[S.name]=String(S.schema.default));c(S=>({...F,...S}))}},[s,n.parameters]),y.useEffect(()=>{if(s&&n.requestBody?.content?.["application/json"]?.schema&&!d){const F=n.requestBody.content["application/json"].schema,S=$0(a,F);u(JSON.stringify(S,null,2))}},[s,n.requestBody,a,d]);const _=(()=>{const F=[];for(const S of n.parameters||[])if(S.in==="path"||S.required){const E=l[S.name];(E===void 0||E==="")&&F.push(S.name)}return F})(),N=async()=>{if(_.length>0){p({status:0,statusText:"Validation Error",headers:{},body:`Missing required parameters: ${_.join(", ")}`,duration:0});return}b(!0),p(null);try{let F=t;const S=new URLSearchParams;for(const ue of n.parameters||[]){const X=l[ue.name];X!==void 0&&X!==""&&(ue.in==="path"?F=F.replace(`{${ue.name}}`,encodeURIComponent(X)):ue.in==="query"&&S.append(ue.name,X))}const E=S.toString(),U=`${F}${E?`?${E}`:""}`,I={"Content-Type":"application/json"};i&&(I["X-API-Key"]=i);const H={method:e.toUpperCase(),headers:I};["post","put","patch"].includes(e)&&d&&(H.body=d);const R=performance.now(),Q=await fetch(U,H),re=Math.round(performance.now()-R),J={};Q.headers.forEach((ue,X)=>{J[X]=ue});let de;Q.headers.get("content-type")?.includes("application/json")?de=await Q.json():de=await Q.text(),p({status:Q.status,statusText:Q.statusText,headers:J,body:de,duration:re})}catch(F){p({status:0,statusText:"Network Error",headers:{},body:F instanceof Error?F.message:"Unknown error",duration:0})}finally{b(!1)}},C=async()=>{if(m){const F=typeof m.body=="string"?m.body:JSON.stringify(m.body,null,2);try{await navigator.clipboard.writeText(F),g(!0),setTimeout(()=>g(!1),2e3)}catch{const S=document.createElement("textarea");S.value=F,S.style.position="fixed",S.style.left="-999999px",document.body.appendChild(S),S.select(),document.execCommand("copy"),document.body.removeChild(S),g(!0),setTimeout(()=>g(!1),2e3)}}},P=(n.parameters||[]).filter(F=>F.in==="path"),T=(n.parameters||[]).filter(F=>F.in==="query"),A=["post","put","patch"].includes(e)&&n.requestBody;return r.jsxs("div",{className:"border border-bambu-dark-tertiary rounded-lg overflow-hidden",children:[r.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?r.jsx(Ln,{className:"w-4 h-4 text-bambu-gray flex-shrink-0"}):r.jsx(Va,{className:"w-4 h-4 text-bambu-gray flex-shrink-0"}),r.jsx("span",{className:`px-2 py-0.5 text-xs font-mono font-semibold uppercase rounded border ${bat[e]||"bg-gray-500/20 text-gray-400"}`,children:e}),r.jsx("code",{className:"text-sm text-white font-mono flex-1 truncate",children:t}),n.summary&&r.jsx("span",{className:"text-sm text-bambu-gray truncate max-w-[40%]",children:n.summary})]}),s&&r.jsxs("div",{className:"border-t border-bambu-dark-tertiary p-4 space-y-4 bg-bambu-dark/50",children:[n.description&&r.jsx("p",{className:"text-sm text-bambu-gray",children:n.description}),P.length>0&&r.jsxs("div",{className:"space-y-2",children:[r.jsx("h4",{className:"text-sm font-medium text-white",children:"Path Parameters"}),r.jsx("div",{className:"space-y-2",children:P.map(F=>r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsxs("label",{className:"text-sm text-bambu-gray w-32 flex-shrink-0",children:[F.name,F.required&&r.jsx("span",{className:"text-red-400 ml-1",children:"*"})]}),r.jsx("input",{type:"text",value:l[F.name]||"",onChange:S=>c(E=>({...E,[F.name]:S.target.value})),placeholder:F.description||F.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"})]},F.name))})]}),T.length>0&&r.jsxs("div",{className:"space-y-2",children:[r.jsx("h4",{className:"text-sm font-medium text-white",children:"Query Parameters"}),r.jsx("div",{className:"space-y-2",children:T.map(F=>r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsxs("label",{className:"text-sm text-bambu-gray w-32 flex-shrink-0",children:[F.name,F.required&&r.jsx("span",{className:"text-red-400 ml-1",children:"*"})]}),F.schema?.enum?r.jsxs("select",{value:l[F.name]||"",onChange:S=>c(E=>({...E,[F.name]:S.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:[r.jsx("option",{value:"",children:"-- Select --"}),F.schema.enum.map(S=>r.jsx("option",{value:S,children:S},S))]}):r.jsx("input",{type:"text",value:l[F.name]||"",onChange:S=>c(E=>({...E,[F.name]:S.target.value})),placeholder:F.description||F.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"})]},F.name))})]}),A&&r.jsxs("div",{className:"space-y-2",children:[r.jsx("h4",{className:"text-sm font-medium text-white",children:"Request Body"}),r.jsx("textarea",{value:d,onChange:F=>u(F.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..."})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsxs(Me,{onClick:N,disabled:f,children:[f?r.jsx(pt,{className:"w-4 h-4 animate-spin"}):r.jsx(fs,{className:"w-4 h-4"}),"Execute"]}),_.length>0&&r.jsxs("span",{className:"text-xs text-yellow-400 flex items-center gap-1",children:[r.jsx($a,{className:"w-3 h-3"}),"Fill in: ",_.join(", ")]})]}),m&&r.jsxs("div",{className:"space-y-2",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("h4",{className:"text-sm font-medium text-white flex items-center gap-2",children:["Response",r.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]}),r.jsxs("span",{className:"text-xs text-bambu-gray",children:[m.duration,"ms"]})]}),r.jsx(Me,{variant:"secondary",size:"sm",onClick:C,children:w?r.jsx(wr,{className:"w-3 h-3 text-green-400"}):r.jsx(Mi,{className:"w-3 h-3"})})]}),r.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 vat({apiKey:t=""}){const[e,n]=y.useState(null),[a,i]=y.useState(!0),[s,o]=y.useState(null),[l,c]=y.useState(new Set),[d,u]=y.useState("");if(y.useEffect(()=>{async function g(){try{const x=await fetch("/openapi.json");if(!x.ok)throw new Error("Failed to fetch OpenAPI schema");const _=await x.json();n(_)}catch(x){o(x instanceof Error?x.message:"Unknown error")}finally{i(!1)}}g()},[]),a)return r.jsx("div",{className:"flex justify-center py-12",children:r.jsx(pt,{className:"w-8 h-8 text-bambu-green animate-spin"})});if(s||!e)return r.jsx(Ct,{children:r.jsx(At,{className:"py-8",children:r.jsxs("div",{className:"text-center text-red-400",children:[r.jsx($a,{className:"w-12 h-12 mx-auto mb-3 opacity-50"}),r.jsx("p",{children:"Failed to load API schema"}),r.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:s})]})})});const m={};for(const[g,x]of Object.entries(e.paths))for(const[_,N]of Object.entries(x)){if(_==="parameters")continue;const C=N.tags||["Other"];for(const P of C)m[P]||(m[P]=[]),m[P].push({path:g,method:_,spec:N})}const p=Object.entries(m).map(([g,x])=>{if(!d)return{tag:g,endpoints:x};const _=x.filter(({path:N,method:C,spec:P})=>{const T=d.toLowerCase();return N.toLowerCase().includes(T)||C.toLowerCase().includes(T)||(P.summary?.toLowerCase()||"").includes(T)||(P.description?.toLowerCase()||"").includes(T)});return{tag:g,endpoints:_}}).filter(({endpoints:g})=>g.length>0).sort((g,x)=>g.tag.localeCompare(x.tag)),f=g=>{c(x=>{const _=new Set(x);return _.has(g)?_.delete(g):_.add(g),_})},b=()=>{c(new Set(p.map(g=>g.tag)))},w=()=>{c(new Set)};return r.jsxs("div",{className:"space-y-4",children:[r.jsxs("div",{className:"flex items-center justify-between gap-4",children:[r.jsx("div",{className:"flex-1",children:r.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"})}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(Me,{variant:"secondary",size:"sm",onClick:b,children:"Expand All"}),r.jsx(Me,{variant:"secondary",size:"sm",onClick:w,children:"Collapse All"}),r.jsxs("a",{href:"/docs",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1 text-sm text-bambu-green hover:underline",children:[r.jsx(Rr,{className:"w-4 h-4"}),"Swagger UI"]})]})]}),r.jsxs("p",{className:"text-sm text-bambu-gray",children:[p.reduce((g,x)=>g+x.endpoints.length,0)," endpoints in ",p.length," categories"]}),r.jsx("div",{className:"space-y-3",children:p.map(({tag:g,endpoints:x})=>r.jsxs(Ct,{children:[r.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:r.jsxs("div",{className:"flex items-center gap-2",children:[l.has(g)?r.jsx(Ln,{className:"w-5 h-5 text-bambu-gray"}):r.jsx(Va,{className:"w-5 h-5 text-bambu-gray"}),r.jsx("h3",{className:"text-base font-semibold text-white capitalize",children:g.replace(/-/g," ")}),r.jsx("span",{className:"text-xs bg-bambu-dark-tertiary px-2 py-0.5 rounded-full text-bambu-gray",children:x.length})]})}),l.has(g)&&r.jsx(At,{className:"pt-0 space-y-2",children:x.map(({path:_,method:N,spec:C})=>r.jsx(yat,{path:_,method:N,spec:C,schema:e,apiKey:t},`${N}-${_}`))})]},g))})]})}const wat=["general","plugs","notifications","queue","filament","network","apikeys","virtual-printer","spoolbuddy","failure-detection","users","backup"];jn({labelKey:"settings.general",tab:"general",keywords:"language date time format printer model printers cards",anchor:"card-general"});jn({labelKey:"settings.appearance",tab:"general",keywords:"theme dark light mode colors",anchor:"card-appearance"});jn({labelKey:"settings.archiveSettings",tab:"general",keywords:"archive auto save thumbnails captures",anchor:"card-archive"});jn({labelKey:"settings.camera",tab:"general",keywords:"camera external video stream",anchor:"card-camera"});jn({labelKey:"settings.costTracking",tab:"general",keywords:"currency filament cost energy kwh price",anchor:"card-cost"});jn({labelKey:"settings.fileManager",tab:"general",keywords:"file manager archive mode disk warning storage",anchor:"card-filemanager"});jn({labelKey:"settings.updates",tab:"general",keywords:"updates version firmware beta check",anchor:"card-updates"});jn({labelKey:"settings.dataManagement",tab:"general",keywords:"data reset clear logs notifications preferences",anchor:"card-data"});jn({labelKey:"settings.smartPlugs",tab:"plugs",keywords:"smart plug energy power automation tapo kasa tplink shelly",anchor:"card-plugs"});jn({labelKey:"settings.providers",tab:"notifications",keywords:"telegram discord email notification providers webhook",anchor:"card-providers"});jn({labelKey:"settings.messageTemplates",tab:"notifications",keywords:"message templates notification text edit",anchor:"card-templates"});jn({labelKey:"settings.defaultPrintOptions",labelFallback:"Default Print Options",tab:"queue",keywords:"print bed leveling flow calibration vibration first layer timelapse",anchor:"card-print-options"});jn({labelKey:"settings.staggeredStart",labelFallback:"Staggered Start",tab:"queue",keywords:"staggered batch delay start queue group",anchor:"card-staggered"});jn({labelKey:"settings.plateClear",labelFallback:"Plate-Clear Confirmation",tab:"queue",keywords:"plate clear confirm auto queue",anchor:"card-plate"});jn({labelKey:"settings.gcodeInjection",labelFallback:"G-code Injection",tab:"queue",keywords:"gcode injection start end autoprint farmloop swapmod autoclear printflow",anchor:"card-gcode"});jn({labelKey:"settings.slicerCard",labelFallback:"Slicer",tab:"queue",keywords:"slicer orcaslicer bambustudio orca bambu api sidecar url docker preferred",anchor:"card-slicer"});jn({labelKey:"settings.queueDrying",tab:"queue",keywords:"drying presets temperature time humidity ams",anchor:"card-drying"});jn({labelKey:"settings.filamentChecks",tab:"filament",keywords:"filament check warning runout remaining",anchor:"card-filamentchecks"});jn({labelKey:"settings.printModal",tab:"filament",keywords:"print modal custom mapping",anchor:"card-printmodal"});jn({labelKey:"settings.amsDisplayThresholds",tab:"filament",keywords:"ams humidity temperature threshold history retention",anchor:"card-amsthresholds"});jn({labelKey:"settings.externalUrl",tab:"network",keywords:"external url reverse proxy public notification link",anchor:"card-externalurl"});jn({labelKey:"settings.ftpRetry",tab:"network",keywords:"ftp retry upload retries backoff",anchor:"card-ftpretry"});jn({labelKey:"settings.homeAssistant",tab:"network",keywords:"home assistant ha hass mqtt integration",anchor:"card-ha"});jn({labelKey:"settings.mqttPublishing",tab:"network",keywords:"mqtt publish broker topic",anchor:"card-mqtt"});jn({labelKey:"settings.prometheusMetrics",tab:"network",keywords:"prometheus metrics grafana monitoring bearer token",anchor:"card-prometheus"});jn({labelKey:"settings.createNewApiKey",tab:"apikeys",keywords:"api key create permission scope",anchor:"card-createapi"});jn({labelKey:"settings.webhookEndpoints",tab:"apikeys",keywords:"webhook endpoint post http",anchor:"card-webhooks"});jn({labelKey:"settings.apiBrowser",tab:"apikeys",keywords:"api browser endpoint documentation test",anchor:"card-apibrowser"});jn({labelKey:"cameraTokens.title",tab:"apikeys",keywords:"camera token long-lived home assistant frigate kiosk stream",anchor:"card-camera-tokens"});jn({labelKey:"settings.tabs.virtualPrinter",tab:"virtual-printer",keywords:"virtual printer proxy archive slicer bambustudio orcaslicer ip bind",anchor:"card-vp"});jn({labelKey:"settings.tabs.spoolbuddy",tab:"spoolbuddy",keywords:"spoolbuddy device scale nfc rfid kiosk unregister",anchor:"card-spoolbuddy"});jn({labelKey:"settings.currentUser",tab:"users",subTab:"users",keywords:"current user profile password change",anchor:"card-currentuser"});jn({labelKey:"settings.users",tab:"users",subTab:"users",keywords:"users accounts list",anchor:"card-users"});jn({labelKey:"settings.groups",tab:"users",subTab:"users",keywords:"groups roles permissions administrators operators viewers",anchor:"card-groups"});jn({labelKey:"settings.email.smtpSettings",labelFallback:"SMTP Configuration",tab:"users",subTab:"email",keywords:"smtp email send server port password auth starttls ssl",anchor:"card-smtp"});jn({labelKey:"settings.ldap.title",labelFallback:"LDAP Authentication",tab:"users",subTab:"ldap",keywords:"ldap active directory ad authentication bind dn search base group mapping",anchor:"card-ldap"});jn({labelKey:"settings.tabs.backup",tab:"backup",keywords:"backup github restore download cloud sync profiles archives",anchor:"card-backup"});jn({labelKey:"externalLinks.title",labelFallback:"Sidebar Links",tab:"general",keywords:"sidebar links external custom navigation url add",anchor:"card-sidebar-links"});jn({labelKey:"settings.filamentTracking",tab:"filament",keywords:"spoolman filament tracking inventory sync remote integration",anchor:"card-spoolman"});jn({labelKey:"settings.catalog.spoolCatalog",labelFallback:"Spool Catalog",tab:"filament",keywords:"spool catalog entries brand material reset import export",anchor:"card-spool-catalog"});jn({labelKey:"settings.colorCatalog.title",labelFallback:"Color Catalog",tab:"filament",keywords:"color catalog hex swatch palette sync reset",anchor:"card-color-catalog"});jn({labelKey:"settings.tabs.failureDetection",labelFallback:"Failure Detection",tab:"failure-detection",keywords:"failure detection ai ml obico spaghetti detect monitoring",anchor:"card-fd-ml"});jn({labelKey:"failureDetection.perPrinterTitle",labelFallback:"Per-Printer Settings",tab:"failure-detection",keywords:"failure detection per printer enable per-printer sensitivity",anchor:"card-fd-perprinter"});jn({labelKey:"failureDetection.statusTitle",labelFallback:"Detection Status",tab:"failure-detection",keywords:"failure detection status running connection",anchor:"card-fd-status"});jn({labelKey:"failureDetection.historyTitle",labelFallback:"Detection History",tab:"failure-detection",keywords:"failure detection history log events",anchor:"card-fd-history"});jn({labelKey:"settings.email.advancedAuth",labelFallback:"Advanced Email Authentication",tab:"users",subTab:"email",keywords:"email authentication advanced password reset self-service forgot",anchor:"card-email-advanced-auth"});jn({labelKey:"settings.email.testConnection",labelFallback:"Test SMTP Connection",tab:"users",subTab:"email",keywords:"email smtp test connection send check",anchor:"card-email-test"});jn({labelKey:"settings.twoFa.totpTitle",labelFallback:"Authenticator App (TOTP)",tab:"users",subTab:"twofa",keywords:"two factor 2fa totp authenticator app google authy otp",anchor:"card-2fa-totp"});jn({labelKey:"settings.twoFa.emailOtpTitle",labelFallback:"Email One-Time Codes",tab:"users",subTab:"twofa",keywords:"two factor 2fa email otp one time code",anchor:"card-2fa-emailotp"});jn({labelKey:"settings.twoFa.linkedAccounts",labelFallback:"Linked Accounts",tab:"users",subTab:"twofa",keywords:"two factor 2fa linked accounts sso oidc provider google github",anchor:"card-2fa-linked"});jn({labelKey:"settings.oidc.title",labelFallback:"Single Sign-On (OIDC)",tab:"users",subTab:"oidc",keywords:"sso oidc openid single sign-on pocketid authentik keycloak google okta azure provider",anchor:"card-oidc"});jn({labelKey:"settings.ldap.serverConfig",labelFallback:"LDAP Server Configuration",tab:"users",subTab:"ldap",keywords:"ldap server url bind dn user search base group filter tls",anchor:"card-ldap-server"});jn({labelKey:"backup.githubBackup",labelFallback:"GitHub Backup",tab:"backup",keywords:"github backup cloud remote sync profiles token",anchor:"card-backup-github"});jn({labelKey:"backup.history",labelFallback:"Backup History",tab:"backup",keywords:"backup history log runs github commits",anchor:"card-backup-history"});jn({labelKey:"backup.localBackup",labelFallback:"Local Backup",tab:"backup",keywords:"local backup download zip manual export",anchor:"card-backup-local"});jn({labelKey:"backup.scheduledBackup",labelFallback:"Scheduled Backups",tab:"backup",keywords:"scheduled backup automatic hourly daily weekly retention local path",anchor:"card-backup-scheduled"});const Sat={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"},dQ=["bg-blue-500","bg-green-500","bg-yellow-500","bg-red-500","bg-orange-500","bg-teal-500","bg-cyan-500","bg-purple-500"],uQ=(t,e)=>Sat[t]||dQ[e%dQ.length];function _at(){const t=en(),e=Di(),[n,a]=ab(),{t:i,i18n:s}=kt(),{showToast:o}=rn(),{authEnabled:l,user:c,isAdmin:d,refreshAuth:u,hasPermission:m}=cr(),{mode:p,darkStyle:f,darkBackground:b,darkAccent:w,lightStyle:g,lightBackground:x,lightAccent:_,setDarkStyle:N,setDarkBackground:C,setDarkAccent:P,setLightStyle:T,setLightBackground:A,setLightAccent:F}=cb(),[S,E]=y.useState(null),[U,I]=y.useState(!1),[H,R]=y.useState(null),[Q,re]=y.useState(!1),[J,de]=y.useState(null),[pe,ue]=y.useState(null),[X,ae]=y.useState(""),[me,be]=y.useState(""),[Ce,$]=y.useState(!1),[W,D]=y.useState(JZ()),j=n.get("tab"),B=j==="email",Y=B?"users":j&&wat.includes(j)?j:"general",[O,ie]=y.useState(Y),[z,G]=y.useState(B?"email":"users"),K=Se=>{ie(Se),Se==="users"&&G("users"),Se==="general"?n.delete("tab"):n.set("tab",Se),a(n,{replace:!0})},[Z,oe]=y.useState(!1),[ee,ge]=y.useState(""),[ce,le]=y.useState({can_queue:!0,can_control_printer:!1,can_read_status:!0,can_access_cloud:!1}),[q,L]=y.useState(null),[ne,ye]=y.useState(null),[we,Ne]=y.useState(""),[ve,xe]=y.useState(!1),[Ee,ze]=y.useState(!1),[_e,Oe]=y.useState(null),[Ie,We]=y.useState(!1),[at,lt]=y.useState(!1),[Fe,tt]=y.useState(!1),[Pe,Ye]=y.useState({currentPassword:"",newPassword:"",confirmPassword:""}),[Ue,fe]=y.useState(!1),[Ae,qe]=y.useState(!1),[nt,Qe]=y.useState(!1),[gt,ct]=y.useState(!1),[rt,Ot]=y.useState(null),[Wt,Zt]=y.useState(null),[Yt,un]=y.useState(null),[bn,dt]=y.useState(!1),[st,vt]=y.useState({username:"",password:"",email:"",confirmPassword:"",role:"user",group_ids:[]}),[_t,Dt]=y.useState(null),[De,je]=y.useState(null),[$e,Je]=y.useState(!1),[Re,mt]=y.useState({}),[he,Le]=y.useState({}),Xe=Se=>{D(Se),Bve(Se),o(i("settings.toast.settingsSaved"),"success")},Ze=()=>{localStorage.removeItem("sidebarOrder"),window.location.reload()},Ke=!!S?.default_sidebar_order,bt=async Se=>{try{if(Se){let Rt;const an=localStorage.getItem("sidebarOrder");try{Rt=an?JSON.parse(an):vm.map(Bn=>Bn.id)}catch{Rt=vm.map(Bn=>Bn.id)}(!Array.isArray(Rt)||Rt.length===0)&&(Rt=vm.map(Bn=>Bn.id));const An=JSON.stringify({order:Rt});await se.updateSettings({default_sidebar_order:An}),E(Bn=>Bn&&{...Bn,default_sidebar_order:An}),o(i("settings.sidebarDefaultSet"),"success")}else await se.updateSettings({default_sidebar_order:""}),E(Rt=>Rt&&{...Rt,default_sidebar_order:""}),o(i("settings.sidebarDefaultCleared"),"success");t.invalidateQueries({queryKey:["settings"]}),t.invalidateQueries({queryKey:["default-sidebar-order"]})}catch{o(i("settings.sidebarDefaultFailed"),"error")}},{data:et,isLoading:jt}=Ve({queryKey:["settings"],queryFn:se.getSettings}),{data:St,isLoading:It,isFetching:zt}=Ve({queryKey:["storage-usage"],queryFn:()=>se.getStorageUsage(),enabled:O==="general",staleTime:1/0,refetchInterval:!1,refetchOnWindowFocus:!1,refetchOnReconnect:!1}),He=async()=>{qe(!0);try{const Se=await se.getStorageUsage({refresh:!0});t.setQueryData(["storage-usage"],Se)}catch(Se){const Rt=Se instanceof Error?Se.message:"Failed to refresh storage usage";o(Rt,"error")}finally{qe(!1)}},{data:Ge,isLoading:Vt}=Ve({queryKey:["smart-plugs"],queryFn:se.getSmartPlugs}),{data:Qt,isLoading:mn}=Ve({queryKey:["smart-plugs-energy",Ge?.map(Se=>Se.id)],queryFn:async()=>{if(!Ge||Ge.length===0)return null;const Se=await Promise.all(Ge.filter(Na=>Na.enabled).map(async Na=>{try{const ot=await se.getSmartPlugStatus(Na.id);return{plug:Na,status:ot}}catch{return{plug:Na,status:null}}}));let Rt=0,an=0,An=0,Bn=0,ba=0;for(const{plug:Na,status:ot}of Se){const $t=Na.plug_type==="mqtt"&&ot?.energy?.power!=null;(ot?.reachable||$t)&&ot?.energy&&(ba++,ot.energy?.power!=null&&(Rt+=ot.energy.power),ot.energy?.today!=null&&(an+=ot.energy.today),ot.energy?.yesterday!=null&&(An+=ot.energy.yesterday),ot.energy?.total!=null&&(Bn+=ot.energy.total))}return{totalPower:Rt,totalToday:an,totalYesterday:An,totalLifetime:Bn,reachableCount:ba,totalPlugs:Ge.filter(Na=>Na.enabled).length}},enabled:O==="plugs"&&!!Ge&&Ge.length>0,refetchInterval:O==="plugs"?1e4:!1}),{data:wn,isLoading:gn}=Ve({queryKey:["notification-providers"],queryFn:se.getNotificationProviders}),{data:Cn,isLoading:Mn}=Ve({queryKey:["api-keys"],queryFn:se.getAPIKeys}),xr=it({mutationFn:Se=>se.createAPIKey(Se),onSuccess:Se=>{L(Se.key||null),oe(!1),ge(""),t.invalidateQueries({queryKey:["api-keys"]}),o(i("settings.toast.apiKeyCreated"))},onError:Se=>{o(`Failed to create API key: ${Se.message}`,"error")}}),Er=it({mutationFn:Se=>se.deleteAPIKey(Se),onSuccess:(Se,Rt)=>{t.setQueryData(["api-keys"],an=>(an??[]).filter(An=>An.id!==Rt)),o(i("settings.toast.apiKeyDeleted"))},onError:Se=>{o(`Failed to delete API key: ${Se.message}`,"error")}}),{data:zn}=Ve({queryKey:["printers"],queryFn:se.getPrinters}),{data:Xa,isLoading:Kn}=Ve({queryKey:["notification-templates"],queryFn:se.getNotificationTemplates}),{data:Ar}=Ve({queryKey:["virtual-printer-settings"],queryFn:WF.getSettings,refetchInterval:1e4}),ca=Ar?.status?.running??!1,{data:jr}=Ve({queryKey:["spoolbuddy-devices"],queryFn:()=>Xr.getDevices(),refetchInterval:15e3}),da=jr?.length??0,Ki=jr?.some(Se=>Se.online)??!1,{data:Yi}=Ve({queryKey:["obico-status"],queryFn:se.getObicoStatus,refetchInterval:15e3}),bd=!!(Yi?.is_running&&Yi?.enabled),{data:Lc}=Ve({queryKey:["ffmpeg-status"],queryFn:se.checkFfmpeg}),{data:$s}=Ve({queryKey:["version"],queryFn:se.getVersion}),Ft=!l||m("library:purge"),{data:cn}=Ve({queryKey:["library-trash-settings"],queryFn:()=>se.getLibraryTrashSettings(),enabled:Ft}),hr=it({mutationFn:Se=>se.updateLibraryTrashSettings(Se),onSuccess:()=>{t.invalidateQueries({queryKey:["library-trash-settings"]}),o(i("settings.toast.settingsSaved"),"success")},onError:Se=>o(Se.message||i("libraryAutoPurge.saveFailed"),"error")}),Gt=Se=>{cn&&hr.mutate({retention_days:cn.retention_days,auto_purge_enabled:cn.auto_purge_enabled,auto_purge_days:cn.auto_purge_days,auto_purge_include_never_printed:cn.auto_purge_include_never_printed,...Se})},Ol=!l||m("archives:purge"),{data:mo}=Ve({queryKey:["archive-purge-settings"],queryFn:()=>se.getArchivePurgeSettings(),enabled:Ol}),xd=it({mutationFn:Se=>se.updateArchivePurgeSettings(Se),onSuccess:()=>{t.invalidateQueries({queryKey:["archive-purge-settings"]}),o(i("settings.toast.settingsSaved"),"success")},onError:Se=>o(Se.message||i("archiveAutoPurge.saveFailed"),"error")}),Rc=Se=>{mo&&xd.mutate({enabled:mo.enabled,days:mo.days,...Se})},{data:Or,refetch:mf,isRefetching:il}=Ve({queryKey:["updateCheck"],queryFn:se.checkForUpdates,enabled:et?.check_updates!==!1,staleTime:300*1e3}),{data:Xi,refetch:sl}=Ve({queryKey:["updateStatus"],queryFn:se.getUpdateStatus,refetchInterval:Se=>{const Rt=Se.state.data;return Rt?.status==="downloading"||Rt?.status==="installing"?1e3:!1}}),{data:vs}=Ve({queryKey:["mqtt-status"],queryFn:se.getMQTTStatus,refetchInterval:O==="network"?5e3:!1}),{data:zl}=Ve({queryKey:["github-backup-status"],queryFn:se.getGitHubBackupStatus}),{data:po}=Ve({queryKey:["cloud-status"],queryFn:se.getCloudStatus}),{data:di={advanced_auth_enabled:!1,smtp_configured:!1}}=Ve({queryKey:["advancedAuthStatus"],queryFn:()=>se.getAdvancedAuthStatus()}),{data:lp}=Ve({queryKey:["ldapStatus"],queryFn:()=>se.getLDAPStatus()}),{data:pf}=Ve({queryKey:["twoFAStatus"],queryFn:()=>se.get2FAStatus()}),{data:yd=[]}=Ve({queryKey:["oidcProvidersAll"],queryFn:()=>se.getOIDCProvidersAll(),enabled:d}),{data:Ic=[],isLoading:cp}=Ve({queryKey:["users"],queryFn:()=>se.getUsers(),enabled:l&&m("users:read")}),{data:Qr=[],isLoading:Do}=Ve({queryKey:["groups"],queryFn:()=>se.getGroups(),enabled:l&&m("groups:read")}),ol=it({mutationFn:Se=>se.createUser(Se),onSuccess:()=>{t.invalidateQueries({queryKey:["users"]}),t.invalidateQueries({queryKey:["groups"]}),Qe(!1),vt({username:"",password:"",email:"",confirmPassword:"",role:"user",group_ids:[]}),o(i("settings.toast.userCreated"))},onError:Se=>{o(Se.message,"error")}}),ll=it({mutationFn:({id:Se,data:Rt})=>se.updateUser(Se,Rt),onSuccess:()=>{t.invalidateQueries({queryKey:["users"]}),t.invalidateQueries({queryKey:["groups"]}),ct(!1),Ot(null),vt({username:"",password:"",email:"",confirmPassword:"",role:"user",group_ids:[]}),o(i("settings.toast.userUpdated"))},onError:Se=>{o(Se.message,"error")}}),cl=it({mutationFn:({id:Se,deleteItems:Rt})=>se.deleteUser(Se,Rt),onSuccess:()=>{t.invalidateQueries({queryKey:["users"]}),o(i("settings.toast.userDeleted")),Zt(null),un(null)},onError:Se=>{o(Se.message,"error")}}),vd=it({mutationFn:Se=>se.resetUserPassword({user_id:Se}),onSuccess:Se=>{o(Se.message,"success")},onError:Se=>{o(Se.message,"error")}}),dp=async Se=>{Zt(Se),dt(!0);try{const Rt=await se.getUserItemsCount(Se);un(Rt)}catch{un({archives:0,queue_items:0,library_files:0})}finally{dt(!1)}},Fo=it({mutationFn:Se=>se.deleteGroup(Se),onSuccess:()=>{t.invalidateQueries({queryKey:["groups"]}),o(i("settings.toast.groupDeleted"))},onError:Se=>{o(Se.message,"error")}}),wd=()=>{const Se=di?.advanced_auth_enabled||!1;if(!st.username){o(i("settings.toast.fillRequiredFields"),"error");return}if(Se&&!st.email){o("Email is required when advanced authentication is enabled","error");return}if(!Se){if(!st.password){o(i("settings.toast.fillRequiredFields"),"error");return}if(st.password!==st.confirmPassword){o(i("settings.toast.passwordsDoNotMatch"),"error");return}const Rt=cN(st.password);if(Rt){o(i({tooShort:"settings.toast.passwordTooShort",needsUppercase:"settings.toast.passwordNeedsUppercase",needsLowercase:"settings.toast.passwordNeedsLowercase",needsDigit:"settings.toast.passwordNeedsDigit",needsSpecial:"settings.toast.passwordNeedsSpecial"}[Rt]),"error");return}}ol.mutate({username:st.username,password:Se?void 0:st.password,email:st.email||void 0,role:st.role,group_ids:st.group_ids.length>0?st.group_ids:void 0})},gb=Se=>{if(st.password){if(st.password!==st.confirmPassword){o(i("settings.toast.passwordsDoNotMatch"),"error");return}const an=cN(st.password);if(an){o(i({tooShort:"settings.toast.passwordTooShort",needsUppercase:"settings.toast.passwordNeedsUppercase",needsLowercase:"settings.toast.passwordNeedsLowercase",needsDigit:"settings.toast.passwordNeedsDigit",needsSpecial:"settings.toast.passwordNeedsSpecial"}[an]),"error");return}}const Rt={username:st.username||void 0,password:st.password||void 0,email:st.email||void 0,role:st.role,group_ids:st.group_ids};Rt.password||delete Rt.password,ll.mutate({id:Se,data:Rt})},hv=Se=>{Ot(Se.id),vt({username:Se.username,password:"",email:Se.email||"",confirmPassword:"",role:Se.role,group_ids:Se.groups?.map(Rt=>Rt.id)||[]}),ct(!0)},hf=Se=>{vt(Rt=>({...Rt,group_ids:Rt.group_ids.includes(Se)?Rt.group_ids.filter(an=>an!==Se):[...Rt.group_ids,Se]}))},ff=it({mutationFn:se.applyUpdate,onSuccess:Se=>{Se.is_ha_addon||Se.is_docker?o(Se.message,"error"):sl()}}),[ho,up]=y.useState(null),Cu=it({mutationFn:se.testAllNotificationProviders,onSuccess:Se=>{up(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")}}),Lo=it({mutationFn:async Se=>{if(!Ge)return{success:0,failed:0};const Rt=Ge.filter(An=>An.enabled),an=await Promise.all(Rt.map(async An=>{try{return await se.controlSmartPlug(An.id,Se),{success:!0}}catch{return{success:!1}}}));return{success:an.filter(An=>An.success).length,failed:an.filter(An=>!An.success).length}},onSuccess:(Se,Rt)=>{t.invalidateQueries({queryKey:["smart-plugs"]}),t.invalidateQueries({queryKey:["smart-plugs-energy"]}),Se.failed===0?o(`All ${Se.success} plugs turned ${Rt}`,"success"):o(`${Se.success} plugs turned ${Rt}, ${Se.failed} failed`,"error")},onError:Se=>{o(`Failed: ${Se.message}`,"error")}}),dl=y.useRef(null),Sd=y.useRef(null),ws=y.useRef(!1),mp=y.useRef(!0);y.useEffect(()=>{if(et&&!S){const Se={...et,external_url:et.external_url||window.location.origin};E(Se),setTimeout(()=>{mp.current=!1},100)}},[et,S]);const Pu=it({mutationFn:se.updateSettings,onSuccess:Se=>{t.setQueryData(["settings"],Se),t.invalidateQueries({queryKey:["archiveStats"]}),o(i("settings.toast.settingsSaved"),"success")},onError:Se=>{o(`Failed to save: ${Se.message}`,"error")},onSettled:()=>{ws.current=!1}}),Tu=it({mutationFn:({id:Se,data:Rt})=>se.updatePrinter(Se,Rt),onSuccess:()=>{t.invalidateQueries({queryKey:["printers"]}),o(i("settings.toast.cameraSettingsSaved"),"success")},onError:Se=>{o(`Failed to update printer: ${Se.message}`,"error")}});y.useEffect(()=>{if(!(mp.current||!S||!et||l&&!m("settings:update")||!(et.auto_archive!==S.auto_archive||et.save_thumbnails!==S.save_thumbnails||et.capture_finish_photo!==S.capture_finish_photo||et.default_filament_cost!==S.default_filament_cost||et.currency!==S.currency||et.energy_cost_per_kwh!==S.energy_cost_per_kwh||et.energy_tracking_mode!==S.energy_tracking_mode||et.check_updates!==S.check_updates||(et.check_printer_firmware??!0)!==(S.check_printer_firmware??!0)||(et.include_beta_updates??!1)!==(S.include_beta_updates??!1)||et.notification_language!==S.notification_language||(et.bed_cooled_threshold??35)!==(S.bed_cooled_threshold??35)||et.ams_humidity_good!==S.ams_humidity_good||et.ams_humidity_fair!==S.ams_humidity_fair||et.ams_temp_good!==S.ams_temp_good||et.ams_temp_fair!==S.ams_temp_fair||et.ams_history_retention_days!==S.ams_history_retention_days||et.disable_filament_warnings!==S.disable_filament_warnings||et.prefer_lowest_filament!==S.prefer_lowest_filament||(et.queue_drying_enabled??!1)!==(S.queue_drying_enabled??!1)||(et.queue_drying_block??!1)!==(S.queue_drying_block??!1)||(et.ambient_drying_enabled??!1)!==(S.ambient_drying_enabled??!1)||(et.drying_presets??"")!==(S.drying_presets??"")||et.per_printer_mapping_expanded!==S.per_printer_mapping_expanded||et.date_format!==S.date_format||et.time_format!==S.time_format||et.default_printer_id!==S.default_printer_id||et.ftp_retry_enabled!==S.ftp_retry_enabled||et.ftp_retry_count!==S.ftp_retry_count||et.ftp_retry_delay!==S.ftp_retry_delay||et.ftp_timeout!==S.ftp_timeout||et.mqtt_enabled!==S.mqtt_enabled||et.mqtt_broker!==S.mqtt_broker||et.mqtt_port!==S.mqtt_port||et.mqtt_username!==S.mqtt_username||et.mqtt_password!==S.mqtt_password||et.mqtt_topic_prefix!==S.mqtt_topic_prefix||et.mqtt_use_tls!==S.mqtt_use_tls||et.external_url!==S.external_url||et.ha_enabled!==S.ha_enabled||et.ha_url!==S.ha_url||et.ha_token!==S.ha_token||(et.library_archive_mode??"ask")!==(S.library_archive_mode??"ask")||Number(et.library_disk_warning_gb??5)!==Number(S.library_disk_warning_gb??5)||(et.camera_view_mode??"window")!==(S.camera_view_mode??"window")||(et.preferred_slicer??"bambu_studio")!==(S.preferred_slicer??"bambu_studio")||(et.use_slicer_api??!1)!==(S.use_slicer_api??!1)||(et.orcaslicer_api_url??"")!==(S.orcaslicer_api_url??"")||(et.bambu_studio_api_url??"")!==(S.bambu_studio_api_url??"")||et.prometheus_enabled!==S.prometheus_enabled||et.prometheus_token!==S.prometheus_token||(et.user_notifications_enabled??!0)!==(S.user_notifications_enabled??!0)||(et.default_bed_levelling??!0)!==(S.default_bed_levelling??!0)||(et.default_flow_cali??!1)!==(S.default_flow_cali??!1)||(et.default_vibration_cali??!0)!==(S.default_vibration_cali??!0)||(et.default_layer_inspect??!1)!==(S.default_layer_inspect??!1)||(et.default_timelapse??!1)!==(S.default_timelapse??!1)||(et.stagger_group_size??2)!==(S.stagger_group_size??2)||(et.stagger_interval_minutes??5)!==(S.stagger_interval_minutes??5)||(et.require_plate_clear??!1)!==(S.require_plate_clear??!1)))&&!ws.current)return dl.current&&clearTimeout(dl.current),dl.current=setTimeout(()=>{if(ws.current)return;ws.current=!0;const Rt={auto_archive:S.auto_archive,save_thumbnails:S.save_thumbnails,capture_finish_photo:S.capture_finish_photo,default_filament_cost:S.default_filament_cost,currency:S.currency,energy_cost_per_kwh:S.energy_cost_per_kwh,energy_tracking_mode:S.energy_tracking_mode,check_updates:S.check_updates,check_printer_firmware:S.check_printer_firmware,include_beta_updates:S.include_beta_updates,notification_language:S.notification_language,bed_cooled_threshold:S.bed_cooled_threshold,ams_humidity_good:S.ams_humidity_good,ams_humidity_fair:S.ams_humidity_fair,ams_temp_good:S.ams_temp_good,ams_temp_fair:S.ams_temp_fair,ams_history_retention_days:S.ams_history_retention_days,disable_filament_warnings:S.disable_filament_warnings,prefer_lowest_filament:S.prefer_lowest_filament,queue_drying_enabled:S.queue_drying_enabled,queue_drying_block:S.queue_drying_block,ambient_drying_enabled:S.ambient_drying_enabled,drying_presets:S.drying_presets,per_printer_mapping_expanded:S.per_printer_mapping_expanded,date_format:S.date_format,time_format:S.time_format,default_printer_id:S.default_printer_id,ftp_retry_enabled:S.ftp_retry_enabled,ftp_retry_count:S.ftp_retry_count,ftp_retry_delay:S.ftp_retry_delay,ftp_timeout:S.ftp_timeout,mqtt_enabled:S.mqtt_enabled,mqtt_broker:S.mqtt_broker,mqtt_port:S.mqtt_port,mqtt_username:S.mqtt_username,mqtt_password:S.mqtt_password,mqtt_topic_prefix:S.mqtt_topic_prefix,mqtt_use_tls:S.mqtt_use_tls,external_url:S.external_url,ha_enabled:S.ha_enabled,ha_url:S.ha_url,ha_token:S.ha_token,library_archive_mode:S.library_archive_mode,library_disk_warning_gb:S.library_disk_warning_gb,camera_view_mode:S.camera_view_mode,preferred_slicer:S.preferred_slicer,use_slicer_api:S.use_slicer_api,orcaslicer_api_url:S.orcaslicer_api_url,bambu_studio_api_url:S.bambu_studio_api_url,prometheus_enabled:S.prometheus_enabled,prometheus_token:S.prometheus_token,user_notifications_enabled:S.user_notifications_enabled,default_bed_levelling:S.default_bed_levelling,default_flow_cali:S.default_flow_cali,default_vibration_cali:S.default_vibration_cali,default_layer_inspect:S.default_layer_inspect,default_timelapse:S.default_timelapse,stagger_group_size:S.stagger_group_size,stagger_interval_minutes:S.stagger_interval_minutes,require_plate_clear:S.require_plate_clear};Pu.mutate(Rt)},500),()=>{dl.current&&clearTimeout(dl.current)}},[S,et,Pu,l,m,o,i]);const _n=y.useCallback((Se,Rt)=>{if(l&&!m("settings:update")){o(i("settings.toast.noPermissionUpdate"),"error");return}E(an=>an?{...an,[Se]:Rt}:null)},[l,m,o,i]),Ro=async(Se,Rt,an)=>{if(!Rt){o(i("settings.toast.enterCameraUrl"),"error");return}Le(An=>({...An,[Se]:!0})),mt(An=>({...An,[Se]:null}));try{const An=await se.testExternalCamera(Se,Rt,an);mt(Bn=>({...Bn,[Se]:An})),An.success?o(i("settings.toast.cameraConnected",{resolution:An.resolution||""}),"success"):o(An.error||i("settings.toast.connectionFailed"),"error")}catch(An){const Bn=An instanceof Error?An.message:i("settings.toast.testFailed");mt(ba=>({...ba,[Se]:{success:!1,error:Bn}})),o(Bn,"error")}finally{Le(An=>({...An,[Se]:!1}))}},[gf,_d]=y.useState({}),kd=y.useRef({}),Nd=y.useRef(new Set),[bf,bb]=y.useState({}),Ul=y.useRef({}),xf=y.useRef(new Set);y.useEffect(()=>{if(zn){const Se={},Rt={};zn.forEach(an=>{an.external_camera_url&&!Nd.current.has(an.id)&&(Se[an.id]=an.external_camera_url,Nd.current.add(an.id)),an.external_camera_snapshot_url&&!xf.current.has(an.id)&&(Rt[an.id]=an.external_camera_snapshot_url,xf.current.add(an.id))}),Object.keys(Se).length>0&&_d(an=>({...an,...Se})),Object.keys(Rt).length>0&&bb(an=>({...an,...Rt}))}},[zn]);const xb=(Se,Rt)=>{_d(an=>({...an,[Se]:Rt})),kd.current[Se]&&clearTimeout(kd.current[Se]),kd.current[Se]=setTimeout(()=>{Tu.mutate({id:Se,data:{external_camera_url:Rt||null}})},800)},fv=(Se,Rt)=>{bb(an=>({...an,[Se]:Rt})),Ul.current[Se]&&clearTimeout(Ul.current[Se]),Ul.current[Se]=setTimeout(()=>{Tu.mutate({id:Se,data:{external_camera_snapshot_url:Rt||null}})},800)},yf=(Se,Rt)=>{const an={};Rt.type!==void 0&&(an.external_camera_type=Rt.type||null),Rt.enabled!==void 0&&(an.external_camera_enabled=Rt.enabled),Rt.rotation!==void 0&&(an.camera_rotation=Rt.rotation),Tu.mutate({id:Se,data:an})};if(jt||!S)return r.jsx("div",{className:"p-4 md:p-8 flex justify-center",children:r.jsx(pt,{className:"w-8 h-8 text-bambu-green animate-spin"})});const Oc=fat().map(Se=>({...Se,label:i(Se.labelKey,Se.labelFallback??Se.labelKey)})),Qi=me.trim().toLowerCase(),fi=Qi?Oc.filter(Se=>Se.label.toLowerCase().includes(Qi)||Se.keywords.toLowerCase().includes(Qi)).slice(0,8):[],Au=Se=>{K(Se.tab),Se.subTab&&G(Se.subTab),be(""),setTimeout(()=>{const Rt=document.getElementById(Se.anchor);Rt&&(Rt.scrollIntoView({behavior:"smooth",block:"start"}),Rt.classList.add("ring-2","ring-bambu-green"),setTimeout(()=>Rt.classList.remove("ring-2","ring-bambu-green"),1500))},50)};return r.jsx(xve,{density:"dense",children:r.jsxs("div",{className:"p-4 md:p-8",children:[r.jsxs("div",{className:"mb-4 flex flex-col sm:flex-row sm:items-center sm:justify-between gap-3",children:[r.jsxs("div",{children:[r.jsxs("h1",{className:"text-2xl font-bold text-white flex items-center gap-3",children:[r.jsx(gy,{className:"w-7 h-7 text-bambu-green"}),i("settings.title")]}),r.jsx("p",{className:"text-bambu-gray mt-1",children:i("settings.configureBambuddy")})]}),r.jsxs("div",{className:"relative sm:w-72",children:[r.jsx(Sr,{className:"w-4 h-4 text-bambu-gray absolute left-3 top-1/2 -translate-y-1/2 pointer-events-none"}),r.jsx("input",{type:"text",value:me,onChange:Se=>be(Se.target.value),placeholder:i("settings.searchPlaceholder","Search settings…"),className:"w-full pl-9 pr-8 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green"}),me&&r.jsx("button",{onClick:()=>be(""),className:"absolute right-2 top-1/2 -translate-y-1/2 p-1 text-bambu-gray hover:text-white","aria-label":"Clear",children:r.jsx(Ht,{className:"w-3.5 h-3.5"})}),fi.length>0&&r.jsx("div",{className:"absolute top-full left-0 right-0 mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl z-30 overflow-hidden",children:fi.map(Se=>r.jsxs("button",{onClick:()=>Au(Se),className:"w-full px-3 py-2 text-left hover:bg-bambu-dark-tertiary transition-colors border-b border-bambu-dark-tertiary last:border-b-0",children:[r.jsx("p",{className:"text-sm text-white",children:Se.label}),r.jsxs("p",{className:"text-xs text-bambu-gray",children:[i(`settings.tabs.${Se.tab==="virtual-printer"?"virtualPrinter":Se.tab==="failure-detection"?"failureDetection":Se.tab}`),Se.subTab?` › ${i(`settings.tabs.${Se.subTab}`,Se.subTab)}`:""]})]},Se.anchor))}),Qi&&fi.length===0&&r.jsx("div",{className:"absolute top-full left-0 right-0 mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl z-30 p-3",children:r.jsx("p",{className:"text-xs text-bambu-gray italic",children:i("settings.noSearchResults","No matching settings.")})})]})]}),r.jsxs("div",{className:"flex flex-col lg:flex-row gap-4 lg:gap-6",children:[r.jsxs("nav",{className:"flex flex-wrap gap-1 border-b border-bambu-dark-tertiary lg:flex-col lg:flex-nowrap lg:gap-0 lg:border-b-0 lg:border-r lg:w-48 lg:flex-shrink-0 lg:self-start lg:sticky lg:top-4",children:[r.jsxs("button",{onClick:()=>K("general"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${O==="general"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[r.jsx(gy,{className:"w-4 h-4"}),i("settings.tabs.general")]}),r.jsxs("button",{onClick:()=>K("plugs"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${O==="plugs"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[r.jsx(xc,{className:"w-4 h-4"}),i("settings.tabs.smartPlugs"),Ge&&Ge.length>0&&r.jsx("span",{className:"text-xs bg-bambu-dark-tertiary px-1.5 py-0.5 rounded-full",children:Ge.length})]}),r.jsxs("button",{onClick:()=>K("notifications"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${O==="notifications"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[r.jsx(kh,{className:"w-4 h-4"}),i("settings.tabs.notifications"),wn&&wn.length>0&&r.jsx("span",{className:"text-xs bg-bambu-dark-tertiary px-1.5 py-0.5 rounded-full",children:wn.length})]}),r.jsxs("button",{onClick:()=>K("queue"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${O==="queue"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[r.jsx(jw,{className:"w-4 h-4"}),i("settings.tabs.queue","Workflow")]}),r.jsxs("button",{onClick:()=>K("filament"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${O==="filament"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[r.jsx(jge,{className:"w-4 h-4"}),i("settings.tabs.filament")]}),r.jsxs("button",{onClick:()=>K("network"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${O==="network"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[r.jsx(Ah,{className:"w-4 h-4"}),i("settings.tabs.network"),r.jsx("span",{className:`w-2 h-2 rounded-full ${vs?.enabled?"bg-green-400":"bg-gray-500"}`})]}),r.jsxs("button",{onClick:()=>K("apikeys"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${O==="apikeys"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[r.jsx(vo,{className:"w-4 h-4"}),i("settings.tabs.apiKeys"),Cn&&Cn.length>0&&r.jsx("span",{className:"text-xs bg-bambu-dark-tertiary px-1.5 py-0.5 rounded-full",children:Cn.length})]}),r.jsxs("button",{onClick:()=>K("virtual-printer"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${O==="virtual-printer"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[r.jsx(pr,{className:"w-4 h-4"}),i("settings.tabs.virtualPrinter"),r.jsx("span",{className:`w-2 h-2 rounded-full ${ca?"bg-green-400":"bg-gray-500"}`})]}),r.jsxs("button",{onClick:()=>K("spoolbuddy"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${O==="spoolbuddy"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[r.jsx(FZ,{className:"w-4 h-4"}),i("settings.tabs.spoolbuddy"),da>0&&r.jsx("span",{className:"text-xs bg-bambu-dark-tertiary px-1.5 py-0.5 rounded-full",children:da}),r.jsx("span",{className:`w-2 h-2 rounded-full ${Ki?"bg-green-400":"bg-gray-500"}`})]}),r.jsxs("button",{onClick:()=>K("failure-detection"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${O==="failure-detection"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[r.jsx(LZ,{className:"w-4 h-4"}),i("settings.tabs.failureDetection"),r.jsx("span",{className:`w-2 h-2 rounded-full ${bd?"bg-green-400":"bg-gray-500"}`})]}),r.jsxs("button",{onClick:()=>K("users"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${O==="users"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[r.jsx(gm,{className:"w-4 h-4"}),i("settings.tabs.users"),l&&r.jsx("span",{className:"w-2 h-2 rounded-full bg-green-400"})]}),r.jsxs("button",{onClick:()=>K("backup"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${O==="backup"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[r.jsx(hc,{className:"w-4 h-4"}),i("settings.tabs.backup"),r.jsx("span",{className:`w-2 h-2 rounded-full ${po?.is_authenticated&&zl?.configured&&zl?.enabled||et?.local_backup_enabled?"bg-green-400":"bg-gray-500"}`})]})]}),r.jsxs("div",{className:"flex-1 min-w-0",children:[O==="general"&&r.jsxs("div",{className:"flex flex-col lg:flex-row gap-4 lg:gap-6",children:[r.jsxs("div",{className:"space-y-3 flex-1 lg:max-w-xl",children:[r.jsxs(Ct,{id:"card-general",children:[r.jsx(pn,{children:r.jsx("h2",{className:"text-lg font-semibold text-white",children:i("settings.general")})}),r.jsxs(At,{className:"space-y-3",children:[r.jsxs("div",{children:[r.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[r.jsx(no,{className:"w-4 h-4 inline mr-1"}),i("settings.language")]}),r.jsxs("div",{className:"relative",children:[r.jsx("select",{value:s.language,onChange:Se=>{const Rt=Se.target.value;if(l&&!m("settings:update")){o(i("settings.toast.noPermissionUpdate"),"error");return}s.changeLanguage(Rt),Pu.mutate({language:Rt})},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:$H.map(Se=>r.jsxs("option",{value:Se.code,children:[Se.nativeName," (",Se.name,")"]},Se.code))}),r.jsx(Ln,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}),r.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:i("settings.languageDescription")})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:i("settings.defaultView")}),r.jsxs("div",{className:"relative",children:[r.jsx("select",{value:W,onChange:Se=>Xe(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:vm.map(Se=>r.jsx("option",{value:Se.to,children:i(Se.labelKey)},Se.id))}),r.jsx(Ln,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}),r.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:i("settings.defaultViewDescription")})]}),r.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:i("settings.dateFormat")}),r.jsxs("div",{className:"relative",children:[r.jsxs("select",{value:S.date_format||"system",onChange:Se=>_n("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:[r.jsx("option",{value:"system",children:i("settings.systemDefault")}),r.jsx("option",{value:"us",children:i("settings.dateFormatUs")}),r.jsx("option",{value:"eu",children:i("settings.dateFormatEu")}),r.jsx("option",{value:"iso",children:i("settings.dateFormatIso")})]}),r.jsx(Ln,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:i("settings.timeFormat")}),r.jsxs("div",{className:"relative",children:[r.jsxs("select",{value:S.time_format||"system",onChange:Se=>_n("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:[r.jsx("option",{value:"system",children:i("settings.systemDefault")}),r.jsx("option",{value:"12h",children:i("settings.timeFormat12")}),r.jsx("option",{value:"24h",children:i("settings.timeFormat24")})]}),r.jsx(Ln,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]})]})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:i("settings.defaultPrinter")}),r.jsxs("div",{className:"relative",children:[r.jsxs("select",{value:S.default_printer_id??"",onChange:Se=>_n("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:[r.jsx("option",{value:"",children:i("settings.noDefaultPrinter")}),zn?.map(Se=>r.jsx("option",{value:Se.id,children:Se.name},Se.id))]}),r.jsx(Ln,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}),r.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:i("settings.defaultPrinterDescription")})]}),r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-white",children:i("settings.sidebarOrder")}),r.jsxs("p",{className:"text-sm text-bambu-gray",children:[i("settings.sidebarOrderDescription"),l&&m("settings:update")&&` ${i("settings.sidebarOrderSetDefaultHint")}`]})]}),r.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[r.jsxs(Me,{variant:"secondary",size:"sm",onClick:Ze,children:[r.jsx(gs,{className:"w-4 h-4"}),i("settings.reset")]}),l&&m("settings:update")&&r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:"text-sm text-bambu-gray whitespace-nowrap",children:i("settings.setDefault")}),r.jsx(En,{checked:Ke,onChange:bt,disabled:jt})]})]})]})]})]}),r.jsxs(Ct,{id:"card-appearance",children:[r.jsx(pn,{children:r.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[r.jsx(jS,{className:"w-5 h-5"}),i("settings.appearance")]})}),r.jsxs(At,{className:"space-y-3",children:[r.jsxs("div",{className:`space-y-3 p-4 rounded-lg border ${p==="dark"?"border-bambu-green bg-bambu-green/5":"border-bambu-dark-tertiary"}`,children:[r.jsxs("h3",{className:"text-sm font-medium text-white flex items-center gap-2",children:[i("settings.darkMode"),p==="dark"&&r.jsx("span",{className:"text-xs text-bambu-green",children:i("settings.active")})]}),r.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:i("settings.background")}),r.jsxs("select",{value:b,onChange:Se=>{C(Se.target.value),o(i("settings.toast.settingsSaved"),"success")},className:"w-full px-2 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[r.jsx("option",{value:"neutral",children:i("settings.bgNeutral")}),r.jsx("option",{value:"warm",children:i("settings.bgWarm")}),r.jsx("option",{value:"cool",children:i("settings.bgCool")}),r.jsx("option",{value:"oled",children:i("settings.bgOled")}),r.jsx("option",{value:"slate",children:i("settings.bgSlate")}),r.jsx("option",{value:"forest",children:i("settings.bgForest")})]})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:i("settings.accent")}),r.jsxs("select",{value:w,onChange:Se=>{P(Se.target.value),o(i("settings.toast.settingsSaved"),"success")},className:"w-full px-2 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[r.jsx("option",{value:"green",children:i("settings.accentGreen")}),r.jsx("option",{value:"teal",children:i("settings.accentTeal")}),r.jsx("option",{value:"blue",children:i("settings.accentBlue")}),r.jsx("option",{value:"orange",children:i("settings.accentOrange")}),r.jsx("option",{value:"purple",children:i("settings.accentPurple")}),r.jsx("option",{value:"red",children:i("settings.accentRed")})]})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:i("settings.style")}),r.jsxs("select",{value:f,onChange:Se=>{N(Se.target.value),o(i("settings.toast.settingsSaved"),"success")},className:"w-full px-2 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[r.jsx("option",{value:"classic",children:i("settings.styleClassic")}),r.jsx("option",{value:"glow",children:i("settings.styleGlow")}),r.jsx("option",{value:"vibrant",children:i("settings.styleVibrant")})]})]})]})]}),r.jsxs("div",{className:`space-y-3 p-4 rounded-lg border ${p==="light"?"border-bambu-green bg-bambu-green/5":"border-bambu-dark-tertiary"}`,children:[r.jsxs("h3",{className:"text-sm font-medium text-white flex items-center gap-2",children:[i("settings.lightMode"),p==="light"&&r.jsx("span",{className:"text-xs text-bambu-green",children:i("settings.active")})]}),r.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:i("settings.background")}),r.jsxs("select",{value:x,onChange:Se=>{A(Se.target.value),o(i("settings.toast.settingsSaved"),"success")},className:"w-full px-2 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[r.jsx("option",{value:"neutral",children:i("settings.bgNeutral")}),r.jsx("option",{value:"warm",children:i("settings.bgWarm")}),r.jsx("option",{value:"cool",children:i("settings.bgCool")})]})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:i("settings.accent")}),r.jsxs("select",{value:_,onChange:Se=>{F(Se.target.value),o(i("settings.toast.settingsSaved"),"success")},className:"w-full px-2 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[r.jsx("option",{value:"green",children:i("settings.accentGreen")}),r.jsx("option",{value:"teal",children:i("settings.accentTeal")}),r.jsx("option",{value:"blue",children:i("settings.accentBlue")}),r.jsx("option",{value:"orange",children:i("settings.accentOrange")}),r.jsx("option",{value:"purple",children:i("settings.accentPurple")}),r.jsx("option",{value:"red",children:i("settings.accentRed")})]})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:i("settings.style")}),r.jsxs("select",{value:g,onChange:Se=>{T(Se.target.value),o(i("settings.toast.settingsSaved"),"success")},className:"w-full px-2 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[r.jsx("option",{value:"classic",children:i("settings.styleClassic")}),r.jsx("option",{value:"glow",children:i("settings.styleGlow")}),r.jsx("option",{value:"vibrant",children:i("settings.styleVibrant")})]})]})]})]}),r.jsx("p",{className:"text-xs text-bambu-gray",children:i("settings.themeToggleHint")})]})]}),r.jsxs(Ct,{id:"card-archive",children:[r.jsx(pn,{children:r.jsx("h2",{className:"text-lg font-semibold text-white",children:i("settings.archiveSettings")})}),r.jsxs(At,{className:"space-y-3",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-white",children:i("settings.autoArchivePrints")}),r.jsx("p",{className:"text-sm text-bambu-gray",children:i("settings.autoArchiveDescription")})]}),r.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:S.auto_archive,onChange:Se=>_n("auto_archive",Se.target.checked),className:"sr-only peer"}),r.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"})]})]}),r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-white",children:i("settings.saveThumbnails")}),r.jsx("p",{className:"text-sm text-bambu-gray",children:i("settings.saveThumbnailsDescription")})]}),r.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:S.save_thumbnails,onChange:Se=>_n("save_thumbnails",Se.target.checked),className:"sr-only peer"}),r.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"})]})]}),r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-white",children:i("settings.captureFinishPhoto")}),r.jsx("p",{className:"text-sm text-bambu-gray",children:i("settings.captureFinishPhotoDescription")})]}),r.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:S.capture_finish_photo,onChange:Se=>_n("capture_finish_photo",Se.target.checked),className:"sr-only peer"}),r.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.capture_finish_photo&&Lc&&!Lc.installed&&r.jsxs("div",{className:"flex items-start gap-2 p-3 bg-yellow-500/10 border border-yellow-500/30 rounded-lg",children:[r.jsx(Nn,{className:"w-5 h-5 text-yellow-500 flex-shrink-0 mt-0.5"}),r.jsxs("div",{className:"text-sm",children:[r.jsx("p",{className:"text-yellow-500 font-medium",children:i("settings.ffmpegNotInstalled")}),r.jsx("p",{className:"text-bambu-gray mt-1",children:i("settings.ffmpegRequired")})]})]}),Ol&&mo&&r.jsxs("div",{className:"border-t border-bambu-dark-tertiary pt-3 mt-3 space-y-3",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-white",children:i("archiveAutoPurge.enableLabel")}),r.jsx("p",{className:"text-sm text-bambu-gray",children:i("archiveAutoPurge.enableDescription")})]}),r.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:mo.enabled,onChange:Se=>Rc({enabled:Se.target.checked}),className:"sr-only peer"}),r.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"})]})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:i("archiveAutoPurge.ageLabel")}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("input",{type:"number",min:7,max:3650,disabled:!mo.enabled,value:mo.days,onChange:Se=>Rc({days:Math.max(7,Math.min(3650,parseInt(Se.target.value||"0",10)||0))}),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 disabled:opacity-50"}),r.jsx("span",{className:"text-bambu-gray",children:i("archiveAutoPurge.days")})]}),r.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:i("archiveAutoPurge.ageDescription")})]})]})]})]})]}),r.jsxs("div",{className:"space-y-3 flex-1 lg:max-w-md",children:[r.jsxs(Ct,{id:"card-camera",children:[r.jsx(pn,{children:r.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[r.jsx(iC,{className:"w-5 h-5 text-bambu-green"}),i("settings.camera")]})}),r.jsxs(At,{className:"space-y-3",children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:i("settings.cameraViewMode")}),r.jsxs("select",{value:S.camera_view_mode??"window",onChange:Se=>_n("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:[r.jsx("option",{value:"window",children:i("settings.newWindow")}),r.jsx("option",{value:"embedded",children:i("settings.embeddedOverlay")})]}),r.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:S.camera_view_mode==="embedded"?i("settings.cameraOverlayDescription"):i("settings.cameraWindowDescription")})]}),r.jsxs("div",{className:"border-t border-bambu-dark-tertiary pt-4 mt-4",children:[r.jsx("h3",{className:"text-sm font-medium text-white mb-2",children:i("settings.externalCameras")}),r.jsx("p",{className:"text-xs text-bambu-gray mb-3",children:i("settings.externalCamerasDescription")}),zn&&zn.length>0?r.jsx("div",{className:"space-y-3",children:zn.map(Se=>r.jsxs("div",{className:"p-3 bg-bambu-dark rounded-lg",children:[r.jsxs("div",{className:"flex items-center justify-between mb-2",children:[r.jsx("span",{className:"text-white font-medium text-sm",children:Se.name}),r.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:Se.external_camera_enabled,onChange:Rt=>yf(Se.id,{enabled:Rt.target.checked}),className:"sr-only peer"}),r.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&&r.jsxs("div",{className:"space-y-2 mt-2",children:[r.jsx("input",{type:"text",placeholder:Se.external_camera_type==="usb"?i("settings.cameraPlaceholderUsb"):i("settings.cameraPlaceholderUrl"),value:gf[Se.id]??Se.external_camera_url??"",onChange:Rt=>xb(Se.id,Rt.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"}),r.jsxs("div",{className:"flex gap-2",children:[r.jsxs("select",{value:Se.external_camera_type||"mjpeg",onChange:Rt=>yf(Se.id,{type:Rt.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:[r.jsx("option",{value:"mjpeg",children:i("settings.cameraTypeMjpeg")}),r.jsx("option",{value:"rtsp",children:i("settings.cameraTypeRtsp")}),r.jsx("option",{value:"snapshot",children:i("settings.cameraTypeSnapshot")}),r.jsx("option",{value:"usb",children:i("settings.cameraTypeUsb")})]}),r.jsx(Me,{size:"sm",variant:"secondary",onClick:()=>Ro(Se.id,gf[Se.id]??Se.external_camera_url??"",Se.external_camera_type||"mjpeg"),disabled:he[Se.id]||!(gf[Se.id]??Se.external_camera_url),children:he[Se.id]?r.jsx(pt,{className:"w-4 h-4 animate-spin"}):i("settings.test")})]}),Re[Se.id]&&r.jsx("div",{className:`text-xs flex items-center gap-1 ${Re[Se.id]?.success?"text-green-500":"text-red-500"}`,children:Re[Se.id]?.success?r.jsxs(r.Fragment,{children:[r.jsx(wr,{className:"w-3 h-3"}),i("settings.connected"),Re[Se.id]?.resolution&&` (${Re[Se.id]?.resolution})`]}):r.jsxs(r.Fragment,{children:[r.jsx(Da,{className:"w-3 h-3"}),Re[Se.id]?.error||i("settings.toast.connectionFailed")]})}),(Se.external_camera_type==="mjpeg"||Se.external_camera_type==="rtsp"||Se.external_camera_type==="usb")&&r.jsxs("div",{className:"space-y-1",children:[r.jsx("label",{className:"text-xs text-bambu-gray",children:i("settings.cameraSnapshotUrl","Snapshot URL (optional)")}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx("input",{type:"text",placeholder:i("settings.cameraSnapshotUrlPlaceholder","http://192.168.1.61:1984/api/frame.jpeg?src=printer"),value:bf[Se.id]??Se.external_camera_snapshot_url??"",onChange:Rt=>fv(Se.id,Rt.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"}),r.jsx(Me,{size:"sm",variant:"secondary",onClick:()=>Ro(Se.id,bf[Se.id]??Se.external_camera_snapshot_url??"","snapshot"),disabled:he[Se.id]||!(bf[Se.id]??Se.external_camera_snapshot_url),children:he[Se.id]?r.jsx(pt,{className:"w-4 h-4 animate-spin"}):i("settings.test")})]}),r.jsx("p",{className:"text-xs text-bambu-gray opacity-75",children:i("settings.cameraSnapshotUrlHelp","Single-frame URL used for notification thumbnails, finish photos, timelapse and plate detection. Leave blank to capture from the live stream above. Useful for go2rtc (/api/frame.jpeg) and IP cameras with a dedicated snapshot endpoint.")})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("label",{className:"text-xs text-bambu-gray",children:i("settings.cameraRotation")}),r.jsxs("select",{value:Se.camera_rotation||0,onChange:Rt=>yf(Se.id,{rotation:parseInt(Rt.target.value)}),className:"px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-xs focus:border-bambu-green focus:outline-none",children:[r.jsx("option",{value:0,children:"0°"}),r.jsx("option",{value:90,children:"90°"}),r.jsx("option",{value:180,children:"180°"}),r.jsx("option",{value:270,children:"270°"})]})]})]})]},Se.id))}):r.jsx("p",{className:"text-xs text-bambu-gray italic",children:i("settings.noPrintersConfigured")})]})]})]}),r.jsxs(Ct,{id:"card-cost",children:[r.jsx(pn,{children:r.jsx("h2",{className:"text-lg font-semibold text-white",children:i("settings.costTracking")})}),r.jsxs(At,{className:"space-y-3",children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:i("settings.currency")}),r.jsx("select",{value:S.currency,onChange:Se=>_n("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:b7e.map(Se=>r.jsx("option",{value:Se.code,children:Se.label},Se.code))})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:i("settings.defaultFilamentCost")}),r.jsxs("div",{className:"relative",children:[r.jsx("span",{className:"absolute left-3 top-1/2 -translate-y-1/2 text-bambu-gray text-sm pointer-events-none",children:Vo(S.currency)}),r.jsx("input",{type:"number",step:"0.01",min:"0",value:S.default_filament_cost,onChange:Se=>_n("default_filament_cost",parseFloat(Se.target.value)||0),style:{paddingLeft:`${Math.max(2,Vo(S.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"})]})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:i("settings.electricityCost")}),r.jsxs("div",{className:"relative",children:[r.jsx("span",{className:"absolute left-3 top-1/2 -translate-y-1/2 text-bambu-gray text-sm pointer-events-none",children:Vo(S.currency)}),r.jsx("input",{type:"number",step:"0.001",min:"0",value:S.energy_cost_per_kwh,onChange:Se=>_n("energy_cost_per_kwh",parseFloat(Se.target.value)||0),style:{paddingLeft:`${Math.max(2,Vo(S.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"})]})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:i("settings.energyDisplayMode")}),r.jsxs("select",{value:S.energy_tracking_mode||"total",onChange:Se=>_n("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:[r.jsx("option",{value:"print",children:i("settings.printsOnly")}),r.jsx("option",{value:"total",children:i("settings.totalConsumption")})]}),r.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:S.energy_tracking_mode==="print"?i("settings.energyModePrintDescription"):i("settings.energyModeTotalDescription")})]})]})]}),r.jsxs(Ct,{id:"card-filemanager",children:[r.jsx(pn,{children:r.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[r.jsx(Bs,{className:"w-5 h-5 text-bambu-green"}),i("settings.fileManager")]})}),r.jsxs(At,{className:"space-y-3",children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:i("settings.createArchiveEntry")}),r.jsxs("select",{value:S.library_archive_mode??"ask",onChange:Se=>_n("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:[r.jsx("option",{value:"always",children:i("settings.archiveMode.always")}),r.jsx("option",{value:"never",children:i("settings.archiveMode.never")}),r.jsx("option",{value:"ask",children:i("settings.archiveMode.ask")})]}),r.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:i("settings.createArchiveEntryDescription")})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:i("settings.lowDiskSpaceWarning")}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("input",{type:"number",min:"0.5",max:"100",step:"0.5",value:S.library_disk_warning_gb??5,onChange:Se=>_n("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"}),r.jsx("span",{className:"text-bambu-gray",children:"GB"})]}),r.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:i("settings.lowDiskSpaceDescription")})]}),Ft&&cn&&r.jsxs("div",{className:"border-t border-bambu-dark-tertiary pt-3 mt-3 space-y-3",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-white",children:i("libraryAutoPurge.enableLabel")}),r.jsx("p",{className:"text-sm text-bambu-gray",children:i("libraryAutoPurge.enableDescription")})]}),r.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:cn.auto_purge_enabled,onChange:Se=>Gt({auto_purge_enabled:Se.target.checked}),className:"sr-only peer"}),r.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"})]})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:i("libraryAutoPurge.ageLabel")}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("input",{type:"number",min:7,max:3650,disabled:!cn.auto_purge_enabled,value:cn.auto_purge_days,onChange:Se=>Gt({auto_purge_days:Math.max(7,Math.min(3650,parseInt(Se.target.value||"0",10)||0))}),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 disabled:opacity-50"}),r.jsx("span",{className:"text-bambu-gray",children:i("libraryAutoPurge.days")})]}),r.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:i("libraryAutoPurge.ageDescription")})]}),r.jsxs("label",{className:"flex items-center gap-2 text-sm text-white cursor-pointer",children:[r.jsx("input",{type:"checkbox",disabled:!cn.auto_purge_enabled,checked:cn.auto_purge_include_never_printed,onChange:Se=>Gt({auto_purge_include_never_printed:Se.target.checked}),className:"rounded border-gray-300 disabled:opacity-50"}),i("libraryAutoPurge.includeNeverPrinted")]})]})]})]})]}),r.jsxs("div",{className:"space-y-3 flex-1 lg:max-w-sm",children:[r.jsx(Yrt,{}),r.jsxs(Ct,{id:"card-updates",children:[r.jsx(pn,{children:r.jsx("h2",{className:"text-lg font-semibold text-white",children:i("settings.updates")})}),r.jsxs(At,{className:"space-y-3",children:[r.jsx("p",{className:"text-xs font-medium text-bambu-gray uppercase tracking-wider",children:i("settings.printerFirmware")}),r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-white",children:i("settings.checkPrinterFirmware")}),r.jsx("p",{className:"text-sm text-bambu-gray",children:i("settings.checkFirmwareDescription")})]}),r.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:S.check_printer_firmware??!0,onChange:Se=>_n("check_printer_firmware",Se.target.checked),className:"sr-only peer"}),r.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"})]})]}),r.jsx("div",{className:"border-t border-bambu-dark-tertiary pt-4",children:r.jsx("p",{className:"text-xs font-medium text-bambu-gray uppercase tracking-wider mb-4",children:i("settings.bambuddySoftware")})}),r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-white",children:i("settings.checkForUpdatesLabel")}),r.jsx("p",{className:"text-sm text-bambu-gray",children:i("settings.autoCheckDescription")})]}),r.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:S.check_updates,onChange:Se=>_n("check_updates",Se.target.checked),className:"sr-only peer"}),r.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"})]})]}),r.jsxs("div",{className:`flex items-center justify-between ${S.check_updates?"":"opacity-50"}`,children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-white",children:i("settings.includeBetaUpdates")}),r.jsx("p",{className:"text-sm text-bambu-gray",children:i("settings.includeBetaUpdatesDesc")})]}),r.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:S.include_beta_updates??!1,onChange:Se=>_n("include_beta_updates",Se.target.checked),disabled:!S.check_updates,className:"sr-only peer"}),r.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"})]})]}),r.jsxs("div",{children:[r.jsxs("div",{className:"flex items-center justify-between mb-2",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-white",children:i("settings.currentVersion")}),r.jsxs("p",{className:"text-sm text-bambu-gray",children:["v",$s?.version||"..."]})]}),r.jsxs(Me,{variant:"secondary",size:"sm",onClick:()=>mf(),disabled:il,children:[il?r.jsx(pt,{className:"w-4 h-4 animate-spin"}):r.jsx(sr,{className:"w-4 h-4"}),i("settings.checkNow")]})]}),Or?.update_available?r.jsxs("div",{className:"mt-4 p-3 bg-bambu-green/10 border border-bambu-green/30 rounded-lg",children:[r.jsxs("div",{className:"flex items-start justify-between",children:[r.jsxs("div",{children:[r.jsxs("p",{className:"text-bambu-green font-medium",children:["Update available: v",Or.latest_version]}),Or.release_name&&Or.release_name!==Or.latest_version&&r.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:Or.release_name})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[Or.release_notes&&r.jsx("button",{onClick:()=>We(!0),className:"text-bambu-gray hover:text-white transition-colors text-sm underline",children:i("settings.releaseNotes")}),Or.release_url&&r.jsx("a",{href:Or.release_url,target:"_blank",rel:"noopener noreferrer",className:"text-bambu-gray hover:text-white transition-colors",title:i("settings.viewReleaseOnGitHub"),children:r.jsx(Rr,{className:"w-4 h-4"})})]})]}),Xi?.status==="downloading"||Xi?.status==="installing"?r.jsxs("div",{className:"mt-3",children:[r.jsxs("div",{className:"flex items-center gap-2 text-sm text-bambu-gray",children:[r.jsx(pt,{className:"w-4 h-4 animate-spin"}),r.jsx("span",{children:Xi.message})]}),r.jsx("div",{className:"mt-2 w-full bg-bambu-dark-tertiary rounded-full h-2",children:r.jsx("div",{className:"bg-bambu-green h-2 rounded-full transition-all duration-300",style:{width:`${Xi.progress}%`}})})]}):Xi?.status==="complete"?r.jsx("div",{className:"mt-3 p-2 bg-bambu-green/20 rounded text-sm text-bambu-green",children:Xi.message}):Xi?.status==="error"?r.jsx("div",{className:"mt-3 p-2 bg-red-500/20 rounded text-sm text-red-400",children:Xi.error||Xi.message}):Or?.is_ha_addon?r.jsx("div",{className:"mt-3 p-3 bg-bambu-dark-tertiary rounded-lg",children:r.jsx("p",{className:"text-sm text-bambu-gray",children:i("settings.updateViaHomeAssistant")})}):Or?.is_docker?r.jsxs("div",{className:"mt-3 p-3 bg-bambu-dark-tertiary rounded-lg",children:[r.jsx("p",{className:"text-sm text-bambu-gray mb-2",children:i("settings.updateViaDocker")}),r.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"})]}):r.jsxs(Me,{className:"mt-3",onClick:()=>ff.mutate(),disabled:ff.isPending,children:[ff.isPending?r.jsx(pt,{className:"w-4 h-4 animate-spin"}):r.jsx(Yr,{className:"w-4 h-4"}),i("settings.installUpdate")]})]}):Or?.error?r.jsx("div",{className:"mt-2 p-2 bg-red-500/10 border border-red-500/30 rounded text-sm text-red-400",children:i("settings.failedToCheckUpdates",{error:Or.error})}):Or&&!Or.update_available?r.jsx("p",{className:"mt-2 text-sm text-bambu-gray",children:i("settings.latestVersionRunning")}):null]})]})]}),r.jsxs(Ct,{id:"card-data",children:[r.jsx(pn,{children:r.jsx("h2",{className:"text-lg font-semibold text-white",children:i("settings.dataManagement")})}),r.jsxs(At,{className:"space-y-3",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-white",children:i("settings.clearNotificationLogs")}),r.jsx("p",{className:"text-sm text-bambu-gray",children:i("settings.clearNotificationLogsDescription")})]}),r.jsxs(Me,{variant:"secondary",size:"sm",onClick:()=>xe(!0),children:[r.jsx(Jt,{className:"w-4 h-4"}),i("common.clear")]})]}),r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-white",children:i("settings.resetUiPreferences")}),r.jsx("p",{className:"text-sm text-bambu-gray",children:i("settings.resetUiPreferencesDescription")})]}),r.jsxs(Me,{variant:"secondary",size:"sm",onClick:()=>ze(!0),children:[r.jsx(Jt,{className:"w-4 h-4"}),i("settings.reset")]})]}),r.jsxs("div",{className:"pt-4 border-t border-bambu-dark-tertiary",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-white",children:i("settings.storageUsage","Storage Usage")}),r.jsx("p",{className:"text-sm text-bambu-gray",children:i("settings.storageUsageDescription","Breakdown of data usage by category")})]}),r.jsxs(Me,{variant:"secondary",size:"sm",onClick:He,disabled:zt||Ae,children:[r.jsx(sr,{className:`w-4 h-4 ${zt||Ae?"animate-spin":""}`}),i("common.refresh","Refresh")]})]}),r.jsx("div",{className:"mt-3",children:It?r.jsxs("div",{className:"flex items-center gap-2 text-sm text-bambu-gray",children:[r.jsx(pt,{className:"w-4 h-4 animate-spin"}),i("common.loading","Loading")]}):St?r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"w-full h-3 bg-bambu-dark rounded-full overflow-hidden flex",children:St.categories.filter(Se=>Se.bytes>0).map((Se,Rt)=>r.jsx("div",{className:`${uQ(Se.key,Rt)} h-full`,style:{width:`${Se.percent_of_total}%`},title:`${Se.label}: ${Se.formatted}`},Se.key))}),r.jsx("div",{className:"mt-3 flex flex-wrap gap-3",children:St.categories.filter(Se=>Se.bytes>0).map((Se,Rt)=>r.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[r.jsx("span",{className:`w-3 h-3 rounded-full ${uQ(Se.key,Rt)}`}),r.jsx("span",{className:"text-bambu-gray",children:Se.label}),r.jsx("span",{className:"text-white",children:Se.formatted}),r.jsxs("span",{className:"text-bambu-gray",children:["(",Se.percent_of_total.toFixed(1),"%)"]})]},Se.key))}),r.jsxs("div",{className:"mt-2 text-xs text-bambu-gray",children:[i("settings.storageUsageTotal","Total"),": ",r.jsx("span",{className:"text-white",children:St.total_formatted}),St.scan_errors>0&&r.jsxs("span",{className:"ml-2 text-amber-400",children:[i("settings.storageUsageErrors","Scan errors"),": ",St.scan_errors]})]}),St.other_breakdown?.length>0&&r.jsxs("div",{className:"mt-4",children:[r.jsx("p",{className:"text-xs text-bambu-gray mb-2",children:i("settings.storageUsageOtherBreakdown","Other breakdown")}),r.jsx("div",{className:"space-y-2",children:St.other_breakdown.map(Se=>r.jsxs("div",{className:"flex items-center justify-between text-xs",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:"text-white",children:Se.label}),r.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"?i("settings.storageUsageSystem","System"):i("settings.storageUsageData","Data")})]}),r.jsxs("div",{className:"flex items-center gap-2 text-bambu-gray",children:[r.jsx("span",{className:"text-white",children:Se.formatted}),r.jsxs("span",{children:["(",Se.percent_of_total.toFixed(1),"%)"]})]})]},`${Se.bucket}-${Se.kind}`))})]})]}):r.jsx("p",{className:"text-sm text-bambu-gray",children:i("settings.storageUsageUnavailable","Storage usage data is unavailable")})})]}),r.jsxs("div",{className:"flex items-center justify-between pt-4 border-t border-bambu-dark-tertiary",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-white",children:i("settings.backupRestore")}),r.jsx("p",{className:"text-sm text-bambu-gray",children:i("settings.backupRestoreDescription")})]}),r.jsxs(Me,{variant:"secondary",size:"sm",onClick:()=>K("backup"),children:[r.jsx(hc,{className:"w-4 h-4"}),i("settings.goToBackup")]})]})]})]})]})]}),O==="network"&&S&&r.jsxs("div",{className:"flex flex-col lg:flex-row gap-6",children:[r.jsxs("div",{className:"flex-1 lg:max-w-xl space-y-3",children:[r.jsxs(Ct,{id:"card-externalurl",children:[r.jsx(pn,{children:r.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[r.jsx(no,{className:"w-5 h-5 text-blue-400"}),i("settings.externalUrl")]})}),r.jsxs(At,{className:"space-y-3",children:[r.jsx("p",{className:"text-sm text-bambu-gray",children:i("settings.externalUrlDescription")}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:i("settings.bambuddyUrl")}),r.jsx("input",{type:"text",value:S.external_url??"",onChange:Se=>_n("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"}),r.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:i("settings.externalUrlHint")})]})]})]}),r.jsxs(Ct,{id:"card-ftpretry",children:[r.jsx(pn,{children:r.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[r.jsx(sr,{className:"w-5 h-5 text-blue-400"}),i("settings.ftpRetry")]})}),r.jsxs(At,{className:"space-y-3",children:[r.jsx("p",{className:"text-sm text-bambu-gray",children:i("settings.ftpRetryDescription")}),r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-white",children:i("settings.enableRetry")}),r.jsx("p",{className:"text-sm text-bambu-gray",children:i("settings.autoRetryDescription")})]}),r.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:S.ftp_retry_enabled??!0,onChange:Se=>_n("ftp_retry_enabled",Se.target.checked),className:"sr-only peer"}),r.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.ftp_retry_enabled&&r.jsxs("div",{className:"space-y-3 pt-2 border-t border-bambu-dark-tertiary",children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:i("settings.retryAttempts")}),r.jsxs("div",{className:"relative w-44",children:[r.jsx("select",{value:S.ftp_retry_count??3,onChange:Se=>_n("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=>r.jsx("option",{value:Se,children:i("settings.time",{count:Se})},Se))}),r.jsx(Ln,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:i("settings.retryDelay")}),r.jsxs("div",{className:"relative w-44",children:[r.jsx("select",{value:S.ftp_retry_delay??2,onChange:Se=>_n("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=>r.jsx("option",{value:Se,children:i("settings.second",{count:Se})},Se))}),r.jsx(Ln,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:i("settings.connectionTimeout")}),r.jsxs("div",{className:"relative w-44",children:[r.jsx("select",{value:S.ftp_timeout??30,onChange:Se=>_n("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,180,300].map(Se=>r.jsx("option",{value:Se,children:i("settings.nSeconds",{count:Se})},Se))}),r.jsx(Ln,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}),r.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:i("settings.increaseForWeakWifi")})]})]})]})]})]}),r.jsxs("div",{className:"flex-1 lg:max-w-xl space-y-3",children:[r.jsxs(Ct,{id:"card-ha",children:[r.jsx(pn,{children:r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[r.jsx(PS,{className:"w-5 h-5 text-bambu-green"}),i("settings.homeAssistant")]}),S.ha_enabled&&De&&r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:`w-2.5 h-2.5 rounded-full ${De.success?"bg-green-400":"bg-red-400"}`}),r.jsx("span",{className:`text-sm ${De.success?"text-green-400":"text-red-400"}`,children:De.success?i("settings.connected"):i("settings.disconnected")})]})]})}),r.jsxs(At,{className:"space-y-3",children:[r.jsx("p",{className:"text-sm text-bambu-gray",children:i("settings.homeAssistantFullDescription")}),r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{className:"flex-1",children:[r.jsx("p",{className:"text-white",children:i("settings.enableHomeAssistant")}),r.jsx("p",{className:"text-xs text-bambu-gray",children:i("settings.homeAssistantDescription")}),S.ha_env_managed&&r.jsxs("div",{className:"flex items-center gap-1 mt-1",children:[r.jsx(lc,{className:"w-3 h-3 text-bambu-green"}),r.jsx("span",{className:"text-xs text-bambu-green",children:i("settings.autoEnabledViaEnv")})]})]}),r.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:S.ha_enabled??!1,onChange:Se=>_n("ha_enabled",Se.target.checked),disabled:S.ha_env_managed,className:"sr-only peer"}),r.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.ha_env_managed?"opacity-60 cursor-not-allowed":""}`})]})]}),S.ha_enabled&&r.jsxs(r.Fragment,{children:[r.jsxs("div",{children:[r.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[i("settings.homeAssistantUrl"),S.ha_url_from_env&&r.jsx("span",{className:"ml-2 text-xs text-bambu-green",children:i("settings.environmentManagedLabel")})]}),r.jsxs("div",{className:"relative",children:[r.jsx("input",{type:"text",value:S.ha_url??"",onChange:Se=>_n("ha_url",Se.target.value),placeholder:"http://192.168.1.100:8123",disabled:S.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 ${S.ha_url_from_env?"opacity-60 cursor-not-allowed":""}`}),S.ha_url_from_env&&r.jsx(lc,{className:"absolute right-3 top-2.5 w-4 h-4 text-bambu-gray"})]}),S.ha_url_from_env&&r.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:i("settings.urlFromEnvReadOnly")})]}),r.jsxs("div",{children:[r.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[i("settings.longLivedAccessToken"),S.ha_token_from_env&&r.jsx("span",{className:"ml-2 text-xs text-bambu-green",children:i("settings.environmentManagedLabel")})]}),r.jsxs("div",{className:"relative",children:[r.jsx("input",{type:"password",value:S.ha_token??"",onChange:Se=>_n("ha_token",Se.target.value),placeholder:"eyJ0eXAiOiJKV1QiLC...",disabled:S.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 ${S.ha_token_from_env?"opacity-60 cursor-not-allowed":""}`}),S.ha_token_from_env&&r.jsx(lc,{className:"absolute right-3 top-2.5 w-4 h-4 text-bambu-gray"})]}),S.ha_token_from_env?r.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:i("settings.tokenFromEnvReadOnly")}):r.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:i("settings.haTokenHint")})]}),S.ha_url&&S.ha_token&&r.jsx("div",{className:"pt-2 border-t border-bambu-dark-tertiary",children:r.jsxs(Me,{variant:"secondary",size:"sm",disabled:$e,onClick:async()=>{Je(!0),je(null);try{const Se=await se.testHAConnection(S.ha_url,S.ha_token);je(Se)}catch(Se){je({success:!1,message:null,error:Se instanceof Error?Se.message:i("common.unknownError")})}finally{Je(!1)}},children:[$e?r.jsx(pt,{className:"w-4 h-4 animate-spin"}):r.jsx(Ah,{className:"w-4 h-4"}),i("settings.testConnection")]})})]})]})]}),r.jsxs(Ct,{id:"card-mqtt",children:[r.jsx(pn,{children:r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[r.jsx(Ah,{className:"w-5 h-5 text-blue-400"}),i("settings.mqttPublishing")]}),vs?.enabled&&r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:`w-2.5 h-2.5 rounded-full ${vs.connected?"bg-green-400":"bg-red-400"}`}),r.jsx("span",{className:`text-sm ${vs.connected?"text-green-400":"text-red-400"}`,children:vs.connected?i("settings.connected"):i("settings.disconnected")})]})]})}),r.jsxs(At,{className:"space-y-3",children:[r.jsx("p",{className:"text-sm text-bambu-gray",children:i("settings.mqttDescription")}),r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-white",children:i("settings.enableMqtt")}),r.jsx("p",{className:"text-sm text-bambu-gray",children:i("settings.mqttEnableDescription")})]}),r.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:S.mqtt_enabled??!1,onChange:Se=>_n("mqtt_enabled",Se.target.checked),className:"sr-only peer"}),r.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.mqtt_enabled&&r.jsxs("div",{className:"space-y-3 pt-2 border-t border-bambu-dark-tertiary",children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:i("settings.brokerHostname")}),r.jsx("input",{type:"text",value:S.mqtt_broker??"",onChange:Se=>_n("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"})]}),r.jsxs("div",{className:"flex items-end gap-4",children:[r.jsxs("div",{className:"flex-1",children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:i("settings.port")}),r.jsx("input",{type:"number",min:"1",max:"65535",value:S.mqtt_port??1883,onChange:Se=>_n("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"})]}),r.jsxs("div",{className:"flex items-center gap-3 pb-2",children:[r.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:S.mqtt_use_tls??!1,onChange:Se=>{const Rt=Se.target.checked;_n("mqtt_use_tls",Rt);const an=S.mqtt_port??1883;Rt&&an===1883?_n("mqtt_port",8883):!Rt&&an===8883&&_n("mqtt_port",1883)},className:"sr-only peer"}),r.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"})]}),r.jsx("span",{className:"text-white text-sm",children:i("settings.useTls")})]})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:i("settings.usernameOptional")}),r.jsx("input",{type:"text",value:S.mqtt_username??"",onChange:Se=>_n("mqtt_username",Se.target.value),placeholder:i("settings.leaveEmptyForAnonymous"),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:i("settings.passwordOptional")}),r.jsx("input",{type:"password",value:S.mqtt_password??"",onChange:Se=>_n("mqtt_password",Se.target.value),placeholder:i("settings.leaveEmptyForAnonymous"),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:i("settings.topicPrefix")}),r.jsx("input",{type:"text",value:S.mqtt_topic_prefix??"bambuddy",onChange:Se=>_n("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"}),r.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:i("settings.topicPrefixHint",{prefix:S.mqtt_topic_prefix||"bambuddy"})})]}),vs&&r.jsx("div",{className:"pt-3 mt-3 border-t border-bambu-dark-tertiary",children:r.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[r.jsx("span",{className:`w-2 h-2 rounded-full ${vs.connected?"bg-green-400":"bg-red-400"}`}),r.jsx("span",{className:"text-bambu-gray",children:vs.connected?r.jsxs(r.Fragment,{children:[i("settings.mqttConnectedTo")," ",r.jsxs("span",{className:"text-white",children:[vs.broker,":",vs.port]})]}):i("settings.spoolmanDisconnected")})]})})]})]})]})]}),r.jsx("div",{className:"flex-1 lg:max-w-md space-y-3",children:r.jsxs(Ct,{id:"card-prometheus",children:[r.jsx(pn,{children:r.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[r.jsx(aC,{className:"w-5 h-5 text-orange-400"}),i("settings.prometheusMetrics")]})}),r.jsxs(At,{className:"space-y-3",children:[r.jsx("p",{className:"text-sm text-bambu-gray",children:i("settings.prometheusEndpointDescription")}),r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-white",children:i("settings.enableMetricsEndpoint")}),r.jsx("p",{className:"text-xs text-bambu-gray",children:i("settings.prometheusDescription")})]}),r.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:S.prometheus_enabled??!1,onChange:Se=>_n("prometheus_enabled",Se.target.checked),className:"sr-only peer"}),r.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.prometheus_enabled&&r.jsxs("div",{className:"space-y-3 pt-2 border-t border-bambu-dark-tertiary",children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:i("settings.bearerTokenOptional")}),r.jsx("input",{type:"password",value:S.prometheus_token??"",onChange:Se=>_n("prometheus_token",Se.target.value),placeholder:i("settings.leaveEmptyForNoAuth"),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"}),r.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:i("settings.bearerTokenHint")})]}),r.jsxs("div",{className:"pt-2 border-t border-bambu-dark-tertiary",children:[r.jsx("p",{className:"text-sm text-white mb-2",children:i("settings.availableMetrics")}),r.jsxs("div",{className:"text-xs text-bambu-gray space-y-1",children:[r.jsxs("p",{children:[r.jsx("code",{className:"text-orange-400",children:"bambuddy_printer_connected"})," - ",i("settings.metricsConnectionStatus")]}),r.jsxs("p",{children:[r.jsx("code",{className:"text-orange-400",children:"bambuddy_printer_state"})," - ",i("settings.metricsPrinterState")]}),r.jsxs("p",{children:[r.jsx("code",{className:"text-orange-400",children:"bambuddy_print_progress"})," - ",i("settings.metricsPrintProgress")]}),r.jsxs("p",{children:[r.jsx("code",{className:"text-orange-400",children:"bambuddy_bed_temp_celsius"})," - ",i("settings.metricsBedTemp")]}),r.jsxs("p",{children:[r.jsx("code",{className:"text-orange-400",children:"bambuddy_nozzle_temp_celsius"})," - ",i("settings.metricsNozzleTemp")]}),r.jsxs("p",{children:[r.jsx("code",{className:"text-orange-400",children:"bambuddy_prints_total"})," - ",i("settings.metricsPrintsTotal")]}),r.jsx("p",{className:"text-bambu-gray/70 italic",children:i("settings.metricsMore")})]})]})]})]})]})})]}),De&&r.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50",children:r.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg p-6 max-w-md w-full mx-4",children:[r.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[De.success?r.jsx(wr,{className:"w-8 h-8 text-green-400"}):r.jsx(Da,{className:"w-8 h-8 text-red-400"}),r.jsx("h3",{className:"text-lg font-medium text-white",children:De.success?i("settings.connectionSuccessful"):i("settings.connectionFailed")})]}),r.jsx("p",{className:"text-bambu-gray mb-6",children:De.success?De.message||i("settings.haConnectionSuccess"):De.error||i("settings.haConnectionFailed")}),r.jsx("div",{className:"flex justify-end",children:r.jsx(Me,{variant:"primary",onClick:()=>je(null),children:i("settings.ok")})})]})}),O==="plugs"&&r.jsxs("div",{id:"card-plugs",children:[r.jsxs("div",{className:"flex items-start justify-between mb-6",children:[r.jsxs("div",{children:[r.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[r.jsx(xc,{className:"w-5 h-5 text-bambu-green"}),i("settings.smartPlugs")]}),r.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:i("settings.smartPlugsDescription")})]}),r.jsxs("div",{className:"flex items-center gap-2 pt-1 shrink-0",children:[Ge&&Ge.filter(Se=>Se.enabled).length>1&&r.jsxs(r.Fragment,{children:[r.jsxs(Me,{variant:"secondary",size:"sm",className:"whitespace-nowrap",onClick:()=>Oe("on"),disabled:Lo.isPending,title:i("settings.turnAllPlugsOn"),children:[Lo.isPending?r.jsx(pt,{className:"w-4 h-4 animate-spin"}):r.jsx(wu,{className:"w-4 h-4 text-bambu-green"}),i("settings.allOn")]}),r.jsxs(Me,{variant:"secondary",size:"sm",className:"whitespace-nowrap",onClick:()=>Oe("off"),disabled:Lo.isPending,title:i("settings.turnAllPlugsOff"),children:[Lo.isPending?r.jsx(pt,{className:"w-4 h-4 animate-spin"}):r.jsx(ES,{className:"w-4 h-4 text-red-400"}),i("settings.allOff")]})]}),r.jsxs(Me,{className:"whitespace-nowrap",onClick:()=>{R(null),I(!0)},children:[r.jsx(ar,{className:"w-4 h-4"}),i("settings.addSmartPlug")]})]})]}),Ge&&Ge.length>0&&r.jsxs(Ct,{className:"mb-6",children:[r.jsx(pn,{children:r.jsxs("h3",{className:"text-base font-semibold text-white flex items-center gap-2",children:[r.jsx(Nc,{className:"w-4 h-4 text-yellow-400"}),i("settings.energySummary"),mn&&r.jsx(pt,{className:"w-4 h-4 animate-spin text-bambu-gray ml-2"})]})}),r.jsx(At,{children:Qt?r.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[r.jsxs("div",{className:"bg-bambu-dark rounded-lg p-3",children:[r.jsxs("div",{className:"flex items-center gap-2 text-bambu-gray text-xs mb-1",children:[r.jsx(Nc,{className:"w-3 h-3"}),i("settings.currentPower")]}),r.jsxs("div",{className:"text-xl font-bold text-white",children:[Qt.totalPower.toFixed(1),r.jsx("span",{className:"text-sm font-normal text-bambu-gray ml-1",children:"W"})]}),r.jsx("div",{className:"text-xs text-bambu-gray mt-1",children:i("settings.plugsOnline",{reachable:Qt.reachableCount,total:Qt.totalPlugs})})]}),r.jsxs("div",{className:"bg-bambu-dark rounded-lg p-3",children:[r.jsxs("div",{className:"flex items-center gap-2 text-bambu-gray text-xs mb-1",children:[r.jsx(Sa,{className:"w-3 h-3"}),i("settings.today")]}),r.jsxs("div",{className:"text-xl font-bold text-white",children:[Qt.totalToday.toFixed(3),r.jsx("span",{className:"text-sm font-normal text-bambu-gray ml-1",children:"kWh"})]}),(S?.energy_cost_per_kwh??0)>0&&r.jsxs("div",{className:"text-xs text-bambu-gray mt-1",children:["~",(Qt.totalToday*(S?.energy_cost_per_kwh??0)).toFixed(2)," ",Vo(S?.currency||"USD")]})]}),r.jsxs("div",{className:"bg-bambu-dark rounded-lg p-3",children:[r.jsxs("div",{className:"flex items-center gap-2 text-bambu-gray text-xs mb-1",children:[r.jsx(aC,{className:"w-3 h-3"}),i("settings.yesterday")]}),r.jsxs("div",{className:"text-xl font-bold text-white",children:[Qt.totalYesterday.toFixed(3),r.jsx("span",{className:"text-sm font-normal text-bambu-gray ml-1",children:"kWh"})]}),(S?.energy_cost_per_kwh??0)>0&&r.jsxs("div",{className:"text-xs text-bambu-gray mt-1",children:["~",(Qt.totalYesterday*(S?.energy_cost_per_kwh??0)).toFixed(2)," ",Vo(S?.currency||"USD")]})]}),r.jsxs("div",{className:"bg-bambu-dark rounded-lg p-3",children:[r.jsxs("div",{className:"flex items-center gap-2 text-bambu-gray text-xs mb-1",children:[r.jsx(QN,{className:"w-3 h-3"}),i("settings.total")]}),r.jsxs("div",{className:"text-xl font-bold text-white",children:[Qt.totalLifetime.toFixed(1),r.jsx("span",{className:"text-sm font-normal text-bambu-gray ml-1",children:"kWh"})]}),(S?.energy_cost_per_kwh??0)>0&&r.jsxs("div",{className:"text-xs text-bambu-gray mt-1",children:["~",(Qt.totalLifetime*(S?.energy_cost_per_kwh??0)).toFixed(2)," ",Vo(S?.currency||"USD")]})]})]}):mn?null:r.jsx("p",{className:"text-sm text-bambu-gray",children:i("settings.enablePlugsForSummary")})})]}),Vt?r.jsx("div",{className:"flex justify-center py-12",children:r.jsx(pt,{className:"w-8 h-8 text-bambu-green animate-spin"})}):Ge&&Ge.length>0?r.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4",children:Ge.map(Se=>r.jsx(Nrt,{plug:Se,onEdit:Rt=>{R(Rt),I(!0)}},Se.id))}):r.jsx(Ct,{children:r.jsx(At,{className:"py-12",children:r.jsxs("div",{className:"text-center text-bambu-gray",children:[r.jsx(xc,{className:"w-16 h-16 mx-auto mb-4 opacity-30"}),r.jsx("p",{className:"text-lg font-medium text-white mb-2",children:i("settings.noSmartPlugsTitle")}),r.jsx("p",{className:"text-sm mb-4",children:i("settings.noSmartPlugsDescription")}),r.jsxs(Me,{onClick:()=>{R(null),I(!0)},children:[r.jsx(ar,{className:"w-4 h-4"}),i("settings.addFirstSmartPlug")]})]})})})]}),O==="notifications"&&r.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-4",children:[r.jsxs("div",{children:[r.jsxs("div",{className:"flex items-center justify-between mb-4",children:[r.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",id:"card-providers",children:[r.jsx(kh,{className:"w-5 h-5 text-bambu-green"}),i("settings.providers")]}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsxs(Me,{size:"sm",variant:"secondary",onClick:()=>$(!0),children:[r.jsx(Aw,{className:"w-4 h-4"}),i("settings.log")]}),wn&&wn.length>0&&r.jsxs(Me,{size:"sm",variant:"secondary",onClick:()=>{up(null),Cu.mutate()},disabled:Cu.isPending,children:[Cu.isPending?r.jsx(pt,{className:"w-4 h-4 animate-spin"}):r.jsx(DS,{className:"w-4 h-4"}),i("settings.testAll")]}),r.jsxs(Me,{size:"sm",onClick:()=>{de(null),re(!0)},children:[r.jsx(ar,{className:"w-4 h-4"}),i("settings.addNotificationProvider")]})]})]}),r.jsx(Ct,{className:"mb-4",children:r.jsx(At,{className:"py-3",children:r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-white text-sm font-medium",children:i("settings.notificationLanguage")}),r.jsx("p",{className:"text-xs text-bambu-gray",children:i("settings.notificationLanguageDescription")})]}),r.jsx("select",{value:S.notification_language||"en",onChange:Se=>_n("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:$H.map(Se=>r.jsx("option",{value:Se.code,children:Se.nativeName},Se.code))})]})})}),r.jsx(Ct,{className:"mb-4",children:r.jsx(At,{className:"py-3",children:r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-white text-sm font-medium",children:i("settings.bedCooledThreshold")}),r.jsx("p",{className:"text-xs text-bambu-gray",children:i("settings.bedCooledThresholdDescription")})]}),r.jsxs("div",{className:"flex items-center gap-1",children:[r.jsx("input",{type:"number",min:20,max:80,step:1,value:S.bed_cooled_threshold??35,onChange:Se=>_n("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"}),r.jsx("span",{className:"text-sm text-bambu-gray",children:"°C"})]})]})})}),r.jsx(Ct,{className:"mb-4",children:r.jsx(At,{className:"py-3",children:r.jsxs("div",{className:`flex items-center justify-between ${di?.advanced_auth_enabled?"":"opacity-50"}`,children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-white text-sm font-medium",children:i("settings.userNotificationsEnabled")}),r.jsx("p",{className:"text-xs text-bambu-gray",children:di?.advanced_auth_enabled?i("settings.userNotificationsEnabledDescription"):i("settings.userNotificationsDisabledHint")})]}),r.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[r.jsx("input",{type:"checkbox",className:"sr-only peer",checked:S.user_notifications_enabled??!0,disabled:!di?.advanced_auth_enabled,onChange:Se=>_n("user_notifications_enabled",Se.target.checked)}),r.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 peer-disabled:cursor-not-allowed"})]})]})})}),ho&&r.jsx(Ct,{className:"mb-4",children:r.jsxs(At,{className:"py-3",children:[r.jsxs("div",{className:"flex items-center justify-between mb-2",children:[r.jsx("span",{className:"text-sm font-medium text-white",children:i("settings.testResults")}),r.jsx("button",{onClick:()=>up(null),className:"text-bambu-gray hover:text-white text-xs",children:i("common.dismiss")})]}),r.jsxs("div",{className:"flex items-center gap-4 text-sm mb-2",children:[r.jsxs("span",{className:"flex items-center gap-1 text-bambu-green",children:[r.jsx(wr,{className:"w-4 h-4"}),i("settings.testPassedCount",{count:ho.success})]}),ho.failed>0&&r.jsxs("span",{className:"flex items-center gap-1 text-red-400",children:[r.jsx(Da,{className:"w-4 h-4"}),i("settings.testFailedCount",{count:ho.failed})]})]}),ho.results.filter(Se=>!Se.success).length>0&&r.jsx("div",{className:"space-y-1 mt-2 pt-2 border-t border-bambu-dark-tertiary",children:ho.results.filter(Se=>!Se.success).map(Se=>r.jsxs("div",{className:"text-xs text-red-400",children:[r.jsxs("span",{className:"font-medium",children:[Se.provider_name,":"]})," ",Se.message]},Se.provider_id))})]})}),gn?r.jsx("div",{className:"flex justify-center py-12",children:r.jsx(pt,{className:"w-6 h-6 text-bambu-green animate-spin"})}):wn&&wn.length>0?r.jsx("div",{className:"space-y-3",children:wn.map(Se=>r.jsx(Prt,{provider:Se,onEdit:Rt=>{de(Rt),re(!0)}},Se.id))}):r.jsx(Ct,{children:r.jsx(At,{className:"py-8",children:r.jsxs("div",{className:"text-center text-bambu-gray",children:[r.jsx(kh,{className:"w-12 h-12 mx-auto mb-3 opacity-30"}),r.jsx("p",{className:"text-sm font-medium text-white mb-2",children:i("settings.noProvidersTitle")}),r.jsx("p",{className:"text-xs mb-3",children:i("settings.noProvidersDescription")}),r.jsxs(Me,{size:"sm",onClick:()=>{de(null),re(!0)},children:[r.jsx(ar,{className:"w-4 h-4"}),i("settings.addProvider")]})]})})})]}),r.jsxs("div",{children:[r.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2 mb-2",id:"card-templates",children:[r.jsx(Bs,{className:"w-5 h-5 text-bambu-green"}),i("settings.messageTemplates")]}),r.jsx("p",{className:"text-sm text-bambu-gray mb-3",children:i("settings.messageTemplatesDescription")}),r.jsxs("div",{className:"relative mb-3",children:[r.jsx(Sr,{className:"w-4 h-4 text-bambu-gray absolute left-3 top-1/2 -translate-y-1/2 pointer-events-none"}),r.jsx("input",{type:"text",value:X,onChange:Se=>ae(Se.target.value),placeholder:i("settings.filterTemplates","Filter templates…"),className:"w-full pl-9 pr-8 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green"}),X&&r.jsx("button",{onClick:()=>ae(""),className:"absolute right-2 top-1/2 -translate-y-1/2 p-1 text-bambu-gray hover:text-white","aria-label":"Clear filter",children:r.jsx(Ht,{className:"w-3.5 h-3.5"})})]}),Kn?r.jsx("div",{className:"flex justify-center py-8",children:r.jsx(pt,{className:"w-6 h-6 text-bambu-green animate-spin"})}):Xa&&Xa.length>0?(()=>{const Se=X.trim().toLowerCase(),Rt=[...Xa].sort((an,An)=>an.name.localeCompare(An.name)).filter(an=>!Se||an.name.toLowerCase().includes(Se)||(an.title_template||"").toLowerCase().includes(Se));return Rt.length===0?r.jsx("p",{className:"text-sm text-bambu-gray italic text-center py-6",children:i("settings.noTemplatesMatch","No templates match your filter.")}):r.jsx("div",{className:"space-y-2",children:Rt.map(an=>r.jsx(Ct,{className:"cursor-pointer hover:border-bambu-green/50 transition-colors",onClick:()=>ue(an),children:r.jsx(At,{className:"py-2.5 px-3",children:r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{className:"min-w-0 flex-1",children:[r.jsx("p",{className:"text-white font-medium text-sm truncate",children:an.name}),r.jsx("p",{className:"text-bambu-gray text-xs truncate mt-0.5",children:an.title_template})]}),r.jsx("button",{className:"p-1.5 hover:bg-bambu-dark-tertiary rounded transition-colors shrink-0 ml-2",onClick:An=>{An.stopPropagation(),ue(an)},children:r.jsx(fc,{className:"w-4 h-4 text-bambu-gray"})})]})})},an.id))})})():r.jsx(Ct,{children:r.jsx(At,{className:"py-8",children:r.jsxs("div",{className:"text-center text-bambu-gray",children:[r.jsx(Bs,{className:"w-12 h-12 mx-auto mb-3 opacity-30"}),r.jsx("p",{className:"text-sm",children:i("settings.noTemplatesAvailable")})]})})})]})]}),O==="apikeys"&&r.jsxs("div",{className:m("api_keys:read")?"grid grid-cols-1 xl:grid-cols-2 gap-4":"grid grid-cols-1 gap-4",children:[r.jsxs("div",{children:[m("api_keys:read")&&r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"flex items-start justify-between gap-4 mb-6",children:[r.jsxs("div",{className:"flex-1",children:[r.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",id:"card-createapi",children:[r.jsx(vo,{className:"w-5 h-5 text-bambu-green"}),i("settings.apiKeys")]}),r.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:i("settings.apiKeysDescription")})]}),r.jsxs(Me,{size:"sm",onClick:()=>oe(!0),className:"flex-shrink-0",children:[r.jsx(ar,{className:"w-4 h-4"}),i("settings.createKey")]})]}),q&&r.jsx(Ct,{className:"mb-6 border-bambu-green",children:r.jsx(At,{className:"py-4",children:r.jsxs("div",{className:"flex items-start gap-3",children:[r.jsx(wr,{className:"w-5 h-5 text-bambu-green flex-shrink-0 mt-0.5"}),r.jsxs("div",{className:"flex-1",children:[r.jsx("p",{className:"text-white font-medium mb-1",children:i("settings.apiKeyCreated")}),r.jsx("p",{className:"text-sm text-bambu-gray mb-2",children:i("settings.apiKeyCopyWarning")}),r.jsxs("div",{className:"flex items-center gap-2 bg-bambu-dark rounded-lg p-2",children:[r.jsx("code",{className:"flex-1 text-sm text-bambu-green font-mono break-all",children:q}),r.jsx(Me,{variant:"secondary",size:"sm",onClick:async()=>{try{if(navigator.clipboard&&navigator.clipboard.writeText)await navigator.clipboard.writeText(q);else{const Se=document.createElement("textarea");Se.value=q,Se.style.position="fixed",Se.style.left="-999999px",document.body.appendChild(Se),Se.select(),document.execCommand("copy"),document.body.removeChild(Se)}o(i("settings.toast.keyCopied"))}catch{o(i("settings.toast.copyFailed"),"error")}},children:r.jsx(Mi,{className:"w-4 h-4"})})]}),r.jsxs("div",{className:"flex gap-2 mt-3",children:[r.jsx(Me,{variant:"secondary",size:"sm",onClick:()=>{Ne(q),o(i("settings.toast.keyAddedToBrowser"))},children:i("settings.useInApiBrowser")}),r.jsx(Me,{variant:"secondary",size:"sm",onClick:()=>L(null),children:i("common.dismiss")})]})]})]})})}),Z&&r.jsxs(Ct,{className:"mb-6",children:[r.jsx(pn,{children:r.jsx("h3",{className:"text-base font-semibold text-white",children:i("settings.createNewApiKey")})}),r.jsxs(At,{className:"space-y-3",children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:i("settings.keyName")}),r.jsx("input",{type:"text",value:ee,onChange:Se=>ge(Se.target.value),placeholder:i("settings.keyNamePlaceholder"),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-2",children:i("common.permissions")}),r.jsxs("div",{className:"space-y-2",children:[r.jsxs("label",{className:"flex items-center gap-3 cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:ce.can_read_status,onChange:Se=>le(Rt=>({...Rt,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"}),r.jsxs("div",{children:[r.jsx("span",{className:"text-white",children:i("settings.readStatus")}),r.jsx("p",{className:"text-xs text-bambu-gray",children:i("settings.readStatusDescription")})]})]}),r.jsxs("label",{className:"flex items-center gap-3 cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:ce.can_queue,onChange:Se=>le(Rt=>({...Rt,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"}),r.jsxs("div",{children:[r.jsx("span",{className:"text-white",children:i("settings.manageQueue")}),r.jsx("p",{className:"text-xs text-bambu-gray",children:i("settings.manageQueueDescription")})]})]}),r.jsxs("label",{className:"flex items-center gap-3 cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:ce.can_control_printer,onChange:Se=>le(Rt=>({...Rt,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"}),r.jsxs("div",{children:[r.jsx("span",{className:"text-white",children:i("settings.controlPrinter")}),r.jsx("p",{className:"text-xs text-bambu-gray",children:i("settings.controlPrinterDescription")})]})]}),r.jsxs("label",{className:"flex items-center gap-3 cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:ce.can_access_cloud,onChange:Se=>le(Rt=>({...Rt,can_access_cloud:Se.target.checked})),className:"w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green"}),r.jsxs("div",{children:[r.jsx("span",{className:"text-white",children:i("settings.cloudAccess","Allow cloud access")}),r.jsx("p",{className:"text-xs text-bambu-gray",children:i("settings.cloudAccessDescription","Read Bambu Cloud presets and filaments on your behalf. Requires you to be signed into Bambu Cloud.")})]})]})]})]}),r.jsxs("div",{className:"flex items-center gap-2 pt-2",children:[r.jsxs(Me,{onClick:()=>xr.mutate({name:ee||i("settings.unnamedKey"),...ce}),disabled:xr.isPending,children:[xr.isPending?r.jsx(pt,{className:"w-4 h-4 animate-spin"}):r.jsx(ar,{className:"w-4 h-4"}),i("settings.createKey")]}),r.jsx(Me,{variant:"secondary",onClick:()=>oe(!1),children:i("common.cancel")})]})]})]}),Mn?r.jsx("div",{className:"flex justify-center py-12",children:r.jsx(pt,{className:"w-8 h-8 text-bambu-green animate-spin"})}):Cn&&Cn.length>0?r.jsx("div",{className:"space-y-3",children:Cn.map(Se=>r.jsx(Ct,{children:r.jsx(At,{className:"py-3",children:r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx(vo,{className:`w-5 h-5 ${Se.enabled?"text-bambu-green":"text-bambu-gray"}`}),r.jsxs("div",{children:[r.jsx("p",{className:"text-white font-medium",children:Se.name}),r.jsxs("p",{className:"text-xs text-bambu-gray",children:[Se.key_prefix,"••••••••",Se.last_used&&` · ${i("settings.lastUsed")}: ${Lg(Se.last_used)}`]})]})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsxs("div",{className:"flex gap-1 text-xs flex-wrap justify-end",children:[Se.can_read_status&&r.jsx("span",{className:"px-1.5 py-0.5 bg-blue-500/20 text-blue-400 rounded",children:i("settings.read")}),Se.can_queue&&r.jsx("span",{className:"px-1.5 py-0.5 bg-green-500/20 text-green-400 rounded",children:i("queue.title")}),Se.can_control_printer&&r.jsx("span",{className:"px-1.5 py-0.5 bg-orange-500/20 text-orange-400 rounded",children:i("settings.control")}),Se.can_access_cloud&&r.jsx("span",{className:"px-1.5 py-0.5 bg-purple-500/20 text-purple-400 rounded",children:i("settings.cloudBadge","Cloud")}),Se.user_id===null&&r.jsx("span",{className:"px-1.5 py-0.5 bg-yellow-500/20 text-yellow-400 rounded",title:i("settings.legacyKeyTooltip","Created before per-user ownership; recreate to use cloud access"),children:i("settings.legacyKey","Legacy")})]}),r.jsx(Me,{variant:"secondary",size:"sm",onClick:()=>ye(Se.id),children:r.jsx(Jt,{className:"w-4 h-4 text-red-400"})})]})]})})},Se.id))}):r.jsx(Ct,{children:r.jsx(At,{className:"py-12",children:r.jsxs("div",{className:"text-center text-bambu-gray",children:[r.jsx(vo,{className:"w-16 h-16 mx-auto mb-4 opacity-30"}),r.jsx("p",{className:"text-lg font-medium text-white mb-2",children:i("settings.apiKeysEmptyTitle")}),r.jsx("p",{className:"text-sm mb-4",children:i("settings.apiKeysEmptyDescription")}),r.jsxs(Me,{onClick:()=>oe(!0),children:[r.jsx(ar,{className:"w-4 h-4"}),i("settings.createFirstKey")]})]})})}),r.jsxs(Ct,{className:"mt-6",children:[r.jsx(pn,{children:r.jsx("h3",{className:"text-base font-semibold text-white",id:"card-webhooks",children:i("settings.webhookEndpoints")})}),r.jsxs(At,{className:"space-y-3 text-sm",children:[r.jsx("p",{className:"text-bambu-gray",children:i("settings.webhookApiKeyHint")}),r.jsxs("div",{className:"space-y-2 font-mono text-xs",children:[r.jsxs("div",{className:"p-2 bg-bambu-dark rounded",children:[r.jsx("span",{className:"text-blue-400",children:"GET"})," ",r.jsx("span",{className:"text-white",children:"/api/v1/webhook/status"}),r.jsxs("span",{className:"text-bambu-gray",children:[" - ",i("settings.webhook.getAllStatus")]})]}),r.jsxs("div",{className:"p-2 bg-bambu-dark rounded",children:[r.jsx("span",{className:"text-blue-400",children:"GET"})," ",r.jsx("span",{className:"text-white",children:"/api/v1/webhook/status/:id"}),r.jsxs("span",{className:"text-bambu-gray",children:[" - ",i("settings.webhook.getSpecificStatus")]})]}),r.jsxs("div",{className:"p-2 bg-bambu-dark rounded",children:[r.jsx("span",{className:"text-green-400",children:"POST"})," ",r.jsx("span",{className:"text-white",children:"/api/v1/webhook/queue"}),r.jsxs("span",{className:"text-bambu-gray",children:[" - ",i("settings.webhook.addToQueue")]})]}),r.jsxs("div",{className:"p-2 bg-bambu-dark rounded",children:[r.jsx("span",{className:"text-orange-400",children:"POST"})," ",r.jsx("span",{className:"text-white",children:"/api/v1/webhook/printer/:id/pause"}),r.jsxs("span",{className:"text-bambu-gray",children:[" - ",i("settings.webhook.pausePrint")]})]}),r.jsxs("div",{className:"p-2 bg-bambu-dark rounded",children:[r.jsx("span",{className:"text-orange-400",children:"POST"})," ",r.jsx("span",{className:"text-white",children:"/api/v1/webhook/printer/:id/resume"}),r.jsxs("span",{className:"text-bambu-gray",children:[" - ",i("settings.webhook.resumePrint")]})]}),r.jsxs("div",{className:"p-2 bg-bambu-dark rounded",children:[r.jsx("span",{className:"text-red-400",children:"POST"})," ",r.jsx("span",{className:"text-white",children:"/api/v1/webhook/printer/:id/stop"}),r.jsxs("span",{className:"text-bambu-gray",children:[" - ",i("settings.webhook.stopPrint")]})]})]})]})]})]}),r.jsxs(Ct,{className:"mt-6",children:[r.jsx(pn,{children:r.jsxs("h3",{className:"text-base font-semibold text-white flex items-center gap-2",id:"card-camera-tokens",children:[r.jsx(iC,{className:"w-4 h-4 text-bambu-green"}),i("cameraTokens.title","Camera API Tokens")]})}),r.jsx(At,{children:r.jsx(krt,{})})]})]}),m("api_keys:read")&&r.jsxs("div",{children:[r.jsxs("div",{className:"mb-6",children:[r.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",id:"card-apibrowser",children:[r.jsx(no,{className:"w-5 h-5 text-bambu-green"}),i("settings.apiBrowser")]}),r.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:i("settings.apiBrowserDescription")})]}),r.jsx(Ct,{className:"mb-4",children:r.jsxs(At,{className:"py-3",children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-2",children:i("settings.apiKeyForTesting")}),r.jsx("input",{type:"text",value:we,onChange:Se=>Ne(Se.target.value),placeholder:i("settings.apiKeyPlaceholder"),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white font-mono text-sm focus:border-bambu-green focus:outline-none"}),r.jsx("p",{className:"text-xs text-bambu-gray mt-2",children:i("settings.apiKeyHint")})]})}),r.jsx(vat,{apiKey:we})]})]}),O==="virtual-printer"&&r.jsx("div",{id:"card-vp",children:r.jsx(Zrt,{})}),O==="spoolbuddy"&&r.jsx("div",{id:"card-spoolbuddy",children:r.jsx(eat,{})}),O==="queue"&&S&&r.jsxs("div",{className:"flex flex-col lg:flex-row gap-4 lg:gap-6",children:[r.jsxs("div",{className:"lg:w-1/2 space-y-3",children:[r.jsxs(Ct,{id:"card-print-options",children:[r.jsx(pn,{children:r.jsxs("h3",{className:"text-base font-semibold text-white flex items-center gap-2",children:[r.jsx(jw,{className:"w-4 h-4 text-bambu-green"}),i("settings.defaultPrintOptions","Default Print Options")]})}),r.jsxs(At,{className:"space-y-3",children:[r.jsx("p",{className:"text-xs text-bambu-gray",children:i("settings.defaultPrintOptionsDescription","Set default values for print options when starting new prints. These can be overridden per print in the print dialog.")}),[{key:"default_bed_levelling",label:i("settings.defaultBedLevelling","Bed Levelling"),desc:i("settings.defaultBedLevellingDesc","Auto-level bed before print"),fallback:!0},{key:"default_flow_cali",label:i("settings.defaultFlowCali","Flow Calibration"),desc:i("settings.defaultFlowCaliDesc","Calibrate extrusion flow"),fallback:!1},{key:"default_vibration_cali",label:i("settings.defaultVibrationCali","Vibration Calibration"),desc:i("settings.defaultVibrationCaliDesc","Reduce ringing artifacts"),fallback:!0},{key:"default_layer_inspect",label:i("settings.defaultLayerInspect","First Layer Inspection"),desc:i("settings.defaultLayerInspectDesc","AI inspection of first layer"),fallback:!1},{key:"default_timelapse",label:i("settings.defaultTimelapse","Timelapse"),desc:i("settings.defaultTimelapseDesc","Record timelapse video"),fallback:!1}].map(({key:Se,label:Rt,desc:an,fallback:An})=>r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{className:"flex-1 mr-4",children:[r.jsx("p",{className:"text-sm text-white",children:Rt}),r.jsx("p",{className:"text-xs text-bambu-gray mt-0.5",children:an})]}),r.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:S[Se]??An,onChange:Bn=>_n(Se,Bn.target.checked),className:"sr-only peer"}),r.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"})]})]},Se))]})]}),r.jsxs(Ct,{id:"card-staggered",children:[r.jsx(pn,{children:r.jsxs("h3",{className:"text-base font-semibold text-white flex items-center gap-2",children:[r.jsx(oa,{className:"w-4 h-4 text-bambu-green"}),i("settings.staggeredStart","Staggered Start")]})}),r.jsxs(At,{className:"space-y-3",children:[r.jsx("p",{className:"text-xs text-bambu-gray",children:i("settings.staggeredStartDescription","Default group size and interval when staggering multi-printer batch starts. Can be overridden per batch in the print modal.")}),r.jsxs("div",{className:"flex gap-4",children:[r.jsxs("div",{className:"flex-1",children:[r.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:i("settings.staggerGroupSize","Group size")}),r.jsx("input",{type:"number",min:1,max:50,value:S.stagger_group_size??2,onChange:Se=>_n("stagger_group_size",Math.max(1,Math.min(50,parseInt(Se.target.value)||1))),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green"}),r.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:i("settings.staggerGroupSizeHelp","Printers to start simultaneously per group")})]}),r.jsxs("div",{className:"flex-1",children:[r.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:i("settings.staggerInterval","Interval (minutes)")}),r.jsx("input",{type:"number",min:1,max:60,value:S.stagger_interval_minutes??5,onChange:Se=>_n("stagger_interval_minutes",Math.max(1,Math.min(60,parseInt(Se.target.value)||1))),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green"}),r.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:i("settings.staggerIntervalHelp","Delay between each group starting")})]})]})]})]}),r.jsxs(Ct,{id:"card-plate",children:[r.jsx(pn,{children:r.jsxs("h3",{className:"text-base font-semibold text-white flex items-center gap-2",children:[r.jsx(Sl,{className:"w-4 h-4 text-bambu-green"}),i("settings.plateClear","Plate-Clear Confirmation")]})}),r.jsx(At,{className:"space-y-3",children:r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{className:"flex-1 mr-4",children:[r.jsx("p",{className:"text-sm text-white",children:i("settings.requirePlateClear","Require plate-clear confirmation")}),r.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:i("settings.requirePlateClearDescription",'When enabled, the scheduler waits for per-printer plate-clear confirmation before starting queued prints on printers with finished jobs. Disabling this also hides the plate status badge and the "Mark plate as cleared" button on printer cards.')})]}),r.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:S.require_plate_clear??!1,onChange:Se=>_n("require_plate_clear",Se.target.checked),className:"sr-only peer"}),r.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"})]})]})})]}),r.jsxs(Ct,{id:"card-gcode",children:[r.jsx(pn,{children:r.jsxs("h3",{className:"text-base font-semibold text-white flex items-center gap-2",children:[r.jsx(Gy,{className:"w-4 h-4 text-bambu-green"}),i("settings.gcodeInjection","G-code Injection")]})}),r.jsxs(At,{className:"space-y-3",children:[r.jsx("p",{className:"text-xs text-bambu-gray",children:i("settings.gcodeInjectionDescription",'Configure custom G-code to inject at the start and/or end of prints for auto-print systems like Farmloop, SwapMod, AutoClear, and Printflow 3D. Snippets are configured per printer model and applied when "Inject G-code" is enabled on a queue item.')}),(()=>{const Se=(()=>{try{return S.gcode_snippets?JSON.parse(S.gcode_snippets):{}}catch{return{}}})(),Rt=[...new Set((zn||[]).filter(Bn=>Bn.model).map(Bn=>Bn.model))].sort(),an=(Bn,ba,Na)=>{const ot={...Se};ot[Bn]||(ot[Bn]={start_gcode:"",end_gcode:""}),ot[Bn][ba]=Na,!ot[Bn].start_gcode&&!ot[Bn].end_gcode&&delete ot[Bn];const $t=Object.keys(ot).length>0?JSON.stringify(ot):"";E(sn=>sn?{...sn,gcode_snippets:$t}:null),Sd.current=$t},An=()=>{Sd.current!==null&&(Pu.mutate({gcode_snippets:Sd.current}),Sd.current=null)};return Rt.length===0?r.jsx("p",{className:"text-sm text-bambu-gray italic",children:i("settings.gcodeInjectionNoPrinters","No printers found. Add printers to configure G-code snippets.")}):Rt.map(Bn=>{const ba=Se[Bn]||{start_gcode:"",end_gcode:""},Na=!!(ba.start_gcode||ba.end_gcode);return r.jsx(o5,{defaultOpen:Na,className:"border border-bambu-dark-tertiary rounded-lg px-3 py-2",summary:r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("h4",{className:"text-sm font-medium text-white",children:Bn}),Na&&r.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-bambu-green/20 text-bambu-green",children:i("settings.gcodeConfigured","Configured")})]}),children:r.jsxs("div",{className:"space-y-2",children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:i("settings.gcodeStartLabel","Start G-code")}),r.jsx("textarea",{value:ba.start_gcode,onChange:ot=>an(Bn,"start_gcode",ot.target.value),onBlur:An,placeholder:i("settings.gcodeStartPlaceholder","G-code prepended before the print starts..."),rows:3,className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-xs font-mono focus:outline-none focus:border-bambu-green resize-y"})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:i("settings.gcodeEndLabel","End G-code")}),r.jsx("textarea",{value:ba.end_gcode,onChange:ot=>an(Bn,"end_gcode",ot.target.value),onBlur:An,placeholder:i("settings.gcodeEndPlaceholder","G-code appended after the print ends..."),rows:3,className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-xs font-mono focus:outline-none focus:border-bambu-green resize-y"})]})]})},Bn)})})()]})]})]}),r.jsxs("div",{className:"lg:w-1/2 space-y-3",children:[r.jsxs(Ct,{id:"card-slicer",children:[r.jsx(pn,{children:r.jsxs("h3",{className:"text-base font-semibold text-white flex items-center gap-2",children:[r.jsx(cu,{className:"w-4 h-4 text-bambu-green"}),i("settings.slicerCard","Slicer")]})}),r.jsxs(At,{className:"space-y-3",children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:i("settings.preferredSlicer")}),r.jsxs("div",{className:"relative",children:[r.jsxs("select",{value:S.preferred_slicer??"bambu_studio",onChange:Se=>_n("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:[r.jsx("option",{value:"bambu_studio",children:i("settings.slicerBambuStudio")}),r.jsx("option",{value:"orcaslicer",children:i("settings.slicerOrcaSlicer")})]}),r.jsx(Ln,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}),r.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:i("settings.preferredSlicerDescription")}),(S.preferred_slicer??"bambu_studio")==="orcaslicer"&&r.jsx("div",{role:"alert",className:"text-xs text-amber-200 bg-amber-900/20 border border-amber-700/40 rounded p-2 mt-2",children:i("settings.orcaslicerKnownIssuesWarning","OrcaSlicer 2.3.2 / 2.4.0-dev have known CLI bugs that block slicing many Bambu-authored 3MFs — see upstream issues #12426 (segfault on painted multi-extruder files) and #13386 (parameter-range strict-validation reject). Bambu Studio is recommended until the upstream fixes land.")})]}),r.jsxs("div",{className:"flex items-center justify-between gap-3",children:[r.jsxs("div",{className:"min-w-0",children:[r.jsx("p",{className:"text-white",children:i("settings.useSlicerApi")}),r.jsx("p",{className:"text-sm text-bambu-gray",children:i("settings.useSlicerApiDescription")})]}),r.jsxs("label",{className:"flex items-center cursor-pointer shrink-0",children:[r.jsx("input",{type:"checkbox",checked:S.use_slicer_api??!1,onChange:Se=>_n("use_slicer_api",Se.target.checked),className:"sr-only peer"}),r.jsx("div",{className:"relative w-11 h-6 bg-bambu-dark-tertiary rounded-full peer peer-checked:bg-bambu-green peer-focus:outline-none peer-focus:ring-2 peer-focus:ring-bambu-green/50 transition-colors after:content-[''] after:absolute after:top-0.5 after:left-0.5 after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-transform peer-checked:after:translate-x-5"})]})]}),(S.use_slicer_api??!1)&&r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:(S.preferred_slicer??"bambu_studio")==="orcaslicer"?i("settings.orcaslicerApiUrl","OrcaSlicer sidecar URL"):i("settings.bambuStudioApiUrl","Bambu Studio sidecar URL")}),r.jsx("input",{type:"text",value:((S.preferred_slicer??"bambu_studio")==="orcaslicer"?S.orcaslicer_api_url:S.bambu_studio_api_url)??"",onChange:Se=>_n((S.preferred_slicer??"bambu_studio")==="orcaslicer"?"orcaslicer_api_url":"bambu_studio_api_url",Se.target.value),placeholder:(S.preferred_slicer??"bambu_studio")==="orcaslicer"?"http://localhost:3003":"http://localhost:3001",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none placeholder:text-bambu-gray/40"}),r.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:i("settings.slicerApiUrlDescription","URL of the slicer-API sidecar container. Leave blank to use the SLICER_API_URL / BAMBU_STUDIO_API_URL env var defaults.")})]})]})]}),(S.use_slicer_api??!1)&&r.jsx(xrt,{}),r.jsxs(Ct,{children:[r.jsx(pn,{children:r.jsxs("h3",{className:"text-base font-semibold text-white flex items-center gap-2",id:"card-drying",children:[r.jsx(mm,{className:"w-4 h-4 text-amber-400"}),i("settings.queueDrying")]})}),r.jsxs(At,{className:"space-y-3",children:[r.jsx("p",{className:"text-xs text-bambu-gray",children:i("settings.queueDryingDescription")}),r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-white",children:i("settings.queueDryingEnabled")}),r.jsx("p",{className:"text-xs text-bambu-gray mt-0.5",children:i("settings.queueDryingEnabledDescription")})]}),r.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:S.queue_drying_enabled??!1,onChange:Se=>_n("queue_drying_enabled",Se.target.checked),className:"sr-only peer"}),r.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.queue_drying_enabled&&r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-white",children:i("settings.queueDryingBlock")}),r.jsx("p",{className:"text-xs text-bambu-gray mt-0.5",children:i("settings.queueDryingBlockDescription")})]}),r.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:S.queue_drying_block??!1,onChange:Se=>_n("queue_drying_block",Se.target.checked),className:"sr-only peer"}),r.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-amber-500"})]})]}),r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-white",children:i("settings.ambientDryingEnabled")}),r.jsx("p",{className:"text-xs text-bambu-gray mt-0.5",children:i("settings.ambientDryingEnabledDescription")})]}),r.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:S.ambient_drying_enabled??!1,onChange:Se=>_n("ambient_drying_enabled",Se.target.checked),className:"sr-only peer"}),r.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"})]})]}),r.jsxs("div",{className:"space-y-2",children:[r.jsx("p",{className:"text-sm text-white font-medium",children:i("settings.dryingPresets")}),r.jsx("p",{className:"text-xs text-bambu-gray",children:i("settings.dryingPresetsDescription")}),r.jsx("div",{className:"overflow-x-auto",children:r.jsxs("table",{className:"w-full text-xs",children:[r.jsx("thead",{children:r.jsxs("tr",{className:"text-bambu-gray border-b border-bambu-dark-tertiary",children:[r.jsx("th",{className:"text-left py-1.5",children:i("settings.dryingFilament")}),r.jsx("th",{className:"text-center py-1.5",colSpan:2,children:"AMS 2 Pro"}),r.jsx("th",{className:"text-center py-1.5",colSpan:2,children:"AMS-HT"})]})}),r.jsx("tbody",{children:(()=>{const Se={PLA:{n3f:45,n3s:45,n3f_hours:12,n3s_hours:12},PETG:{n3f:65,n3s:65,n3f_hours:12,n3s_hours:12},TPU:{n3f:65,n3s:75,n3f_hours:12,n3s_hours:18},ABS:{n3f:65,n3s:80,n3f_hours:12,n3s_hours:8},ASA:{n3f:65,n3s:80,n3f_hours:12,n3s_hours:8},PA:{n3f:65,n3s:85,n3f_hours:12,n3s_hours:12},PC:{n3f:65,n3s:80,n3f_hours:12,n3s_hours:8},PVA:{n3f:65,n3s:85,n3f_hours:12,n3s_hours:18}};let Rt={...Se};try{if(S.drying_presets){const An=JSON.parse(S.drying_presets);typeof An=="object"&&An!==null&&(Rt={...Se,...An})}}catch{}const an=(An,Bn,ba)=>{const Na={...Rt,[An]:{...Rt[An],[Bn]:ba}};_n("drying_presets",JSON.stringify(Na))};return Object.entries(Rt).map(([An,Bn])=>r.jsxs("tr",{className:"border-b border-bambu-dark-tertiary/50",children:[r.jsx("td",{className:"py-1.5 pr-2 text-white font-medium",children:An}),r.jsx("td",{className:"py-1 px-1",children:r.jsxs("div",{className:"flex items-center justify-end gap-1",children:[r.jsx("input",{type:"number",min:30,max:65,value:Bn.n3f,onChange:ba=>an(An,"n3f",Math.max(1,parseInt(ba.target.value)||0)),className:"w-14 px-1.5 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-center text-xs focus:border-amber-500/50 focus:outline-none [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none"}),r.jsx("span",{className:"text-bambu-gray",children:"°C"})]})}),r.jsx("td",{className:"py-1 px-1",children:r.jsxs("div",{className:"flex items-center gap-1",children:[r.jsx("input",{type:"number",min:1,max:24,value:Bn.n3f_hours,onChange:ba=>an(An,"n3f_hours",Math.max(1,parseInt(ba.target.value)||0)),className:"w-14 px-1.5 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-center text-xs focus:border-amber-500/50 focus:outline-none [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none"}),r.jsx("span",{className:"text-bambu-gray",children:"h"})]})}),r.jsx("td",{className:"py-1 px-1",children:r.jsxs("div",{className:"flex items-center justify-end gap-1",children:[r.jsx("input",{type:"number",min:30,max:85,value:Bn.n3s,onChange:ba=>an(An,"n3s",Math.max(1,parseInt(ba.target.value)||0)),className:"w-14 px-1.5 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-center text-xs focus:border-amber-500/50 focus:outline-none [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none"}),r.jsx("span",{className:"text-bambu-gray",children:"°C"})]})}),r.jsx("td",{className:"py-1 px-1",children:r.jsxs("div",{className:"flex items-center gap-1",children:[r.jsx("input",{type:"number",min:1,max:24,value:Bn.n3s_hours,onChange:ba=>an(An,"n3s_hours",Math.max(1,parseInt(ba.target.value)||0)),className:"w-14 px-1.5 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-center text-xs focus:border-amber-500/50 focus:outline-none [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none"}),r.jsx("span",{className:"text-bambu-gray",children:"h"})]})})]},An))})()})]})})]})]})]})]})]}),O==="filament"&&S&&r.jsx(r.Fragment,{children:r.jsxs("div",{className:"flex flex-col lg:flex-row gap-4 lg:gap-6",children:[r.jsxs("div",{className:"lg:w-1/3 space-y-3",children:[r.jsx(Lrt,{}),r.jsxs(Ct,{id:"card-filamentchecks",children:[r.jsx(pn,{children:r.jsx("h2",{className:"text-lg font-semibold text-white",children:i("settings.filamentChecks")})}),r.jsxs(At,{className:"space-y-3",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-white",children:i("settings.disableFilamentWarnings")}),r.jsx("p",{className:"text-sm text-bambu-gray",children:i("settings.disableFilamentWarningsDesc")})]}),r.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:S.disable_filament_warnings,onChange:Se=>_n("disable_filament_warnings",Se.target.checked),className:"sr-only peer"}),r.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"})]})]}),r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-white",children:i("settings.preferLowestFilament")}),r.jsx("p",{className:"text-sm text-bambu-gray",children:i("settings.preferLowestFilamentDesc")})]}),r.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:S.prefer_lowest_filament,onChange:Se=>_n("prefer_lowest_filament",Se.target.checked),className:"sr-only peer"}),r.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"})]})]})]})]}),r.jsxs(Ct,{id:"card-printmodal",children:[r.jsx(pn,{children:r.jsx("h2",{className:"text-lg font-semibold text-white",children:i("settings.printModal")})}),r.jsx(At,{className:"space-y-3",children:r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-white",children:i("settings.expandCustomMapping")}),r.jsx("p",{className:"text-sm text-bambu-gray",children:i("settings.expandCustomMappingDescription")})]}),r.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:S.per_printer_mapping_expanded??!1,onChange:Se=>_n("per_printer_mapping_expanded",Se.target.checked),className:"sr-only peer"}),r.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"})]})]})})]}),r.jsxs(Ct,{id:"card-amsthresholds",children:[r.jsx(pn,{children:r.jsx("h2",{className:"text-lg font-semibold text-white",children:i("settings.amsDisplayThresholds")})}),r.jsxs(At,{className:"space-y-3",children:[r.jsx("p",{className:"text-sm text-bambu-gray",children:i("settings.amsThresholdsDescription")}),r.jsxs("div",{className:"space-y-3",children:[r.jsxs("div",{className:"flex items-center gap-2 text-white",children:[r.jsx(bO,{className:"w-4 h-4 text-blue-400"}),r.jsx("span",{className:"font-medium",children:i("settings.humidity")})]}),r.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[r.jsxs("div",{children:[r.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[i("settings.goodGreen")," ≤"]}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("input",{type:"number",min:"0",max:"100",value:S.ams_humidity_good??40,onChange:Se=>_n("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"}),r.jsx("span",{className:"text-bambu-gray",children:"%"})]})]}),r.jsxs("div",{children:[r.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[i("settings.fairOrange")," ≤"]}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("input",{type:"number",min:"0",max:"100",value:S.ams_humidity_fair??60,onChange:Se=>_n("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"}),r.jsx("span",{className:"text-bambu-gray",children:"%"})]})]})]}),r.jsx("p",{className:"text-xs text-bambu-gray",children:i("settings.aboveFairBad")}),r.jsx("p",{className:"text-xs text-amber-400/70",children:i("settings.fairAlsoDryingThreshold")})]}),r.jsxs("div",{className:"space-y-3 pt-2 border-t border-bambu-dark-tertiary",children:[r.jsxs("div",{className:"flex items-center gap-2 text-white",children:[r.jsx(FS,{className:"w-4 h-4 text-orange-400"}),r.jsx("span",{className:"font-medium",children:i("settings.temperature")})]}),r.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[r.jsxs("div",{children:[r.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[i("settings.goodBlue")," ≤"]}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("input",{type:"number",step:"0.5",min:"0",max:"60",value:S.ams_temp_good??28,onChange:Se=>_n("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"}),r.jsx("span",{className:"text-bambu-gray",children:"°C"})]})]}),r.jsxs("div",{children:[r.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[i("settings.fairOrange")," ≤"]}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("input",{type:"number",step:"0.5",min:"0",max:"60",value:S.ams_temp_fair??35,onChange:Se=>_n("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"}),r.jsx("span",{className:"text-bambu-gray",children:"°C"})]})]})]}),r.jsx("p",{className:"text-xs text-bambu-gray",children:i("settings.aboveFairHot")})]}),r.jsxs("div",{className:"space-y-3 pt-4 border-t border-bambu-dark-tertiary",children:[r.jsxs("div",{className:"flex items-center gap-2 text-white",children:[r.jsx(hc,{className:"w-4 h-4 text-purple-400"}),r.jsx("span",{className:"font-medium",children:i("settings.historyRetention")})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:i("settings.keepSensorHistory")}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("input",{type:"number",min:"1",max:"365",value:S.ams_history_retention_days??30,onChange:Se=>_n("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"}),r.jsx("span",{className:"text-bambu-gray",children:i("common.days")})]})]}),r.jsx("p",{className:"text-xs text-bambu-gray",children:i("settings.historyRetentionDescription")})]})]})]})]}),r.jsxs("div",{className:"lg:w-2/3 space-y-3",children:[r.jsx(Irt,{}),r.jsx(Wrt,{})]})]})}),ne!==null&&r.jsx(vn,{title:i("settings.deleteApiKeyTitle"),message:i("settings.deleteApiKeyMessage"),confirmText:i("settings.deleteKey"),variant:"danger",onConfirm:()=>{Er.mutate(ne),ye(null)},onCancel:()=>ye(null)}),U&&r.jsx(Crt,{plug:H,onClose:()=>{I(!1),R(null)}}),Q&&r.jsx(Art,{provider:J,onClose:()=>{re(!1),de(null)}}),pe&&r.jsx(jrt,{template:pe,onClose:()=>ue(null)}),Ce&&r.jsx(Ert,{onClose:()=>$(!1)}),ve&&r.jsx(vn,{title:i("settings.clearNotificationLogs"),message:i("settings.clearLogsMessage"),confirmText:i("settings.clearLogs"),variant:"warning",onConfirm:async()=>{xe(!1);try{const Se=await se.clearNotificationLogs(30);o(Se.message,"success")}catch{o(i("settings.toast.clearLogsFailed"),"error")}},onCancel:()=>xe(!1)}),Ee&&r.jsx(vn,{title:i("settings.resetUiPreferences"),message:i("settings.resetUiPreferencesMessage"),confirmText:i("settings.resetPreferences"),variant:"default",onConfirm:()=>{ze(!1),localStorage.clear(),o(i("settings.toast.uiPreferencesReset"),"success"),setTimeout(()=>window.location.reload(),1e3)},onCancel:()=>ze(!1)}),_e&&r.jsx(vn,{title:`Turn All Plugs ${_e==="on"?"On":"Off"}`,message:`This will turn ${_e==="on"?"ON":"OFF"} all ${Ge?.filter(Se=>Se.enabled).length||0} enabled smart plugs. ${_e==="off"?"Any running printers may be affected!":""}`,confirmText:`Turn All ${_e==="on"?"On":"Off"}`,variant:_e==="off"?"danger":"warning",onConfirm:()=>{const Se=_e;Oe(null),Lo.mutate(Se)},onCancel:()=>Oe(null)}),Ie&&Or?.release_notes&&r.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",onClick:()=>We(!1),children:r.jsxs(Ct,{className:"w-full max-w-2xl max-h-[80vh] flex flex-col",onClick:Se=>Se.stopPropagation(),children:[r.jsxs(pn,{className:"flex flex-row items-center justify-between shrink-0",children:[r.jsxs("div",{children:[r.jsxs("h2",{className:"text-lg font-semibold text-white",children:["Release Notes - v",Or.latest_version]}),Or.release_name&&Or.release_name!==Or.latest_version&&r.jsx("p",{className:"text-sm text-bambu-gray",children:Or.release_name})]}),r.jsx("button",{onClick:()=>We(!1),className:"p-1 rounded hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white",children:r.jsx(Ht,{className:"w-5 h-5"})})]}),r.jsx(At,{className:"overflow-y-auto flex-1",children:r.jsx("pre",{className:"text-sm text-bambu-gray whitespace-pre-wrap font-sans",children:Or.release_notes})}),r.jsxs("div",{className:"p-4 border-t border-bambu-dark-tertiary shrink-0 flex gap-2",children:[Or.release_url&&r.jsx("a",{href:Or.release_url,target:"_blank",rel:"noopener noreferrer",className:"flex-1",children:r.jsxs(Me,{variant:"secondary",className:"w-full",children:[r.jsx(Rr,{className:"w-4 h-4"}),"View on GitHub"]})}),r.jsx(Me,{onClick:()=>We(!1),className:"flex-1",children:"Close"})]})]})}),O==="users"&&r.jsxs("div",{className:"space-y-3",children:[r.jsxs("div",{className:"flex gap-1 border-b border-bambu-dark-tertiary",children:[r.jsxs("button",{onClick:()=>G("users"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${z==="users"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[r.jsx(gm,{className:"w-4 h-4"}),i("settings.tabs.users")]}),r.jsxs("button",{onClick:()=>G("email"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${z==="email"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[r.jsx(qm,{className:"w-4 h-4"}),i("settings.tabs.emailAuth")||"Email Authentication",di?.advanced_auth_enabled&&r.jsx("span",{className:"w-2 h-2 rounded-full bg-green-400"})]}),r.jsxs("button",{onClick:()=>G("ldap"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${z==="ldap"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[r.jsx(Sl,{className:"w-4 h-4"}),i("settings.tabs.ldap")||"LDAP",lp?.ldap_enabled&&r.jsx("span",{className:"w-2 h-2 rounded-full bg-green-400"})]}),r.jsxs("button",{onClick:()=>G("twofa"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${z==="twofa"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[r.jsx(Sl,{className:"w-4 h-4"}),i("settings.tabs.twoFa"),r.jsx("span",{className:`w-2 h-2 rounded-full ${pf?.totp_enabled||pf?.email_otp_enabled?"bg-green-400":"bg-bambu-gray/40"}`})]}),d&&r.jsxs("button",{onClick:()=>G("oidc"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${z==="oidc"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[r.jsx(no,{className:"w-4 h-4"}),i("settings.tabs.oidc"),r.jsx("span",{className:`w-2 h-2 rounded-full ${yd.some(Se=>Se.is_enabled)?"bg-green-400":"bg-bambu-gray/40"}`})]}),d&&r.jsxs("button",{onClick:()=>G("security"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${z==="security"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[r.jsx(Sl,{className:"w-4 h-4"}),i("settings.tabs.security")]})]}),z==="users"&&r.jsxs(r.Fragment,{children:[r.jsx(Ct,{children:r.jsx(At,{className:"py-4",children:r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{className:"flex items-center gap-3",children:[r.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?r.jsx(lc,{className:"w-5 h-5 text-green-400"}):r.jsx(K0,{className:"w-5 h-5 text-gray-400"})}),r.jsxs("div",{children:[r.jsx("h3",{className:"text-white font-medium",children:i("settings.authentication")}),r.jsx("p",{className:"text-sm text-bambu-gray",children:i(l?"settings.authEnabledDescription":"settings.authDisabledDescription")})]})]}),l?c?.is_admin&&r.jsxs(Me,{variant:"secondary",onClick:()=>lt(!0),children:[r.jsx(K0,{className:"w-4 h-4"}),i("common.disable")]}):r.jsxs(Me,{onClick:()=>e("/setup"),children:[r.jsx(lc,{className:"w-4 h-4"}),i("common.enable")]})]})})}),di?.advanced_auth_enabled&&r.jsx(Ct,{className:"border-blue-500/30 bg-blue-500/5",children:r.jsx(At,{className:"py-4",children:r.jsxs("div",{className:"flex items-start gap-3",children:[r.jsx("div",{className:"w-10 h-10 rounded-full flex items-center justify-center bg-blue-500/20 flex-shrink-0",children:r.jsx(qm,{className:"w-5 h-5 text-blue-400"})}),r.jsxs("div",{children:[r.jsx("h3",{className:"text-white font-medium",children:i("settings.email.advancedAuthEnabled")}),r.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:i("settings.email.advancedAuthEnabledDesc")})]})]})})}),l&&r.jsxs("div",{className:"grid grid-cols-1 xl:grid-cols-2 gap-6",children:[r.jsxs("div",{className:"space-y-3",children:[c&&r.jsxs(Ct,{children:[r.jsx(pn,{children:r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("h3",{className:"text-lg font-semibold text-white flex items-center gap-2",id:"card-currentuser",children:[r.jsx(gm,{className:"w-5 h-5 text-bambu-green"}),i("settings.currentUser")]}),c.auth_source!=="ldap"&&r.jsxs(Me,{size:"sm",variant:"ghost",onClick:()=>tt(!0),children:[r.jsx(vo,{className:"w-4 h-4"}),i("settings.changePassword")]})]})}),r.jsx(At,{children:r.jsx("div",{className:"flex items-center justify-between",children:r.jsxs("div",{children:[r.jsx("p",{className:"text-white font-medium text-lg",children:c.username}),r.jsxs("div",{className:"flex flex-wrap gap-1 mt-2",children:[c.is_admin&&r.jsx("span",{className:"px-2 py-0.5 rounded-full text-xs font-medium bg-purple-500/20 text-purple-300",children:i("settings.admin")}),c.groups?.map(Se=>r.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))]})]})})})]}),r.jsxs(Ct,{children:[r.jsx(pn,{children:r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("h3",{className:"text-lg font-semibold text-white flex items-center gap-2",id:"card-users",children:[r.jsx(gm,{className:"w-5 h-5 text-bambu-green"}),i("settings.users")]}),m("users:create")&&r.jsxs(Me,{size:"sm",onClick:()=>{Qe(!0),vt({username:"",password:"",email:"",confirmPassword:"",role:"user",group_ids:[]})},children:[r.jsx(ar,{className:"w-4 h-4"}),i("settings.addUser")]})]})}),r.jsx(At,{children:cp?r.jsx("div",{className:"flex items-center justify-center py-8",children:r.jsx(pt,{className:"w-6 h-6 text-bambu-green animate-spin"})}):Ic.length===0?r.jsx("p",{className:"text-center text-bambu-gray py-8",children:i("settings.noUsersFound")}):r.jsx("div",{className:"divide-y divide-bambu-dark-tertiary",children:Ic.map(Se=>r.jsxs("div",{className:"py-3 flex items-center justify-between",children:[r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("p",{className:"text-white font-medium truncate",children:Se.username}),r.jsxs("div",{className:"flex flex-wrap gap-1 mt-1",children:[Se.auth_source==="ldap"&&r.jsx("span",{className:"px-2 py-0.5 rounded-full text-xs font-medium bg-cyan-500/20 text-cyan-300",children:"LDAP"}),Se.is_admin&&r.jsx("span",{className:"px-2 py-0.5 rounded-full text-xs font-medium bg-purple-500/20 text-purple-300",children:i("settings.admin")}),Se.groups?.map(Rt=>r.jsx("span",{className:`px-2 py-0.5 rounded-full text-xs font-medium ${Rt.name==="Administrators"?"bg-purple-500/20 text-purple-300":Rt.name==="Operators"?"bg-blue-500/20 text-blue-300":Rt.name==="Viewers"?"bg-green-500/20 text-green-300":"bg-gray-500/20 text-gray-300"}`,children:Rt.name},Rt.id))]})]}),r.jsxs("div",{className:"flex items-center gap-1 ml-4",children:[m("users:update")&&r.jsx(Me,{size:"sm",variant:"ghost",onClick:()=>hv(Se),children:r.jsx(fc,{className:"w-4 h-4"})}),m("users:delete")&&Se.id!==c?.id&&r.jsx(Me,{size:"sm",variant:"ghost",onClick:()=>dp(Se.id),children:r.jsx(Jt,{className:"w-4 h-4"})})]})]},Se.id))})})]})]}),r.jsx("div",{children:r.jsxs(Ct,{children:[r.jsx(pn,{children:r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("h3",{className:"text-lg font-semibold text-white flex items-center gap-2",id:"card-groups",children:[r.jsx(Sl,{className:"w-5 h-5 text-bambu-green"}),i("settings.groups")]}),m("groups:create")&&r.jsxs(Me,{size:"sm",onClick:()=>e("/groups/new"),children:[r.jsx(ar,{className:"w-4 h-4"}),i("settings.addGroup")]})]})}),r.jsx(At,{children:Do?r.jsx("div",{className:"flex items-center justify-center py-8",children:r.jsx(pt,{className:"w-6 h-6 text-bambu-green animate-spin"})}):Qr.length===0?r.jsx("p",{className:"text-center text-bambu-gray py-8",children:i("settings.noGroupsFound")}):r.jsx("div",{className:"divide-y divide-bambu-dark-tertiary",children:Qr.map(Se=>r.jsxs("div",{className:"py-3",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(Sl,{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"}`}),r.jsx("span",{className:"text-white font-medium",children:Se.name}),Se.is_system&&r.jsx("span",{className:"px-2 py-0.5 rounded text-xs bg-yellow-500/20 text-yellow-400",children:i("settings.system")})]}),r.jsxs("div",{className:"flex items-center gap-1",children:[m("groups:update")&&r.jsx(Me,{size:"sm",variant:"ghost",onClick:()=>e(`/groups/${Se.id}/edit`),children:r.jsx(fc,{className:"w-4 h-4"})}),m("groups:delete")&&!Se.is_system&&r.jsx(Me,{size:"sm",variant:"ghost",onClick:()=>Dt(Se.id),children:r.jsx(Jt,{className:"w-4 h-4"})})]})]}),r.jsx("p",{className:"text-sm text-bambu-gray mt-1 ml-6",children:Se.description||i("settings.noDescription")}),r.jsxs("div",{className:"flex items-center gap-4 mt-2 ml-6 text-xs text-bambu-gray",children:[r.jsx("span",{children:i("settings.userCount",{count:Se.user_count})}),r.jsx("span",{children:i("settings.permissionCount",{count:Se.permissions.length})})]})]},Se.id))})})]})})]}),!l&&r.jsx(Ct,{children:r.jsx(At,{className:"py-6",children:r.jsxs("div",{className:"text-center",children:[r.jsx(K0,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),r.jsx("h3",{className:"text-lg font-medium text-white mb-2",children:i("settings.authDisabledTitle")}),r.jsx("p",{className:"text-sm text-bambu-gray mb-4 max-w-md mx-auto",children:i("settings.authDisabledMessage")}),r.jsxs("ul",{className:"space-y-2 text-sm text-bambu-gray mb-6 text-left max-w-xs mx-auto",children:[r.jsxs("li",{className:"flex items-start gap-2",children:[r.jsx(wr,{className:"w-4 h-4 text-bambu-green mt-0.5 flex-shrink-0"}),r.jsx("span",{children:i("settings.authDisabledFeature1")})]}),r.jsxs("li",{className:"flex items-start gap-2",children:[r.jsx(wr,{className:"w-4 h-4 text-bambu-green mt-0.5 flex-shrink-0"}),r.jsx("span",{children:i("settings.authDisabledFeature2")})]}),r.jsxs("li",{className:"flex items-start gap-2",children:[r.jsx(wr,{className:"w-4 h-4 text-bambu-green mt-0.5 flex-shrink-0"}),r.jsx("span",{children:i("settings.authDisabledFeature3")})]})]}),r.jsxs(Me,{onClick:()=>e("/setup"),children:[r.jsx(lc,{className:"w-4 h-4"}),i("settings.enableAuthentication")]})]})})})]}),z==="email"&&r.jsx("div",{className:"max-w-5xl",id:"card-smtp",children:r.jsx(lat,{})}),z==="ldap"&&r.jsx("div",{className:"max-w-5xl",id:"card-ldap",children:r.jsx(dat,{})}),z==="twofa"&&r.jsx("div",{className:"max-w-2xl",children:r.jsx(mat,{})}),z==="oidc"&&d&&r.jsx("div",{className:"max-w-3xl",children:r.jsx(hat,{})}),z==="security"&&d&&r.jsx("div",{className:"max-w-3xl",children:r.jsx(gat,{})})]}),nt&&!di?.advanced_auth_enabled&&r.jsx("div",{className:"fixed inset-0 bg-black flex items-center justify-center z-50 p-4",onClick:()=>{Qe(!1),vt({username:"",password:"",email:"",confirmPassword:"",role:"user",group_ids:[]})},children:r.jsxs(Ct,{className:"w-full max-w-md",onClick:Se=>Se.stopPropagation(),children:[r.jsx(pn,{children:r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(gm,{className:"w-5 h-5 text-bambu-green"}),r.jsx("h2",{className:"text-lg font-semibold text-white",children:i("settings.createUser")})]}),r.jsx(Me,{variant:"ghost",size:"sm",onClick:()=>{Qe(!1),vt({username:"",password:"",email:"",confirmPassword:"",role:"user",group_ids:[]})},children:r.jsx(Ht,{className:"w-5 h-5"})})]})}),r.jsxs(At,{children:[r.jsxs("div",{className:"space-y-3",children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:i("settings.username")}),r.jsx("input",{type:"text",value:st.username,onChange:Se=>vt({...st,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:i("settings.enterUsername"),autoComplete:"username"})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:i("settings.password")}),r.jsx("input",{type:"password",value:st.password,onChange:Se=>vt({...st,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:i("settings.enterPassword"),autoComplete:"new-password",minLength:8}),r.jsx("p",{className:"text-bambu-gray text-xs mt-1",children:i("settings.passwordRequirements")})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:i("settings.confirmPassword")}),r.jsx("input",{type:"password",value:st.confirmPassword,onChange:Se=>vt({...st,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 ${st.confirmPassword&&st.password!==st.confirmPassword?"border-red-500":"border-bambu-dark-tertiary"}`,placeholder:i("settings.confirmPasswordPlaceholder"),autoComplete:"new-password",minLength:6}),st.confirmPassword&&st.password!==st.confirmPassword&&r.jsx("p",{className:"text-red-400 text-xs mt-1",children:i("settings.passwordsDoNotMatch")})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:i("settings.groups")}),r.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:[Qr.map(Se=>r.jsxs("label",{className:"flex items-center gap-3 px-2 py-1.5 rounded hover:bg-bambu-dark-tertiary cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:st.group_ids.includes(Se.id),onChange:()=>hf(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"}),r.jsx("span",{className:"text-sm text-white",children:Se.name}),Se.is_system&&r.jsx("span",{className:"text-xs text-yellow-400",children:i("settings.systemBadge")})]},Se.id)),Qr.length===0&&r.jsx("p",{className:"text-sm text-bambu-gray",children:i("settings.noGroupsAvailable")})]})]})]}),r.jsxs("div",{className:"mt-6 flex justify-end gap-3",children:[r.jsx(Me,{variant:"secondary",onClick:()=>{Qe(!1),vt({username:"",password:"",email:"",confirmPassword:"",role:"user",group_ids:[]})},children:i("common.cancel")}),r.jsx(Me,{onClick:wd,disabled:ol.isPending||!st.username||!st.password||st.password!==st.confirmPassword||cN(st.password)!==null,children:ol.isPending?r.jsxs(r.Fragment,{children:[r.jsx(pt,{className:"w-4 h-4 animate-spin"}),i("settings.creating")]}):r.jsxs(r.Fragment,{children:[r.jsx(ar,{className:"w-4 h-4"}),i("settings.createUser")]})})]})]})]})}),nt&&di?.advanced_auth_enabled&&r.jsx(Frt,{formData:st,setFormData:vt,groups:Qr,onClose:()=>{Qe(!1),vt({username:"",password:"",email:"",confirmPassword:"",role:"user",group_ids:[]})},onCreate:wd,isCreating:ol.isPending,isCreateButtonDisabled:ol.isPending||!st.username||!st.email}),gt&&rt!==null&&r.jsx("div",{className:"fixed inset-0 bg-black flex items-center justify-center z-50 p-4",onClick:()=>{ct(!1),Ot(null),vt({username:"",password:"",email:"",confirmPassword:"",role:"user",group_ids:[]})},children:r.jsxs(Ct,{className:"w-full max-w-md",onClick:Se=>Se.stopPropagation(),children:[r.jsx(pn,{children:r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(fc,{className:"w-5 h-5 text-bambu-green"}),r.jsx("h2",{className:"text-lg font-semibold text-white",children:i("settings.editUser")})]}),r.jsx(Me,{variant:"ghost",size:"sm",onClick:()=>{ct(!1),Ot(null),vt({username:"",password:"",email:"",confirmPassword:"",role:"user",group_ids:[]})},children:r.jsx(Ht,{className:"w-5 h-5"})})]})}),r.jsxs(At,{children:[r.jsxs("div",{className:"space-y-3",children:[r.jsxs("div",{children:[r.jsxs("label",{className:"block text-sm font-medium text-white mb-2",children:[i("settings.username")," ",di?.advanced_auth_enabled&&r.jsx("span",{className:"text-red-400",children:"*"})]}),r.jsx("input",{type:"text",value:st.username,onChange:Se=>vt({...st,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:i("settings.enterUsername"),autoComplete:"username"})]}),r.jsxs("div",{children:[r.jsxs("label",{className:"block text-sm font-medium text-white mb-2",children:[i("users.form.email")||"Email"," ",di?.advanced_auth_enabled?r.jsx("span",{className:"text-red-400",children:"*"}):r.jsxs("span",{className:"text-bambu-gray font-normal",children:["(",i("users.form.optional")||"optional",")"]})]}),r.jsx("input",{type:"email",value:st.email,onChange:Se=>vt({...st,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:i("users.form.emailPlaceholder")||"user@example.com",required:di?.advanced_auth_enabled})]}),!di?.advanced_auth_enabled&&r.jsxs(r.Fragment,{children:[r.jsxs("div",{children:[r.jsxs("label",{className:"block text-sm font-medium text-white mb-2",children:[i("users.form.password")||"Password"," ",r.jsxs("span",{className:"text-bambu-gray font-normal",children:["(",i("users.form.leaveBlankToKeep")||"leave blank to keep current",")"]})]}),r.jsx("input",{type:"password",value:st.password,onChange:Se=>vt({...st,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:i("settings.enterNewPassword"),autoComplete:"new-password",minLength:8}),r.jsx("p",{className:"text-bambu-gray text-xs mt-1",children:i("settings.passwordRequirements")})]}),st.password&&r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:i("settings.confirmPassword")}),r.jsx("input",{type:"password",value:st.confirmPassword,onChange:Se=>vt({...st,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 ${st.confirmPassword&&st.password!==st.confirmPassword?"border-red-500":"border-bambu-dark-tertiary"}`,placeholder:i("settings.confirmNewPassword"),autoComplete:"new-password",minLength:6}),st.confirmPassword&&st.password!==st.confirmPassword&&r.jsx("p",{className:"text-red-400 text-xs mt-1",children:i("settings.passwordsDoNotMatch")})]})]}),di?.advanced_auth_enabled&&r.jsxs("div",{className:"bg-bambu-dark-secondary/50 border border-bambu-green/20 rounded-lg p-3 space-y-3",children:[r.jsx("p",{className:"text-sm text-bambu-gray",children:i("users.form.passwordManagedByAdvancedAuth")||'Password is managed by Advanced Authentication. Use "Reset Password" to send a new password to the user via email.'}),r.jsx(Me,{variant:"secondary",size:"sm",onClick:()=>rt&&vd.mutate(rt),disabled:vd.isPending||!st.email,className:"w-full",children:vd.isPending?r.jsxs(r.Fragment,{children:[r.jsx(pt,{className:"w-4 h-4 animate-spin"}),i("users.form.resettingPassword")||"Resetting Password..."]}):r.jsxs(r.Fragment,{children:[r.jsx(gs,{className:"w-4 h-4"}),i("users.form.resetPassword")||"Reset Password"]})})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:i("users.form.groups")||"Groups"}),r.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:Qr.map(Se=>r.jsxs("label",{className:"flex items-center gap-3 px-2 py-1.5 rounded hover:bg-bambu-dark-tertiary cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:st.group_ids.includes(Se.id),onChange:()=>hf(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"}),r.jsx("span",{className:"text-sm text-white",children:Se.name}),Se.is_system&&r.jsxs("span",{className:"text-xs text-yellow-400",children:["(",i("users.system")||"System",")"]})]},Se.id))})]})]}),r.jsxs("div",{className:"mt-6 flex justify-end gap-3",children:[r.jsx(Me,{variant:"secondary",onClick:()=>{ct(!1),Ot(null),vt({username:"",password:"",email:"",confirmPassword:"",role:"user",group_ids:[]})},children:i("users.modal.cancel")||"Cancel"}),r.jsx(Me,{onClick:()=>gb(rt),disabled:ll.isPending||!st.username||di?.advanced_auth_enabled&&!st.email||!!(!di?.advanced_auth_enabled&&st.password&&(st.password!==st.confirmPassword||cN(st.password)!==null)),children:ll.isPending?r.jsxs(r.Fragment,{children:[r.jsx(pt,{className:"w-4 h-4 animate-spin"}),i("users.modal.saving")||"Saving..."]}):r.jsxs(r.Fragment,{children:[r.jsx(us,{className:"w-4 h-4"}),i("users.modal.saveChanges")||"Save Changes"]})})]})]})]})}),Wt!==null&&r.jsx("div",{className:"fixed inset-0 bg-black/80 flex items-center justify-center z-50 p-4",onClick:()=>{Zt(null),un(null)},children:r.jsxs(Ct,{className:"w-full max-w-md",onClick:Se=>Se.stopPropagation(),children:[r.jsx(pn,{children:r.jsxs("div",{className:"flex items-center gap-2 text-red-400",children:[r.jsx(Jt,{className:"w-5 h-5"}),r.jsx("h3",{className:"text-lg font-semibold",children:i("settings.deleteUserTitle")})]})}),r.jsx(At,{className:"space-y-3",children:bn?r.jsx("div",{className:"flex items-center justify-center py-4",children:r.jsx("div",{className:"animate-spin rounded-full h-6 w-6 border-2 border-bambu-green border-t-transparent"})}):Yt&&Yt.archives+Yt.queue_items+Yt.library_files>0?r.jsxs(r.Fragment,{children:[r.jsx("p",{className:"text-white",children:i("settings.userHasCreated")}),r.jsxs("ul",{className:"list-disc list-inside text-bambu-gray space-y-1",children:[Yt.archives>0&&r.jsxs("li",{children:[Yt.archives," archive",Yt.archives!==1?"s":""]}),Yt.queue_items>0&&r.jsxs("li",{children:[Yt.queue_items," queue item",Yt.queue_items!==1?"s":""]}),Yt.library_files>0&&r.jsxs("li",{children:[Yt.library_files," library file",Yt.library_files!==1?"s":""]})]}),r.jsx("p",{className:"text-bambu-gray text-sm",children:i("settings.userItemsQuestion")}),r.jsxs("div",{className:"flex flex-col gap-2",children:[r.jsx(Me,{variant:"danger",onClick:()=>cl.mutate({id:Wt,deleteItems:!0}),disabled:cl.isPending,className:"justify-center",children:i("settings.deleteUserAndItems")}),r.jsx(Me,{variant:"secondary",onClick:()=>cl.mutate({id:Wt,deleteItems:!1}),disabled:cl.isPending,className:"justify-center",children:i("settings.deleteUserKeepItems")}),r.jsx(Me,{variant:"ghost",onClick:()=>{Zt(null),un(null)},disabled:cl.isPending,className:"justify-center",children:i("common.cancel")})]})]}):r.jsxs(r.Fragment,{children:[r.jsx("p",{className:"text-white",children:i("settings.deleteUserConfirm")}),r.jsx("p",{className:"text-bambu-gray text-sm",children:i("settings.actionCannotBeUndone")}),r.jsxs("div",{className:"flex gap-2 justify-end",children:[r.jsx(Me,{variant:"ghost",onClick:()=>{Zt(null),un(null)},disabled:cl.isPending,children:i("common.cancel")}),r.jsx(Me,{variant:"danger",onClick:()=>cl.mutate({id:Wt,deleteItems:!1}),disabled:cl.isPending,children:i("settings.deleteUserTitle")})]})]})})]})}),_t!==null&&r.jsx(vn,{title:i("settings.deleteGroupTitle"),message:i("settings.deleteGroupMessage"),confirmText:i("settings.deleteGroup"),variant:"danger",onConfirm:()=>{Fo.mutate(_t),Dt(null)},onCancel:()=>Dt(null)}),O==="failure-detection"&&r.jsx("div",{id:"card-failure-detection",children:r.jsx(iat,{})}),O==="backup"&&r.jsxs("div",{id:"card-backup",children:[r.jsxs("div",{className:"mb-4 p-3 bg-amber-500/10 border border-amber-500/30 rounded-lg flex items-start gap-2",children:[r.jsx(Sl,{className:"text-amber-400 flex-shrink-0 mt-0.5",size:16}),r.jsx("p",{className:"text-sm text-amber-400",children:i("backup.includesEncryptionKey")})]}),r.jsx(aat,{})]}),at&&r.jsx(vn,{title:i("settings.disableAuthenticationTitle"),message:i("settings.disableAuthenticationMessage"),confirmText:i("settings.disableAuthentication"),variant:"danger",onConfirm:async()=>{try{await se.disableAuth(),o(i("settings.toast.authDisabled"),"success"),await u(),lt(!1),window.location.href="/"}catch(Se){const Rt=Se instanceof Error?Se.message:i("settings.toast.authDisableFailed");o(Rt,"error")}},onCancel:()=>lt(!1)}),Fe&&r.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",onClick:()=>{tt(!1),Ye({currentPassword:"",newPassword:"",confirmPassword:""})},children:r.jsxs(Ct,{className:"w-full max-w-md",onClick:Se=>Se.stopPropagation(),children:[r.jsx(pn,{children:r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(vo,{className:"w-5 h-5 text-bambu-green"}),r.jsx("h2",{className:"text-lg font-semibold text-white",children:i("settings.changePassword")})]}),r.jsx(Me,{variant:"ghost",size:"sm",onClick:()=>{tt(!1),Ye({currentPassword:"",newPassword:"",confirmPassword:""})},children:r.jsx(Ht,{className:"w-5 h-5"})})]})}),r.jsxs(At,{children:[r.jsxs("div",{className:"space-y-3",children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:"Current Password"}),r.jsx("input",{type:"password",value:Pe.currentPassword,onChange:Se=>Ye({...Pe,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:i("settings.enterCurrentPassword"),autoComplete:"current-password"})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:"New Password"}),r.jsx("input",{type:"password",value:Pe.newPassword,onChange:Se=>Ye({...Pe,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:i("settings.enterNewPasswordMin6"),autoComplete:"new-password",minLength:6})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:"Confirm New Password"}),r.jsx("input",{type:"password",value:Pe.confirmPassword,onChange:Se=>Ye({...Pe,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 ${Pe.confirmPassword&&Pe.newPassword!==Pe.confirmPassword?"border-red-500":"border-bambu-dark-tertiary"}`,placeholder:i("settings.confirmNewPassword"),autoComplete:"new-password",minLength:6}),Pe.confirmPassword&&Pe.newPassword!==Pe.confirmPassword&&r.jsx("p",{className:"text-red-400 text-xs mt-1",children:i("settings.passwordsDoNotMatch")})]})]}),r.jsxs("div",{className:"mt-6 flex justify-end gap-3",children:[r.jsx(Me,{variant:"secondary",onClick:()=>{tt(!1),Ye({currentPassword:"",newPassword:"",confirmPassword:""})},children:i("common.cancel")}),r.jsx(Me,{onClick:async()=>{if(Pe.newPassword!==Pe.confirmPassword){o(i("settings.toast.passwordsDoNotMatch"),"error");return}if(Pe.newPassword.length<6){o(i("settings.toast.passwordTooShort"),"error");return}fe(!0);try{await se.changePassword(Pe.currentPassword,Pe.newPassword),o(i("settings.toast.passwordChanged"),"success"),tt(!1),Ye({currentPassword:"",newPassword:"",confirmPassword:""})}catch(Se){const Rt=Se instanceof Error?Se.message:"Failed to change password";o(Rt,"error")}finally{fe(!1)}},disabled:Ue||!Pe.currentPassword||!Pe.newPassword||Pe.newPassword!==Pe.confirmPassword||Pe.newPassword.length<6,children:Ue?r.jsxs(r.Fragment,{children:[r.jsx(pt,{className:"w-4 h-4 animate-spin"}),i("settings.changing")]}):r.jsxs(r.Fragment,{children:[r.jsx(vo,{className:"w-4 h-4"}),i("settings.changePassword")]})})]})]})]})})]})]})]})})}const Ace=t=>{const e=parseFloat(t);return(Math.trunc(e*1e3)/1e3).toFixed(3)},kat=t=>t.startsWith("HH")?"HF":"S",Nat=t=>{const e=t.match(/^([A-Z]{2}\d{2})/);return e?e[1]:"HH00"},jce=t=>{const e=["High Flow_","High Flow ","Standard_","Standard ","HF_","HF ","S_","S "];for(const a of e)if(t.startsWith(a))return t.slice(a.length);const n=t.indexOf("_");return n>0?t.slice(n+1):t};function lF({profile:t,onEdit:e,onCopy:n,selectionMode:a,isSelected:i,onToggleSelect:s,note:o}){const l=kat(t.nozzle_id),c=t.nozzle_diameter,d=()=>{a&&s?s():e()};return r.jsxs("div",{className:"flex items-center gap-2",children:[a&&r.jsx("button",{onClick:s,className:"text-bambu-gray hover:text-white transition-colors p-1",children:i?r.jsx(bs,{className:"w-4 h-4 text-bambu-green"}):r.jsx(so,{className:"w-4 h-4"})}),r.jsxs("button",{onClick:d,className:`flex-1 text-left px-3 py-2 bg-bambu-dark rounded hover:bg-bambu-dark-tertiary transition-colors ${i?"ring-1 ring-bambu-green":""}`,children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:"text-bambu-green font-mono text-sm font-bold whitespace-nowrap",children:Ace(t.k_value)}),r.jsx("span",{className:"text-white text-sm truncate flex-1",title:t.name,children:t.name||"Unnamed"}),o&&r.jsx("span",{title:"Has note",children:r.jsx(IZ,{className:"w-3 h-3 text-yellow-500"})}),r.jsxs("span",{className:"text-xs text-bambu-gray whitespace-nowrap",children:[l," ",c]})]}),o&&r.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]})]}),!a&&n&&r.jsx("button",{onClick:u=>{u.stopPropagation(),n()},className:"text-bambu-gray hover:text-white transition-colors p-1",title:"Copy profile",children:r.jsx(Mi,{className:"w-4 h-4"})})]})}function cF({profile:t,printerId:e,nozzleDiameter:n,existingProfiles:a=[],builtinFilaments:i=[],isDualNozzle:s=!1,initialNote:o="",initialNoteKey:l=null,onClose:c,onSave:d,onSaveNote:u,hasPermission:m}){const{t:p}=kt(),{showToast:f}=rn(),[b,w]=y.useState(t?.name||""),[g,x]=y.useState(t?.k_value?Ace(t.k_value):"0.020"),[_,N]=y.useState(t?.filament_id||""),[C,P]=y.useState(t?.nozzle_id?Nat(t.nozzle_id):"HH00"),[T,A]=y.useState(t?.nozzle_diameter||n),[F,S]=y.useState(t?[t.extruder_id]:s?[0,1]:[0]),[E,U]=y.useState(!1),[I,H]=y.useState({current:0,total:0}),[R,Q]=y.useState(o),re=pa.useMemo(()=>{const me=new Map;for(const Ce of i)me.set(Ce.filament_id,Ce.name);const be=new Map;for(const Ce of a)if(Ce.filament_id&&!be.has(Ce.filament_id)){const W=me.get(Ce.filament_id)||jce(Ce.name||"");be.set(Ce.filament_id,{id:Ce.filament_id,name:W||Ce.filament_id})}return Array.from(be.values()).sort((Ce,$)=>Ce.name.localeCompare($.name))},[a,i]),J=it({mutationFn:me=>(console.log("[KProfile] Calling API..."),se.setKProfile(e,me)),onSuccess:me=>{if(console.log("[KProfile] Save success:",me),f(p("kProfiles.toast.profileSaved")),u&&R!==o){let be;R===""&&l?be=l:t&&t.slot_id>0?be=t.setting_id||`slot_${t.slot_id}_${t.filament_id}_${t.extruder_id}`:be=`name_${b}_${_}`,u(be,R)}U(!0),setTimeout(()=>{U(!1),d()},2500)},onError:me=>{console.error("[KProfile] Save error:",me),f(me.message,"error"),U(!1)}}),de=it({mutationFn:me=>(console.log("[KProfile] Deleting profile..."),se.deleteKProfile(e,me)),onSuccess:me=>{console.log("[KProfile] Delete success:",me),f(p("kProfiles.toast.profileDeleted")),U(!0),setTimeout(()=>{U(!1),c()},4e3)},onError:me=>{console.error("[KProfile] Delete error:",me),f(me.message,"error"),U(!1)}}),[pe,ue]=y.useState(!1),X=()=>{t&&de.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})},ae=async me=>{if(me.preventDefault(),s&&!t&&F.length===0){f(p("kProfiles.toast.selectAtLeastOneExtruder"),"error");return}const be=parseFloat(g).toFixed(6),Ce=`${C}-${T}`;if(t||F.length===1){const W={name:b,k_value:be,filament_id:_,nozzle_id:Ce,nozzle_diameter:T,extruder_id:t?t.extruder_id:F[0],setting_id:t?.setting_id,slot_id:t?.slot_id??0};console.log("[KProfile] Saving profile:",W),J.mutate(W);return}U(!0),H({current:1,total:F.length});const $=F.map(W=>({name:b,k_value:be,filament_id:_,nozzle_id:Ce,nozzle_diameter:T,extruder_id:W,setting_id:void 0,slot_id:0}));console.log(`[KProfile] Saving ${$.length} profiles in batch:`,$);try{if(await se.setKProfilesBatch(e,$),f(p("kProfiles.toast.profilesSaved",{count:F.length})),u&&R){const W=`name_${b}_${_}`;u(W,R)}}catch(W){console.error("[KProfile] Failed to save batch:",W),f(p("kProfiles.toast.failedToSaveBatch"),"error"),U(!1),H({current:0,total:0});return}H({current:F.length,total:F.length}),setTimeout(()=>{U(!1),H({current:0,total:0}),d()},3e3)};return r.jsxs("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",children:[r.jsxs(Ct,{className:"w-full max-w-md relative",children:[E&&r.jsxs("div",{className:"absolute inset-0 bg-bambu-dark-secondary/90 flex flex-col items-center justify-center z-10 rounded-lg",children:[r.jsx(pt,{className:"w-8 h-8 text-bambu-green animate-spin mb-3"}),r.jsx("p",{className:"text-white font-medium",children:I.total>1?p("kProfiles.modal.savingExtruder",{current:I.current,total:I.total}):p("kProfiles.modal.syncing")}),r.jsx("p",{className:"text-bambu-gray text-sm mt-1",children:p("kProfiles.modal.pleaseWait")})]}),r.jsxs(At,{className:"p-0",children:[r.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[r.jsx("h2",{className:"text-xl font-semibold text-white",children:p(t?"kProfiles.modal.editTitle":"kProfiles.modal.addTitle")}),r.jsx("button",{onClick:c,className:"text-bambu-gray hover:text-white transition-colors",disabled:E,children:r.jsx(Ht,{className:"w-5 h-5"})})]}),r.jsxs("form",{onSubmit:ae,className:"p-4 space-y-4",children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:p("kProfiles.modal.profileName")}),r.jsx("input",{type:"text",value:b,onChange:me=>w(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})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:p("kProfiles.modal.kValue")}),r.jsx("input",{type:"text",inputMode:"decimal",value:g,onChange:me=>{const be=me.target.value;(be===""||/^\d*\.?\d*$/.test(be))&&x(be)},onBlur:me=>{const be=parseFloat(me.target.value);isNaN(be)||x((Math.trunc(be*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}),r.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:p("kProfiles.modal.kValueHelp")})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:p("kProfiles.modal.filament")}),r.jsxs("select",{value:_,onChange:me=>{const be=me.target.value;if(N(be),!t&&be&&!b){const Ce=re.find($=>$.id===be);Ce&&w(`${C==="HH00"?"HF":"S"} ${Ce.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:[r.jsx("option",{value:"",children:p("kProfiles.modal.selectFilament")}),t?.filament_id&&r.jsx("option",{value:t.filament_id,children:re.find(me=>me.id===t.filament_id)?.name||t.filament_id},t.filament_id),!t&&re.map(me=>r.jsx("option",{value:me.id,children:me.name},me.id))]}),!t&&re.length===0&&r.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:p("kProfiles.modal.noFilamentsHelp")})]}),r.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:p("kProfiles.modal.flowType")}),r.jsxs("select",{value:C,onChange:me=>{const be=me.target.value;if(P(be),!t&&_&&!b){const Ce=re.find($=>$.id===_);Ce&&w(`${be==="HS00"?"HF":"S"} ${Ce.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:[r.jsx("option",{value:"HH00",children:p("kProfiles.modal.highFlow")}),r.jsx("option",{value:"HS00",children:p("kProfiles.modal.standard")})]})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:p("kProfiles.modal.nozzleSize")}),r.jsxs("select",{value:T,onChange:me=>A(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:[r.jsx("option",{value:"0.2",children:"0.2mm"}),r.jsx("option",{value:"0.4",children:"0.4mm"}),r.jsx("option",{value:"0.6",children:"0.6mm"}),r.jsx("option",{value:"0.8",children:"0.8mm"})]})]})]}),s&&r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:p(t?"kProfiles.modal.extruder":"kProfiles.modal.extruders")}),t?r.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")}):r.jsxs("div",{className:"flex gap-4",children:[r.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:F.includes(1),onChange:me=>{me.target.checked?S([...F,1]):S(F.filter(be=>be!==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"}),r.jsx("span",{className:"text-white",children:p("kProfiles.modal.left")})]}),r.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:F.includes(0),onChange:me=>{me.target.checked?S([...F,0]):S(F.filter(be=>be!==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"}),r.jsx("span",{className:"text-white",children:p("kProfiles.modal.right")})]})]})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:p("kProfiles.modal.notes")}),r.jsx("textarea",{value:R,onChange:me=>Q(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"}),r.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:p("kProfiles.modal.notesHelp")})]}),r.jsxs("div",{className:"flex gap-2 pt-4",children:[t&&r.jsx(Me,{type:"button",variant:"secondary",onClick:()=>ue(!0),disabled:de.isPending||E||!m("kprofiles:delete"),title:m("kprofiles:delete")?void 0:p("kProfiles.permission.noDelete"),className:"text-red-500 hover:bg-red-500/10",children:de.isPending?r.jsx(pt,{className:"w-4 h-4 animate-spin"}):r.jsx(Jt,{className:"w-4 h-4"})}),r.jsx(Me,{type:"button",variant:"secondary",onClick:c,disabled:E,className:"flex-1",children:p("common.cancel")}),r.jsxs(Me,{type:"submit",disabled:J.isPending||E||!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:[J.isPending?r.jsx(pt,{className:"w-4 h-4 animate-spin"}):r.jsx(CS,{className:"w-4 h-4"}),p("common.save")]})]})]})]})]}),pe&&r.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-[60]",children:r.jsx(Ct,{className:"w-full max-w-sm",children:r.jsxs(At,{className:"p-6",children:[r.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[r.jsx("div",{className:"w-10 h-10 rounded-full bg-red-500/20 flex items-center justify-center",children:r.jsx(Jt,{className:"w-5 h-5 text-red-500"})}),r.jsxs("div",{children:[r.jsx("h3",{className:"text-lg font-semibold text-white",children:p("kProfiles.deleteConfirm.title")}),r.jsx("p",{className:"text-sm text-bambu-gray",children:p("kProfiles.deleteConfirm.cannotUndo")})]})]}),r.jsx("p",{className:"text-bambu-gray mb-6",children:p("kProfiles.deleteConfirm.message",{name:t?.name})}),r.jsxs("div",{className:"flex gap-3",children:[r.jsx(Me,{variant:"secondary",onClick:()=>ue(!1),className:"flex-1",children:p("common.cancel")}),r.jsxs(Me,{onClick:()=>{ue(!1),X()},disabled:de.isPending,className:"flex-1 bg-red-500 hover:bg-red-600 text-white",children:[de.isPending?r.jsx(pt,{className:"w-4 h-4 animate-spin"}):r.jsx(Jt,{className:"w-4 h-4"}),p("common.delete")]})]})]})})})]})}const dN={NOZZLE_DIAMETER:"bambusy_kprofiles_nozzle",SORT_OPTION:"bambusy_kprofiles_sort"};function Cat(){const{t}=kt(),{showToast:e}=rn(),{hasPermission:n}=cr(),[a,i]=y.useState(null),[s,o]=y.useState(()=>localStorage.getItem(dN.NOZZLE_DIAMETER)||"0.4"),[l,c]=y.useState(null),[d,u]=y.useState(!1),[m,p]=y.useState(null),[f,b]=y.useState(""),[w,g]=y.useState("all"),[x,_]=y.useState("all"),[N,C]=y.useState(()=>localStorage.getItem(dN.SORT_OPTION)||"name"),[P,T]=y.useState(!1),[A,F]=y.useState(new Set),[S,E]=y.useState(!1),[U,I]=y.useState(!1),H=y.useCallback(L=>`${L.slot_id}_${L.extruder_id}`,[]);y.useEffect(()=>{localStorage.setItem(dN.NOZZLE_DIAMETER,s)},[s]),y.useEffect(()=>{localStorage.setItem(dN.SORT_OPTION,N)},[N]);const{data:R,isLoading:Q}=Ve({queryKey:["printers"],queryFn:se.getPrinters}),{data:re,isLoading:J,isFetching:de,error:pe,refetch:ue}=Ve({queryKey:["kprofiles",a,s],queryFn:async()=>{console.log("[KProfiles] Fetching profiles for printer",a,"nozzle",s);const L=await se.getKProfiles(a,s);return console.log("[KProfiles] Received profiles:",L?.profiles?.length||0,"profiles"),L},enabled:!!a,retry:!1,staleTime:0,gcTime:0,refetchOnMount:"always"}),{data:X}=Ve({queryKey:["kprofiles",a,"0.4"],queryFn:()=>se.getKProfiles(a,"0.4"),enabled:!!a,staleTime:6e4}),{data:ae}=Ve({queryKey:["builtinFilaments"],queryFn:()=>se.getBuiltinFilaments(),staleTime:3e5}),{data:me}=Ve({queryKey:["filamentIdMap"],queryFn:()=>se.getFilamentIdMap(),staleTime:3e5}),{data:be,refetch:Ce}=Ve({queryKey:["kprofile-notes",a],queryFn:()=>se.getKProfileNotes(a),enabled:!!a,staleTime:3e4}),$=pe?.message?.includes("not connected");y.useEffect(()=>{if(!a&&R&&R.length>0){const L=R.find(ne=>ne.is_active);L&&i(L.id)}},[a,R]),y.useEffect(()=>{if(a){const L=setTimeout(()=>{ue()},150);return()=>clearTimeout(L)}},[a,s]);const W=R?.filter(L=>L.is_active)||[],D=pa.useMemo(()=>{const L=new Map;if(ae)for(const ne of ae)L.set(ne.filament_id,ne.name);if(me)for(const[ne,ye]of Object.entries(me))L.has(ne)||L.set(ne,ye);return L},[ae,me]),j=pa.useMemo(()=>Array.from(D.entries()).map(([L,ne])=>({filament_id:L,name:ne})),[D]),B=pa.useCallback(L=>D.get(L.filament_id)||jce(L.name),[D]),Y=pa.useMemo(()=>re?.profiles?re.profiles.filter(ne=>{const ye=f.toLowerCase(),we=!ye||ne.name.toLowerCase().includes(ye)||ne.filament_id.toLowerCase().includes(ye),Ne=w==="all"||w==="left"&&ne.extruder_id===1||w==="right"&&ne.extruder_id===0,ve=x==="all"||x==="hf"&&ne.nozzle_id.startsWith("HH")||x==="s"&&ne.nozzle_id.startsWith("HS");return we&&Ne&&ve}).sort((ne,ye)=>{switch(N){case"k_value":return parseFloat(ne.k_value)-parseFloat(ye.k_value);case"filament":return B(ne).localeCompare(B(ye));default:return ne.name.localeCompare(ye.name)}}):[],[re?.profiles,f,w,x,N,B]),O=R?.find(L=>L.id===a),ie=O?.nozzle_count===2;y.useEffect(()=>{const L=ne=>{ne.target instanceof HTMLInputElement||ne.target instanceof HTMLTextAreaElement||ne.target instanceof HTMLSelectElement||l||d||m||(ne.key==="r"||ne.key==="R"?(ne.preventDefault(),ue()):ne.key==="n"||ne.key==="N"?(ne.preventDefault(),u(!0)):ne.key==="Escape"&&P&&(ne.preventDefault(),T(!1),F(new Set)))};return window.addEventListener("keydown",L),()=>window.removeEventListener("keydown",L)},[l,d,m,P,ue]);const z=y.useCallback(()=>{if(!re?.profiles||re.profiles.length===0){e(t("kProfiles.toast.noProfilesToExport"),"error");return}const L={version:1,exported_at:new Date().toISOString(),printer:O?.name||"Unknown",nozzle_diameter:s,profiles:re.profiles.map(Ne=>({name:Ne.name,k_value:Ne.k_value,filament_id:Ne.filament_id,nozzle_id:Ne.nozzle_id,nozzle_diameter:Ne.nozzle_diameter,extruder_id:Ne.extruder_id}))},ne=new Blob([JSON.stringify(L,null,2)],{type:"application/json"}),ye=URL.createObjectURL(ne),we=document.createElement("a");we.href=ye,we.download=`kprofiles_${O?.name||"printer"}_${s}mm_${new Date().toISOString().split("T")[0]}.json`,document.body.appendChild(we),we.click(),document.body.removeChild(we),URL.revokeObjectURL(ye),e(t("kProfiles.toast.exportedProfiles",{count:re.profiles.length}))},[re?.profiles,O,s,e,t]),G=y.useCallback(()=>{const L=document.createElement("input");L.type="file",L.accept=".json",L.onchange=async ne=>{const ye=ne.target.files?.[0];if(ye)try{const we=await ye.text(),Ne=JSON.parse(we);if(!Ne.profiles||!Array.isArray(Ne.profiles)){e(t("kProfiles.toast.invalidFileFormat"),"error");return}let ve=0;for(const xe of Ne.profiles)if(!(!xe.name||!xe.k_value||!xe.filament_id))try{await se.setKProfile(a,{name:xe.name,k_value:parseFloat(xe.k_value).toFixed(6),filament_id:xe.filament_id,nozzle_id:xe.nozzle_id||`HH00-${s}`,nozzle_diameter:xe.nozzle_diameter||s,extruder_id:xe.extruder_id??0,slot_id:0}),ve++,await new Promise(Ee=>setTimeout(Ee,500))}catch(Ee){console.error("Failed to import profile:",xe.name,Ee)}e(t("kProfiles.toast.importedProfiles",{count:ve,total:Ne.profiles.length})),ue()}catch(we){console.error("Import error:",we),e(t("kProfiles.toast.failedToParseImport"),"error")}},L.click()},[a,s,e,ue,t]),K=y.useCallback(L=>{F(ne=>{const ye=new Set(ne);return ye.has(L)?ye.delete(L):ye.add(L),ye})},[]),Z=y.useCallback(()=>{F(new Set(Y.map(L=>H(L))))},[Y,H]),oe=y.useCallback(()=>{A.size!==0&&E(!0)},[A.size]),ee=y.useCallback(async()=>{const L=Y.filter(ye=>A.has(H(ye)));I(!0);let ne=0;for(const ye of L)try{await se.deleteKProfile(a,{slot_id:ye.slot_id,extruder_id:ye.extruder_id,nozzle_id:ye.nozzle_id,nozzle_diameter:ye.nozzle_diameter,filament_id:ye.filament_id,setting_id:ye.setting_id}),ne++,await new Promise(we=>setTimeout(we,300))}catch(we){console.error("Failed to delete profile:",ye.name,we)}e(t("kProfiles.toast.profilesDeleted",{count:ne})),I(!1),E(!1),T(!1),F(new Set),ue()},[a,A,Y,e,ue,H,t]),ge=y.useCallback(L=>{const ne=[];return L.setting_id&&ne.push(L.setting_id),ne.push(`slot_${L.slot_id}_${L.filament_id}_${L.extruder_id}`),ne.push(`name_${L.name}_${L.filament_id}`),ne},[]),ce=y.useCallback(async(L,ne)=>{if(a)try{await se.setKProfileNote(a,L,ne),Ce()}catch(ye){console.error("Failed to save note:",ye),e(t("kProfiles.toast.failedToSaveNote"),"error")}},[a,Ce,e,t]),le=y.useCallback(L=>{if(!be?.notes)return{note:"",key:null};const ne=ge(L);for(const ye of ne)if(be.notes[ye])return{note:be.notes[ye],key:ye};return{note:"",key:null}},[be,ge]),q=y.useCallback(L=>le(L).note,[le]);return Q?r.jsx("div",{className:"flex justify-center py-12",children:r.jsx(pt,{className:"w-8 h-8 text-bambu-green animate-spin"})}):!R||R.length===0?r.jsx(Ct,{children:r.jsxs(At,{className:"py-12 text-center",children:[r.jsx($a,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),r.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:t("kProfiles.noPrintersConfigured")}),r.jsx("p",{className:"text-bambu-gray",children:t("kProfiles.addPrinterInSettings")})]})}):W.length===0?r.jsx(Ct,{children:r.jsxs(At,{className:"py-12 text-center",children:[r.jsx(pr,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),r.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:t("kProfiles.noActivePrinters")}),r.jsx("p",{className:"text-bambu-gray",children:t("kProfiles.enablePrinterConnection")})]})}):r.jsxs(r.Fragment,{children:[de&&!J&&r.jsxs("div",{className:"fixed inset-0 bg-black/50 flex flex-col items-center justify-center z-40",children:[r.jsx(pt,{className:"w-10 h-10 text-bambu-green animate-spin mb-3"}),r.jsx("p",{className:"text-white font-medium",children:t("kProfiles.loadingProfiles")})]}),r.jsxs("div",{className:"flex flex-wrap gap-4 mb-6",children:[r.jsxs("div",{className:"flex-1 min-w-48",children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:t("kProfiles.printer")}),r.jsx("select",{value:a||"",onChange:L=>i(parseInt(L.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.map(L=>r.jsx("option",{value:L.id,children:L.name},L.id))})]}),r.jsxs("div",{className:"w-32",children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:t("kProfiles.nozzle")}),r.jsxs("select",{value:s,onChange:L=>o(L.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:[r.jsx("option",{value:"0.2",children:"0.2mm"}),r.jsx("option",{value:"0.4",children:"0.4mm"}),r.jsx("option",{value:"0.6",children:"0.6mm"}),r.jsx("option",{value:"0.8",children:"0.8mm"})]})]}),r.jsxs("div",{className:"flex items-end gap-2",children:[r.jsxs(Me,{variant:"secondary",onClick:()=>ue(),disabled:de||!n("kprofiles:read"),title:n("kprofiles:read")?void 0:t("kProfiles.permission.noRead"),children:[r.jsx(sr,{className:`w-4 h-4 ${de?"animate-spin":""}`}),t("kProfiles.refresh")]}),r.jsxs(Me,{onClick:()=>u(!0),disabled:!n("kprofiles:create"),title:n("kprofiles:create")?void 0:t("kProfiles.permission.noCreate"),children:[r.jsx(ar,{className:"w-4 h-4"}),t("kProfiles.addProfile")]})]})]}),r.jsxs("div",{className:"flex flex-wrap gap-4 mb-4",children:[r.jsxs("div",{className:"flex-1 min-w-48 relative",children:[r.jsx(Sr,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray"}),r.jsx("input",{type:"text",value:f,onChange:L=>b(L.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"})]}),ie&&r.jsx("div",{className:"w-36",children:r.jsxs("select",{value:w,onChange:L=>g(L.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:[r.jsx("option",{value:"all",children:t("kProfiles.allExtruders")}),r.jsx("option",{value:"left",children:t("kProfiles.leftOnly")}),r.jsx("option",{value:"right",children:t("kProfiles.rightOnly")})]})}),r.jsx("div",{className:"w-32",children:r.jsxs("select",{value:x,onChange:L=>_(L.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:[r.jsx("option",{value:"all",children:t("kProfiles.allFlow")}),r.jsx("option",{value:"hf",children:t("kProfiles.hfOnly")}),r.jsx("option",{value:"s",children:t("kProfiles.sOnly")})]})}),r.jsx("div",{className:"w-32",children:r.jsxs("select",{value:N,onChange:L=>C(L.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:[r.jsx("option",{value:"name",children:t("kProfiles.sortName")}),r.jsx("option",{value:"k_value",children:t("kProfiles.sortKValue")}),r.jsx("option",{value:"filament",children:t("kProfiles.sortFilament")})]})})]}),r.jsxs("div",{className:"flex flex-wrap gap-2 mb-6",children:[r.jsxs(Me,{variant:"secondary",onClick:z,disabled:!re?.profiles?.length||!n("kprofiles:read"),title:n("kprofiles:read")?void 0:t("kProfiles.permission.noExport"),children:[r.jsx(Yr,{className:"w-4 h-4"}),t("kProfiles.export")]}),r.jsxs(Me,{variant:"secondary",onClick:G,disabled:!n("kprofiles:create"),title:n("kprofiles:create")?void 0:t("kProfiles.permission.noImport"),children:[r.jsx(ka,{className:"w-4 h-4"}),t("kProfiles.import")]}),r.jsx("div",{className:"flex-1"}),P?r.jsxs(r.Fragment,{children:[r.jsxs(Me,{variant:"secondary",onClick:Z,children:[r.jsx(bs,{className:"w-4 h-4"}),t("kProfiles.selectAll")]}),r.jsxs(Me,{variant:"secondary",onClick:oe,disabled:A.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:[r.jsx(Jt,{className:"w-4 h-4"}),t("kProfiles.delete")," (",A.size,")"]}),r.jsxs(Me,{variant:"secondary",onClick:()=>{T(!1),F(new Set)},children:[r.jsx(Ht,{className:"w-4 h-4"}),t("common.cancel")]})]}):r.jsxs(Me,{variant:"secondary",onClick:()=>T(!0),disabled:!Y.length||!n("kprofiles:delete"),title:n("kprofiles:delete")?void 0:t("kProfiles.permission.noDelete"),children:[r.jsx(bs,{className:"w-4 h-4"}),t("kProfiles.select")]})]}),J?r.jsx("div",{className:"flex justify-center py-12",children:r.jsx(pt,{className:"w-8 h-8 text-bambu-green animate-spin"})}):$?r.jsx(Ct,{children:r.jsxs(At,{className:"py-12 text-center",children:[r.jsx(mu,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),r.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:t("kProfiles.printerOffline")}),r.jsx("p",{className:"text-bambu-gray mb-4",children:t("kProfiles.printerOfflineDesc")}),r.jsxs(Me,{variant:"secondary",onClick:()=>ue(),children:[r.jsx(sr,{className:"w-4 h-4"}),t("common.refresh")]})]})}):Y.length>0?ie?r.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[r.jsxs("div",{children:[r.jsx("h3",{className:"text-sm font-medium text-bambu-gray mb-2 px-1",children:t("kProfiles.leftExtruder")}),r.jsx("div",{className:"space-y-1",children:Y.filter(L=>L.extruder_id===1).map(L=>r.jsx(lF,{profile:L,onEdit:()=>c(L),onCopy:()=>p(L),selectionMode:P,isSelected:A.has(H(L)),onToggleSelect:()=>K(H(L)),note:q(L)},H(L)))})]}),r.jsxs("div",{children:[r.jsx("h3",{className:"text-sm font-medium text-bambu-gray mb-2 px-1",children:t("kProfiles.rightExtruder")}),r.jsx("div",{className:"space-y-1",children:Y.filter(L=>L.extruder_id===0).map(L=>r.jsx(lF,{profile:L,onEdit:()=>c(L),onCopy:()=>p(L),selectionMode:P,isSelected:A.has(H(L)),onToggleSelect:()=>K(H(L)),note:q(L)},H(L)))})]})]}):r.jsx("div",{className:"space-y-1",children:Y.map(L=>r.jsx(lF,{profile:L,onEdit:()=>c(L),onCopy:()=>p(L),selectionMode:P,isSelected:A.has(H(L)),onToggleSelect:()=>K(H(L)),note:q(L)},H(L)))}):f||w!=="all"||x!=="all"?r.jsx(Ct,{children:r.jsxs(At,{className:"py-12 text-center",children:[r.jsx(Sr,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),r.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:t("kProfiles.noMatchingProfiles")}),r.jsx("p",{className:"text-bambu-gray",children:t("kProfiles.noMatchingProfilesDesc")})]})}):r.jsx(Ct,{children:r.jsxs(At,{className:"py-12 text-center",children:[r.jsx(CS,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),r.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:t("kProfiles.noKProfiles")}),r.jsx("p",{className:"text-bambu-gray mb-4",children:t("kProfiles.noKProfilesDesc",{diameter:s})}),r.jsxs(Me,{onClick:()=>u(!0),children:[r.jsx(ar,{className:"w-4 h-4"}),t("kProfiles.createFirstProfile")]})]})}),l&&a&&(()=>{const{note:L,key:ne}=le(l);return r.jsx(cF,{profile:l,printerId:a,nozzleDiameter:s,existingProfiles:X?.profiles||re?.profiles,builtinFilaments:j,isDualNozzle:ie,initialNote:L,initialNoteKey:ne,onSaveNote:ce,hasPermission:n,onClose:()=>{console.log("[KProfiles] Edit modal onClose - refetching profiles..."),c(null),ue()},onSave:()=>{c(null),ue()}})})(),d&&a&&r.jsx(cF,{printerId:a,nozzleDiameter:s,existingProfiles:X?.profiles||re?.profiles,builtinFilaments:j,isDualNozzle:ie,onSaveNote:ce,hasPermission:n,onClose:()=>{u(!1),ue()},onSave:()=>{u(!1),ue()}}),m&&a&&r.jsx(cF,{printerId:a,nozzleDiameter:s,existingProfiles:X?.profiles||re?.profiles,builtinFilaments:j,isDualNozzle:ie,onSaveNote:ce,hasPermission:n,profile:{...m,slot_id:0,name:`${m.name} (Copy)`},onClose:()=>{p(null),ue()},onSave:()=>{p(null),ue()}}),S&&r.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",children:r.jsx(Ct,{className:"w-full max-w-sm",children:r.jsxs(At,{className:"p-6",children:[r.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[r.jsx("div",{className:"w-10 h-10 rounded-full bg-red-500/20 flex items-center justify-center",children:r.jsx(Jt,{className:"w-5 h-5 text-red-500"})}),r.jsxs("div",{children:[r.jsx("h3",{className:"text-lg font-semibold text-white",children:t("kProfiles.bulkDelete.title")}),r.jsx("p",{className:"text-sm text-bambu-gray",children:t("kProfiles.bulkDelete.cannotUndo")})]})]}),r.jsx("p",{className:"text-bambu-gray mb-6",children:t("kProfiles.bulkDelete.message",{count:A.size})}),r.jsxs("div",{className:"flex gap-3",children:[r.jsx(Me,{variant:"secondary",onClick:()=>E(!1),disabled:U,className:"flex-1",children:t("common.cancel")}),r.jsxs(Me,{onClick:ee,disabled:U,className:"flex-1 bg-red-500 hover:bg-red-600 text-white",children:[U?r.jsx(pt,{className:"w-4 h-4 animate-spin"}):r.jsx(Jt,{className:"w-4 h-4"}),t("common.delete")]})]})]})})})]})}const Mce=["PLA","PETG","PCTG","ABS","ASA","TPU","PC","PA","PVA","HIPS","PP","PET","NYLON"],Pat={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 Tat(t){const e=t.toUpperCase();for(const n of Mce)if(new RegExp(`\\b${n}\\b`).test(e))return n;return null}function Aat(t){const e=t.replace(/@.+$/,"").trim(),n=e.toUpperCase();for(const a of Mce){const i=n.indexOf(a);if(i>0){const s=e.slice(0,i).trim();if(s&&s.length>1)return s}}return null}function dF({preset:t,onDelete:e,onExpand:n,isExpanded:a}){const{t:i}=kt(),{hasPermission:s}=cr(),o=t.filament_type||Tat(t.name),l=t.filament_vendor||Aat(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=Pat[o.toUpperCase()]||null),r.jsx(Ct,{className:"bg-bambu-dark border-bambu-dark-tertiary hover:border-bambu-dark-tertiary/80 transition-colors",children:r.jsxs(At,{className:"p-3",children:[r.jsxs("div",{className:"flex items-start justify-between gap-2",children:[r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[t.preset_type==="filament"&&r.jsx("div",{className:`w-4 h-4 rounded-full border border-black/20 flex-shrink-0 ${!d&&!c?"opacity-25":d?"":"opacity-50"}`,style:{backgroundColor:c?`#${c}`:"#666"}}),r.jsx("span",{className:"text-sm font-medium text-white truncate",children:t.name})]}),r.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[o&&r.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-bambu-green/20 text-bambu-green",children:o}),l&&r.jsx("span",{className:"text-xs text-bambu-gray",children:l}),r.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-blue-500/20 text-blue-400",children:i("profiles.localProfiles.badge")})]})]}),r.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[s("settings:update")&&r.jsx("button",{onClick:()=>e(t.id),className:"p-1 text-bambu-gray hover:text-red-400 transition-colors",title:i("profiles.localProfiles.delete"),children:r.jsx(Jt,{className:"w-3.5 h-3.5"})}),r.jsx("button",{onClick:()=>n(a?null:t.id),className:"p-1 text-bambu-gray hover:text-white transition-colors",children:a?r.jsx(tl,{className:"w-3.5 h-3.5"}):r.jsx(Ln,{className:"w-3.5 h-3.5"})})]})]}),a&&r.jsxs("div",{className:"mt-3 pt-3 border-t border-bambu-dark-tertiary text-xs space-y-1.5",children:[o&&r.jsxs("div",{className:"flex justify-between",children:[r.jsx("span",{className:"text-bambu-gray",children:i("profiles.localProfiles.filamentType")}),r.jsx("span",{className:"text-white",children:o})]}),l&&r.jsxs("div",{className:"flex justify-between",children:[r.jsx("span",{className:"text-bambu-gray",children:i("profiles.localProfiles.vendor")}),r.jsx("span",{className:"text-white",children:l})]}),t.nozzle_temp_min!=null&&t.nozzle_temp_max!=null&&r.jsxs("div",{className:"flex justify-between",children:[r.jsx("span",{className:"text-bambu-gray",children:i("profiles.localProfiles.nozzleTemp")}),r.jsxs("span",{className:"text-white",children:[t.nozzle_temp_min,"–",t.nozzle_temp_max,"°C"]})]}),t.filament_cost&&r.jsxs("div",{className:"flex justify-between",children:[r.jsx("span",{className:"text-bambu-gray",children:i("profiles.localProfiles.cost")}),r.jsx("span",{className:"text-white",children:t.filament_cost})]}),t.filament_density&&r.jsxs("div",{className:"flex justify-between",children:[r.jsx("span",{className:"text-bambu-gray",children:i("profiles.localProfiles.density")}),r.jsxs("span",{className:"text-white",children:[t.filament_density," g/cm³"]})]}),t.pressure_advance&&r.jsxs("div",{className:"flex justify-between",children:[r.jsx("span",{className:"text-bambu-gray",children:i("profiles.localProfiles.pressureAdvance")}),r.jsx("span",{className:"text-white",children:t.pressure_advance})]}),t.compatible_printers&&r.jsxs("div",{className:"flex justify-between",children:[r.jsx("span",{className:"text-bambu-gray",children:i("profiles.localProfiles.compatiblePrinters")}),r.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&&r.jsxs("div",{className:"flex justify-between",children:[r.jsx("span",{className:"text-bambu-gray",children:i("profiles.localProfiles.inheritsFrom")}),r.jsx("span",{className:"text-white truncate ml-2",children:t.inherits})]}),r.jsxs("div",{className:"flex justify-between",children:[r.jsx("span",{className:"text-bambu-gray",children:i("profiles.localProfiles.source")}),r.jsx("span",{className:"text-white capitalize",children:t.source})]})]})]})})}function jat(){const{t}=kt(),{hasPermission:e}=cr(),n=en(),{showToast:a}=rn(),[i,s]=y.useState(""),[o,l]=y.useState(null),[c,d]=y.useState(!1),[u,m]=y.useState(null),{data:p,isLoading:f}=Ve({queryKey:["localPresets"],queryFn:()=>se.getLocalPresets()}),b=it({mutationFn:async A=>{const F=[];for(const S of Array.from(A)){const E=new FormData;E.append("file",S),F.push(await se.importLocalPresets(E))}return F},onSuccess:A=>{n.invalidateQueries({queryKey:["localPresets"]});let F=0,S=0,E=0;for(const U of A)F+=U.imported,S+=U.skipped,E+=U.errors.length;F>0&&a(t("profiles.localProfiles.toast.importSuccess",{count:F})),S>0&&a(t("profiles.localProfiles.toast.importSkipped",{count:S}),"warning"),E>0&&a(t("profiles.localProfiles.toast.importError",{count:E}),"error")},onError:A=>{a(A.message,"error")}}),w=it({mutationFn:A=>se.deleteLocalPreset(A),onSuccess:()=>{n.invalidateQueries({queryKey:["localPresets"]}),m(null),a(t("profiles.localProfiles.toast.deleted"))}}),g=y.useCallback(A=>{!A||A.length===0||b.mutate(A)},[b]),x=y.useCallback(A=>{A.preventDefault(),d(!1),g(A.dataTransfer.files)},[g]),_=y.useCallback(A=>{if(!i)return A;const F=i.toLowerCase();return A.filter(S=>S.name.toLowerCase().includes(F)||S.filament_type?.toLowerCase().includes(F)||S.filament_vendor?.toLowerCase().includes(F))},[i]),N=y.useMemo(()=>_(p?.filament||[]),[p?.filament,_]),C=y.useMemo(()=>_(p?.printer||[]),[p?.printer,_]),P=y.useMemo(()=>_(p?.process||[]),[p?.process,_]),T=N.length+C.length+P.length;return f?r.jsx("div",{className:"flex items-center justify-center py-16",children:r.jsx(pt,{className:"w-8 h-8 text-bambu-green animate-spin"})}):r.jsxs("div",{className:"space-y-6",children:[e("settings:update")&&r.jsxs("div",{onDragOver:A=>{A.preventDefault(),d(!0)},onDragLeave:()=>d(!1),onDrop:x,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:[r.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:A=>g(A.target.files)}),b.isPending?r.jsxs("div",{className:"flex items-center justify-center gap-2",children:[r.jsx(pt,{className:"w-5 h-5 text-bambu-green animate-spin"}),r.jsx("span",{className:"text-bambu-gray",children:t("profiles.localProfiles.importing")})]}):r.jsxs(r.Fragment,{children:[r.jsx(ka,{className:"w-8 h-8 text-bambu-gray mx-auto mb-2"}),r.jsx("p",{className:"text-sm text-white font-medium",children:t("profiles.localProfiles.import")}),r.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:t("profiles.localProfiles.importDesc")})]})]}),T>0&&r.jsxs("div",{className:"relative",children:[r.jsx(Sr,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray"}),r.jsx("input",{type:"text",value:i,onChange:A=>s(A.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"})]}),T===0&&!f&&r.jsxs("div",{className:"text-center py-12",children:[r.jsx(ob,{className:"w-12 h-12 text-bambu-gray mx-auto mb-3 opacity-50"}),r.jsx("p",{className:"text-bambu-gray",children:t("profiles.localProfiles.noPresets")}),r.jsx("p",{className:"text-xs text-bambu-gray/60 mt-1",children:t("profiles.localProfiles.importDesc")})]}),T>0&&r.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6",children:[N.length>0&&r.jsxs("div",{children:[r.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[r.jsx(ST,{className:"w-4 h-4 text-bambu-green"}),r.jsx("h3",{className:"text-sm font-medium text-white",children:t("profiles.localProfiles.filament")}),r.jsxs("span",{className:"text-xs text-bambu-gray",children:["(",N.length,")"]})]}),r.jsx("div",{className:"space-y-2",children:N.map(A=>r.jsx(dF,{preset:A,onDelete:F=>m(F),onExpand:l,isExpanded:o===A.id},A.id))})]}),P.length>0&&r.jsxs("div",{children:[r.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[r.jsx(oa,{className:"w-4 h-4 text-blue-400"}),r.jsx("h3",{className:"text-sm font-medium text-white",children:t("profiles.localProfiles.process")}),r.jsxs("span",{className:"text-xs text-bambu-gray",children:["(",P.length,")"]})]}),r.jsx("div",{className:"space-y-2",children:P.map(A=>r.jsx(dF,{preset:A,onDelete:F=>m(F),onExpand:l,isExpanded:o===A.id},A.id))})]}),C.length>0&&r.jsxs("div",{children:[r.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[r.jsx(uu,{className:"w-4 h-4 text-orange-400"}),r.jsx("h3",{className:"text-sm font-medium text-white",children:t("profiles.localProfiles.printer")}),r.jsxs("span",{className:"text-xs text-bambu-gray",children:["(",C.length,")"]})]}),r.jsx("div",{className:"space-y-2",children:C.map(A=>r.jsx(dF,{preset:A,onDelete:F=>m(F),onExpand:l,isExpanded:o===A.id},A.id))})]})]}),u!==null&&r.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50",children:r.jsxs("div",{className:"bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg p-6 max-w-sm mx-4",children:[r.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[r.jsx($a,{className:"w-5 h-5 text-red-400"}),r.jsx("h3",{className:"text-white font-medium",children:t("profiles.localProfiles.deleteConfirmTitle")})]}),r.jsx("p",{className:"text-sm text-bambu-gray mb-4",children:t("profiles.localProfiles.deleteConfirm")}),r.jsxs("div",{className:"flex justify-end gap-2",children:[r.jsx(Me,{variant:"secondary",size:"sm",onClick:()=>m(null),children:t("profiles.localProfiles.cancel")}),r.jsxs(Me,{variant:"danger",size:"sm",onClick:()=>w.mutate(u),disabled:w.isPending,children:[w.isPending?r.jsx(pt,{className:"w-4 h-4 animate-spin"}):r.jsx(Jt,{className:"w-4 h-4"}),t("profiles.localProfiles.delete")]})]})]})})]})}function aU(t,e){const n=`${t} ${e||""}`,a=n.match(/@?\s*(?:BBL\s+)?(?:Bambu\s+Lab\s+)?([XPAH][1-9][A-Z]?(?:\s*(?:Carbon|mini))?|H2D)/i),i=a?a[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:i,nozzle:o,layerHeight:c,filamentType:u}}function vS(t){return/^(P[FPM]US|PF\d|PP\d)/.test(t)}function Mat({onSuccess:t,t:e}){const{showToast:n}=rn(),[a,i]=y.useState("email"),[s,o]=y.useState(""),[l,c]=y.useState(""),[d,u]=y.useState(""),[m,p]=y.useState(""),[f,b]=y.useState("global"),[w,g]=y.useState(null),[x,_]=y.useState(null),N=it({mutationFn:()=>se.cloudLogin(s,l,f),onSuccess:F=>{F.success?(n(e("profiles.login.toast.loggedIn")),t()):F.needs_verification?(g(F.verification_type||"email"),_(F.tfa_key||null),F.verification_type==="totp"?n(e("profiles.login.toast.enterTotp")):n(e("profiles.login.toast.codeSent")),i("code")):n(F.message,"error")},onError:F=>n(F.message,"error")}),C=it({mutationFn:()=>se.cloudVerify(s,d,x||void 0,f),onSuccess:F=>{F.success?(n(e("profiles.login.toast.loggedIn")),t()):n(F.message,"error")},onError:F=>n(F.message,"error")}),P=it({mutationFn:()=>se.cloudSetToken(m,f),onSuccess:()=>{n(e("profiles.login.toast.tokenSet")),t()},onError:F=>n(F.message,"error")}),T=F=>{F.preventDefault(),a==="email"?N.mutate():a==="code"?C.mutate():a==="token"&&P.mutate()},A=N.isPending||C.isPending||P.isPending;return r.jsx(Ct,{className:"max-w-md mx-auto",children:r.jsxs(At,{children:[r.jsxs("div",{className:"text-center mb-6",children:[r.jsx("div",{className:"inline-flex items-center justify-center w-12 h-12 rounded-xl bg-bambu-green/20 mb-3",children:r.jsx(Hh,{className:"w-6 h-6 text-bambu-green"})}),r.jsx("h2",{className:"text-xl font-semibold text-white",children:e("profiles.login.title")}),r.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:e("profiles.login.subtitle")})]}),r.jsxs("form",{onSubmit:T,className:"space-y-4",children:[a==="email"&&r.jsxs(r.Fragment,{children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:e("profiles.login.email")}),r.jsx("input",{type:"email",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 placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none",placeholder:"your@email.com",required:!0})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:e("profiles.login.password")}),r.jsx("input",{type:"password",value:l,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 placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none",placeholder:"••••••••",required:!0})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:e("profiles.login.region")}),r.jsxs("select",{value:f,onChange:F=>b(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:[r.jsx("option",{value:"global",children:e("profiles.login.regionGlobal")}),r.jsx("option",{value:"china",children:e("profiles.login.regionChina")})]})]})]}),a==="code"&&r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:e(w==="totp"?"profiles.login.totpCode":"profiles.login.verificationCode")}),r.jsx("p",{className:"text-xs text-bambu-gray mb-2",children:w==="totp"?e("profiles.login.enterTotpHint"):e("profiles.login.checkEmail",{email:s})}),r.jsx("input",{type:"text",value:d,onChange:F=>u(F.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})]}),a==="token"&&r.jsxs(r.Fragment,{children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:e("profiles.login.accessToken")}),r.jsx("p",{className:"text-xs text-bambu-gray mb-2",children:e("profiles.login.accessTokenHint")}),r.jsx("textarea",{value:m,onChange:F=>p(F.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})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:e("profiles.login.region")}),r.jsxs("select",{value:f,onChange:F=>b(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:[r.jsx("option",{value:"global",children:e("profiles.login.regionGlobal")}),r.jsx("option",{value:"china",children:e("profiles.login.regionChina")})]})]})]}),r.jsxs("div",{className:"flex gap-2 max-[550px]:flex-wrap max-[550px]:items-center",children:[a==="code"&&r.jsx(Me,{type:"button",variant:"secondary",onClick:()=>i("email"),className:"flex-1",children:e("profiles.login.back")}),r.jsxs(Me,{type:"submit",disabled:A,className:"flex-1",children:[A?r.jsx(pt,{className:"w-4 h-4 animate-spin"}):r.jsx(Y0,{className:"w-4 h-4"}),e(a==="email"?"profiles.login.loginButton":a==="code"?"profiles.login.verifyButton":"profiles.login.setTokenButton")]})]}),a==="email"&&r.jsx("div",{className:"pt-4 border-t border-bambu-dark-tertiary",children:r.jsxs("button",{type:"button",onClick:()=>i("token"),className:"text-sm text-bambu-gray hover:text-white flex items-center gap-2 transition-colors",children:[r.jsx(vo,{className:"w-4 h-4"}),e("profiles.login.useToken")]})}),a==="token"&&r.jsx("div",{className:"pt-4 border-t border-bambu-dark-tertiary",children:r.jsxs("button",{type:"button",onClick:()=>i("email"),className:"text-sm text-bambu-gray hover:text-white flex items-center gap-2 transition-colors",children:[r.jsx(Y0,{className:"w-4 h-4"}),e("profiles.login.useEmail")]})})]})]})})}function Lx({label:t,value:e,options:n,onChange:a}){const[i,s]=y.useState(!1),o=n.find(l=>l.value===e);return r.jsxs("div",{className:"relative",children:[r.jsxs("button",{onClick:()=>s(!i),className:"flex items-center gap-2 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-sm text-white hover:border-bambu-gray-dark transition-colors",children:[r.jsxs("span",{className:"text-bambu-gray",children:[t,":"]}),r.jsx("span",{children:o?.label||"All"}),r.jsx(Ln,{className:`w-4 h-4 text-bambu-gray transition-transform ${i?"rotate-180":""}`})]}),i&&r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"fixed inset-0 z-10",onClick:()=>s(!1)}),r.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=>r.jsxs("button",{onClick:()=>{a(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:[r.jsx("span",{children:l.label}),l.count!==void 0&&r.jsx("span",{className:"text-bambu-gray text-xs",children:l.count})]},l.value))})]})]})}function Eat(){const[t,e]=y.useState(!1);y.useEffect(()=>{const a=()=>{e(window.scrollY>300)};return window.addEventListener("scroll",a),()=>window.removeEventListener("scroll",a)},[]);const n=()=>{window.scrollTo({top:0,behavior:"smooth"})};return t?r.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:r.jsx(Hm,{className:"w-5 h-5"})}):null}function uF({setting:t,onClick:e,onDuplicate:n,compareMode:a,isCompareSelected:i,compareIndex:s,compareDisabled:o,t:l}){const c=aU(t.name),d=vS(t.setting_id);return r.jsxs("div",{className:"flex items-center gap-2 group",children:[r.jsx("button",{onClick:e,disabled:o,className:`flex-1 text-left px-3 py-2 rounded transition-colors ${i?"bg-blue-500/20 border border-blue-500/50":o?"bg-bambu-dark/50 opacity-40 cursor-not-allowed":"bg-bambu-dark hover:bg-bambu-dark-tertiary"} ${a&&!o?"cursor-pointer":""}`,children:r.jsxs("div",{className:"flex items-center gap-2",children:[i&&s!==void 0&&r.jsx("span",{className:"flex-shrink-0 w-5 h-5 rounded-full bg-blue-500 text-white text-xs flex items-center justify-center font-medium",children:s+1}),!i&&d&&r.jsx("span",{className:"flex-shrink-0 w-1.5 h-1.5 rounded-full bg-bambu-green",title:l("profiles.presets.myPreset")}),r.jsx("span",{className:"text-white text-sm truncate flex-1",title:t.name,children:t.name}),c.filamentType&&t.type==="filament"&&r.jsx("span",{className:"text-xs text-bambu-gray whitespace-nowrap",children:c.filamentType}),c.layerHeight&&t.type==="process"&&r.jsx("span",{className:"text-xs text-bambu-gray whitespace-nowrap",children:c.layerHeight}),c.printer&&r.jsx("span",{className:"text-xs text-bambu-gray whitespace-nowrap",children:c.printer})]})}),r.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:r.jsx(Mi,{className:"w-4 h-4"})})]})}function KI(t,e=0){const n=" ".repeat(e);if(t===null)return"null";if(t===void 0)return"undefined";if(typeof t=="string"){if(t.includes("\\n")||t.includes(` `)){const i=t.replace(/\\n/g,` `).replace(/\\"/g,'"').replace(/\\t/g," ").split(` `);if(i.length>1)return`""" diff --git a/static/index.html b/static/index.html index 232a8002f..e8800202b 100644 --- a/static/index.html +++ b/static/index.html @@ -26,7 +26,7 @@ - +