From 6530a6af061e15ac64a611de10e207ad3f85f26f Mon Sep 17 00:00:00 2001 From: maziggy Date: Mon, 27 Jul 2026 08:27:05 +0200 Subject: [PATCH] fix(library): send camera stream token for 3D Preview plate thumbnails (#2661) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The File Manager 3D Preview dialog (ModelViewerModal) rendered plate thumbnails with the raw thumbnail_url. The plate-thumbnail endpoints are gated behind a camera stream token passed as ?token= (an can't send an Authorization header), so with auth enabled the browser fetched without a token and got 401 "Valid camera stream token required" — broken image icons for every plate. The Slice dialog's picker (PlatePickerModal) and the Print modal's PlateSelector already append the token via withStreamToken(), which is why the same file's thumbnails showed there. Wrap the thumbnail src in withStreamToken(), matching the other two call sites. The token is synced app-wide and withStreamToken() is a no-op when auth is off, so non-auth setups are unchanged. --- CHANGELOG.md | 1 + .../components/ModelViewerModal.test.tsx | 28 +++++++++++++++++++ frontend/src/components/ModelViewerModal.tsx | 4 +-- .../{index-Bx0t8q7D.js => index-DYQO8a-5.js} | 2 +- static/index.html | 2 +- 5 files changed, 33 insertions(+), 4 deletions(-) rename static/assets/{index-Bx0t8q7D.js => index-DYQO8a-5.js} (99%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d2af54ca..e79402bb6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ All notable changes to Bambuddy will be documented in this file. ## [1.2.6b1] - Unreleased ### Fixed +- **3D Preview plate thumbnails were broken (401) in File Manager when login was enabled (#2661, reporter @fbordonaro)** — Opening a multi-plate 3MF via **File Manager → 3D Preview** showed broken-image icons for every plate thumbnail, and the network tab showed `GET /api/v1/library/files//plate-thumbnail/` returning **401 "Valid camera stream token required."** The Slice dialog displayed the same file's thumbnails correctly, which is what made it look inconsistent. **Root cause.** The plate-thumbnail endpoints (both archive and library) are gated behind a **camera stream token** passed as a `?token=` query param, because an `` tag can't send an `Authorization: Bearer` header. Every place that renders these thumbnails is supposed to append the token via the `withStreamToken()` helper — `PlatePickerModal` (the Slice dialog's multi-plate picker) and the Print modal's `PlateSelector` both do — but the **3D Preview dialog** (`ModelViewerModal`) rendered the raw `thumbnail_url` with no token, so with auth enabled the browser fetched without one and got a 401. **Fix.** `ModelViewerModal` now wraps the plate thumbnail `src` in `withStreamToken()`, matching the two existing call sites. The token is already synced app-wide (the same global the working pickers read), and `withStreamToken()` is a no-op when auth is off, so nothing changes for non-auth setups. Covered by a component test asserting the plate thumbnail `` carries the `?token=` query param. - **Force color match dispatched a print onto the wrong PLA variant — Matte jobs went to Basic and Silk printers alike, and the wrong AMS slot on a printer holding two same-colour variants (#2650, reporter @MartinNYHC)** — With **Force color match** on, a job sliced for **White PLA Matte** was dispatched to every printer that had *any* white PLA loaded — the ones holding White PLA **Basic** and White PLA **Silk+** included — so a matte model came out glossy on the wrong machine. **Root cause.** Bambu's MQTT status reports every PLA sub-variant as `tray_type == "PLA"`; the Basic/Matte/Silk distinction is carried only in `tray_info_idx` (`GFA00` = Basic, `GFA01` = Matte, `GFA06` = Silk, …), which the 3MF's `slice_info.config` also records per filament. Three places dropped it: the Virtual-Printer queue built each force override as `{slot_id, type, color, force_color_match}` without the parsed `tray_info_idx`; the scheduler's eligibility check (`_get_missing_force_color_slots`) compared loaded trays on `(type, colour)` only — so `(PLA, #FFFFFF)` matched Basic, Matte and Silk indiscriminately and all three printers looked eligible; and the AMS slot mapper cleared `tray_info_idx` when applying the override, so even on the correct printer it could pick a different-variant tray of the same colour. **Fix.** The force override now carries the 3MF's `tray_info_idx`; a slot counts as satisfied only when a loaded tray matches type **and** colour **and** the variant (identical `tray_info_idx`, *or* either side lacks one); and the slot mapper now keeps the variant for force-colour overrides so it pins the matching tray. A blank idx on either side (custom/third-party spools report none, and older 3MFs carry none) falls back to the historical type+colour behaviour, so those setups are unaffected, and a manual filament *swap* (a preference override) still clears the idx so it matches the swapped-in spool rather than the old one. A job sliced for GFA01 now goes only to a printer with GFA01 loaded, and lands on that printer's GFA01 tray. The printer-card queue-compatibility hint (which printers show a pending job as runnable) now applies the same variant rule. Covered by scheduler tests (Matte requirement rejects Basic/Silk, accepts Matte, blank loaded idx falls back, requirement without an idx unchanged; the mapper pins the GFA01 tray over a same-colour GFA00 on both the 3MF and no-3MF paths; a preference swap still matches by colour), a Virtual-Printer test asserting the override carries `tray_info_idx`, and frontend tests for the variant-aware queue hint (rejects other variants, accepts the match, blank-idx and no-variant-data fall back). diff --git a/frontend/src/__tests__/components/ModelViewerModal.test.tsx b/frontend/src/__tests__/components/ModelViewerModal.test.tsx index 09b0b1da5..8db3a65f3 100644 --- a/frontend/src/__tests__/components/ModelViewerModal.test.tsx +++ b/frontend/src/__tests__/components/ModelViewerModal.test.tsx @@ -7,6 +7,7 @@ import { describe, it, expect, vi, beforeEach } from 'vitest'; import { screen, fireEvent, waitFor } from '@testing-library/react'; import { render } from '../utils'; import { ModelViewerModal } from '../../components/ModelViewerModal'; +import { setStreamToken } from '../../api/client'; import { http, HttpResponse } from 'msw'; import { server } from '../mocks/server'; @@ -385,6 +386,33 @@ describe('ModelViewerModal', () => { }); }); + // #2661: plate-thumbnail endpoints are gated behind a camera stream token + // (an can't send a Bearer header), so the src must carry ?token=. + // Without it the 3D Preview thumbnails 401 while the Slice dialog (which + // already appends the token) shows the same file's thumbnails fine. + it('appends the camera stream token to plate thumbnail URLs', async () => { + setStreamToken('tok-2661'); + try { + render( + + ); + + await waitFor(() => { + expect(screen.getByText('Plate 1')).toBeInTheDocument(); + }); + + const thumb = screen.getByAltText('Plate 1') as HTMLImageElement; + expect(thumb.src).toContain('/api/v1/archives/1/plates/1/thumbnail'); + expect(thumb.src).toContain('token=tok-2661'); + } finally { + setStreamToken(null); + } + }); + it('allows plate selection via click', async () => { render( {plate.has_thumbnail && plate.thumbnail_url ? ( {`Plate diff --git a/static/assets/index-Bx0t8q7D.js b/static/assets/index-DYQO8a-5.js similarity index 99% rename from static/assets/index-Bx0t8q7D.js rename to static/assets/index-DYQO8a-5.js index 62add1933..d8d7b65d8 100644 --- a/static/assets/index-Bx0t8q7D.js +++ b/static/assets/index-DYQO8a-5.js @@ -8715,7 +8715,7 @@ ${t.slice(l+2)}`,d+=1;else break}t.push({indent:l,number:parseInt(s,10),content: `+n+`]`;if(typeof e==`object`){let r=Object.entries(e);return r.length===0?`{}`:`{ `+r.map(([e,r])=>n+` `+JSON.stringify(e)+`: `+P6(r,t+1)).join(`, `)+` -`+n+`}`}return String(e)}function aWe({setting:e,onClose:t,onDeleted:n,onDuplicate:r,onEdit:i,hasPermission:a,t:o}){let{showToast:s}=Pd(),c=oo(),[l,u]=(0,y.useState)(!1),{data:d,isLoading:f}=q({queryKey:[`cloudSettingDetail`,e.setting_id],queryFn:()=>Q.getCloudSettingDetail(e.setting_id)}),p=J({mutationFn:()=>Q.deleteCloudSetting(e.setting_id),onSuccess:()=>{s(o(`profiles.presets.toast.deleted`)),c.invalidateQueries({queryKey:[`cloudSettings`]}),n()},onError:e=>s(e.message,`error`)}),m=j6(e.setting_id),h=A6(e.name,d?.setting?.inherits);return(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,children:(0,K.jsx)(Ed,{className:`w-full max-w-3xl max-h-[90vh] flex flex-col overflow-hidden`,children:(0,K.jsxs)(Od,{className:`p-0 flex flex-col min-h-0 flex-1`,children:[(0,K.jsxs)(`div`,{className:`flex-shrink-0 flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`h2`,{className:`text-xl font-semibold text-white truncate`,children:e.name}),m&&(0,K.jsx)(`span`,{className:`px-2 py-0.5 text-xs font-medium bg-bambu-green/20 text-bambu-green rounded-full`,children:o(`profiles.presets.editable`)})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mt-1 text-sm text-bambu-gray`,children:[(0,K.jsx)(`span`,{className:`capitalize`,children:o(`profiles.presets.types.${e.type}`)}),h.printer&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`span`,{children:`•`}),(0,K.jsx)(`span`,{children:h.printer})]})]})]}),(0,K.jsx)(`button`,{onClick:t,className:`p-2 text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary rounded-lg transition-colors`,children:(0,K.jsx)(qu,{className:`w-5 h-5`})})]}),(0,K.jsx)(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-4`,children:f?(0,K.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,K.jsx)(X,{className:`w-8 h-8 text-bambu-green animate-spin`})}):d?(0,K.jsx)(`pre`,{className:`text-xs text-bambu-gray font-mono whitespace-pre-wrap break-all bg-bambu-dark p-4 rounded-lg border border-bambu-dark-tertiary overflow-x-auto max-w-full`,children:P6(d)}):(0,K.jsx)(`div`,{className:`text-center py-16 text-bambu-gray`,children:o(`profiles.presets.failedToLoadDetails`)})}),l?(0,K.jsxs)(`div`,{className:`flex-shrink-0 p-4 border-t border-bambu-dark-tertiary bg-red-500/5`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-3 text-red-700 dark:text-red-400`,children:[(0,K.jsx)(ku,{className:`w-5 h-5`}),(0,K.jsx)(`span`,{className:`font-medium`,children:o(`profiles.presets.deleteConfirm`)})]}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mb-4`,children:o(`profiles.presets.deleteWarning`,{name:e.name})}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)($,{variant:`secondary`,onClick:()=>u(!1),disabled:p.isPending,className:`flex-1`,children:o(`common.cancel`)}),(0,K.jsxs)($,{variant:`danger`,onClick:()=>p.mutate(),disabled:p.isPending,className:`flex-1`,children:[p.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(Eu,{className:`w-4 h-4`}),o(`common.delete`)]})]})]}):(0,K.jsx)(`div`,{className:`flex-shrink-0 p-4 border-t border-bambu-dark-tertiary`,children:(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)($,{variant:`secondary`,onClick:t,className:`flex-1`,children:o(`common.close`)}),(0,K.jsxs)($,{variant:`secondary`,onClick:r,disabled:!a(`cloud:auth`),title:a(`cloud:auth`)?void 0:o(`profiles.presets.noDuplicatePermission`),children:[(0,K.jsx)(Fs,{className:`w-4 h-4`}),o(`profiles.presets.duplicate`)]}),m&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)($,{variant:`secondary`,onClick:i,disabled:f||!d||!a(`cloud:auth`),title:a(`cloud:auth`)?void 0:o(`profiles.presets.noEditPermission`),children:[(0,K.jsx)(wl,{className:`w-4 h-4`}),o(`common.edit`)]}),(0,K.jsx)($,{variant:`danger`,onClick:()=>u(!0),disabled:!a(`cloud:auth`),title:a(`cloud:auth`)?void 0:o(`profiles.presets.noDeletePermission`),children:(0,K.jsx)(Eu,{className:`w-4 h-4`})})]})]})})]})})})}function F6(){try{let e=localStorage.getItem(`bambusy_preset_templates`);return e?JSON.parse(e):[]}catch{return[]}}function I6(e){localStorage.setItem(`bambusy_preset_templates`,JSON.stringify(e))}function oWe({onClose:e,onApply:t,t:n}){let{showToast:r}=Pd(),[i,a]=(0,y.useState)(F6),[o,s]=(0,y.useState)(`all`),[c,l]=(0,y.useState)(null),[u,d]=(0,y.useState)(``),[f,p]=(0,y.useState)(``),[m,h]=(0,y.useState)(`{}`),[g,_]=(0,y.useState)(null),[v,b]=(0,y.useState)(null),x=o===`all`?i:i.filter(e=>e.type===o),S=e=>{a(e),I6(e)},C=e=>{S(i.filter(t=>t.id!==e)),b(null),r(n(`profiles.templates.toast.deleted`))},w=e=>{l(e.id),d(e.name),p(e.description),h(JSON.stringify(e.settings,null,2)),_(null)},T=()=>{if(!(!c||!u.trim()))try{let e=JSON.parse(m);S(i.map(t=>t.id===c?{...t,name:u.trim(),description:f.trim(),settings:e}:t)),l(null),r(n(`profiles.templates.toast.updated`))}catch(e){_(e.message)}},E=()=>{l(null),d(``),p(``),h(`{}`),_(null)},D=e=>{S(i.map(t=>t.id===e?{...t,showInModal:!t.showInModal}:t))},O={filament:{label:n(`profiles.presets.types.filament`),icon:Gs,color:`text-amber-600 dark:text-amber-400`},print:{label:n(`profiles.presets.types.process`),icon:Jl,color:`text-blue-600 dark:text-blue-400`},printer:{label:n(`profiles.presets.types.printer`),icon:jl,color:`text-purple-600 dark:text-purple-400`}},k=v?i.find(e=>e.id===v):null;return(0,y.useEffect)(()=>{let t=t=>{t.key===`Escape`&&(v?b(null):c?E():e())};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[v,c,e]),(0,K.jsxs)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:[k&&(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-60`,children:(0,K.jsx)(Ed,{className:`w-full max-w-md`,children:(0,K.jsxs)(Od,{className:`p-6`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3 mb-4`,children:[(0,K.jsx)(`div`,{className:`p-2 bg-red-500/20 rounded-lg`,children:(0,K.jsx)(ku,{className:`w-6 h-6 text-red-600 dark:text-red-400`})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h3`,{className:`text-lg font-semibold text-white`,children:n(`profiles.templates.deleteTitle`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`profiles.templates.deleteWarning`)})]})]}),(0,K.jsx)(`p`,{className:`text-white mb-6`,children:n(`profiles.templates.deleteConfirm`,{name:k.name})}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)($,{variant:`secondary`,onClick:()=>b(null),className:`flex-1`,children:n(`common.cancel`)}),(0,K.jsxs)($,{onClick:()=>C(v),className:`flex-1 bg-red-500 hover:bg-red-600`,children:[(0,K.jsx)(Eu,{className:`w-4 h-4`}),n(`common.delete`)]})]})]})})}),(0,K.jsx)(Ed,{className:`w-full max-w-2xl max-h-[80vh] flex flex-col`,children:(0,K.jsxs)(Od,{className:`p-0 flex flex-col h-full`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(lu,{className:`w-5 h-5 text-amber-600 dark:text-amber-400`}),n(`profiles.templates.title`)]}),(0,K.jsx)(`button`,{onClick:e,className:`text-bambu-gray hover:text-white`,children:(0,K.jsx)(qu,{className:`w-5 h-5`})})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 p-4 border-b border-bambu-dark-tertiary`,children:[(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:n(`profiles.templates.typeFilter`)}),[`all`,`filament`,`print`,`printer`].map(e=>(0,K.jsx)(`button`,{onClick:()=>s(e),className:`px-3 py-1 text-sm rounded-lg transition-colors ${o===e?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white`}`,children:e===`all`?n(`common.all`):O[e].label},e))]}),(0,K.jsx)(`div`,{className:`flex-1 overflow-y-auto p-4`,children:x.length===0?(0,K.jsxs)(`div`,{className:`text-center py-12 text-bambu-gray`,children:[(0,K.jsx)(lu,{className:`w-12 h-12 mx-auto mb-4 opacity-30`}),(0,K.jsx)(`p`,{children:n(`profiles.templates.noTemplates`)}),(0,K.jsx)(`p`,{className:`text-sm mt-1`,children:n(`profiles.templates.createFirst`)})]}):(0,K.jsx)(`div`,{className:`space-y-2`,children:x.map(e=>{let r=O[e.type],i=r.icon;return c===e.id?(0,K.jsxs)(`div`,{className:`p-4 bg-bambu-dark rounded-lg border border-bambu-green`,children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-3 mb-3`,children:[(0,K.jsx)(`input`,{type:`text`,value:u,onChange:e=>d(e.target.value),placeholder:n(`profiles.templates.namePlaceholder`),className:`px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`,autoFocus:!0}),(0,K.jsx)(`input`,{type:`text`,value:f,onChange:e=>p(e.target.value),placeholder:n(`profiles.templates.descriptionPlaceholder`),className:`px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`})]}),(0,K.jsxs)(`div`,{className:`mb-3`,children:[(0,K.jsx)(`label`,{className:`text-xs text-bambu-gray mb-1 block`,children:n(`profiles.templates.settingsJson`)}),(0,K.jsx)(`textarea`,{value:m,onChange:e=>{h(e.target.value),_(null)},rows:6,className:`w-full px-3 py-2 bg-bambu-dark-secondary border rounded text-white text-sm font-mono focus:outline-none ${g?`border-red-500`:`border-bambu-dark-tertiary focus:border-bambu-green`}`}),g&&(0,K.jsx)(`p`,{className:`text-xs text-red-700 dark:text-red-400 mt-1`,children:g})]}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsxs)($,{size:`sm`,onClick:T,disabled:!u.trim(),children:[(0,K.jsx)(zl,{className:`w-4 h-4`}),`Save`]}),(0,K.jsx)($,{size:`sm`,variant:`secondary`,onClick:E,children:`Cancel`})]})]},e.id):(0,K.jsxs)(`div`,{className:`flex items-center gap-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary hover:border-bambu-gray-dark transition-colors`,children:[(0,K.jsx)(i,{className:`w-5 h-5 ${r.color} flex-shrink-0`}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsx)(`p`,{className:`text-sm font-medium text-white`,children:e.name}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray truncate`,children:e.description})]}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray-dark px-2 py-1 bg-bambu-dark-secondary rounded`,children:n(`profiles.templates.fieldsCount`,{count:Object.keys(e.settings).length})}),(0,K.jsx)(`button`,{onClick:()=>D(e.id),className:`p-1 transition-colors ${e.showInModal?`text-bambu-green hover:text-bambu-green/70`:`text-bambu-gray hover:text-white`}`,title:e.showInModal?n(`profiles.templates.shownInModals`):n(`profiles.templates.hiddenInModals`),children:e.showInModal?(0,K.jsx)($s,{className:`w-4 h-4`}):(0,K.jsx)(Qs,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>t(e),className:`px-3 py-1 text-xs bg-bambu-green/20 text-bambu-green rounded hover:bg-bambu-green/30 transition-colors`,children:n(`profiles.templates.apply`)}),(0,K.jsx)(`button`,{onClick:()=>w(e),className:`p-1 text-bambu-gray hover:text-white`,title:n(`common.edit`),children:(0,K.jsx)(wl,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>b(e.id),className:`p-1 text-bambu-gray hover:text-red-600 dark:hover:text-red-400`,title:n(`common.delete`),children:(0,K.jsx)(Eu,{className:`w-4 h-4`})})]},e.id)})})})]})})]})}function L6({onClose:e,leftPreset:t,rightPreset:n,leftLabel:r,rightLabel:i,t:a}){let[o,s]=(0,y.useState)(`changes`),[c,l]=(0,y.useState)(``),u=(0,y.useMemo)(()=>{let e=new Set([...Object.keys(t),...Object.keys(n)]),r=[];for(let i of e){if(i===`inherits`||i===`version`)continue;let e=t[i],a=n[i],o=i in t,s=i in n,c;c=!o&&s?`added`:o&&!s?`removed`:JSON.stringify(e)===JSON.stringify(a)?`same`:`changed`,r.push({key:i,left:e,right:a,status:c})}return r.sort((e,t)=>{let n={changed:0,added:1,removed:2,same:3};return n[e.status]===n[t.status]?e.key.localeCompare(t.key):n[e.status]-n[t.status]})},[t,n]),d=(0,y.useMemo)(()=>{let e=[...u];if(o===`changes`&&(e=e.filter(e=>e.status!==`same`)),c){let t=c.toLowerCase();e=e.filter(e=>e.key.toLowerCase().includes(t)||String(e.left).toLowerCase().includes(t)||String(e.right).toLowerCase().includes(t))}return e},[u,o,c]),f=(0,y.useMemo)(()=>({added:u.filter(e=>e.status===`added`).length,removed:u.filter(e=>e.status===`removed`).length,changed:u.filter(e=>e.status===`changed`).length,same:u.filter(e=>e.status===`same`).length}),[u]),p=e=>{if(e===void 0)return`—`;if(e===null)return`null`;if(Array.isArray(e))return e.length===0?`[]`:e.length===1?String(e[0]):e.join(`, `);if(typeof e==`object`)return JSON.stringify(e);let t=String(e);if(t.includes(`\\n`)||t.length>100){let e=t.split(`\\n`).length;if(e>1)return`[${e} lines of G-code/script]`;if(t.length>100)return t.substring(0,100)+`…`}return t};return(0,y.useEffect)(()=>{let t=t=>{t.key===`Escape`&&e()};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e]),(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:(0,K.jsx)(Ed,{className:`w-full max-w-4xl max-h-[85vh] flex flex-col overflow-hidden`,children:(0,K.jsxs)(Od,{className:`p-0 flex flex-col min-h-0 flex-1`,children:[(0,K.jsxs)(`div`,{className:`flex-shrink-0 flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(xc,{className:`w-5 h-5 text-blue-600 dark:text-blue-400`}),a(`profiles.diff.title`)]}),(0,K.jsx)(`button`,{onClick:e,className:`text-bambu-gray hover:text-white`,children:(0,K.jsx)(qu,{className:`w-5 h-5`})})]}),(0,K.jsxs)(`div`,{className:`flex-shrink-0 grid grid-cols-2 gap-4 p-4 border-b border-bambu-dark-tertiary bg-bambu-dark`,children:[(0,K.jsxs)(`div`,{className:`text-center`,children:[(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:a(`profiles.diff.left`)}),(0,K.jsx)(`p`,{className:`text-white font-medium truncate`,children:r})]}),(0,K.jsxs)(`div`,{className:`text-center`,children:[(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:a(`profiles.diff.right`)}),(0,K.jsx)(`p`,{className:`text-white font-medium truncate`,children:i})]})]}),(0,K.jsxs)(`div`,{className:`flex-shrink-0 flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-4 text-sm`,children:[(0,K.jsxs)(`span`,{className:`flex items-center gap-1 text-green-700 dark:text-green-400`,children:[(0,K.jsx)(Ol,{className:`w-3.5 h-3.5`}),f.added,` `,a(`profiles.diff.added`)]}),(0,K.jsxs)(`span`,{className:`flex items-center gap-1 text-red-700 dark:text-red-400`,children:[(0,K.jsx)(cl,{className:`w-3.5 h-3.5`}),f.removed,` `,a(`profiles.diff.removed`)]}),(0,K.jsxs)(`span`,{className:`flex items-center gap-1 text-amber-700 dark:text-amber-400`,children:[(0,K.jsx)(Io,{className:`w-3.5 h-3.5`}),f.changed,` `,a(`profiles.diff.changed`)]}),(0,K.jsxs)(`span`,{className:`flex items-center gap-1 text-bambu-gray`,children:[(0,K.jsx)(Ys,{className:`w-3.5 h-3.5`}),f.same,` `,a(`profiles.diff.same`)]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(Wl,{className:`absolute left-2 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,K.jsx)(`input`,{type:`text`,value:c,onChange:e=>l(e.target.value),placeholder:a(`profiles.diff.searchFields`),className:`pl-8 pr-3 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none w-48`})]}),f.same>0&&(0,K.jsxs)(`div`,{className:`flex rounded overflow-hidden border border-bambu-dark-tertiary`,children:[(0,K.jsx)(`button`,{onClick:()=>s(`changes`),className:`px-3 py-1.5 text-sm transition-colors ${o===`changes`?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white`}`,children:a(`profiles.diff.changes`)}),(0,K.jsx)(`button`,{onClick:()=>s(`all`),className:`px-3 py-1.5 text-sm transition-colors ${o===`all`?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white`}`,children:a(`common.all`)})]})]})]}),(0,K.jsx)(`div`,{className:`flex-1 min-h-0 overflow-y-auto`,children:d.length===0?(0,K.jsxs)(`div`,{className:`text-center py-12 text-bambu-gray`,children:[(0,K.jsx)(Ys,{className:`w-12 h-12 mx-auto mb-4 opacity-30`}),(0,K.jsx)(`p`,{children:a(o===`changes`?`profiles.diff.noDifferences`:`profiles.diff.noFieldsMatch`)})]}):(0,K.jsxs)(`table`,{className:`w-full`,children:[(0,K.jsx)(`thead`,{className:`sticky top-0 bg-bambu-dark-secondary`,children:(0,K.jsxs)(`tr`,{className:`text-sm text-bambu-gray border-b border-bambu-dark-tertiary`,children:[(0,K.jsx)(`th`,{className:`text-left p-3 w-1/3`,children:a(`profiles.diff.field`)}),(0,K.jsx)(`th`,{className:`text-left p-3 w-1/3`,children:r}),(0,K.jsx)(`th`,{className:`text-left p-3 w-1/3`,children:i})]})}),(0,K.jsx)(`tbody`,{children:d.map(e=>{let t={added:`bg-green-500/10`,removed:`bg-red-500/10`,changed:`bg-amber-500/10`,same:``}[e.status],n={added:(0,K.jsx)(Ol,{className:`w-3.5 h-3.5 text-green-600 dark:text-green-400`}),removed:(0,K.jsx)(cl,{className:`w-3.5 h-3.5 text-red-600 dark:text-red-400`}),changed:(0,K.jsx)(Io,{className:`w-3.5 h-3.5 text-amber-600 dark:text-amber-400`}),same:(0,K.jsx)(Ys,{className:`w-3.5 h-3.5 text-bambu-gray-dark`})}[e.status];return(0,K.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary ${t}`,children:[(0,K.jsx)(`td`,{className:`p-3`,children:(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[n,(0,K.jsx)(`span`,{className:`text-sm text-white font-mono`,children:e.key})]})}),(0,K.jsx)(`td`,{className:`p-3`,children:(0,K.jsx)(`span`,{className:`text-sm font-mono break-all ${e.status===`removed`?`text-red-700 dark:text-red-300`:e.status===`changed`?`text-white`:`text-bambu-gray`}`,children:p(e.left)})}),(0,K.jsx)(`td`,{className:`p-3`,children:(0,K.jsx)(`span`,{className:`text-sm font-mono break-all ${e.status===`added`?`text-green-700 dark:text-green-300`:e.status===`changed`?`text-white`:`text-bambu-gray`}`,children:p(e.right)})})]},e.key)})})]})})]})})})}function sWe({onClose:e,initialData:t,allPresets:n,t:r}){let{showToast:i}=Pd(),a=oo(),o=!!t?.setting_id,[s,c]=(0,y.useState)(`common`),[l,u]=(0,y.useState)(t?.type||`filament`),[d,f]=(0,y.useState)(t?.name?o?t.name:`${t.name} (Copy)`:``),[p,m]=(0,y.useState)(t?.base_id||``),[h,g]=(0,y.useState)(``),[_,v]=(0,y.useState)(t?.setting||{inherits:``}),[b,x]=(0,y.useState)(JSON.stringify(t?.setting||{inherits:``},null,2)),[S,C]=(0,y.useState)(null),[w,T]=(0,y.useState)(``),[E,D]=(0,y.useState)(!1),[O,k]=(0,y.useState)(``),[A,j]=(0,y.useState)(!1),[M,N]=(0,y.useState)(F6),[P,F]=(0,y.useState)(!1),[I,L]=(0,y.useState)(``),[R,z]=(0,y.useState)(``),[B,V]=(0,y.useState)(!0),[ee,te]=(0,y.useState)(null),[ne,re]=(0,y.useState)(!1),ie=(0,y.useMemo)(()=>({filament:n.filament,print:n.process,printer:n.printer})[l]||[],[n,l]),H=(0,y.useMemo)(()=>ie.filter(e=>j6(e.setting_id)),[ie]),{data:ae}=q({queryKey:[`cloudFields`,l],queryFn:()=>Q.getCloudFields(l===`print`?`process`:l),staleTime:1e3*60*60}),{data:oe}=q({queryKey:[`allPresetDetails`,l,H.map(e=>e.setting_id).join(`,`)],queryFn:async()=>{let e={};for(let t=0;t{try{let t=await Q.getCloudSettingDetail(e.setting_id);return{id:e.setting_id,detail:t}}catch{return null}}))).forEach(t=>{t&&(e[t.id]=t.detail)})}return e},enabled:H.length>0,staleTime:1e3*60*10}),{data:U,isLoading:se}=q({queryKey:[`cloudSettingDetail`,p],queryFn:()=>Q.getCloudSettingDetail(p),enabled:!!p});(0,y.useEffect)(()=>{s!==`json`&&x(JSON.stringify(_,null,2))},[_,s]);let ce=(0,y.useMemo)(()=>({filament:n.filament,print:n.process,printer:n.printer}[l]||[]).filter(e=>!j6(e.setting_id)).sort((e,t)=>e.name.localeCompare(t.name)),[n,l]);(0,y.useEffect)(()=>{if(!p)return;let e=ce.find(e=>e.setting_id===p);e&&(g(e.name),o||(v({inherits:e.name}),x(JSON.stringify({inherits:e.name},null,2))))},[p,ce,o]);let le=(0,y.useMemo)(()=>{let e=ae?.fields||[],t=new Set(e.map(e=>e.key)),n=new Set,i=new Set([`inherits`,`updated_time`,`compatible_printers`,`compatible_prints`]);oe&&Object.values(oe).forEach(e=>{e?.setting&&Object.keys(e.setting).forEach(e=>{!t.has(e)&&!i.has(e)&&n.add(e)})}),Object.keys(_).forEach(e=>{!t.has(e)&&!i.has(e)&&n.add(e)});let a=Array.from(n).sort().map(e=>({key:e,label:e.replace(/_/g,` `).replace(/\b\w/g,e=>e.toUpperCase()),type:`text`,category:`discovered`,description:r(`profiles.presets.discoveredFromPresets`)}));return[...e,...a]},[ae,oe,_,r]),ue=le.filter(e=>e.label.toLowerCase().includes(w.toLowerCase())||e.key.toLowerCase().includes(w.toLowerCase())),de=()=>{if(O.trim()){let e=O.trim().toLowerCase().replace(/\s+/g,`_`);fe(e,``),k(``),j(!1),i(r(`profiles.presets.toast.fieldAdded`,{key:e}))}},fe=(e,t)=>{v(n=>{let r={...n};return t===``||t===void 0?delete r[e]:r[e]=t,r})},pe=e=>{v(t=>({...t,...e.settings})),te(e.name),i(r(`profiles.templates.toast.applied`))},me=()=>{if(!I.trim())return;let e={..._};if(delete e.inherits,Object.keys(e).length===0){i(r(`profiles.presets.noOverridesToSave`),`error`);return}let t={id:Date.now().toString(),name:I.trim(),description:R.trim()||r(`profiles.presets.customTemplate`),type:l,settings:e,showInModal:B},n=[...M,t];N(n),I6(n),F(!1),L(``),z(``),V(!0),i(r(`profiles.templates.toast.created`))},he=(0,y.useMemo)(()=>M.filter(e=>e.type===l&&e.showInModal),[l,M]),ge=e=>{x(e);try{v(JSON.parse(e)),C(null)}catch(e){C(e.message)}},_e=e=>{e.preventDefault(),D(!1);let t=e.dataTransfer.files[0];if(t&&t.name.endsWith(`.json`)){let e=new FileReader;e.onload=e=>{try{let t=e.target?.result,n=JSON.parse(t),a=n.setting||n;v(e=>({...e,...a})),x(JSON.stringify({..._,...a},null,2)),i(r(`profiles.presets.fileImported`))}catch{i(r(`profiles.presets.invalidJsonFile`),`error`)}},e.readAsText(t)}},ve=J({mutationFn:()=>{let e={..._},t=l===`filament`?`filament_settings_id`:l===`print`?`print_settings_id`:`printer_settings_id`;e[t]=`"${d}"`;let n={type:l,name:d,base_id:p,setting:e};return Q.createCloudSetting(n)},onSuccess:async()=>{i(r(`profiles.presets.toast.created`)),await a.refetchQueries({queryKey:[`cloudSettings`]}),e()},onError:e=>i(e.message,`error`)}),ye=J({mutationFn:()=>{if(!t?.setting_id)throw Error(r(`profiles.presets.noSettingId`));return Q.updateCloudSetting(t.setting_id,{name:d,setting:_})},onSuccess:async()=>{i(r(`profiles.presets.toast.updated`)),a.removeQueries({queryKey:[`cloudSettingDetail`]}),await a.refetchQueries({queryKey:[`cloudSettings`]}),e()},onError:e=>i(e.message,`error`)}),be=o?ye:ve,xe=U?.setting?.inherits,Se=xe?ce.find(e=>e.name===xe):void 0,{data:Ce}=q({queryKey:[`cloudSettingDetail`,Se?.setting_id],queryFn:()=>Q.getCloudSettingDetail(Se.setting_id),enabled:!!Se?.setting_id}),we=(0,y.useMemo)(()=>{let e=Ce?.setting||{},t=U?.setting||{},n=p&&oe?.[p]?.setting?oe[p].setting:{};return{...e,...t,...n}},[p,U,Ce,oe]),Te=e=>{if(e==null)return``;if(Array.isArray(e)){let t=[...new Set(e.map(e=>String(e)))];return t.length===1?t[0]:e.join(`, `)}return String(e)},Ee=e=>{let t=_[e.key],n=we[e.key],i=Te(n),a=se?r(`common.loading`):i||``,o=`w-full px-3 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`;if(e.type===`boolean`){let r=t===`1`||t===void 0&&n===`1`;return(0,K.jsx)(`button`,{type:`button`,onClick:()=>fe(e.key,t===`1`?`0`:`1`),className:`w-8 h-5 rounded-full transition-colors ${r?`bg-bambu-green`:`bg-bambu-dark-tertiary`}`,children:(0,K.jsx)(`div`,{className:`w-4 h-4 rounded-full bg-white shadow transition-transform ${r?`translate-x-3.5`:`translate-x-0.5`}`})})}return e.type===`select`?(0,K.jsxs)(`select`,{value:t||``,onChange:t=>fe(e.key,t.target.value),className:o,children:[(0,K.jsx)(`option`,{value:``,children:a}),e.options?.map(e=>(0,K.jsx)(`option`,{value:e.value,children:e.label},e.value))]}):(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`input`,{type:e.type===`number`?`number`:`text`,value:t===void 0?``:String(t),onChange:t=>fe(e.key,t.target.value),step:e.step,min:e.min,max:e.max,placeholder:a,className:o}),e.unit&&(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray whitespace-nowrap`,children:e.unit})]})},De=(0,y.useMemo)(()=>U?.setting?U.setting:{},[U]);return(0,K.jsxs)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,onDragOver:e=>{e.preventDefault(),D(!0)},onDragLeave:()=>D(!1),onDrop:_e,children:[ne&&p&&(0,K.jsx)(L6,{onClose:()=>re(!1),leftPreset:De,rightPreset:_,leftLabel:r(`profiles.presets.baseLabel`,{name:h||p}),rightLabel:r(`profiles.presets.currentLabel`,{name:d||r(`profiles.presets.newPreset`)}),t:r}),(0,K.jsx)(Ed,{className:`w-full max-w-6xl max-h-[90vh] flex flex-col overflow-y-auto`,children:(0,K.jsxs)(Od,{className:`p-0 flex flex-col h-full`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h2`,{className:`text-xl font-semibold text-white`,children:r(o?`profiles.presets.editPreset`:t?`profiles.presets.duplicatePreset`:`profiles.presets.createNewPreset`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:r(`profiles.presets.customizeSettings`)})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[p&&(0,K.jsxs)(`button`,{onClick:()=>re(!0),className:`flex items-center gap-2 px-3 py-2 text-sm text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary rounded-lg transition-colors`,title:r(`profiles.presets.compareWithBase`),children:[(0,K.jsx)(xc,{className:`w-4 h-4`}),r(`profiles.presets.compare`)]}),(0,K.jsx)(`button`,{onClick:e,className:`p-2 text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary rounded-lg transition-colors`,children:(0,K.jsx)(qu,{className:`w-5 h-5`})})]})]}),E&&(0,K.jsx)(`div`,{className:`absolute inset-0 bg-bambu-green/10 border-2 border-dashed border-bambu-green rounded-lg flex items-center justify-center z-10`,children:(0,K.jsxs)(`div`,{className:`text-center`,children:[(0,K.jsx)(Nu,{className:`w-12 h-12 text-bambu-green mx-auto mb-2`}),(0,K.jsx)(`p`,{className:`text-bambu-green font-medium`,children:r(`profiles.presets.dropJsonToImport`)})]})}),(0,K.jsxs)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary space-y-3`,children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-3 gap-4 max-[640px]:grid-cols-1`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`common.type`)}),(0,K.jsxs)(`select`,{value:l,onChange:e=>{u(e.target.value),m(``)},className:`w-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:[(0,K.jsx)(`option`,{value:`filament`,children:r(`profiles.presets.types.filament`)}),(0,K.jsx)(`option`,{value:`print`,children:r(`profiles.presets.types.process`)}),(0,K.jsx)(`option`,{value:`printer`,children:r(`profiles.presets.types.printer`)})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`profiles.presets.basePreset`)}),(0,K.jsxs)(`select`,{value:p,onChange:e=>m(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,children:[(0,K.jsx)(`option`,{value:``,children:r(`profiles.presets.selectBasePreset`)}),ce.map(e=>(0,K.jsx)(`option`,{value:e.setting_id,children:e.name},e.setting_id))]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`profiles.presets.presetName`)}),(0,K.jsx)(`input`,{type:`text`,value:d,onChange:e=>f(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,placeholder:r(`profiles.presets.myCustomPreset`)})]})]}),h&&(0,K.jsx)(`div`,{className:`text-xs text-bambu-gray`,children:(0,K.jsxs)(`p`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(as,{className:`w-3 h-3 text-bambu-green`}),r(`profiles.presets.inheritsFrom`),` `,(0,K.jsx)(`span`,{className:`text-white`,children:h}),se&&(0,K.jsx)(X,{className:`w-3 h-3 animate-spin ml-1`})]})})]}),(0,K.jsxs)(`div`,{className:`flex border-b border-bambu-dark-tertiary max-[640px]:flex-wrap max-[640px]:items-center`,children:[(0,K.jsxs)(`button`,{onClick:()=>c(`common`),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${s===`common`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-white border-transparent`}`,children:[(0,K.jsx)(au,{className:`w-4 h-4`}),r(`profiles.presets.tabs.common`)]}),(0,K.jsxs)(`button`,{onClick:()=>c(`fields`),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${s===`fields`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-white border-transparent`}`,children:[(0,K.jsx)(Jc,{className:`w-4 h-4`}),r(`profiles.presets.tabs.allFields`)]}),(0,K.jsxs)(`button`,{onClick:()=>c(`json`),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${s===`json`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-white border-transparent`}`,children:[(0,K.jsx)(ks,{className:`w-4 h-4`}),`JSON`,S&&(0,K.jsx)(ps,{className:`w-3 h-3 text-red-600 dark:text-red-400`})]}),(0,K.jsx)(`div`,{className:`flex-1 max-[640px]:hidden`}),(0,K.jsxs)(`button`,{onClick:()=>{let e=new Blob([JSON.stringify({name:d,type:l,base_id:p,setting:_},null,2)],{type:`application/json`}),t=URL.createObjectURL(e),n=document.createElement(`a`);n.href=t,n.download=`${d||`preset`}.json`,document.body.appendChild(n),n.click(),document.body.removeChild(n),URL.revokeObjectURL(t),i(r(`profiles.presets.toast.exported`))},className:`flex items-center gap-2 px-4 py-3 text-sm text-bambu-gray hover:text-white transition-colors`,title:r(`profiles.presets.exportToJson`),children:[(0,K.jsx)(Ws,{className:`w-4 h-4`}),r(`common.download`)]}),(0,K.jsxs)(`button`,{onClick:()=>document.getElementById(`file-import`)?.click(),className:`flex items-center gap-2 px-4 py-3 text-sm text-bambu-gray hover:text-white transition-colors`,title:r(`profiles.presets.importFromJson`),children:[(0,K.jsx)(Nu,{className:`w-4 h-4`}),r(`common.upload`)]}),(0,K.jsx)(`input`,{id:`file-import`,type:`file`,accept:`.json`,className:`hidden`,onChange:e=>{let t=e.target.files?.[0];if(t){let e=new FileReader;e.onload=e=>{try{let t=JSON.parse(e.target?.result),n=t.setting||t;v(e=>({...e,...n})),i(r(`profiles.presets.fileImported`))}catch{i(r(`profiles.presets.invalidJson`),`error`)}},e.readAsText(t)}}})]}),(0,K.jsxs)(`div`,{className:`flex-1 p-4`,children:[s===`common`&&(0,K.jsxs)(`div`,{className:`space-y-6`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,K.jsxs)(`h3`,{className:`text-sm font-medium text-white flex items-center gap-2`,children:[(0,K.jsx)(lu,{className:`w-4 h-4 text-amber-600 dark:text-amber-400`}),r(`profiles.templates.title`)]}),Object.keys(_).filter(e=>e!==`inherits`).length>0&&(0,K.jsxs)(`button`,{onClick:()=>F(!P),className:`text-xs text-bambu-gray hover:text-white flex items-center gap-1 transition-colors`,children:[(0,K.jsx)(zl,{className:`w-3 h-3`}),r(`profiles.presets.saveAsTemplate`)]})]}),P&&(0,K.jsxs)(`div`,{className:`mb-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-2 mb-2`,children:[(0,K.jsx)(`input`,{type:`text`,value:I,onChange:e=>L(e.target.value),placeholder:r(`profiles.templates.namePlaceholder`),className:`px-3 py-1.5 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`,autoFocus:!0}),(0,K.jsx)(`input`,{type:`text`,value:R,onChange:e=>z(e.target.value),placeholder:r(`profiles.templates.descriptionPlaceholder`),className:`px-3 py-1.5 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsxs)($,{size:`sm`,onClick:me,disabled:!I.trim(),children:[(0,K.jsx)(zl,{className:`w-3 h-3`}),r(`common.save`)]}),(0,K.jsx)($,{size:`sm`,variant:`secondary`,onClick:()=>F(!1),children:r(`common.cancel`)})]}),(0,K.jsxs)(`button`,{onClick:()=>V(!B),className:`flex items-center gap-1.5 text-xs transition-colors ${B?`text-bambu-green`:`text-bambu-gray hover:text-white`}`,children:[B?(0,K.jsx)($s,{className:`w-3.5 h-3.5`}):(0,K.jsx)(Qs,{className:`w-3.5 h-3.5`}),r(B?`profiles.templates.shownInModals`:`profiles.templates.hiddenInModals`)]})]})]}),ee&&(0,K.jsxs)(`div`,{className:`mb-3 px-3 py-2 bg-bambu-green/10 border border-bambu-green/30 rounded-lg flex items-center gap-2`,children:[(0,K.jsx)(as,{className:`w-4 h-4 text-bambu-green`}),(0,K.jsxs)(`span`,{className:`text-sm text-bambu-green`,children:[r(`profiles.presets.templateApplied`),` `,(0,K.jsx)(`span`,{className:`font-medium`,children:ee})]}),(0,K.jsx)(`button`,{onClick:()=>te(null),className:`ml-auto text-bambu-green/70 hover:text-bambu-green`,children:(0,K.jsx)(qu,{className:`w-4 h-4`})})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-3 gap-2`,children:[he.map(e=>(0,K.jsxs)(`button`,{onClick:()=>pe(e),className:`p-3 text-left bg-bambu-dark border border-bambu-dark-tertiary rounded-lg hover:border-bambu-gray-dark transition-colors`,children:[(0,K.jsx)(`p`,{className:`text-sm font-medium text-white`,children:e.name}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e.description})]},e.id)),he.length===0&&(0,K.jsx)(`p`,{className:`col-span-3 text-center text-bambu-gray text-sm py-4`,children:r(`profiles.presets.noTemplatesSelected`)})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray-dark mt-2 text-center`,children:r(`profiles.presets.manageTemplatesHint`)})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h3`,{className:`text-sm font-medium text-white mb-3`,children:r(`profiles.presets.commonSettings`)}),(0,K.jsx)(`div`,{className:`grid grid-cols-2 gap-x-6 gap-y-3`,children:le.slice(0,10).map(e=>(0,K.jsxs)(`div`,{className:`flex items-center justify-between gap-4 max-[640px]:flex-col max-[640px]:items-start`,children:[(0,K.jsx)(`label`,{className:`text-sm text-bambu-gray flex-shrink-0`,children:e.label}),(0,K.jsx)(`div`,{className:`w-48 max-[640px]:w-full`,children:Ee(e)})]},e.key))})]}),Object.keys(_).length>1&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h3`,{className:`text-sm font-medium text-white mb-3`,children:r(`profiles.presets.currentOverrides`)}),(0,K.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:Object.entries(_).filter(([e])=>e!==`inherits`).map(([e,t])=>(0,K.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-2 py-1 bg-bambu-green/10 text-bambu-green text-xs rounded`,children:[e,`: `,String(t).slice(0,20),(0,K.jsx)(`button`,{onClick:()=>fe(e,void 0),className:`hover:text-white`,children:(0,K.jsx)(qu,{className:`w-3 h-3`})})]},e))})]})]}),s===`fields`&&(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-6`,style:{height:`400px`},children:[(0,K.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-3 flex-shrink-0`,children:[(0,K.jsx)(`h3`,{className:`text-sm font-medium text-white`,children:r(`profiles.presets.availableFields`)}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:oe?r(`profiles.templates.fieldsCount`,{count:le.length}):r(`common.loading`)})]}),(0,K.jsxs)(`div`,{className:`relative mb-3 flex-shrink-0`,children:[(0,K.jsx)(Wl,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,K.jsx)(`input`,{type:`text`,value:w,onChange:e=>T(e.target.value),placeholder:r(`profiles.presets.searchFieldsPlaceholder`),className:`w-full pl-10 pr-4 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none`})]}),(0,K.jsxs)(`div`,{className:`flex-1 overflow-y-auto space-y-1 pr-2 min-h-0`,children:[ue.filter(e=>!(e.key in _)).map(e=>{let t=we[e.key],n=Te(t);return(0,K.jsxs)(`div`,{onClick:()=>{v(t=>({...t,[e.key]:n||``}))},className:`flex items-center justify-between gap-2 p-2 rounded-lg hover:bg-bambu-dark-tertiary transition-colors cursor-pointer group`,children:[(0,K.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,K.jsx)(`p`,{className:`text-sm text-white truncate`,children:e.label}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray-dark truncate`,children:e.key})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 flex-shrink-0`,children:[n&&(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray bg-bambu-dark px-2 py-0.5 rounded max-w-32 truncate`,title:n,children:[n.slice(0,20),n.length>20?`...`:``]}),(0,K.jsx)(`div`,{className:`w-6 h-6 flex items-center justify-center rounded bg-bambu-dark-tertiary group-hover:bg-bambu-green/20 transition-colors`,children:(0,K.jsx)(Ol,{className:`w-4 h-4 text-bambu-gray group-hover:text-bambu-green transition-colors`})})]})]},e.key)}),ue.filter(e=>!(e.key in _)).length===0&&(0,K.jsx)(`p`,{className:`text-center text-bambu-gray py-4 text-sm`,children:r(w?`profiles.presets.noMatchingFields`:`profiles.presets.allFieldsAdded`)})]}),(0,K.jsx)(`div`,{className:`pt-3 mt-3 border-t border-bambu-dark-tertiary flex-shrink-0`,children:A?(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)(`input`,{type:`text`,value:O,onChange:e=>k(e.target.value),onKeyDown:e=>e.key===`Enter`&&de(),placeholder:`custom_field_name`,className:`flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white font-mono text-sm placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none`,autoFocus:!0}),(0,K.jsx)($,{size:`sm`,onClick:de,disabled:!O.trim(),children:(0,K.jsx)(Ol,{className:`w-4 h-4`})}),(0,K.jsx)($,{size:`sm`,variant:`secondary`,onClick:()=>{j(!1),k(``)},children:(0,K.jsx)(qu,{className:`w-4 h-4`})})]}):(0,K.jsxs)(`button`,{onClick:()=>j(!0),className:`w-full flex items-center justify-center gap-2 p-2 text-sm text-bambu-gray hover:text-white border border-dashed border-bambu-dark-tertiary hover:border-bambu-gray-dark rounded-lg transition-colors`,children:[(0,K.jsx)(Ol,{className:`w-4 h-4`}),r(`profiles.presets.addCustomField`)]})})]}),(0,K.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-3 flex-shrink-0`,children:[(0,K.jsx)(`h3`,{className:`text-sm font-medium text-white`,children:r(`profiles.presets.yourOverrides`)}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:r(`profiles.templates.fieldsCount`,{count:Object.keys(_).filter(e=>e!==`inherits`).length})})]}),(0,K.jsxs)(`div`,{className:`flex-1 overflow-y-auto space-y-2 pr-2 min-h-0`,children:[Object.entries(_).filter(([e])=>e!==`inherits`).map(([e,t])=>{let n=le.find(t=>t.key===e);return(0,K.jsxs)(`div`,{className:`p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-sm font-medium text-white`,children:n?.label||e}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray-dark`,children:e})]}),(0,K.jsx)(`button`,{onClick:()=>fe(e,void 0),className:`p-1 text-bambu-gray hover:text-red-600 dark:hover:text-red-400 transition-colors`,children:(0,K.jsx)(qu,{className:`w-4 h-4`})})]}),n?Ee(n):(0,K.jsx)(`input`,{type:`text`,value:String(t),onChange:t=>fe(e,t.target.value),className:`w-full px-3 py-1.5 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`})]},e)}),Object.keys(_).filter(e=>e!==`inherits`).length===0&&(0,K.jsxs)(`div`,{className:`text-center py-8 text-bambu-gray`,children:[(0,K.jsx)(au,{className:`w-8 h-8 mx-auto mb-2 opacity-50`}),(0,K.jsx)(`p`,{className:`text-sm`,children:r(`profiles.presets.noOverridesYet`)}),(0,K.jsx)(`p`,{className:`text-xs mt-1`,children:r(`profiles.presets.clickFieldsToAdd`)})]})]}),Object.keys(_).filter(e=>e!==`inherits`).length>0&&(0,K.jsx)(`div`,{className:`pt-3 mt-3 border-t border-bambu-dark-tertiary flex-shrink-0`,children:(0,K.jsxs)(`button`,{onClick:()=>{F(!0),c(`common`)},className:`w-full flex items-center justify-center gap-2 p-2 text-sm text-bambu-gray hover:text-white border border-dashed border-bambu-dark-tertiary hover:border-bambu-gray-dark rounded-lg transition-colors`,children:[(0,K.jsx)(zl,{className:`w-4 h-4`}),r(`profiles.presets.saveAsTemplate`)]})})]})]}),s===`json`&&(0,K.jsxs)(`div`,{className:`space-y-2`,children:[S&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-red-700 dark:text-red-400 text-sm`,children:[(0,K.jsx)(ps,{className:`w-4 h-4`}),S]}),(0,K.jsx)(`textarea`,{value:b,onChange:e=>ge(e.target.value),className:`w-full h-80 px-3 py-2 bg-bambu-dark border rounded-lg text-white text-xs font-mono focus:outline-none resize-none ${S?`border-red-500 focus:border-red-500`:`border-bambu-dark-tertiary focus:border-bambu-green`}`,spellCheck:!1}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:r(`profiles.presets.jsonTip`)})]})]}),(0,K.jsxs)(`div`,{className:`p-4 border-t border-bambu-dark-tertiary flex gap-2`,children:[(0,K.jsx)($,{variant:`secondary`,onClick:e,className:`flex-1`,children:r(`common.cancel`)}),(0,K.jsxs)($,{onClick:()=>be.mutate(),disabled:be.isPending||!d.trim()||!o&&!p||!!S,className:`flex-1`,children:[be.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):o?(0,K.jsx)(zl,{className:`w-4 h-4`}):(0,K.jsx)(Ol,{className:`w-4 h-4`}),r(o?`common.save`:t?`common.duplicate`:`common.create`)]})]})]})})]})}function cWe({settings:e,lastSyncTime:t,onRefresh:n,isRefreshing:r,printers:i,hasPermission:a,t:o}){let[s,c]=(0,y.useState)(``),[l,u]=(0,y.useState)(`all`),[d,f]=(0,y.useState)(`all`),[p,m]=(0,y.useState)(`all`),[h,g]=(0,y.useState)(`all`),[_,v]=(0,y.useState)(`all`),[b,x]=(0,y.useState)(`all`),[S,C]=(0,y.useState)(null),[w,T]=(0,y.useState)(!1),[E,D]=(0,y.useState)(!1),[O,k]=(0,y.useState)(null),[A,j]=(0,y.useState)(null),[M,N]=(0,y.useState)(null),[P,F]=(0,y.useState)(!1),[I,L]=(0,y.useState)([null,null]),[R,z]=(0,y.useState)(!1),[B,V]=(0,y.useState)(null),ee=oo(),te=(0,y.useMemo)(()=>[...e.filament.map(e=>({...e,type:`filament`})),...e.printer.map(e=>({...e,type:`printer`})),...e.process.map(e=>({...e,type:`process`}))].map(e=>({...e,meta:A6(e.name)})),[e]),ne=(0,y.useMemo)(()=>{let e=new Set,t=new Set,n=new Set;return te.forEach(r=>{r.meta.nozzle&&e.add(r.meta.nozzle),r.meta.filamentType&&t.add(r.meta.filamentType),r.meta.layerHeight&&n.add(r.meta.layerHeight)}),{printers:i.map(e=>({id:e.id.toString(),name:e.name})),nozzles:Array.from(e).sort((e,t)=>parseFloat(e)-parseFloat(t)),filaments:Array.from(t).sort(),layerHeights:Array.from(n).sort((e,t)=>parseFloat(e)-parseFloat(t))}},[te,i]),re=(0,y.useMemo)(()=>p===`all`?null:i.find(e=>e.id.toString()===p)?.model||null,[p,i]),ie=(0,y.useMemo)(()=>te.filter(e=>l===`all`||e.type===l).filter(e=>{if(d===`all`)return!0;let t=j6(e.setting_id);return d===`custom`?t:!t}).filter(e=>{if(p===`all`||!re)return!0;let t=e.meta.printer?.toLowerCase()||``,n=re.toLowerCase();return t.includes(n)||n.includes(t)}).filter(e=>h===`all`||e.meta.nozzle===h).filter(e=>_===`all`||e.meta.filamentType===_).filter(e=>b===`all`||e.meta.layerHeight===b).filter(e=>s===``||e.name.toLowerCase().includes(s.toLowerCase())).sort((e,t)=>e.name.localeCompare(t.name)),[te,l,d,p,re,h,_,b,s]),H=e=>{if(P){let t=I[0]?.setting_id===e.setting_id,n=I[1]?.setting_id===e.setting_id;if(t)L([I[1],null]);else if(n)L([I[0],null]);else if(!I[0])L([e,null]);else if(I[1]){if(I[0].type!==e.type)return;L([I[0],e])}else{if(I[0].type!==e.type)return;L([I[0],e])}}else C(e)},ae=e=>{if(I[0]?.setting_id===e.setting_id)return 0;if(I[1]?.setting_id===e.setting_id)return 1},oe=async e=>{try{let t=await Q.getCloudSettingDetail(e.setting_id);k({type:e.type===`process`?`print`:e.type,name:e.name,base_id:t.base_id||`GFSA00`,setting:t.setting||{}}),C(null)}catch(e){console.error(`Failed to fetch preset details for duplication:`,e)}},U=async e=>{try{ee.removeQueries({queryKey:[`cloudSettingDetail`,e.setting_id]});let t=await Q.getCloudSettingDetail(e.setting_id);j({type:e.type===`process`?`print`:e.type,name:e.name,base_id:t.base_id||`GFSA00`,setting:t.setting||{},setting_id:e.setting_id}),C(null)}catch(e){console.error(`Failed to fetch preset details for editing:`,e)}},se=()=>{u(`all`),f(`all`),m(`all`),g(`all`),v(`all`),x(`all`),c(``)},ce=l!==`all`||d!==`all`||p!==`all`||h!==`all`||_!==`all`||b!==`all`||s!==``,le=e.filament.length+e.printer.length+e.process.length;return(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`space-y-4 mb-6`,children:[(0,K.jsxs)(`div`,{className:`flex flex-col sm:flex-row gap-3`,children:[(0,K.jsxs)(`div`,{className:`relative flex-1`,children:[(0,K.jsx)(Wl,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,K.jsx)(`input`,{type:`text`,value:s,onChange:e=>c(e.target.value),placeholder:o(`profiles.cloudView.searchPlaceholder`),className:`w-full pl-10 pr-4 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none`})]}),(0,K.jsxs)(`div`,{className:`flex gap-2 max-[550px]:flex-wrap max-[550px]:items-center`,children:[(0,K.jsxs)($,{variant:P?`primary`:`secondary`,onClick:()=>{P?(F(!1),L([null,null])):F(!0)},children:[(0,K.jsx)(xc,{className:`w-4 h-4`}),o(P?`common.cancel`:`profiles.presets.compare`)]}),(0,K.jsxs)($,{variant:`secondary`,onClick:()=>D(!0),disabled:!a(`cloud:auth`),title:a(`cloud:auth`)?void 0:o(`profiles.cloudView.noTemplatesPermission`),children:[(0,K.jsx)(lu,{className:`w-4 h-4`}),o(`profiles.cloudView.templates`)]}),(0,K.jsxs)($,{variant:`secondary`,onClick:n,disabled:r||!a(`cloud:auth`),title:a(`cloud:auth`)?void 0:o(`profiles.cloudView.noRefreshPermission`),children:[(0,K.jsx)(Pl,{className:`w-4 h-4 ${r?`animate-spin`:``}`}),o(`profiles.cloudView.refresh`)]}),(0,K.jsxs)($,{onClick:()=>T(!0),disabled:!a(`cloud:auth`),title:a(`cloud:auth`)?void 0:o(`profiles.cloudView.noCreatePermission`),children:[(0,K.jsx)(Ol,{className:`w-4 h-4`}),o(`profiles.cloudView.newPreset`)]})]})]}),(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,K.jsx)(_c,{className:`w-4 h-4 text-bambu-gray`}),(0,K.jsx)(M6,{label:o(`profiles.cloudView.filters.type`),value:l,options:[{value:`all`,label:o(`profiles.cloudView.filters.all`),count:le},{value:`filament`,label:o(`profiles.cloudView.filters.filament`),count:e.filament.length},{value:`printer`,label:o(`profiles.cloudView.filters.printer`),count:e.printer.length},{value:`process`,label:o(`profiles.cloudView.filters.process`),count:e.process.length}],onChange:e=>u(e)}),(0,K.jsx)(M6,{label:o(`profiles.cloudView.filters.owner`),value:d,options:[{value:`all`,label:o(`profiles.cloudView.filters.all`)},{value:`custom`,label:o(`profiles.cloudView.filters.myPresets`)},{value:`builtin`,label:o(`profiles.cloudView.filters.builtIn`)}],onChange:e=>f(e)}),ne.printers.length>0&&(0,K.jsx)(M6,{label:o(`profiles.cloudView.filters.printer`),value:p,options:[{value:`all`,label:o(`profiles.cloudView.filters.all`)},...ne.printers.map(e=>({value:e.id,label:e.name}))],onChange:m}),ne.nozzles.length>0&&(0,K.jsx)(M6,{label:o(`profiles.cloudView.filters.nozzle`),value:h,options:[{value:`all`,label:o(`profiles.cloudView.filters.all`)},...ne.nozzles.map(e=>({value:e,label:e}))],onChange:g}),ne.filaments.length>0&&(l===`all`||l===`filament`)&&(0,K.jsx)(M6,{label:o(`profiles.cloudView.filters.filament`),value:_,options:[{value:`all`,label:o(`profiles.cloudView.filters.all`)},...ne.filaments.map(e=>({value:e,label:e}))],onChange:v}),ne.layerHeights.length>0&&(l===`all`||l===`process`)&&(0,K.jsx)(M6,{label:o(`profiles.cloudView.filters.layer`),value:b,options:[{value:`all`,label:o(`profiles.cloudView.filters.all`)},...ne.layerHeights.map(e=>({value:e,label:e}))],onChange:x}),ce&&(0,K.jsx)(`button`,{onClick:se,className:`px-3 py-2 text-sm text-bambu-gray hover:text-white transition-colors`,children:o(`profiles.cloudView.clearFilters`)})]})]}),P&&(0,K.jsx)(`div`,{className:`mb-4 p-3 bg-blue-500/10 border border-blue-500/30 rounded-lg`,children:(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,K.jsx)(xc,{className:`w-5 h-5 text-blue-600 dark:text-blue-400`}),(0,K.jsx)(`span`,{className:`text-white font-medium`,children:o(`profiles.cloudView.compareMode`)}),(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:I[0]?o(`profiles.cloudView.selectAnotherPreset`,{type:I[0].type}):o(`profiles.cloudView.clickTwoPresets`)})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`px-2 py-1 text-sm rounded truncate max-w-[200px] ${I[0]?`bg-blue-500/30 text-blue-700 dark:text-blue-300`:`bg-bambu-dark text-bambu-gray`}`,children:I[0]?I[0].name:o(`profiles.cloudView.selectFirst`)}),(0,K.jsx)(Io,{className:`w-4 h-4 text-bambu-gray`}),(0,K.jsx)(`span`,{className:`px-2 py-1 text-sm rounded truncate max-w-[200px] ${I[1]?`bg-blue-500/30 text-blue-700 dark:text-blue-300`:`bg-bambu-dark text-bambu-gray`}`,children:I[1]?I[1].name:o(`profiles.cloudView.selectSecond`)})]}),I[0]&&I[1]&&(0,K.jsxs)($,{size:`sm`,onClick:async()=>{try{let[e,t]=await Promise.all([Q.getCloudSettingDetail(I[0].setting_id),Q.getCloudSettingDetail(I[1].setting_id)]);V([e.setting||{},t.setting||{}]),z(!0)}catch{}},children:[(0,K.jsx)(xc,{className:`w-4 h-4`}),o(`profiles.cloudView.compareNow`)]})]})]})}),(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center gap-4 mb-4 text-sm text-bambu-gray`,children:[t&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(ws,{className:`w-3 h-3`}),o(`profiles.cloudView.lastSynced`),` `,Lf(t.toISOString(),`system`,o)]}),(0,K.jsx)(`span`,{children:o(`profiles.cloudView.showingCount`,{showing:ie.length,total:le})}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-bambu-green`}),(0,K.jsxs)(`span`,{children:[`= `,o(`profiles.presets.myPreset`)]})]})]}),ie.length===0?(0,K.jsxs)(`div`,{className:`text-center py-16`,children:[(0,K.jsx)(Vc,{className:`w-12 h-12 text-bambu-gray-dark mx-auto mb-4`}),(0,K.jsx)(`p`,{className:`text-bambu-gray`,children:o(`profiles.cloudView.noPresetsFound`)}),ce&&(0,K.jsx)(`button`,{onClick:se,className:`mt-2 text-sm text-bambu-green hover:text-bambu-green-light`,children:o(`profiles.cloudView.clearFilters`)})]}):(0,K.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-6`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-3 px-1`,children:[(0,K.jsx)(Gs,{className:`w-4 h-4 text-amber-600 dark:text-amber-400`}),(0,K.jsx)(`h3`,{className:`text-sm font-medium text-bambu-gray`,children:o(`profiles.cloudView.columns.filament`)}),(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray-dark`,children:[`(`,ie.filter(e=>e.type===`filament`).length,`)`]})]}),(0,K.jsxs)(`div`,{className:`space-y-1 max-h-[calc(100vh-320px)] overflow-y-auto pr-1`,children:[ie.filter(e=>e.type===`filament`).map(e=>(0,K.jsx)(N6,{setting:e,onClick:()=>H(e),onDuplicate:()=>oe(e),compareMode:P,isCompareSelected:ae(e)!==void 0,compareIndex:ae(e),compareDisabled:P&&!!I[0]&&I[0].type!==e.type,t:o},e.setting_id)),ie.filter(e=>e.type===`filament`).length===0&&(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray-dark px-3 py-2`,children:o(`profiles.cloudView.noFilamentPresets`)})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-3 px-1`,children:[(0,K.jsx)(Jl,{className:`w-4 h-4 text-blue-600 dark:text-blue-400`}),(0,K.jsx)(`h3`,{className:`text-sm font-medium text-bambu-gray`,children:o(`profiles.cloudView.columns.process`)}),(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray-dark`,children:[`(`,ie.filter(e=>e.type===`process`).length,`)`]})]}),(0,K.jsxs)(`div`,{className:`space-y-1 max-h-[calc(100vh-320px)] overflow-y-auto pr-1`,children:[ie.filter(e=>e.type===`process`).map(e=>(0,K.jsx)(N6,{setting:e,onClick:()=>H(e),onDuplicate:()=>oe(e),compareMode:P,isCompareSelected:ae(e)!==void 0,compareIndex:ae(e),compareDisabled:P&&!!I[0]&&I[0].type!==e.type,t:o},e.setting_id)),ie.filter(e=>e.type===`process`).length===0&&(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray-dark px-3 py-2`,children:o(`profiles.cloudView.noProcessPresets`)})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-3 px-1`,children:[(0,K.jsx)(jl,{className:`w-4 h-4 text-purple-600 dark:text-purple-400`}),(0,K.jsx)(`h3`,{className:`text-sm font-medium text-bambu-gray`,children:o(`profiles.cloudView.columns.printer`)}),(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray-dark`,children:[`(`,ie.filter(e=>e.type===`printer`).length,`)`]})]}),(0,K.jsxs)(`div`,{className:`space-y-1 max-h-[calc(100vh-320px)] overflow-y-auto pr-1`,children:[ie.filter(e=>e.type===`printer`).map(e=>(0,K.jsx)(N6,{setting:e,onClick:()=>H(e),onDuplicate:()=>oe(e),compareMode:P,isCompareSelected:ae(e)!==void 0,compareIndex:ae(e),compareDisabled:P&&!!I[0]&&I[0].type!==e.type,t:o},e.setting_id)),ie.filter(e=>e.type===`printer`).length===0&&(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray-dark px-3 py-2`,children:o(`profiles.cloudView.noPrinterPresets`)})]})]})]}),S&&(0,K.jsx)(aWe,{setting:S,onClose:()=>C(null),onDeleted:()=>C(null),onDuplicate:()=>oe(S),onEdit:()=>U(S),hasPermission:a,t:o}),(w||O||A||M)&&(0,K.jsx)(sWe,{onClose:()=>{T(!1),k(null),j(null),N(null)},initialData:A||O||(M?{type:M.type,name:``,base_id:``,setting:M.setting}:void 0),allPresets:e,t:o}),E&&(0,K.jsx)(oWe,{onClose:()=>D(!1),onApply:e=>{N({type:e.type,setting:e.settings}),D(!1)},t:o}),R&&B&&I[0]&&I[1]&&(0,K.jsx)(L6,{onClose:()=>{z(!1),V(null)},leftPreset:B[0],rightPreset:B[1],leftLabel:I[0].name,rightLabel:I[1].name,t:o})]})}function lWe(){let{t:e}=W(),t=oo(),{showToast:n}=Pd(),{hasPermission:r}=bd(),[i,a]=(0,y.useState)(`cloud`),[o,s]=(0,y.useState)(),{data:c,isLoading:l}=q({queryKey:[`cloudStatus`],queryFn:Q.getCloudStatus}),{data:u=[]}=q({queryKey:[`printers`],queryFn:Q.getPrinters}),{data:d,isLoading:f,refetch:p,dataUpdatedAt:m}=q({queryKey:[`cloudSettings`],queryFn:()=>Q.getCloudSettings(),enabled:!!c?.is_authenticated,retry:!1,staleTime:1e3*60*5});(0,y.useEffect)(()=>{m&&s(new Date(m))},[m]);let h=J({mutationFn:Q.cloudLogout,onSuccess:()=>{t.invalidateQueries({queryKey:[`cloudStatus`]}),t.removeQueries({queryKey:[`cloudSettings`]}),n(e(`profiles.toast.loggedOut`))}});return l?(0,K.jsx)(`div`,{className:`p-4 md:p-8 flex items-center justify-center min-h-[400px]`,children:(0,K.jsx)(X,{className:`w-8 h-8 text-bambu-green animate-spin`})}):(0,K.jsxs)(`div`,{className:`p-4 md:p-8`,children:[(0,K.jsxs)(`div`,{className:`mb-6`,children:[(0,K.jsxs)(`h1`,{className:`text-2xl font-bold text-white flex items-center gap-3`,children:[(0,K.jsx)(Ds,{className:`w-7 h-7 text-bambu-green`}),e(`profiles.title`)]}),(0,K.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:e(`profiles.subtitle`)})]}),(0,K.jsxs)(`div`,{className:`flex border-b border-bambu-dark-tertiary mb-6`,children:[(0,K.jsxs)(`button`,{onClick:()=>a(`cloud`),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${i===`cloud`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-white border-transparent`}`,children:[(0,K.jsx)(Ds,{className:`w-4 h-4`}),e(`profiles.tabs.bambuCloud`)]}),(0,K.jsxs)(`button`,{onClick:()=>a(`orca_cloud`),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${i===`orca_cloud`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-white border-transparent`}`,children:[(0,K.jsx)(Ds,{className:`w-4 h-4`}),e(`profiles.tabs.orcaCloud`)]}),(0,K.jsxs)(`button`,{onClick:()=>a(`local`),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${i===`local`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-white border-transparent`}`,children:[(0,K.jsx)(Dc,{className:`w-4 h-4`}),e(`profiles.tabs.local`)]}),(0,K.jsxs)(`button`,{onClick:()=>a(`kprofiles`),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${i===`kprofiles`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-white border-transparent`}`,children:[(0,K.jsx)(vc,{className:`w-4 h-4`}),e(`profiles.tabs.kprofiles`)]})]}),i===`cloud`&&(0,K.jsxs)(K.Fragment,{children:[c?.is_authenticated&&(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-3 mb-6 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`w-2 h-2 rounded-full bg-bambu-green animate-pulse`}),(0,K.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[e(`profiles.connectedAs`),` `,(0,K.jsx)(`span`,{className:`text-white`,children:c.email}),c.region&&(0,K.jsx)(`span`,{className:`ml-2 px-2 py-0.5 text-xs rounded bg-bambu-dark-tertiary text-bambu-gray`,children:c.region===`china`?e(`profiles.login.regionChina`):e(`profiles.login.regionGlobal`)})]})]}),(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:()=>h.mutate(),disabled:h.isPending||!r(`cloud:auth`),title:r(`cloud:auth`)?void 0:e(`profiles.noLogoutPermission`),children:[(0,K.jsx)(Qc,{className:`w-4 h-4`}),e(`profiles.logout`)]})]}),c?.sign_in_expired&&(0,K.jsxs)(`div`,{className:`flex items-start gap-3 p-3 mb-6 rounded-lg border border-yellow-500/40 bg-yellow-500/10`,children:[(0,K.jsx)(ku,{className:`w-5 h-5 shrink-0 text-yellow-400 mt-0.5`}),(0,K.jsxs)(`div`,{className:`text-sm`,children:[(0,K.jsx)(`p`,{className:`text-white font-medium`,children:e(`profiles.signInExpiredTitle`)}),(0,K.jsx)(`p`,{className:`text-bambu-gray`,children:e(`profiles.signInExpiredBody`)})]})]}),c?.is_authenticated?f?(0,K.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,K.jsx)(X,{className:`w-8 h-8 text-bambu-green animate-spin`})}):d?(0,K.jsx)(cWe,{settings:d,lastSyncTime:o,onRefresh:()=>p(),isRefreshing:f,printers:u,hasPermission:r,t:e}):(0,K.jsxs)(`div`,{className:`text-center py-16`,children:[(0,K.jsx)(`p`,{className:`text-bambu-gray mb-4`,children:e(`profiles.failedToLoad`)}),(0,K.jsx)($,{onClick:()=>p(),children:e(`profiles.retry`)})]}):(0,K.jsx)(rWe,{onSuccess:()=>{t.invalidateQueries({queryKey:[`cloudStatus`]})},t:e})]}),i===`orca_cloud`&&(0,K.jsx)(tWe,{}),i===`local`&&(0,K.jsx)(XUe,{}),i===`kprofiles`&&(0,K.jsx)(KUe,{}),(0,K.jsx)(iWe,{})]})}function uWe(e,t){let n=(t||``).toUpperCase().replace(/[- ]/g,``),r=n.includes(`X1`),i=n.includes(`P1`),a=n.includes(`A1MINI`),o=n.includes(`A1`)&&!a,s=n.includes(`H2D`),c=n.includes(`H2C`),l=n.includes(`H2S`),u=s||c||l,d=n.includes(`P2S`),f=n.includes(`X2D`),p=d||f;switch(e){case`Lubricate Steel Rods`:return p?`https://wiki.bambulab.com/en/p2s/maintenance/lubricate-x-y-z-axis`:null;case`Clean Steel Rods`:return p?`https://wiki.bambulab.com/en/p2s/maintenance/lubricate-x-y-z-axis`:null;case`Lubricate Linear Rails`:return a?`https://wiki.bambulab.com/en/a1-mini/maintenance/lubricate-y-axis`:o?`https://wiki.bambulab.com/en/a1/maintenance/lubricate-y-axis`:u?`https://wiki.bambulab.com/en/h2/maintenance/x-axis-lubrication`:null;case`Clean Nozzle/Hotend`:return r||i?`https://wiki.bambulab.com/en/x1/troubleshooting/nozzle-clog`:a||o?`https://wiki.bambulab.com/en/a1-mini/troubleshooting/nozzle-clog`:u?`https://wiki.bambulab.com/en/h2/maintenance/nozzl-cold-pull-maintenance-and-cleaning`:p?`https://wiki.bambulab.com/en/p2s/maintenance/cold-pull-maintenance-hotend`:`https://wiki.bambulab.com/en/x1/troubleshooting/nozzle-clog`;case`Check Belt Tension`:return r?`https://wiki.bambulab.com/en/x1/maintenance/belt-tension`:i?`https://wiki.bambulab.com/en/p1/maintenance/p1p-maintenance`:a?`https://wiki.bambulab.com/en/a1-mini/maintenance/belt_tension`:o?`https://wiki.bambulab.com/en/a1/maintenance/belt_tension`:s?`https://wiki.bambulab.com/en/h2/maintenance/belt-tension`:c?`https://wiki.bambulab.com/en/h2c/maintenance/belt-tension`:l?`https://wiki.bambulab.com/en/h2s/maintenance/belt-tension`:p?`https://wiki.bambulab.com/en/p2s/maintenance/belt-tension`:`https://wiki.bambulab.com/en/x1/maintenance/belt-tension`;case`Clean Carbon Rods`:return r||i?`https://wiki.bambulab.com/en/general/carbon-rods-clearance`:null;case`Clean Linear Rails`:return a?`https://wiki.bambulab.com/en/a1-mini/maintenance/lubricate-y-axis`:o?`https://wiki.bambulab.com/en/a1/maintenance/lubricate-y-axis`:u?`https://wiki.bambulab.com/en/h2/maintenance/x-axis-lubrication`:null;case`Clean Build Plate`:return`https://wiki.bambulab.com/en/filament-acc/acc/pei-plate-clean-guide`;case`Check PTFE Tube`:return r||i?`https://wiki.bambulab.com/en/x1/maintenance/replace-ptfe-tube`:a||o?`https://wiki.bambulab.com/en/a1-mini/maintenance/ptfe-tube`:s?`https://wiki.bambulab.com/en/h2/maintenance/replace-ptfe-tube-on-h2d-printer`:l?`https://wiki.bambulab.com/en/h2s/maintenance/replace-ptfe-tube-on-h2s-printer`:c?`https://wiki.bambulab.com/en/h2/maintenance/replace-ptfe-tube-on-h2d-printer`:`https://wiki.bambulab.com/en/x1/maintenance/replace-ptfe-tube`;case`Replace HEPA Filter`:case`HEPA Filter`:case`Replace Carbon Filter`:case`Carbon Filter`:return u?`https://wiki.bambulab.com/en/h2/maintenance/replace-smoke-purifier-air-filte`:`https://wiki.bambulab.com/en/x1/maintenance/replace-carbon-filter`;case`Lubricate Left Nozzle Rail`:case`Left Nozzle Rail`:return u?`https://wiki.bambulab.com/en/h2/maintenance/x-axis-lubrication`:null;default:return null}}var R6={Droplet:Gs,Flame:cc,Ruler:Rl,Sparkles:lu,Square:fu,Cable:Xo,Wrench:Ku,Calendar:$o,Timer:Tu,Cog:Ms,Fan:ec,Zap:Yu,Wind:Wu,Thermometer:wu,Layers:Vc,Box:qo,Target:yu,RefreshCw:Pl,Settings:Yl,Filter:_c,CircleDot:_s};function z6(e){return e&&R6[e]||Ku}function B6(e,t,n){if(t===`days`){if(e<1)return n?n(`common.today`):`Today`;if(e===1)return n?n(`maintenance.day`):`1 day`;if(e<7){let t=Math.round(e);return n?n(`maintenance.days`,{count:t}):`${t} days`}if(e<180){let t=Math.round(e/7);return t===1?n?n(`maintenance.week`):`1 week`:n?n(`maintenance.weeks`,{count:t}):`${t} weeks`}let t=Math.round(e/30);return t===1?n?n(`maintenance.month`):`1 month`:n?n(`maintenance.months`,{count:t}):`${t} months`}else{if(e<1)return`${Math.round(e*60)}m`;if(e<24)return`${e<10?e.toFixed(1):Math.round(e)}h`;let t=e/24;if(t<7)return`${t<2?t.toFixed(1):Math.round(t)}d`;let n=t/7;return n<12?`${n<2?n.toFixed(1):Math.round(n)}w`:`${Math.round(n/4)}mo`}}function V6(e,t,n){return t===`days`?e===1?n?n(`maintenance.day`):`1 day`:e===7?n?n(`maintenance.week`):`1 week`:e===14?n?n(`maintenance.weeks`,{count:2}):`2 weeks`:e===30?n?n(`maintenance.month`):`1 month`:e===60?n?n(`maintenance.months`,{count:2}):`2 months`:e===90?n?n(`maintenance.months`,{count:3}):`3 months`:e===180?n?n(`maintenance.months`,{count:6}):`6 months`:e===365?n?n(`maintenance.year`):`1 year`:n?n(`maintenance.days`,{count:e}):`${e} days`:`${e}h`}function dWe({item:e,onPerform:t,onToggle:n,hasPermission:r,t:i}){let a=z6(e.maintenance_type_icon),o=e.interval_type||`hours`,s=(()=>{if(o===`days`){let t=e.days_since_maintenance??0;return Math.max(0,Math.min(100,t/e.interval_hours*100))}return Math.max(0,Math.min(100,(e.interval_hours-e.hours_until_due)/e.interval_hours*100))})(),c=()=>e.enabled?e.is_due?`text-red-700 dark:text-red-400`:e.is_warning?`text-amber-700 dark:text-amber-400`:`text-bambu-green`:`text-bambu-gray`;return(0,K.jsx)(`div`,{className:`rounded-xl border p-4 transition-all ${e.enabled?e.is_due?`bg-red-500/5 border-red-500/20`:e.is_warning?`bg-amber-500/5 border-amber-500/20`:`bg-bambu-dark-secondary border-bambu-dark-tertiary`:`bg-bambu-dark-secondary/50`}`,children:(0,K.jsxs)(`div`,{className:`flex items-start gap-3 max-[550px]:flex-wrap`,children:[(0,K.jsxs)(`div`,{className:`relative p-2.5 rounded-lg shrink-0 ${e.is_due?`bg-red-500/20`:e.is_warning?`bg-amber-500/20`:e.enabled?`bg-bambu-dark`:`bg-bambu-dark/50`}`,children:[(0,K.jsx)(a,{className:`w-5 h-5 ${c()}`}),e.enabled&&(e.is_due||e.is_warning)&&(0,K.jsx)(`span`,{className:`absolute -top-1 -right-1 w-2.5 h-2.5 rounded-full ${e.is_due?`bg-red-500`:`bg-amber-500`} animate-pulse`})]}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`h3`,{className:`font-medium truncate ${e.enabled?`text-white`:`text-bambu-gray`}`,children:e.maintenance_type_name}),o===`days`&&(0,K.jsx)(`span`,{title:i(`maintenance.timeBasedInterval`),children:(0,K.jsx)($o,{className:`w-3.5 h-3.5 text-bambu-gray shrink-0`})}),(()=>{let t=e.maintenance_type_wiki_url||uWe(e.maintenance_type_name,e.printer_model);return t?(0,K.jsx)(`a`,{href:t,target:`_blank`,rel:`noopener noreferrer`,className:`text-bambu-gray hover:text-bambu-green transition-colors shrink-0`,title:i(`maintenance.viewDocumentation`),onClick:e=>e.stopPropagation(),children:(0,K.jsx)(Zs,{className:`w-3.5 h-3.5`})}):null})()]}),(0,K.jsx)(`div`,{className:`mt-2 mb-1.5`,children:(0,K.jsx)(`div`,{className:`w-full h-1.5 bg-bambu-dark rounded-full overflow-hidden`,children:(0,K.jsx)(`div`,{className:`h-full rounded-full transition-all duration-500 ${e.enabled?e.is_due?`bg-red-500`:e.is_warning?`bg-amber-500`:`bg-bambu-green`:`bg-bambu-gray/30`}`,style:{width:`${s}%`}})})}),(0,K.jsxs)(`div`,{className:`text-xs flex items-center gap-1 ${c()}`,children:[e.is_due&&(0,K.jsx)(ku,{className:`w-3 h-3`}),e.is_warning&&!e.is_due&&(0,K.jsx)(ws,{className:`w-3 h-3`}),!e.is_due&&!e.is_warning&&e.enabled&&(0,K.jsx)(as,{className:`w-3 h-3`}),(()=>{if(!e.enabled)return i(`common.disabled`);if(o===`days`){let t=e.days_until_due??0;return e.is_due?i(`maintenance.overdueBy`,{duration:B6(Math.abs(t),`days`,i)}):e.is_warning?i(`maintenance.dueIn`,{duration:B6(t,`days`,i)}):i(`maintenance.timeLeft`,{duration:B6(t,`days`,i)})}else return e.is_due?i(`maintenance.overdueBy`,{duration:B6(Math.abs(e.hours_until_due),`hours`,i)}):e.is_warning?i(`maintenance.dueIn`,{duration:B6(e.hours_until_due,`hours`,i)}):i(`maintenance.timeLeft`,{duration:B6(e.hours_until_due,`hours`,i)})})()]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0 max-[550px]:w-full max-[550px]:justify-end max-[550px]:mt-1`,children:[(0,K.jsx)(`span`,{title:r(`maintenance:update`)?void 0:i(`maintenance.noPermissionUpdate`),children:(0,K.jsx)(cU,{checked:e.enabled,onChange:t=>n(e.id,t),disabled:!r(`maintenance:update`)})}),(0,K.jsxs)($,{size:`sm`,variant:e.is_due?`primary`:`secondary`,onClick:()=>t(e.id),disabled:!e.enabled||!r(`maintenance:update`),title:r(`maintenance:update`)?void 0:i(`maintenance.noPermissionPerform`),className:`!px-3`,children:[(0,K.jsx)(Il,{className:`w-3.5 h-3.5`}),i(`common.reset`)]})]})]})})}function fWe({overview:e,onPerform:t,onToggle:n,onSetHours:r,hasPermission:i,t:a}){let[o,s]=(0,y.useState)(!1),[c,l]=(0,y.useState)(!1),[u,d]=(0,y.useState)(e.total_print_hours.toFixed(1)),f=[...e.maintenance_items].sort((e,t)=>e.is_due&&!t.is_due?-1:!e.is_due&&t.is_due?1:e.is_warning&&!t.is_warning?-1:!e.is_warning&&t.is_warning?1:e.maintenance_type_id-t.maintenance_type_id),p=f.find(e=>e.enabled&&(e.is_due||e.is_warning)),m=()=>{let t=parseFloat(u);!isNaN(t)&&t>=0&&(r(e.printer_id,t),l(!1))};return(0,K.jsxs)(Ed,{className:`overflow-hidden`,children:[(0,K.jsxs)(`div`,{className:`p-5`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,K.jsx)(`h2`,{className:`text-xl font-semibold text-white`,children:e.printer_name}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e.due_count>0&&(0,K.jsxs)(`span`,{className:`px-2.5 py-1 bg-red-100 text-red-700 dark:bg-red-500/20 dark:text-red-400 text-xs font-medium rounded-full flex items-center gap-1.5`,children:[(0,K.jsx)(ku,{className:`w-3 h-3`}),a(`maintenance.overdueCount`,{count:e.due_count})]}),e.warning_count>0&&(0,K.jsxs)(`span`,{className:`px-2.5 py-1 bg-amber-100 text-amber-700 dark:bg-amber-500/20 dark:text-amber-400 text-xs font-medium rounded-full flex items-center gap-1.5`,children:[(0,K.jsx)(ws,{className:`w-3 h-3`}),a(`maintenance.dueSoonCount`,{count:e.warning_count})]}),e.due_count===0&&e.warning_count===0&&(0,K.jsxs)(`span`,{className:`px-2.5 py-1 bg-bambu-green/20 text-bambu-green text-xs font-medium rounded-full flex items-center gap-1.5`,children:[(0,K.jsx)(as,{className:`w-3 h-3`}),a(`maintenance.allGood`)]})]})]}),(0,K.jsxs)(`button`,{onClick:()=>s(!o),className:`flex items-center gap-1.5 px-3 py-1.5 text-sm text-bambu-gray hover:text-white hover:bg-bambu-dark rounded-lg transition-colors`,children:[o?(0,K.jsx)(us,{className:`w-4 h-4`}):(0,K.jsx)(ss,{className:`w-4 h-4`}),a(o?`common.collapse`:`common.expand`)]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-6 mt-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`p-2 bg-bambu-dark/50 rounded-lg`,children:(0,K.jsx)(Tu,{className:`w-4 h-4 text-bambu-gray`})}),c?(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`input`,{type:`number`,value:u,onChange:e=>d(e.target.value),onKeyDown:e=>{e.key===`Enter`&&m(),e.key===`Escape`&&l(!1)},className:`w-24 px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm`,min:`0`,step:`1`,autoFocus:!0}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:a(`common.hours`)}),(0,K.jsx)($,{size:`sm`,onClick:m,children:a(`common.save`)}),(0,K.jsx)($,{size:`sm`,variant:`secondary`,onClick:()=>l(!1),children:a(`common.cancel`)})]}):(0,K.jsxs)(`button`,{onClick:()=>{i(`maintenance:update`)&&(d(Math.round(e.total_print_hours).toString()),l(!0))},className:`group ${i(`maintenance:update`)?``:`cursor-not-allowed opacity-60`}`,title:i(`maintenance:update`)?void 0:a(`maintenance.noPermissionEditHours`),children:[(0,K.jsxs)(`div`,{className:`text-sm font-medium text-white ${i(`maintenance:update`)?`group-hover:text-bambu-green`:``} transition-colors flex items-center gap-1`,children:[Math.round(e.total_print_hours),` `,a(`common.hours`),(0,K.jsx)(Sl,{className:`w-3 h-3 text-bambu-gray ${i(`maintenance:update`)?`group-hover:text-bambu-green`:``}`})]}),(0,K.jsx)(`div`,{className:`text-xs text-bambu-gray`,children:a(`maintenance.totalPrintTime`)})]})]}),(0,K.jsx)(`div`,{className:`w-px h-10 bg-bambu-dark-tertiary`}),p&&(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`p-2 rounded-lg ${p.is_due?`bg-red-500/20`:`bg-amber-500/20`}`,children:(0,K.jsx)(z6(p.maintenance_type_icon),{className:`w-4 h-4 ${p.is_due?`text-red-600 dark:text-red-400`:`text-amber-600 dark:text-amber-400`}`})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`div`,{className:`text-sm font-medium ${p.is_due?`text-red-700 dark:text-red-400`:`text-amber-700 dark:text-amber-400`}`,children:p.maintenance_type_name}),(0,K.jsx)(`div`,{className:`text-xs ${p.is_due?`text-red-700/80 dark:text-red-400/70`:`text-amber-700/80 dark:text-amber-400/70`}`,children:p.is_due?a(`common.overdue`):a(`maintenance.dueSoon`)})]})]})]})]}),o&&(0,K.jsx)(Od,{className:`pt-0 border-t border-bambu-dark-tertiary`,children:(0,K.jsx)(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 gap-3 pt-4`,children:f.map(e=>(0,K.jsx)(dWe,{item:e,onPerform:t,onToggle:n,hasPermission:i,t:a},e.id))})})]})}function pWe({overview:e,types:t,onUpdateInterval:n,onAddType:r,onUpdateType:i,onDeleteType:a,onRestoreDefaults:o,isRestoringDefaults:s,onAssignType:c,onRemoveItem:l,hasPermission:u,t:d}){let[f,p]=(0,y.useState)(null),[m,h]=(0,y.useState)(``),[g,_]=(0,y.useState)(`hours`),[v,b]=(0,y.useState)(!1),[x,S]=(0,y.useState)(``),[C,w]=(0,y.useState)(`100`),[T,E]=(0,y.useState)(`hours`),[D,O]=(0,y.useState)(`Wrench`),[k,A]=(0,y.useState)(``),[j,M]=(0,y.useState)(new Set),[N,P]=(0,y.useState)(null),[F,I]=(0,y.useState)(null),L=(0,y.useMemo)(()=>e?e.map(e=>({id:e.printer_id,name:e.printer_name})):[],[e]),R=t=>e?e.filter(e=>e.maintenance_items.some(e=>e.maintenance_type_id===t)).map(e=>({printerId:e.printer_id,printerName:e.printer_name,itemId:e.maintenance_items.find(e=>e.maintenance_type_id===t)?.id})):[],z=t=>{if(!e)return[];let n=new Set(R(t).map(e=>e.printerId));return L.filter(e=>!n.has(e.id))},[B,V]=(0,y.useState)(null),[ee,te]=(0,y.useState)(``),[ne,re]=(0,y.useState)(``),[ie,H]=(0,y.useState)(`hours`),[ae,oe]=(0,y.useState)(`Wrench`),[U,se]=(0,y.useState)(``),ce=e=>{V(e),te(e.name),re(e.default_interval_hours.toString()),H(e.interval_type||`hours`),oe(e.icon||`Wrench`),se(e.wiki_url||``)},le=()=>{B&&ee.trim()&&parseFloat(ne)>0&&(i(B.id,{name:ee.trim(),default_interval_hours:parseFloat(ne),interval_type:ie,icon:ae,wiki_url:U.trim()||null}),V(null))},ue=(e,t,r)=>{let i=parseFloat(m);!isNaN(i)&&i>0&&n(e,{custom_interval_hours:Math.abs(i-t)<.01?null:i,custom_interval_type:g===r?null:g}),p(null)},de=e=>{e.preventDefault(),x.trim()&&parseFloat(C)>0&&j.size>0&&(r({name:x.trim(),default_interval_hours:parseFloat(C),interval_type:T,icon:D,wiki_url:k.trim()||null},Array.from(j)),S(``),w(`100`),E(`hours`),A(``),M(new Set),b(!1))},fe=e=>{M(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},pe=e?.map(e=>({printerId:e.printer_id,printerName:e.printer_name,items:e.maintenance_items.sort((e,t)=>e.maintenance_type_id-t.maintenance_type_id)})).sort((e,t)=>e.printerName.localeCompare(t.printerName))||[],me=t.filter(e=>e.is_system),he=t.filter(e=>!e.is_system);return(0,K.jsxs)(`div`,{className:`space-y-8`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-4`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:d(`maintenance.maintenanceTypes`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:d(`maintenance.maintenanceTypesDescription`)})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)($,{variant:`secondary`,onClick:o,disabled:!u(`maintenance:delete`)||s,title:u(`maintenance:delete`)?void 0:d(`maintenance.noPermissionDeleteTypes`),children:d(`maintenance.restoreDefaults`)}),(0,K.jsxs)($,{onClick:()=>b(!v),disabled:!u(`maintenance:create`),title:u(`maintenance:create`)?void 0:d(`maintenance.noPermissionEditTypes`),children:[(0,K.jsx)(Ol,{className:`w-4 h-4`}),d(`maintenance.addCustomType`)]})]})]}),v&&(0,K.jsx)(Ed,{className:`mb-6`,children:(0,K.jsx)(Od,{className:`py-4`,children:(0,K.jsxs)(`form`,{onSubmit:de,children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4`,children:[(0,K.jsxs)(`div`,{className:`lg:col-span-2`,children:[(0,K.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1.5`,children:d(`common.name`)}),(0,K.jsx)(`input`,{type:`text`,value:x,onChange:e=>S(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,placeholder:d(`maintenance.exampleName`),autoFocus:!0})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1.5`,children:d(`maintenance.intervalType`)}),(0,K.jsxs)(`select`,{value:T,onChange:e=>{E(e.target.value),e.target.value===`days`?w(`30`):w(`100`)},className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,children:[(0,K.jsx)(`option`,{value:`hours`,children:d(`maintenance.printHours`)}),(0,K.jsx)(`option`,{value:`days`,children:d(`maintenance.calendarDays`)})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1.5`,children:d(`maintenance.intervalValue`,{type:T===`days`?d(`maintenance.calendarDays`).toLowerCase():d(`common.hours`)})}),(0,K.jsx)(`input`,{type:`number`,value:C,onChange:e=>w(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,min:`1`})]})]}),(0,K.jsx)(`div`,{className:`mt-4 flex items-end justify-between`,children:(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1.5`,children:d(`maintenance.icon`)}),(0,K.jsx)(`div`,{className:`flex gap-1`,children:Object.keys(R6).map(e=>{let t=R6[e];return(0,K.jsx)(`button`,{type:`button`,onClick:()=>O(e),className:`p-2 rounded-lg transition-colors ${D===e?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary`}`,children:(0,K.jsx)(t,{className:`w-4 h-4`})},e)})})]})}),(0,K.jsxs)(`div`,{className:`mt-4`,children:[(0,K.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1.5`,children:d(`maintenance.documentationLink`)}),(0,K.jsx)(`input`,{type:`url`,value:k,onChange:e=>A(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,placeholder:`https://wiki.bambulab.com/...`})]}),(0,K.jsxs)(`div`,{className:`mt-4`,children:[(0,K.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1.5`,children:d(`maintenance.assignToPrinters`)}),(0,K.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:L.map(e=>(0,K.jsx)(`button`,{type:`button`,onClick:()=>fe(e.id),className:`px-3 py-1.5 rounded-lg text-sm transition-colors ${j.has(e.id)?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary`}`,children:e.name},e.id))}),j.size===0&&(0,K.jsx)(`p`,{className:`text-xs text-orange-700 dark:text-orange-400 mt-1`,children:d(`maintenance.selectAtLeastOnePrinter`)})]}),(0,K.jsxs)(`div`,{className:`mt-4 flex justify-end gap-2`,children:[(0,K.jsx)($,{type:`button`,variant:`secondary`,onClick:()=>{b(!1),M(new Set)},children:d(`common.cancel`)}),(0,K.jsx)($,{type:`submit`,disabled:!x.trim()||j.size===0,children:d(`maintenance.addType`)})]})]})})}),(0,K.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-3`,children:[me.map(e=>{let t=z6(e.icon),n=e.interval_type||`hours`;return(0,K.jsx)(`div`,{className:`bg-bambu-dark-secondary rounded-xl p-4 border border-bambu-dark-tertiary`,children:(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`p-2.5 bg-bambu-dark rounded-lg`,children:(0,K.jsx)(t,{className:`w-5 h-5 text-bambu-gray`})}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsx)(`div`,{className:`text-sm font-medium text-white truncate`,children:e.name}),(0,K.jsxs)(`div`,{className:`text-xs text-bambu-gray mt-0.5 flex items-center gap-1`,children:[n===`days`?(0,K.jsx)($o,{className:`w-3 h-3`}):(0,K.jsx)(Tu,{className:`w-3 h-3`}),V6(e.default_interval_hours,n,d)]})]}),(0,K.jsx)(`button`,{onClick:()=>{u(`maintenance:delete`)&&I(e)},disabled:!u(`maintenance:delete`),title:u(`maintenance:delete`)?void 0:d(`maintenance.noPermissionDeleteTypes`),className:`p-2 rounded-lg hover:bg-bambu-dark text-bambu-gray hover:text-red-600 dark:hover:text-red-400 transition-colors ${u(`maintenance:delete`)?``:`opacity-50 cursor-not-allowed`}`,children:(0,K.jsx)(Eu,{className:`w-4 h-4`})})]})},e.id)}),he.map(e=>{let t=z6(e.icon),n=e.interval_type||`hours`;if(B?.id===e.id)return(0,K.jsx)(`div`,{className:`bg-bambu-dark-secondary rounded-xl p-4 border border-bambu-green`,children:(0,K.jsxs)(`div`,{className:`space-y-3`,children:[(0,K.jsx)(`input`,{type:`text`,value:ee,onChange:e=>te(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,placeholder:d(`common.name`),autoFocus:!0}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsxs)(`select`,{value:ie,onChange:e=>H(e.target.value),className:`flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,children:[(0,K.jsx)(`option`,{value:`hours`,children:d(`maintenance.printHours`)}),(0,K.jsx)(`option`,{value:`days`,children:d(`maintenance.calendarDays`)})]}),(0,K.jsx)(`input`,{type:`number`,value:ne,onChange:e=>re(e.target.value),className:`w-24 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,min:`1`})]}),(0,K.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:Object.keys(R6).map(e=>{let t=R6[e];return(0,K.jsx)(`button`,{type:`button`,onClick:()=>oe(e),className:`p-1.5 rounded transition-colors ${ae===e?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white`}`,children:(0,K.jsx)(t,{className:`w-3.5 h-3.5`})},e)})}),(0,K.jsx)(`input`,{type:`url`,value:U,onChange:e=>se(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,placeholder:d(`maintenance.documentationLink`)}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)($,{size:`sm`,onClick:le,disabled:!ee.trim(),children:d(`common.save`)}),(0,K.jsx)($,{size:`sm`,variant:`secondary`,onClick:()=>V(null),children:d(`common.cancel`)})]})]})},e.id);let r=R(e.id),i=z(e.id),o=N===e.id;return(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl p-4 border border-bambu-green/30`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`p-2.5 bg-bambu-green/20 rounded-lg`,children:(0,K.jsx)(t,{className:`w-5 h-5 text-bambu-green`})}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`text-sm font-medium text-white truncate`,children:e.name}),(0,K.jsx)(`span`,{className:`px-1.5 py-0.5 bg-bambu-green/20 text-bambu-green text-[10px] font-medium rounded`,children:d(`maintenance.custom`)})]}),(0,K.jsxs)(`div`,{className:`text-xs text-bambu-gray mt-0.5 flex items-center gap-1`,children:[n===`days`?(0,K.jsx)($o,{className:`w-3 h-3`}):(0,K.jsx)(Tu,{className:`w-3 h-3`}),V6(e.default_interval_hours,n,d)]})]}),(0,K.jsxs)(`button`,{onClick:()=>P(o?null:e.id),className:`px-2 py-1 rounded-lg border transition-colors flex items-center gap-1 ${r.length>0?`border-bambu-green/50 bg-bambu-green/10 text-bambu-green hover:bg-bambu-green/20`:`border-orange-300 bg-orange-50 text-orange-700 hover:bg-orange-100 dark:border-orange-400/50 dark:bg-orange-400/10 dark:text-orange-400 dark:hover:bg-orange-400/20`}`,title:d(`maintenance.printersAssignedClick`,{count:r.length}),children:[(0,K.jsx)(jl,{className:`w-3 h-3`}),(0,K.jsx)(`span`,{className:`text-xs font-medium`,children:r.length}),(0,K.jsx)(ss,{className:`w-3 h-3 transition-transform ${o?`rotate-180`:``}`})]}),(0,K.jsx)(`button`,{onClick:()=>ce(e),disabled:!u(`maintenance:update`),title:u(`maintenance:update`)?void 0:d(`maintenance.noPermissionEditTypes`),className:`p-2 rounded-lg hover:bg-bambu-dark text-bambu-gray hover:text-white transition-colors ${u(`maintenance:update`)?``:`opacity-50 cursor-not-allowed`}`,children:(0,K.jsx)(Sl,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>{confirm(d(`maintenance.deleteTypeConfirm`,{name:e.name}))&&a(e.id)},disabled:!u(`maintenance:delete`),title:u(`maintenance:delete`)?void 0:d(`maintenance.noPermissionDeleteTypes`),className:`p-2 rounded-lg hover:bg-bambu-dark text-bambu-gray hover:text-red-600 dark:hover:text-red-400 transition-colors ${u(`maintenance:delete`)?``:`opacity-50 cursor-not-allowed`}`,children:(0,K.jsx)(Eu,{className:`w-4 h-4`})})]}),o&&(0,K.jsxs)(`div`,{className:`mt-3 pt-3 border-t border-bambu-dark-tertiary`,children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:d(`maintenance.assignedToPrinters`)}),r.length===0?(0,K.jsx)(`p`,{className:`text-xs text-orange-700 dark:text-orange-400`,children:d(`maintenance.noPrintersAssigned`)}):(0,K.jsx)(`div`,{className:`flex flex-wrap gap-1 mb-2`,children:r.map(e=>(0,K.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-2 py-1 bg-bambu-dark rounded text-xs text-white`,children:[e.printerName,(0,K.jsx)(`button`,{onClick:()=>e.itemId&&l(e.itemId),disabled:!u(`maintenance:delete`),title:u(`maintenance:delete`)?d(`maintenance.removeFromPrinter`):d(`maintenance.noPermissionRemovePrinter`),className:`ml-1 ${u(`maintenance:delete`)?`hover:text-red-600 dark:hover:text-red-400`:`opacity-50 cursor-not-allowed`}`,children:`×`})]},e.printerId))}),i.length>0&&(0,K.jsxs)(`div`,{className:`flex flex-wrap gap-1`,children:[(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray mr-1`,children:d(`maintenance.addPrinterShort`)}),i.map(t=>(0,K.jsxs)(`button`,{onClick:()=>c(t.id,e.id),disabled:!u(`maintenance:create`),title:u(`maintenance:create`)?void 0:d(`maintenance.noPermissionAssignPrinter`),className:`px-2 py-1 bg-bambu-dark rounded text-xs transition-colors ${u(`maintenance:create`)?`hover:bg-bambu-green/20 text-bambu-gray hover:text-bambu-green`:`opacity-50 cursor-not-allowed text-bambu-gray`}`,children:[`+ `,t.name]},t.id))]})]})]},e.id)})]})]}),pe.length>0&&(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`mb-4`,children:[(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:d(`maintenance.intervalOverrides`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:d(`maintenance.intervalOverridesDescription`)})]}),(0,K.jsx)(`div`,{className:`space-y-4`,children:pe.map(e=>(0,K.jsx)(Ed,{children:(0,K.jsxs)(Od,{className:`py-4`,children:[(0,K.jsx)(`h3`,{className:`text-sm font-medium text-white mb-3`,children:e.printerName}),(0,K.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-2`,children:e.items.map(e=>{let n=z6(e.maintenance_type_icon),r=t.find(t=>t.id===e.maintenance_type_id),i=r?.default_interval_hours||e.interval_hours,a=r?.interval_type||`hours`,o=e.interval_type||`hours`,s=f===e.id;return(0,K.jsxs)(`div`,{className:`flex items-center gap-2 p-2.5 bg-bambu-dark rounded-lg`,children:[(0,K.jsx)(n,{className:`w-4 h-4 text-bambu-gray shrink-0`}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray flex-1 truncate`,children:e.maintenance_type_name}),s?(0,K.jsxs)(`div`,{className:`flex items-center gap-1`,children:[g===`days`?(0,K.jsx)($o,{className:`w-3.5 h-3.5 text-bambu-gray shrink-0`}):(0,K.jsx)(Tu,{className:`w-3.5 h-3.5 text-bambu-gray shrink-0`}),(0,K.jsxs)(`select`,{value:g,onChange:e=>_(e.target.value),className:`px-1.5 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-xs`,children:[(0,K.jsx)(`option`,{value:`hours`,children:d(`maintenance.printHours`)}),(0,K.jsx)(`option`,{value:`days`,children:d(`maintenance.calendarDays`)})]}),(0,K.jsx)(`input`,{type:`number`,value:m,onChange:e=>h(e.target.value),onKeyDown:t=>{t.key===`Enter`&&ue(e.id,i,a),t.key===`Escape`&&p(null)},className:`w-16 px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-xs`,min:`1`}),(0,K.jsx)($,{size:`sm`,onClick:()=>ue(e.id,i,a),children:`OK`})]}):(0,K.jsxs)(`button`,{onClick:()=>{u(`maintenance:update`)&&(p(e.id),h(e.interval_hours.toString()),_(o))},disabled:!u(`maintenance:update`),title:u(`maintenance:update`)?void 0:d(`maintenance.noPermissionEditIntervals`),className:`px-2 py-1 bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded text-xs font-medium text-white transition-colors flex items-center gap-1 ${u(`maintenance:update`)?`hover:bg-bambu-dark-secondary hover:border-bambu-green`:`opacity-50 cursor-not-allowed`}`,children:[o===`days`?(0,K.jsx)($o,{className:`w-3 h-3`}):(0,K.jsx)(Tu,{className:`w-3 h-3`}),V6(e.interval_hours,o,d),(0,K.jsx)(Sl,{className:`w-3 h-3 text-bambu-gray`})]})]},e.id)})})]})},e.printerId))})]}),pe.length===0&&(0,K.jsx)(Ed,{children:(0,K.jsxs)(Od,{className:`text-center py-12`,children:[(0,K.jsx)(ws,{className:`w-12 h-12 mx-auto mb-4 text-bambu-gray/30`}),(0,K.jsx)(`p`,{className:`text-bambu-gray`,children:d(`common.noPrinters`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray/70 mt-1`,children:d(`maintenance.intervalOverridesDescription`)})]})}),F&&(0,K.jsx)(Vd,{title:d(`maintenance.deleteSystemTypeTitle`),message:d(`maintenance.deleteSystemTypeMessage`,{name:F.name}),confirmText:d(`common.delete`),cancelText:d(`common.cancel`),variant:`danger`,cancelVariant:`primary`,cardClassName:`bg-red-950/70 border border-red-800/70`,onConfirm:()=>{a(F.id),I(null)},onCancel:()=>I(null)})]})}function mWe(){let{t:e}=W(),t=oo(),{showToast:n}=Pd(),{hasPermission:r}=bd(),[i,a]=(0,y.useState)(`status`),{data:o,isLoading:s}=q({queryKey:[`maintenanceOverview`],queryFn:Q.getMaintenanceOverview}),{data:c}=q({queryKey:[`maintenanceTypes`],queryFn:Q.getMaintenanceTypes}),l=J({mutationFn:({id:e,notes:t})=>Q.performMaintenance(e,t),onSuccess:()=>{t.invalidateQueries({queryKey:[`maintenanceOverview`]}),t.invalidateQueries({queryKey:[`maintenanceSummary`]}),n(e(`maintenance.maintenanceComplete`))},onError:e=>{n(e.message,`error`)}}),u=J({mutationFn:({id:e,data:t})=>Q.updateMaintenanceItem(e,t),onSuccess:()=>{t.invalidateQueries({queryKey:[`maintenanceOverview`]})},onError:e=>{n(e.message,`error`)}}),d=J({mutationFn:({id:e,data:t})=>Q.updateMaintenanceType(e,t),onSuccess:()=>{t.invalidateQueries({queryKey:[`maintenanceTypes`]}),t.invalidateQueries({queryKey:[`maintenanceOverview`]}),n(e(`maintenance.typeUpdated`))},onError:e=>{n(e.message,`error`)}}),f=J({mutationFn:Q.deleteMaintenanceType,onSuccess:()=>{t.invalidateQueries({queryKey:[`maintenanceTypes`]}),t.invalidateQueries({queryKey:[`maintenanceOverview`]}),n(e(`maintenance.typeDeleted`))},onError:e=>{n(e.message,`error`)}}),p=J({mutationFn:Q.restoreDefaultMaintenanceTypes,onSuccess:r=>{t.invalidateQueries({queryKey:[`maintenanceTypes`]}),t.invalidateQueries({queryKey:[`maintenanceOverview`]}),n(e(`maintenance.defaultsRestored`,{count:r.restored}))},onError:e=>{n(e.message,`error`)}}),m=J({mutationFn:({printerId:e,hours:t})=>Q.setPrinterHours(e,t),onSuccess:()=>{t.invalidateQueries({queryKey:[`maintenanceOverview`]}),t.invalidateQueries({queryKey:[`maintenanceSummary`]}),n(e(`maintenance.printHoursUpdated`))},onError:e=>{n(e.message,`error`)}}),h=J({mutationFn:({printerId:e,typeId:t})=>Q.assignMaintenanceType(e,t),onSuccess:()=>{t.invalidateQueries({queryKey:[`maintenanceOverview`]}),n(e(`maintenance.printerAssigned`))},onError:e=>{n(e.message,`error`)}}),g=J({mutationFn:Q.removeMaintenanceItem,onSuccess:()=>{t.invalidateQueries({queryKey:[`maintenanceOverview`]}),n(e(`maintenance.printerRemoved`))},onError:e=>{n(e.message,`error`)}}),_=e=>{l.mutate({id:e})},v=(e,t)=>{u.mutate({id:e,data:{enabled:t}})},b=(e,t)=>{m.mutate({printerId:e,hours:t})};if(s)return(0,K.jsx)(`div`,{className:`p-4 md:p-8 flex justify-center`,children:(0,K.jsx)(X,{className:`w-8 h-8 text-bambu-green animate-spin`})});let x=o?.reduce((e,t)=>e+t.due_count,0)||0,S=o?.reduce((e,t)=>e+t.warning_count,0)||0;return(0,K.jsxs)(`div`,{className:`p-4 md:p-8`,children:[(0,K.jsxs)(`div`,{className:`mb-6`,children:[(0,K.jsxs)(`h1`,{className:`text-2xl font-bold text-white flex items-center gap-3`,children:[(0,K.jsx)(Ku,{className:`w-7 h-7 text-bambu-green`}),e(`maintenance.title`)]}),(0,K.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:i===`status`?(0,K.jsxs)(K.Fragment,{children:[x>0&&(0,K.jsx)(`span`,{className:`text-red-700 dark:text-red-400`,children:e(`maintenance.dueCount`,{count:x})}),x>0&&S>0&&` · `,S>0&&(0,K.jsx)(`span`,{className:`text-amber-700 dark:text-amber-400`,children:e(`maintenance.warningCount`,{count:S})}),x===0&&S===0&&(0,K.jsx)(`span`,{className:`text-bambu-green`,children:e(`maintenance.allOk`)})]}):e(`maintenance.configureSettings`)})]}),(0,K.jsxs)(`div`,{className:`flex gap-1 mb-6 border-b border-bambu-dark-tertiary`,children:[(0,K.jsx)(`button`,{onClick:()=>a(`status`),className:`px-4 py-2 text-sm font-medium border-b-2 -mb-px transition-colors ${i===`status`?`text-bambu-green border-bambu-green`:`text-bambu-gray border-transparent hover:text-white`}`,children:e(`maintenance.statusTab`)}),(0,K.jsx)(`button`,{onClick:()=>a(`settings`),className:`px-4 py-2 text-sm font-medium border-b-2 -mb-px transition-colors ${i===`settings`?`text-bambu-green border-bambu-green`:`text-bambu-gray border-transparent hover:text-white`}`,children:e(`maintenance.settingsTab`)})]}),i===`status`?(0,K.jsx)(`div`,{className:`space-y-6`,children:o&&o.length>0?[...o].sort((e,t)=>{let n=e.due_count*10+e.warning_count,r=t.due_count*10+t.warning_count;return n===r?e.printer_name.localeCompare(t.printer_name):r-n}).map(t=>(0,K.jsx)(fWe,{overview:t,onPerform:_,onToggle:v,onSetHours:b,hasPermission:r,t:e},t.printer_id)):(0,K.jsx)(Ed,{children:(0,K.jsxs)(Od,{className:`text-center py-16`,children:[(0,K.jsx)(Ku,{className:`w-16 h-16 mx-auto mb-4 text-bambu-gray/30`}),(0,K.jsx)(`p`,{className:`text-lg font-medium text-white mb-2`,children:e(`common.noPrinters`)}),(0,K.jsx)(`p`,{className:`text-bambu-gray`,children:e(`maintenance.configureSettings`)})]})})}):(0,K.jsx)(pWe,{overview:o,types:c||[],onUpdateInterval:(e,t)=>u.mutate({id:e,data:t}),onAddType:async(r,i)=>{let a=await Q.createMaintenanceType(r);for(let e of i)await Q.assignMaintenanceType(e,a.id);t.invalidateQueries({queryKey:[`maintenanceTypes`]}),t.invalidateQueries({queryKey:[`maintenanceOverview`]}),n(e(`maintenance.typeUpdated`))},onUpdateType:(e,t)=>d.mutate({id:e,data:t}),onDeleteType:e=>f.mutate(e),onRestoreDefaults:()=>p.mutate(),isRestoringDefaults:p.isPending,onAssignType:(e,t)=>h.mutate({printerId:e,typeId:t}),onRemoveItem:e=>g.mutate(e),hasPermission:r,t:e})]})}var H6=[`#ef4444`,`#f97316`,`#eab308`,`#22c55e`,`#06b6d4`,`#3b82f6`,`#8b5cf6`,`#ec4899`,`#6b7280`];function U6({project:e,onClose:t,onSave:n,isLoading:r,currencySymbol:i,t:a}){let[o,s]=(0,y.useState)(e?.name||``),[c,l]=(0,y.useState)(e?.description||``),[u,d]=(0,y.useState)(e?.color||H6[0]),[f,p]=(0,y.useState)(e?.target_count?.toString()||``),[m,h]=(0,y.useState)(e?.target_parts_count?.toString()||``),[g,_]=(0,y.useState)(e?.status||`active`),[v,b]=(0,y.useState)(e?.tags||``),[x,S]=(0,y.useState)(e?.due_date?.split(`T`)[0]||``),[C,w]=(0,y.useState)(e?.priority||`normal`),[T,E]=(0,y.useState)(e?.budget?.toString()||``),[D,O]=(0,y.useState)(e?.url||``),[k,A]=(0,y.useState)(null),j=oo(),[M,N]=(0,y.useState)(e?.cover_image_filename||null),P=(0,y.useRef)(null),[F,I]=(0,y.useState)(!1),[L,R]=(0,y.useState)(0);return(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg w-full max-w-md border border-bambu-dark-tertiary flex flex-col max-h-[calc(100vh-2rem)]`,children:[(0,K.jsx)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary flex-shrink-0`,children:(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:a(e?`projects.editProject`:`projects.newProject`)})}),(0,K.jsxs)(`form`,{onSubmit:t=>{t.preventDefault();let r=D.trim();if(r&&!/^https?:\/\//i.test(r)){A(a(`projects.urlInvalid`));return}A(null),n({name:o.trim(),description:c.trim()||void 0,color:u,target_count:f?parseInt(f,10):void 0,target_parts_count:m?parseInt(m,10):void 0,tags:e?v.trim()||null:v.trim()||void 0,due_date:e?x||null:x||void 0,priority:C,budget:T.trim()?parseFloat(T):null,url:e?r||null:r||void 0,...e&&{status:g}})},className:`flex flex-col flex-1 min-h-0`,children:[(0,K.jsxs)(`div`,{className:`p-4 space-y-4 overflow-y-auto flex-1`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`common.name`)}),(0,K.jsx)(`input`,{type:`text`,value:o,onChange:e=>s(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:a(`projects.namePlaceholder`),required:!0})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`common.description`)}),(0,K.jsx)(`textarea`,{value:c,onChange:e=>l(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green resize-none`,placeholder:a(`projects.descriptionPlaceholder`),rows:2})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`projects.urlLabel`)}),(0,K.jsx)(`input`,{type:`url`,value:D,onChange:e=>{O(e.target.value),k&&A(null)},className:`w-full bg-bambu-dark border rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none ${k?`border-red-500 focus:border-red-500`:`border-bambu-dark-tertiary focus:border-bambu-green`}`,placeholder:a(`projects.urlPlaceholder`),maxLength:2048}),k&&(0,K.jsx)(`p`,{className:`text-xs text-red-600 dark:text-red-400 mt-1`,children:k})]}),e&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`projects.coverImageLabel`)}),(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`w-20 h-20 rounded bg-bambu-dark border border-bambu-dark-tertiary overflow-hidden flex items-center justify-center flex-shrink-0`,children:M?(0,K.jsx)(`img`,{src:`${Q.getProjectCoverImageUrl(e.id)}?v=${L}`,alt:a(`projects.coverImageAlt`),className:`w-full h-full object-cover`}):(0,K.jsx)(Fc,{className:`w-6 h-6 text-bambu-gray`})}),(0,K.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,K.jsx)(`input`,{ref:P,type:`file`,accept:`image/jpeg,image/png,image/gif,image/webp`,onChange:async t=>{let n=t.target.files?.[0];if(!(!n||!e)){I(!0);try{N((await Q.uploadProjectCoverImage(e.id,n)).filename),R(e=>e+1),j.invalidateQueries({queryKey:[`projects`]})}catch{}finally{I(!1),P.current&&(P.current.value=``)}}},className:`hidden`}),(0,K.jsxs)($,{type:`button`,variant:`secondary`,onClick:()=>P.current?.click(),disabled:F,children:[F?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(Nu,{className:`w-4 h-4 mr-1`}),a(M?`projects.coverImageReplace`:`projects.coverImageUpload`)]}),M&&(0,K.jsxs)($,{type:`button`,variant:`secondary`,onClick:async()=>{if(e){I(!0);try{await Q.deleteProjectCoverImage(e.id),N(null),R(e=>e+1),j.invalidateQueries({queryKey:[`projects`]})}finally{I(!1)}}},disabled:F,children:[(0,K.jsx)(qu,{className:`w-4 h-4 mr-1`}),a(`projects.coverImageRemove`)]})]})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`projects.color`)}),(0,K.jsx)(`div`,{className:`flex gap-2 flex-wrap`,children:H6.map(e=>(0,K.jsx)(`button`,{type:`button`,onClick:()=>d(e),className:`w-8 h-8 rounded-full transition-transform ${u===e?`ring-2 ring-white ring-offset-2 ring-offset-bambu-dark-secondary scale-110`:``}`,style:{backgroundColor:e}},e))})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`projects.targetPlates`)}),(0,K.jsx)(`input`,{type:`number`,value:f,onChange:e=>p(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:a(`projects.targetPlatesPlaceholder`),min:`1`}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:a(`projects.targetPlatesHelp`)})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`projects.targetParts`)}),(0,K.jsx)(`input`,{type:`number`,value:m,onChange:e=>h(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:a(`projects.targetPartsPlaceholder`),min:`1`}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:a(`projects.targetPartsHelp`)})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`projects.tagsLabel`)}),(0,K.jsx)(`input`,{type:`text`,value:v,onChange:e=>b(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:a(`projects.tagsPlaceholder`)})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`projects.dueDate`)}),(0,K.jsx)(`input`,{type:`date`,value:x,onChange:e=>S(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white focus:outline-none focus:border-bambu-green`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`projects.priority`)}),(0,K.jsxs)(`select`,{value:C,onChange:e=>w(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white focus:outline-none focus:border-bambu-green`,children:[(0,K.jsx)(`option`,{value:`low`,children:a(`projects.priorityLow`)}),(0,K.jsx)(`option`,{value:`normal`,children:a(`projects.priorityNormal`)}),(0,K.jsx)(`option`,{value:`high`,children:a(`projects.priorityHigh`)}),(0,K.jsx)(`option`,{value:`urgent`,children:a(`projects.priorityUrgent`)})]})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`projectDetail.cost.budget`)}),(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(`span`,{className:`absolute left-3 top-1/2 -translate-y-1/2 text-bambu-gray pointer-events-none`,children:i}),(0,K.jsx)(`input`,{type:`number`,step:`0.01`,min:`0`,value:T,onChange:e=>E(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded pl-8 pr-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:`0.00`})]})]}),e&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`common.status`)}),(0,K.jsxs)(`select`,{value:g,onChange:e=>_(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white focus:outline-none focus:border-bambu-green`,children:[(0,K.jsx)(`option`,{value:`active`,children:a(`projects.statusActive`)}),(0,K.jsx)(`option`,{value:`completed`,children:a(`projects.statusCompleted`)}),(0,K.jsx)(`option`,{value:`archived`,children:a(`projects.statusArchived`)})]})]})]}),(0,K.jsxs)(`div`,{className:`flex justify-end gap-2 p-4 border-t border-bambu-dark-tertiary flex-shrink-0`,children:[(0,K.jsx)($,{type:`button`,variant:`secondary`,onClick:t,children:a(`common.cancel`)}),(0,K.jsx)($,{type:`submit`,disabled:!o.trim()||r,children:r?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):a(e?`common.save`:`projects.create`)})]})]})]})})}function hWe({projectId:e,altText:t}){let n=(0,y.useRef)(null),[r,i]=(0,y.useState)(!1),[a,o]=(0,y.useState)(null);return(0,K.jsxs)(`div`,{ref:n,className:`relative flex-shrink-0`,onMouseEnter:()=>{if(!n.current)return;let e=n.current.getBoundingClientRect(),t=window.innerWidth,r=window.innerHeight,a=e.right+8;a+384>t-8&&(a=e.left-384-8);let s=e.top;s+384>r-8&&(s=r-384-8),s<8&&(s=8),o({left:a,top:s}),i(!0)},onMouseLeave:()=>i(!1),onClick:e=>e.stopPropagation(),children:[(0,K.jsx)(`div`,{className:`w-10 h-10 rounded-lg overflow-hidden bg-bambu-dark border border-bambu-dark-tertiary`,children:(0,K.jsx)(`img`,{src:Q.getProjectCoverImageUrl(e),alt:t,className:`w-full h-full object-cover`,loading:`lazy`})}),r&&a&&(0,Bp.createPortal)((0,K.jsx)(`div`,{className:`fixed z-[100] w-96 h-96 rounded-lg overflow-hidden border border-bambu-dark-tertiary shadow-2xl bg-bambu-dark pointer-events-none`,style:{left:a.left,top:a.top},"aria-hidden":`true`,children:(0,K.jsx)(`img`,{src:Q.getProjectCoverImageUrl(e),alt:``,className:`w-full h-full object-contain`,loading:`lazy`})}),document.body)]})}function gWe({project:e,onClick:t,onEdit:n,onDelete:r,hasPermission:i,t:a}){let o=e.target_count?Math.round(e.archive_count/e.target_count*100):0,s=e.target_parts_count?Math.round(e.completed_count/e.target_parts_count*100):0,c=e.status===`completed`,l=e.status===`archived`,[u,d]=(0,y.useState)(!1),f=c?{icon:gs,color:`text-bambu-green`,bg:`bg-bambu-green/10`}:l?{icon:jo,color:`text-bambu-gray`,bg:`bg-bambu-gray/10`}:e.queue_count>0?{icon:ws,color:`text-blue-600 dark:text-blue-400`,bg:`bg-blue-50 dark:bg-blue-400/10`}:{icon:uc,color:`text-bambu-gray`,bg:`bg-bambu-gray/10`};return(0,K.jsxs)(`div`,{className:`group relative bg-gradient-to-br from-bambu-card to-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary hover:border-bambu-green/50 hover:shadow-lg hover:shadow-bambu-green/5 transition-all duration-300 cursor-pointer overflow-hidden`,onClick:t,children:[(0,K.jsx)(`div`,{className:`absolute top-0 left-0 w-1.5 h-full`,style:{backgroundColor:e.color||`#6b7280`,boxShadow:`0 0 12px ${e.color||`#6b7280`}40`}}),(0,K.jsxs)(`div`,{className:`p-5 pl-6`,children:[(0,K.jsxs)(`div`,{className:`flex items-start justify-between mb-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0 flex-1`,children:[e.cover_image_filename?(0,K.jsx)(hWe,{projectId:e.id,altText:a(`projects.coverImageAlt`)}):(0,K.jsx)(`div`,{className:`p-2 rounded-lg ${f.bg} flex-shrink-0`,children:(0,K.jsx)(f.icon,{className:`w-5 h-5 ${f.color}`})}),(0,K.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,K.jsx)(`h3`,{className:`font-semibold text-white truncate`,children:e.name}),e.url&&(0,K.jsx)(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,onClick:e=>e.stopPropagation(),title:e.url,"aria-label":a(`projects.openExternalUrl`),className:`inline-flex items-center justify-center w-6 h-6 rounded bg-bambu-dark border border-bambu-dark-tertiary text-bambu-green hover:bg-bambu-green/10 hover:border-bambu-green transition-colors flex-shrink-0`,children:(0,K.jsx)(Zs,{className:`w-3.5 h-3.5`})}),e.target_parts_count?(0,K.jsxs)(`span`,{className:`text-xs px-2 py-0.5 rounded-full whitespace-nowrap font-medium ${s>=100?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark text-bambu-gray`}`,children:[e.completed_count,`/`,e.target_parts_count,` `,a(`projects.parts`)]}):e.target_count?(0,K.jsxs)(`span`,{className:`text-xs px-2 py-0.5 rounded-full whitespace-nowrap font-medium ${o>=100?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark text-bambu-gray`}`,children:[e.archive_count,`/`,e.target_count,` `,a(`projects.plates`)]}):e.completed_count>0?(0,K.jsxs)(`span`,{className:`text-xs px-2 py-0.5 rounded-full whitespace-nowrap font-medium bg-bambu-dark text-bambu-gray`,children:[e.completed_count,` `,a(`projects.parts`)]}):null,c&&(0,K.jsx)(`span`,{className:`text-xs bg-bambu-green/20 text-bambu-green px-2 py-0.5 rounded-full whitespace-nowrap`,children:a(`projects.done`)}),l&&(0,K.jsx)(`span`,{className:`text-xs bg-bambu-gray/20 text-bambu-gray px-2 py-0.5 rounded-full whitespace-nowrap`,children:a(`projects.statusArchived`)})]}),e.description&&(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray/70 mt-1 line-clamp-1`,children:e.description}),e.archives&&e.archives.length>0&&(()=>{let t=e.archives.map(e=>e.filament_type).filter(Boolean).flatMap(e=>e.split(`,`).map(e=>e.trim())).filter(Boolean),n=[...new Set(t)],r=e.archives.map(e=>e.filament_color).filter(Boolean).flatMap(e=>e.split(`,`).map(e=>e.trim())).filter(e=>e.startsWith(`#`)||/^[0-9A-Fa-f]{6}$/.test(e)),i=[...new Set(r)];return n.length===0&&i.length===0?null:(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mt-1.5`,children:[n.slice(0,3).map(e=>(0,K.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 bg-bambu-dark text-bambu-gray rounded`,children:e},e)),i.length>0&&(0,K.jsxs)(`div`,{className:`flex items-center gap-0.5`,children:[i.slice(0,5).map(e=>(0,K.jsx)(`div`,{className:`w-3 h-3 rounded-full border border-black/20`,style:{backgroundColor:e.startsWith(`#`)?e:`#${e}`},title:e},e)),i.length>5&&(0,K.jsxs)(`span`,{className:`text-[10px] text-bambu-gray ml-0.5`,children:[`+`,i.length-5]})]})]})})()]})]}),(0,K.jsxs)(`div`,{className:`relative`,onClick:e=>e.stopPropagation(),children:[(0,K.jsx)(`button`,{className:`p-1.5 rounded-lg hover:bg-bambu-dark text-bambu-gray hover:text-white transition-colors opacity-0 group-hover:opacity-100`,onClick:()=>d(!u),children:(0,K.jsx)(qs,{className:`w-4 h-4`})}),u&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`fixed inset-0 z-10`,onClick:()=>d(!1)}),(0,K.jsxs)(`div`,{className:`absolute right-0 top-8 z-20 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl py-1 min-w-[120px]`,children:[(0,K.jsxs)(`button`,{className:`w-full px-3 py-2 text-left text-sm flex items-center gap-2 ${i(`projects:update`)?`text-white hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{i(`projects:update`)&&(n(),d(!1))},disabled:!i(`projects:update`),title:i(`projects:update`)?void 0:a(`projects.noEditPermission`),children:[(0,K.jsx)(Sl,{className:`w-4 h-4`}),a(`common.edit`)]}),(0,K.jsxs)(`button`,{className:`w-full px-3 py-2 text-left text-sm flex items-center gap-2 ${i(`projects:delete`)?`text-red-600 dark:text-red-400 hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{i(`projects:delete`)&&(r(),d(!1))},disabled:!i(`projects:delete`),title:i(`projects:delete`)?void 0:a(`projects.noDeletePermission`),children:[(0,K.jsx)(Eu,{className:`w-4 h-4`}),a(`common.delete`)]})]})]})]})]}),(0,K.jsx)(`div`,{className:`mb-4`,children:e.target_count||e.target_parts_count?(0,K.jsxs)(`div`,{className:`space-y-3`,children:[e.target_count&&(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between text-xs mb-1`,children:[(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:a(`projects.plates`)}),(0,K.jsxs)(`span`,{className:o>=100?`text-bambu-green font-medium`:`text-white`,children:[e.archive_count,` / `,e.target_count]})]}),(0,K.jsx)(`div`,{className:`h-2 bg-bambu-dark/80 rounded-full overflow-hidden backdrop-blur-sm`,children:(0,K.jsx)(`div`,{className:`h-full transition-all duration-500 ease-out rounded-full relative`,style:{width:`${Math.min(o,100)}%`,background:o>=100?`linear-gradient(90deg, #22c55e, #4ade80)`:`linear-gradient(90deg, ${e.color||`#6b7280`}, ${e.color||`#6b7280`}cc)`,boxShadow:`0 0 8px ${o>=100?`#22c55e`:e.color||`#6b7280`}60`}})})]}),e.target_parts_count&&(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between text-xs mb-1`,children:[(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:a(`projects.parts`)}),(0,K.jsxs)(`span`,{className:s>=100?`text-bambu-green font-medium`:`text-white`,children:[e.completed_count,` / `,e.target_parts_count]})]}),(0,K.jsx)(`div`,{className:`h-2 bg-bambu-dark/80 rounded-full overflow-hidden backdrop-blur-sm`,children:(0,K.jsx)(`div`,{className:`h-full transition-all duration-500 ease-out rounded-full relative`,style:{width:`${Math.min(s,100)}%`,background:s>=100?`linear-gradient(90deg, #22c55e, #4ade80)`:`linear-gradient(90deg, ${e.color||`#6b7280`}, ${e.color||`#6b7280`}cc)`,boxShadow:`0 0 8px ${s>=100?`#22c55e`:e.color||`#6b7280`}60`}})})]}),e.failed_count>0&&(0,K.jsxs)(`div`,{className:`text-xs text-red-600 dark:text-red-400`,children:[e.failed_count,` `,a(`projects.failed`)]})]}):e.completed_count>0||e.failed_count>0?(0,K.jsxs)(`div`,{className:`flex items-center gap-4 text-xs`,children:[e.completed_count>0&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 text-bambu-gray`,children:[(0,K.jsx)(jo,{className:`w-3.5 h-3.5`}),(0,K.jsxs)(`span`,{children:[e.completed_count,` `,a(`projects.completed`)]})]}),e.failed_count>0&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 text-red-600 dark:text-red-400`,children:[(0,K.jsx)(ku,{className:`w-3.5 h-3.5`}),(0,K.jsxs)(`span`,{children:[e.failed_count,` `,a(`projects.failed`)]})]}),e.queue_count>0&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 text-blue-600 dark:text-blue-400`,children:[(0,K.jsx)(ws,{className:`w-3.5 h-3.5`}),(0,K.jsxs)(`span`,{children:[e.queue_count,` `,a(`projects.inQueue`)]})]})]}):(0,K.jsx)(`div`,{className:`text-xs text-bambu-gray/60 italic`,children:a(`projects.noPrintsYet`)})}),e.archives&&e.archives.length>0&&(0,K.jsxs)(`div`,{className:`mb-4`,children:[(0,K.jsx)(`div`,{className:`grid grid-cols-4 gap-1.5`,children:e.archives.slice(0,4).map(e=>(0,K.jsxs)(`div`,{className:`relative aspect-square rounded-lg bg-bambu-dark overflow-hidden border border-bambu-dark-tertiary`,title:e.print_name||`Unknown`,children:[e.thumbnail_path?(0,K.jsx)(`img`,{src:Q.getArchiveThumbnail(e.id),alt:e.print_name||``,className:`w-full h-full object-cover`}):(0,K.jsx)(`div`,{className:`w-full h-full flex items-center justify-center text-bambu-gray/50`,children:(0,K.jsx)(_l,{className:`w-6 h-6`})}),e.status===`failed`&&(0,K.jsx)(`div`,{className:`absolute inset-0 bg-red-500/40 flex items-center justify-center`,children:(0,K.jsx)(ku,{className:`w-4 h-4 text-white`})})]},e.id))}),e.archive_count>4&&(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1.5 text-center`,children:a(`common.more`,{count:e.archive_count-4})})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between pt-3 border-t border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-4 text-xs text-bambu-gray`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5`,title:a(`projects.printJobs`),children:[(0,K.jsx)(Vc,{className:`w-3.5 h-3.5 text-blue-600 dark:text-blue-400`}),(0,K.jsxs)(`span`,{children:[e.archive_count,` `,a(`projects.plates`)]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5`,title:a(`projects.partsPrinted`),children:[(0,K.jsx)(_l,{className:`w-3.5 h-3.5 text-bambu-green`}),(0,K.jsxs)(`span`,{children:[e.completed_count,` `,a(`projects.parts`)]})]}),e.failed_count>0&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 text-red-600 dark:text-red-400`,title:a(`projects.failedParts`),children:[(0,K.jsx)(ku,{className:`w-3.5 h-3.5`}),(0,K.jsx)(`span`,{children:e.failed_count})]}),e.queue_count>0&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 text-yellow-600 dark:text-yellow-400`,title:a(`projects.inQueue`),children:[(0,K.jsx)(qc,{className:`w-3.5 h-3.5`}),(0,K.jsx)(`span`,{children:e.queue_count})]})]}),(0,K.jsx)(cs,{className:`w-4 h-4 text-bambu-gray/50 group-hover:text-bambu-gray transition-colors`})]})]})]})}function _We(){let{t:e}=W(),t=ir(),n=oo(),{showToast:r}=Pd(),{hasPermission:i}=bd(),[a,o]=(0,y.useState)(!1),[s,c]=(0,y.useState)(),[l,u]=(0,y.useState)(`active`),[d,f]=(0,y.useState)(null),{data:p}=q({queryKey:[`settings`],queryFn:Q.getSettings}),m=df(p?.currency||`USD`),{data:h,isLoading:g}=q({queryKey:[`projects`,l===`all`?void 0:l],queryFn:()=>Q.getProjects(l===`all`?void 0:l)}),_=J({mutationFn:e=>Q.createProject(e),onSuccess:()=>{n.invalidateQueries({queryKey:[`projects`]}),o(!1),r(e(`projects.toast.created`),`success`)},onError:e=>{r(e.message,`error`)}}),v=J({mutationFn:({id:e,data:t})=>Q.updateProject(e,t),onSuccess:()=>{n.invalidateQueries({queryKey:[`projects`]}),o(!1),c(void 0),r(e(`projects.toast.updated`),`success`)},onError:e=>{r(e.message,`error`)}}),b=J({mutationFn:e=>Q.deleteProject(e),onSuccess:()=>{f(null),r(e(`projects.toast.deleted`),`success`),setTimeout(()=>window.location.reload(),100)},onError:e=>{f(null),r(e.message,`error`)}}),x=J({mutationFn:e=>Q.importProject(e),onSuccess:()=>{n.invalidateQueries({queryKey:[`projects`]}),r(e(`projects.toast.imported`),`success`)},onError:e=>{r(e.message,`error`)}}),S=(0,y.useRef)(null),C=async()=>{try{let t=await Q.getProjects(),n=await Promise.all(t.map(async e=>await Q.exportProjectJson(e.id))),i=new Blob([JSON.stringify(n,null,2)],{type:`application/json`}),a=URL.createObjectURL(i),o=document.createElement(`a`);o.href=a,o.download=`bambuddy_projects_${new Date().toISOString().split(`T`)[0]}.json`,o.click(),URL.revokeObjectURL(a),r(e(`projects.toast.exported`),`success`)}catch(e){r(e.message,`error`)}},w=()=>{S.current?.click()},T=async t=>{let i=t.target.files?.[0];if(i){try{if(i.name.toLowerCase().endsWith(`.zip`))await Q.importProjectFile(i),n.invalidateQueries({queryKey:[`projects`]}),r(e(`projects.toast.imported`),`success`);else{let t=await i.text(),n=JSON.parse(t),a=Array.isArray(n)?n:[n];for(let e of a)await x.mutateAsync(e);a.length>1&&r(e(`projects.toast.multipleImported`,{count:a.length}),`success`)}}catch(t){r(`${e(`projects.toast.importFailed`)}: ${t.message}`,`error`)}t.target.value=``}},E=e=>{s?v.mutate({id:s.id,data:e}):_.mutate(e)},D=e=>{c(e),o(!0)},O=e=>{t(`/projects/${e.id}`)},k=e=>{f(e)},A=()=>{d!==null&&b.mutate(d)},j=h?.reduce((e,t)=>(e[t.status]=(e[t.status]||0)+1,e.all=(e.all||0)+1,e),{})||{};return(0,K.jsxs)(`div`,{className:`p-4 md:p-8 space-y-8`,children:[(0,K.jsx)(`input`,{ref:S,type:`file`,accept:`.json,.zip`,onChange:T,className:`hidden`}),(0,K.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center justify-between gap-4`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`h1`,{className:`text-2xl font-bold text-white flex items-center gap-3`,children:[(0,K.jsx)(uc,{className:`w-7 h-7 text-bambu-green`}),e(`projects.title`)]}),(0,K.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:e(`projects.subtitle`)})]}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsxs)($,{variant:`secondary`,onClick:w,disabled:!i(`projects:create`),title:i(`projects:create`)?e(`projects.importProject`):e(`projects.noImportPermission`),children:[(0,K.jsx)(Nu,{className:`w-4 h-4 mr-2`}),e(`projects.import`)]}),(0,K.jsxs)($,{variant:`secondary`,onClick:C,disabled:!i(`projects:read`),title:i(`projects:read`)?e(`projects.exportAll`):e(`projects.noExportPermission`),children:[(0,K.jsx)(Ws,{className:`w-4 h-4 mr-2`}),e(`projects.export`)]}),(0,K.jsxs)($,{onClick:()=>o(!0),className:`sm:w-auto w-full`,disabled:!i(`projects:create`),title:i(`projects:create`)?void 0:e(`projects.noCreatePermission`),children:[(0,K.jsx)(Ol,{className:`w-4 h-4 mr-2`}),e(`projects.newProject`)]})]})]}),(0,K.jsx)(`div`,{className:`flex gap-1 p-1 bg-bambu-dark rounded-xl w-fit`,children:[{key:`active`,label:e(`projects.statusActive`),icon:ws},{key:`completed`,label:e(`projects.statusCompleted`),icon:gs},{key:`archived`,label:e(`projects.statusArchived`),icon:jo},{key:`all`,label:e(`common.all`),icon:uc}].map(({key:e,label:t,icon:n})=>(0,K.jsxs)(`button`,{onClick:()=>u(e),className:`flex items-center gap-2 px-4 py-2 text-sm rounded-lg transition-all ${l===e?`bg-bambu-card text-white shadow-sm`:`text-bambu-gray hover:text-white`}`,children:[(0,K.jsx)(n,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{children:t}),j[e]>0&&(0,K.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded-full ${l===e?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark-tertiary`}`,children:j[e]})]},e))}),g?(0,K.jsx)(`div`,{className:`flex items-center justify-center py-20`,children:(0,K.jsxs)(`div`,{className:`flex flex-col items-center gap-3`,children:[(0,K.jsx)(X,{className:`w-8 h-8 animate-spin text-bambu-green`}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`projects.loading`)})]})}):h?.length===0?(0,K.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-20 px-4`,children:[(0,K.jsx)(`div`,{className:`p-4 bg-bambu-dark rounded-2xl mb-4`,children:(0,K.jsx)(uc,{className:`w-12 h-12 text-bambu-gray/50`})}),(0,K.jsx)(`h3`,{className:`text-lg font-medium text-white mb-2`,children:l===`all`?e(`projects.noProjects`):e(`projects.noProjectsFiltered`,{status:l})}),(0,K.jsx)(`p`,{className:`text-bambu-gray text-center max-w-md mb-6`,children:l===`all`?e(`projects.createFirst`):e(`projects.noProjectsFilteredHelp`,{status:l})}),l===`all`&&(0,K.jsxs)($,{onClick:()=>o(!0),disabled:!i(`projects:create`),title:i(`projects:create`)?void 0:e(`projects.noCreatePermission`),children:[(0,K.jsx)(Ol,{className:`w-4 h-4 mr-2`}),e(`projects.createFirstButton`)]})]}):(0,K.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-8`,children:h?.map(t=>(0,K.jsx)(gWe,{project:t,onClick:()=>O(t),onEdit:()=>D(t),onDelete:()=>k(t.id),hasPermission:i,t:e},t.id))}),d!==null&&(0,K.jsx)(Vd,{title:e(`projects.deleteProject`),message:e(`projects.deleteConfirm`),confirmText:e(`projects.deleteProject`),variant:`danger`,onConfirm:A,onCancel:()=>f(null)}),a&&(0,K.jsx)(U6,{project:s,onClose:()=>{o(!1),c(void 0)},onSave:E,isLoading:_.isPending||v.isPending,currencySymbol:m,t:e})]})}function vWe(e){let t=e.toLowerCase();return t.endsWith(`.gcode`)||t.endsWith(`.gcode.3mf`)}function yWe(e){return e>=1e3?`${(e/1e3).toFixed(2)}kg`:`${Math.round(e)}g`}function bWe({status:e,t}){let n={active:`bg-bambu-green/20 text-bambu-green`,completed:`bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400`,archived:`bg-bambu-gray/20 text-bambu-gray`},r=n[e]||n.active,i={active:t(`projectDetail.status.active`),completed:t(`projectDetail.status.completed`),archived:t(`projectDetail.status.archived`)};return(0,K.jsx)(`span`,{className:`px-2 py-1 rounded text-sm font-medium ${r}`,children:i[e]||e.charAt(0).toUpperCase()+e.slice(1)})}function W6({icon:e,label:t,value:n,subValue:r,hint:i,color:a=`text-bambu-gray`}){return(0,K.jsx)(Ed,{children:(0,K.jsx)(Od,{className:`p-4`,children:(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,title:i,children:[(0,K.jsx)(`div`,{className:`p-2 rounded-lg bg-bambu-dark ${a}`,children:(0,K.jsx)(e,{className:`w-5 h-5`})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:t}),(0,K.jsx)(`p`,{className:`text-xl font-semibold text-white`,children:n}),r&&(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray/70`,children:r})]})]})})})}function xWe({archives:e,t}){return e.length===0?(0,K.jsxs)(`div`,{className:`text-center py-8 text-bambu-gray`,children:[(0,K.jsx)(_l,{className:`w-12 h-12 mx-auto mb-2 opacity-50`}),(0,K.jsx)(`p`,{children:t(`projectDetail.noPrints`)})]}):(0,K.jsx)(`div`,{className:`grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 xl:grid-cols-6 gap-3`,children:e.map(e=>(0,K.jsxs)(Oi,{to:`/archives?search=${encodeURIComponent(e.print_name||``)}`,className:`group relative aspect-square rounded-lg bg-bambu-dark border border-bambu-dark-tertiary overflow-hidden hover:border-bambu-green transition-colors`,children:[e.thumbnail_path?(0,K.jsx)(`img`,{src:Q.getArchiveThumbnail(e.id),alt:e.print_name||`Print`,className:`w-full h-full object-cover`}):(0,K.jsx)(`div`,{className:`w-full h-full flex items-center justify-center text-bambu-gray`,children:(0,K.jsx)(_l,{className:`w-8 h-8`})}),e.status===`failed`&&(0,K.jsx)(`div`,{className:`absolute inset-0 bg-red-500/30 flex items-center justify-center`,children:(0,K.jsx)(xs,{className:`w-8 h-8 text-white`})}),e.status===`completed`&&(0,K.jsx)(`div`,{className:`absolute top-1 right-1`,children:(0,K.jsx)(hs,{className:`w-4 h-4 text-bambu-green`})}),(0,K.jsx)(`div`,{className:`absolute inset-x-0 bottom-0 bg-gradient-to-t from-black/80 to-transparent p-2 opacity-0 group-hover:opacity-100 transition-opacity`,children:(0,K.jsx)(`p`,{className:`text-xs text-white truncate`,children:e.print_name||`Unknown`})})]},e.id))})}function SWe({priority:e,t}){let n={low:{color:`bg-gray-500/20 text-gray-400`,label:t(`projectDetail.priority.low`)},normal:{color:`bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400`,label:t(`projectDetail.priority.normal`)},high:{color:`bg-orange-100 dark:bg-orange-500/20 text-orange-700 dark:text-orange-400`,label:t(`projectDetail.priority.high`)},urgent:{color:`bg-red-100 dark:bg-red-500/20 text-red-700 dark:text-red-400`,label:t(`projectDetail.priority.urgent`)}},{color:r,label:i}=n[e]||n.normal;return(0,K.jsxs)(`span`,{className:`px-2 py-1 rounded text-xs font-medium flex items-center gap-1 ${r}`,children:[e===`urgent`&&(0,K.jsx)(ku,{className:`w-3 h-3`}),i]})}function G6(e,t){if(!e)return null;let n=jf(e);if(!n)return null;let r=new Date,i=Math.ceil((n.getTime()-r.getTime())/(1e3*60*60*24));return i<0?{color:`text-red-700 dark:text-red-400`,label:t(`projectDetail.dueDate.overdue`)}:i===0?{color:`text-orange-700 dark:text-orange-400`,label:t(`projectDetail.dueDate.today`)}:i<=3?{color:`text-yellow-700 dark:text-yellow-400`,label:t(`projectDetail.dueDate.daysLeft`,{count:i})}:{color:`text-bambu-gray`,label:t(`projectDetail.dueDate.daysLeft`,{count:i})}}function CWe(){let{id:e}=lr(),t=ir(),{t:n}=W(),r=oo(),{showToast:i}=Pd(),{hasPermission:a}=bd(),[o,s]=(0,y.useState)(!1),[c,l]=(0,y.useState)(!1),[u,d]=(0,y.useState)(``),[f,p]=(0,y.useState)(null),m=parseInt(e||`0`,10),{data:h,isLoading:g,error:_}=q({queryKey:[`project`,m],queryFn:()=>Q.getProject(m),enabled:m>0}),{data:v,isLoading:b}=q({queryKey:[`project-archives`,m],queryFn:()=>Q.getProjectArchives(m),enabled:m>0}),{data:x,isLoading:S}=q({queryKey:[`project-bom`,m],queryFn:()=>Q.getProjectBOM(m),enabled:m>0}),{data:C,isLoading:w}=q({queryKey:[`project-timeline`,m],queryFn:()=>Q.getProjectTimeline(m,20),enabled:m>0}),{data:T}=q({queryKey:[`settings`],queryFn:Q.getSettings}),{data:E}=q({queryKey:[`project-folders`,m],queryFn:()=>Q.getLibraryFoldersByProject(m),enabled:m>0}),{data:D,isLoading:O}=q({queryKey:[`project-files`,m],queryFn:()=>Q.getLibraryFiles(null,!1,m),enabled:m>0}),k=(0,y.useMemo)(()=>{let e=new Map;for(let t of D??[])if(t.folder_id!=null){let n=e.get(t.folder_id)??[];n.push(t),e.set(t.folder_id,n)}return e},[D]),A=df(T?.currency||`USD`),j=T?.time_format||`system`,M=J({mutationFn:e=>Q.updateProject(m,e),onSuccess:()=>{r.invalidateQueries({queryKey:[`project`,m]}),r.invalidateQueries({queryKey:[`projects`]}),s(!1),l(!1),i(n(`projectDetail.toast.projectUpdated`),`success`)},onError:e=>{i(e.message,`error`)}}),N=()=>{d(h?.notes||``),l(!0)},P=()=>{M.mutate({notes:u})},F=()=>{l(!1),d(``)},[I,L]=(0,y.useState)(``),[R,z]=(0,y.useState)(1),[B,V]=(0,y.useState)(``),[ee,te]=(0,y.useState)(``),[ne,re]=(0,y.useState)(``),[ie,H]=(0,y.useState)(!1),[ae,oe]=(0,y.useState)(!1),[U,se]=(0,y.useState)(null),[ce,le]=(0,y.useState)(``),[ue,de]=(0,y.useState)(1),[fe,pe]=(0,y.useState)(``),[me,he]=(0,y.useState)(``),[ge,_e]=(0,y.useState)(``),[ve,ye]=(0,y.useState)({isOpen:!1,title:``,message:``,onConfirm:()=>{}}),be=J({mutationFn:e=>Q.createBOMItem(m,e),onSuccess:()=>{r.invalidateQueries({queryKey:[`project-bom`,m]}),r.invalidateQueries({queryKey:[`project`,m]}),L(``),z(1),V(``),te(``),re(``),H(!1),i(n(`projectDetail.toast.partAdded`),`success`)},onError:e=>i(e.message,`error`)}),xe=J({mutationFn:({itemId:e,data:t})=>Q.updateBOMItem(m,e,t),onSuccess:()=>{r.invalidateQueries({queryKey:[`project-bom`,m]}),r.invalidateQueries({queryKey:[`project`,m]}),se(null)},onError:e=>i(e.message,`error`)}),Se=J({mutationFn:e=>Q.deleteBOMItem(m,e),onSuccess:()=>{r.invalidateQueries({queryKey:[`project-bom`,m]}),r.invalidateQueries({queryKey:[`project`,m]}),i(n(`projectDetail.toast.partRemoved`),`success`)},onError:e=>i(e.message,`error`)}),Ce=e=>{e.preventDefault(),I.trim()&&be.mutate({name:I.trim(),quantity_needed:R,unit_price:B?parseFloat(B):void 0,sourcing_url:ee.trim()||void 0,remarks:ne.trim()||void 0})},we=e=>{let t=e.is_complete?0:e.quantity_needed;xe.mutate({itemId:e.id,data:{quantity_acquired:t}})},Te=(e,t)=>{ye({isOpen:!0,title:n(`projectDetail.bom.deletePart`),message:n(`projectDetail.bom.deleteConfirm`,{name:t}),onConfirm:()=>{ye(e=>({...e,isOpen:!1})),Se.mutate(e)}})},Ee=e=>{se(e),le(e.name),de(e.quantity_needed),pe(e.unit_price?.toString()||``),he(e.sourcing_url||``),_e(e.remarks||``)},De=e=>{e.preventDefault(),!(!U||!ce.trim())&&xe.mutate({itemId:U.id,data:{name:ce.trim(),quantity_needed:ue,unit_price:fe?parseFloat(fe):void 0,sourcing_url:me.trim()||void 0,remarks:ge.trim()||void 0}})},Oe=()=>{se(null)},ke=async()=>{try{let{blob:e,filename:t}=await Q.exportProjectZip(Number(m)),r=URL.createObjectURL(e),a=document.createElement(`a`);a.href=r,a.download=t||`${h?.name||`project`}_${new Date().toISOString().split(`T`)[0]}.zip`,a.click(),URL.revokeObjectURL(r),i(n(`projectDetail.toast.projectExported`),`success`)}catch(e){i(e.message,`error`)}},Ae=J({mutationFn:()=>Q.createTemplateFromProject(m),onSuccess:()=>{r.invalidateQueries({queryKey:[`projects`]}),i(n(`projectDetail.toast.templateCreated`),`success`)},onError:e=>i(e.message,`error`)}),je=e=>Nf(e,j,{month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`});if(g)return(0,K.jsx)(`div`,{className:`flex items-center justify-center py-24`,children:(0,K.jsx)(X,{className:`w-8 h-8 animate-spin text-bambu-green`})});if(_||!h)return(0,K.jsxs)(`div`,{className:`text-center py-24`,children:[(0,K.jsx)(`p`,{className:`text-bambu-gray`,children:_?`${n(`common.error`)}: ${_.message}`:n(`projectDetail.notFound`)}),(0,K.jsx)($,{variant:`secondary`,className:`mt-4`,onClick:()=>t(`/projects`),children:n(`projectDetail.backToProjects`)})]});let Me=h.stats,Ne=Me?.progress_percent??0,Pe=Me?.parts_progress_percent??0;return(0,K.jsxs)(`div`,{className:`p-4 md:p-8 space-y-8`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-bambu-gray`,children:[(0,K.jsx)(Oi,{to:`/projects`,className:`hover:text-white transition-colors`,children:n(`nav.projects`)}),(0,K.jsx)(cs,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{className:`text-white`,children:h.name})]}),(0,K.jsxs)(`div`,{className:`flex items-start justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,K.jsx)(`button`,{onClick:()=>t(`/projects`),className:`p-2 rounded-lg bg-bambu-card hover:bg-bambu-dark-tertiary transition-colors`,children:(0,K.jsx)(Po,{className:`w-5 h-5 text-bambu-gray`})}),(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`w-4 h-4 rounded-full shrink-0`,style:{backgroundColor:h.color||`#6b7280`}}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h1`,{className:`text-2xl font-bold text-white`,children:h.name}),h.description&&(0,K.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:h.description})]})]}),(0,K.jsx)(bWe,{status:h.status,t:n})]}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsxs)($,{variant:`secondary`,onClick:ke,disabled:!a(`projects:read`),title:a(`projects:read`)?n(`projectDetail.exportProject`):n(`projectDetail.noExportPermission`),children:[(0,K.jsx)(Ws,{className:`w-4 h-4 mr-2`}),n(`projectDetail.export`)]}),(0,K.jsxs)($,{onClick:()=>s(!0),disabled:!a(`projects:update`),title:a(`projects:update`)?void 0:n(`projectDetail.noEditPermission`),children:[(0,K.jsx)(Sl,{className:`w-4 h-4 mr-2`}),n(`common.edit`)]})]})]}),(h.target_count||h.target_parts_count)&&(0,K.jsx)(Ed,{children:(0,K.jsxs)(Od,{className:`p-4 space-y-4`,children:[h.target_count&&(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:n(`projectDetail.progress.platesProgress`)}),(0,K.jsxs)(`span`,{className:`text-sm font-medium text-white`,children:[Me?.total_archives||0,` / `,h.target_count,` `,n(`projectDetail.progress.printJobs`)]})]}),(0,K.jsx)(`div`,{className:`h-3 bg-bambu-dark rounded-full overflow-hidden`,children:(0,K.jsx)(`div`,{className:`h-full transition-all duration-500`,style:{width:`${Math.min(Ne,100)}%`,backgroundColor:Ne>=100?`#22c55e`:h.color||`#6b7280`}})}),(0,K.jsxs)(`div`,{className:`flex justify-between mt-1`,children:[(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray/70`,children:n(`projectDetail.progress.percentComplete`,{percent:Ne.toFixed(0)})}),Me?.remaining_prints!=null&&Me.remaining_prints>0&&(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray/70`,children:n(`projectDetail.progress.remaining`,{count:Me.remaining_prints})})]})]}),h.target_parts_count&&(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:n(`projectDetail.progress.partsProgress`)}),(0,K.jsxs)(`span`,{className:`text-sm font-medium text-white`,children:[Me?.completed_prints||0,` / `,h.target_parts_count,` `,n(`projectDetail.progress.parts`)]})]}),(0,K.jsx)(`div`,{className:`h-3 bg-bambu-dark rounded-full overflow-hidden`,children:(0,K.jsx)(`div`,{className:`h-full transition-all duration-500`,style:{width:`${Math.min(Pe,100)}%`,backgroundColor:Pe>=100?`#22c55e`:h.color||`#6b7280`}})}),(0,K.jsxs)(`div`,{className:`flex justify-between mt-1`,children:[(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray/70`,children:n(`projectDetail.progress.percentComplete`,{percent:Pe.toFixed(0)})}),Me?.remaining_parts!=null&&Me.remaining_parts>0&&(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray/70`,children:n(`projectDetail.progress.remaining`,{count:Me.remaining_parts})})]})]})]})}),Me&&(0,K.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-4`,children:[(0,K.jsx)(Ed,{children:(0,K.jsx)(Od,{className:`p-4`,children:(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`p-2 rounded-lg bg-bambu-dark text-bambu-green`,children:(0,K.jsx)(_l,{className:`w-5 h-5`})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`projectDetail.stats.printJobs`)}),(0,K.jsxs)(`p`,{className:`text-xl font-semibold text-white`,children:[Me.total_archives,` `,(0,K.jsx)(`span`,{className:`text-sm font-normal text-bambu-gray`,children:n(`projectDetail.stats.total`)})]}),Me.failed_prints>0&&(0,K.jsx)(`p`,{className:`text-sm text-status-error`,children:n(`projectDetail.stats.failed`,{count:Me.failed_prints})}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`projectDetail.stats.partsPrinted`,{count:Me.completed_prints})})]})]})})}),(0,K.jsx)(W6,{icon:ws,label:n(`projectDetail.stats.printTime`),value:zf(Me.total_print_time_hours),color:`text-yellow-600 dark:text-yellow-400`}),(0,K.jsx)(W6,{icon:jl,label:n(`projectDetail.stats.filamentUsed`),value:yWe(Me.total_filament_grams),color:`text-purple-600 dark:text-purple-400`})]}),Me&&(()=>{let e=Me.estimated_cost+Me.total_energy_cost+Me.bom_cost;return Me.estimated_cost>0||e>0||h.budget!==null})()&&(0,K.jsx)(Ed,{children:(0,K.jsxs)(Od,{className:`p-4`,children:[(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white mb-3`,children:n(`projectDetail.cost.title`)}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-4`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.cost.filamentCost`)}),(0,K.jsxs)(`p`,{className:`text-lg font-semibold text-white`,children:[A,Me.estimated_cost.toFixed(2)]})]}),Me.total_energy_kwh>0&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.cost.energy`)}),(0,K.jsxs)(`p`,{className:`text-lg font-semibold text-white`,children:[Me.total_energy_kwh.toFixed(3),` kWh`,Me.total_energy_cost>0&&(0,K.jsxs)(`span`,{className:`text-sm text-bambu-gray ml-1`,children:[`(`,A,Me.total_energy_cost.toFixed(2),`)`]})]})]}),(()=>{let e=Me.estimated_cost+Me.total_energy_cost+Me.bom_cost;return e<=0?null:(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.cost.totalCost`)}),(0,K.jsxs)(`p`,{className:`text-lg font-semibold text-bambu-green`,children:[A,e.toFixed(2)]}),Me.bom_cost>0&&(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray/70`,children:n(`projectDetail.cost.includesBom`)})]})})(),h.budget!==null&&(()=>{let e=Me.estimated_cost+Me.total_energy_cost+Me.bom_cost,t=h.budget-e;return(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.cost.budget`)}),(0,K.jsxs)(`p`,{className:`text-sm text-bambu-gray`,children:[n(`projectDetail.cost.total`),`: `,(0,K.jsxs)(`span`,{className:`text-white font-semibold`,children:[A,h.budget.toFixed(2)]})]}),(0,K.jsxs)(`p`,{className:`text-sm ${t>=0?`text-bambu-green`:`text-red-700 dark:text-red-400`}`,children:[n(`projectDetail.cost.remaining`),`: `,(0,K.jsxs)(`span`,{className:`font-semibold`,children:[A,t.toFixed(2)]})]})]})})()]})]})}),h.children&&h.children.length>0&&(0,K.jsx)(Ed,{children:(0,K.jsxs)(Od,{className:`p-4`,children:[(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2 mb-3`,children:[(0,K.jsx)(mc,{className:`w-5 h-5`}),n(`projectDetail.subProjects.title`,{count:h.children.length})]}),(0,K.jsx)(`div`,{className:`space-y-2`,children:h.children.map(e=>(0,K.jsxs)(Oi,{to:`/projects/${e.id}`,className:`flex items-center justify-between p-3 bg-bambu-dark rounded-lg hover:bg-bambu-dark-tertiary transition-colors`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`w-3 h-3 rounded-full`,style:{backgroundColor:e.color||`#6b7280`}}),(0,K.jsx)(`span`,{className:`text-white`,children:e.name}),(0,K.jsx)(`span`,{className:`text-xs px-2 py-0.5 rounded ${e.status===`completed`?`bg-status-ok/20 text-status-ok`:e.status===`archived`?`bg-bambu-gray/20 text-bambu-gray`:`bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400`}`,children:e.status})]}),e.progress_percent!==null&&(0,K.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[e.progress_percent.toFixed(0),`%`]})]},e.id))})]})}),h.parent_id&&h.parent_name&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,K.jsx)(Vc,{className:`w-4 h-4 text-bambu-gray`}),(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:n(`projectDetail.partOf`)}),(0,K.jsx)(Oi,{to:`/projects/${h.parent_id}`,className:`text-bambu-green hover:underline`,children:h.parent_name})]}),(h.tags||h.due_date||h.priority!==`normal`)&&(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center gap-4`,children:[h.priority&&h.priority!==`normal`&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.priorityLabel`)}),(0,K.jsx)(SWe,{priority:h.priority,t:n})]}),h.due_date&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)($o,{className:`w-4 h-4 text-bambu-gray`}),(0,K.jsx)(`span`,{className:`text-sm text-white`,children:Mf(h.due_date,{year:`numeric`,month:`short`,day:`numeric`})}),G6(h.due_date,n)&&(0,K.jsxs)(`span`,{className:`text-xs ${G6(h.due_date,n).color}`,children:[`(`,G6(h.due_date,n).label,`)`]})]}),h.tags&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(vu,{className:`w-4 h-4 text-bambu-gray`}),(0,K.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:h.tags.split(`,`).map((e,t)=>(0,K.jsx)(`span`,{className:`px-2 py-0.5 bg-bambu-dark-tertiary text-bambu-gray text-xs rounded`,children:e.trim()},t))})]})]}),(0,K.jsx)(Ed,{children:(0,K.jsxs)(Od,{className:`p-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(ac,{className:`w-5 h-5`}),n(`projectDetail.notes.title`)]}),c?(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:F,disabled:M.isPending,children:[(0,K.jsx)(qu,{className:`w-4 h-4 mr-1`}),n(`common.cancel`)]}),(0,K.jsxs)($,{size:`sm`,onClick:P,disabled:M.isPending,children:[M.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin mr-1`}):(0,K.jsx)(zl,{className:`w-4 h-4 mr-1`}),n(`common.save`)]})]}):(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:N,disabled:!a(`projects:update`),title:a(`projects:update`)?void 0:n(`projectDetail.notes.noEditPermission`),children:[(0,K.jsx)(Sl,{className:`w-4 h-4 mr-1`}),n(`common.edit`)]})]}),c?(0,K.jsx)(r2,{content:u,onChange:d,placeholder:n(`projectDetail.notes.placeholder`)}):h.notes?(0,K.jsx)(`div`,{className:`prose prose-invert prose-sm max-w-none`,dangerouslySetInnerHTML:{__html:JG.sanitize(h.notes)}}):(0,K.jsx)(`p`,{className:`text-bambu-gray/70 text-sm italic`,children:n(`projectDetail.notes.empty`)})]})}),(0,K.jsx)(Ed,{children:(0,K.jsxs)(Od,{className:`p-4`,children:[(0,K.jsx)(`div`,{className:`flex items-center justify-between mb-3`,children:(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(dc,{className:`w-5 h-5`}),n(`projectDetail.files.title`)]})}),(0,K.jsxs)(`p`,{className:`text-xs text-bambu-gray mb-3`,children:[(0,K.jsx)(Oi,{to:`/files`,className:`text-bambu-green hover:underline`,children:n(`projectDetail.files.linkFolders`)}),` `,n(`projectDetail.files.forQuickAccess`)]}),E&&E.length>0?(0,K.jsx)(`div`,{className:`space-y-4`,children:E.map(e=>{let t=k.get(e.id)??[],r=O;return(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(Oi,{to:`/files?folder=${e.id}`,className:`flex items-center justify-between p-3 bg-bambu-dark rounded-lg hover:bg-bambu-dark-tertiary transition-colors mb-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0`,children:[(0,K.jsx)(dc,{className:`w-5 h-5 text-bambu-green shrink-0`}),(0,K.jsxs)(`div`,{className:`min-w-0`,children:[(0,K.jsx)(`p`,{className:`text-sm text-white truncate`,children:e.name}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`projectDetail.files.fileCount`,{count:e.file_count})})]})]}),(0,K.jsx)(cs,{className:`w-4 h-4 text-bambu-gray shrink-0`})]}),r?(0,K.jsx)(`div`,{className:`flex items-center gap-2 px-3 py-2 text-bambu-gray text-sm`,children:(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`})}):t.length===0?(0,K.jsx)(`p`,{className:`text-bambu-gray/60 text-xs italic px-3`,children:n(`projectDetail.files.noFiles`)}):(0,K.jsx)(`div`,{className:`space-y-1 pl-3`,children:t.map(e=>{let t=vWe(e.filename);return(0,K.jsxs)(`div`,{className:`flex items-center gap-3 p-2 rounded-lg hover:bg-bambu-dark-tertiary transition-colors`,children:[(0,K.jsx)(`div`,{className:`w-10 h-10 shrink-0 rounded bg-bambu-dark overflow-hidden flex items-center justify-center`,children:e.thumbnail_path?(0,K.jsx)(`img`,{src:Q.getLibraryFileThumbnailUrl(e.id),alt:e.print_name||e.filename,className:`w-full h-full object-cover`}):(0,K.jsx)(tc,{className:`w-5 h-5 text-bambu-gray/40`})}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsx)(`p`,{className:`text-sm text-white truncate`,title:e.print_name||e.filename,children:e.print_name||e.filename}),(0,K.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded font-medium ${e.file_type===`3mf`?`bg-bambu-green/20 text-bambu-green`:e.file_type===`gcode`||e.file_type===`gcode.3mf`?`bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400`:`bg-bambu-gray/20 text-bambu-gray`}`,children:e.file_type.toUpperCase()})]}),t&&(0,K.jsx)(`div`,{className:`flex items-center gap-1 shrink-0`,children:(0,K.jsx)(`button`,{onClick:()=>p(e),title:n(`common.print`),className:`p-1.5 rounded hover:bg-bambu-green/20 text-bambu-green transition-colors`,children:(0,K.jsx)(jl,{className:`w-4 h-4`})})})]},e.id)})})]},e.id)})}):(0,K.jsx)(`p`,{className:`text-bambu-gray/70 text-sm italic`,children:n(`projectDetail.files.empty`)})]})}),(0,K.jsx)(Ed,{children:(0,K.jsxs)(Od,{className:`p-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-4`,children:[(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(eu,{className:`w-5 h-5`}),n(`projectDetail.bom.title`),Me&&Me.bom_total_items>0&&(0,K.jsxs)(`span`,{className:`text-sm font-normal text-bambu-gray`,children:[`(`,n(`projectDetail.bom.acquired`,{completed:Me.bom_completed_items,total:Me.bom_total_items}),`)`]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[x&&x.some(e=>e.is_complete)&&(0,K.jsx)(`button`,{onClick:()=>oe(!ae),className:`text-xs px-2 py-1 rounded transition-colors ${ae?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark text-bambu-gray hover:text-white`}`,children:n(ae?`projectDetail.bom.showAll`:`projectDetail.bom.hideDone`)}),!ie&&(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:()=>H(!0),disabled:!a(`projects:update`),title:a(`projects:update`)?void 0:n(`projectDetail.bom.noAddPermission`),children:[(0,K.jsx)(Ol,{className:`w-4 h-4 mr-1`}),n(`projectDetail.bom.addPart`)]})]})]}),ie&&(0,K.jsxs)(`form`,{onSubmit:Ce,className:`bg-bambu-dark rounded-lg p-4 mb-4 space-y-3`,children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-3`,children:[(0,K.jsx)(`input`,{type:`text`,value:I,onChange:e=>L(e.target.value),className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:n(`projectDetail.bom.partNamePlaceholder`),autoFocus:!0}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)(`input`,{type:`number`,value:R,onChange:e=>z(parseInt(e.target.value)||1),className:`w-20 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white focus:outline-none focus:border-bambu-green`,min:`1`,placeholder:n(`projectDetail.bom.qty`)}),(0,K.jsx)(`input`,{type:`number`,step:`0.01`,value:B,onChange:e=>V(e.target.value),className:`flex-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:n(`projectDetail.bom.price`,{currency:A})})]})]}),(0,K.jsx)(`input`,{type:`url`,value:ee,onChange:e=>te(e.target.value),className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:n(`projectDetail.bom.sourcingUrlPlaceholder`)}),(0,K.jsx)(`input`,{type:`text`,value:ne,onChange:e=>re(e.target.value),className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:n(`projectDetail.bom.remarksPlaceholder`)}),(0,K.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,K.jsx)($,{type:`button`,variant:`secondary`,size:`sm`,onClick:()=>H(!1),children:n(`common.cancel`)}),(0,K.jsx)($,{type:`submit`,size:`sm`,disabled:!I.trim()||be.isPending,children:be.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):n(`projectDetail.bom.addPart`)})]})]}),S?(0,K.jsx)(`div`,{className:`flex items-center justify-center py-4`,children:(0,K.jsx)(X,{className:`w-6 h-6 animate-spin text-bambu-green`})}):x&&x.length>0?(0,K.jsxs)(`div`,{className:`space-y-2`,children:[x.filter(e=>!ae||!e.is_complete).map(e=>(0,K.jsx)(`div`,{className:`p-3 rounded-lg transition-colors ${e.is_complete?`bg-status-ok/10`:`bg-bambu-dark`}`,children:U?.id===e.id?(0,K.jsxs)(`form`,{onSubmit:De,className:`space-y-3`,children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-3`,children:[(0,K.jsx)(`input`,{type:`text`,value:ce,onChange:e=>le(e.target.value),className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:n(`projectDetail.bom.partName`),autoFocus:!0}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)(`input`,{type:`number`,value:ue,onChange:e=>de(parseInt(e.target.value)||1),className:`w-20 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white focus:outline-none focus:border-bambu-green`,min:`1`,placeholder:n(`projectDetail.bom.qty`)}),(0,K.jsx)(`input`,{type:`number`,step:`0.01`,value:fe,onChange:e=>pe(e.target.value),className:`flex-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:n(`projectDetail.bom.price`,{currency:A})})]})]}),(0,K.jsx)(`input`,{type:`url`,value:me,onChange:e=>he(e.target.value),className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:n(`projectDetail.bom.sourcingUrlPlaceholder`)}),(0,K.jsx)(`input`,{type:`text`,value:ge,onChange:e=>_e(e.target.value),className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:n(`projectDetail.bom.remarksPlaceholder`)}),(0,K.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,K.jsx)($,{type:`button`,variant:`secondary`,size:`sm`,onClick:Oe,children:n(`common.cancel`)}),(0,K.jsx)($,{type:`submit`,size:`sm`,disabled:!ce.trim()||xe.isPending,children:xe.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):n(`common.save`)})]})]}):(0,K.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,K.jsx)(`button`,{onClick:()=>a(`projects:update`)&&we(e),disabled:xe.isPending||!a(`projects:update`),title:a(`projects:update`)?void 0:n(`projectDetail.bom.noUpdatePermission`),className:`w-5 h-5 mt-0.5 rounded border-2 flex items-center justify-center transition-colors shrink-0 ${e.is_complete?`bg-status-ok border-status-ok text-white`:a(`projects:update`)?`border-bambu-gray hover:border-bambu-green`:`border-bambu-gray/50 cursor-not-allowed`}`,children:e.is_complete&&(0,K.jsx)(hs,{className:`w-3 h-3`})}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,K.jsxs)(`p`,{className:`text-sm font-medium ${e.is_complete?`text-bambu-gray line-through`:`text-white`}`,children:[e.name,(0,K.jsxs)(`span`,{className:`text-bambu-gray font-normal ml-2`,children:[`x`,e.quantity_needed]})]}),e.unit_price!==null&&(0,K.jsxs)(`span`,{className:`text-xs text-bambu-green whitespace-nowrap`,children:[A,(e.unit_price*e.quantity_needed).toFixed(2)]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(`button`,{onClick:()=>a(`projects:update`)&&Ee(e),disabled:!a(`projects:update`),className:`p-1 rounded transition-colors shrink-0 ${a(`projects:update`)?`hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white`:`text-bambu-gray/50 cursor-not-allowed`}`,title:a(`projects:update`)?n(`common.edit`):n(`projectDetail.bom.noEditPermission`),children:(0,K.jsx)(wl,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>a(`projects:update`)&&Te(e.id,e.name),disabled:!a(`projects:update`),className:`p-1 rounded transition-colors shrink-0 ${a(`projects:update`)?`hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-red-400`:`text-bambu-gray/50 cursor-not-allowed`}`,title:a(`projects:update`)?n(`common.delete`):n(`projectDetail.bom.noDeletePermission`),children:(0,K.jsx)(Eu,{className:`w-4 h-4`})})]})]}),e.sourcing_url&&(0,K.jsxs)(`a`,{href:e.sourcing_url,target:`_blank`,rel:`noopener noreferrer`,className:`flex items-center gap-1 mt-1 text-xs text-blue-700 dark:text-blue-400 hover:text-blue-900 dark:hover:text-blue-300 transition-colors`,onClick:e=>e.stopPropagation(),children:[(0,K.jsx)(Zs,{className:`w-3 h-3 shrink-0`}),(0,K.jsx)(`span`,{className:`truncate`,children:(()=>{try{return new URL(e.sourcing_url).hostname.replace(`www.`,``)}catch{return e.sourcing_url}})()})]}),e.remarks&&(0,K.jsx)(`p`,{className:`mt-1 text-xs text-bambu-gray/80 italic`,children:e.remarks})]})]})},e.id)),Me&&Me.bom_cost>0&&(0,K.jsxs)(`div`,{className:`pt-2 mt-2 border-t border-bambu-dark-tertiary flex justify-between text-sm`,children:[(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:n(`projectDetail.bom.totalCost`)}),(0,K.jsxs)(`span`,{className:`text-white font-medium`,children:[A,Me.bom_cost.toFixed(2)]})]})]}):(0,K.jsx)(`p`,{className:`text-bambu-gray/70 text-sm italic`,children:n(`projectDetail.bom.empty`)})]})}),(0,K.jsx)(Ed,{children:(0,K.jsxs)(Od,{className:`p-4`,children:[(0,K.jsx)(`div`,{className:`flex items-center justify-between mb-3`,children:(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(Mc,{className:`w-5 h-5`}),n(`projectDetail.timeline.title`)]})}),w?(0,K.jsx)(`div`,{className:`flex items-center justify-center py-4`,children:(0,K.jsx)(X,{className:`w-6 h-6 animate-spin text-bambu-green`})}):C&&C.length>0?(0,K.jsx)(`div`,{className:`space-y-3`,children:C.slice(0,10).map((e,t)=>(0,K.jsxs)(`div`,{className:`flex gap-3`,children:[(0,K.jsxs)(`div`,{className:`w-8 h-8 rounded-full flex items-center justify-center shrink-0 ${e.event_type===`print_completed`?`bg-status-ok/20 text-status-ok`:e.event_type===`print_failed`?`bg-status-error/20 text-status-error`:e.event_type===`print_started`?`bg-yellow-100 dark:bg-yellow-500/20 text-yellow-700 dark:text-yellow-400`:`bg-bambu-dark-tertiary text-bambu-gray`}`,children:[e.event_type===`print_completed`&&(0,K.jsx)(hs,{className:`w-4 h-4`}),e.event_type===`print_failed`&&(0,K.jsx)(xs,{className:`w-4 h-4`}),e.event_type===`print_started`&&(0,K.jsx)(jl,{className:`w-4 h-4`}),e.event_type===`queued`&&(0,K.jsx)(qc,{className:`w-4 h-4`}),e.event_type===`project_created`&&(0,K.jsx)(Ol,{className:`w-4 h-4`})]}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsx)(`p`,{className:`text-sm text-white`,children:e.title}),e.description&&(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray truncate`,children:e.description}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray/70`,children:je(e.timestamp)})]})]},t))}):(0,K.jsx)(`p`,{className:`text-bambu-gray/70 text-sm italic`,children:n(`projectDetail.timeline.empty`)})]})}),!h.is_template&&(0,K.jsx)(`div`,{className:`flex justify-end`,children:(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:()=>Ae.mutate(),disabled:Ae.isPending||!a(`projects:create`),title:a(`projects:create`)?void 0:n(`projectDetail.template.noCreatePermission`),children:[Ae.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin mr-2`}):(0,K.jsx)(Fs,{className:`w-4 h-4 mr-2`}),n(`projectDetail.template.saveAsTemplate`)]})}),Me&&(Me.queued_prints>0||Me.in_progress_prints>0)&&(0,K.jsx)(Ed,{children:(0,K.jsxs)(Od,{className:`p-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(qc,{className:`w-5 h-5`}),n(`projectDetail.queue.title`)]}),(0,K.jsx)(Oi,{to:`/queue?project=${m}`,className:`text-sm text-bambu-green hover:underline`,children:n(`projectDetail.queue.viewAll`)})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-4 text-sm`,children:[Me.in_progress_prints>0&&(0,K.jsx)(`span`,{className:`text-yellow-700 dark:text-yellow-400`,children:n(`projectDetail.queue.printing`,{count:Me.in_progress_prints})}),Me.queued_prints>0&&(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:n(`projectDetail.queue.queued`,{count:Me.queued_prints})})]})]})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`div`,{className:`flex items-center justify-between mb-4`,children:(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(_l,{className:`w-5 h-5`}),n(`projectDetail.prints.title`,{count:v?.length||0})]})}),b?(0,K.jsx)(`div`,{className:`flex items-center justify-center py-8`,children:(0,K.jsx)(X,{className:`w-6 h-6 animate-spin text-bambu-green`})}):(0,K.jsx)(xWe,{archives:v||[],t:n})]}),o&&(0,K.jsx)(U6,{t:n,currencySymbol:A,project:{...h,archive_count:Me?.total_archives||0,total_items:Me?.total_items||0,completed_count:Me?.completed_prints||0,failed_count:Me?.failed_prints||0,queue_count:Me?.queued_prints||0,progress_percent:Me?.progress_percent||null,archives:[]},onClose:()=>s(!1),onSave:e=>M.mutate(e),isLoading:M.isPending}),ve.isOpen&&(0,K.jsx)(Vd,{title:ve.title,message:ve.message,confirmText:n(`common.delete`),variant:`danger`,onConfirm:ve.onConfirm,onCancel:()=>ye(e=>({...e,isOpen:!1}))}),f&&(0,K.jsx)(uW,{mode:`create`,libraryFileId:f.id,archiveName:f.print_name||f.filename,projectId:m,onClose:()=>p(null),onSuccess:()=>{p(null),r.invalidateQueries({queryKey:[`archives`]}),r.invalidateQueries({queryKey:[`queue`]})}})]})}function wWe({archiveId:e,libraryFileId:t,title:n,fileType:r,onClose:i,onSliceWithBambuddy:a}){let{t:o}=W(),{data:s}=q({queryKey:[`settings`],queryFn:Q.getSettings}),c=s?.open_in_slicer||s?.preferred_slicer||`bambu_studio`,l=t!=null,[u,d]=(0,y.useState)(null),[f,p]=(0,y.useState)(null),[m,h]=(0,y.useState)(!0),[g,_]=(0,y.useState)(null),[v,b]=(0,y.useState)(!1),[x,S]=(0,y.useState)(null),[C,w]=(0,y.useState)(0),[T,E]=(0,y.useState)(!1),[D,O]=(0,y.useState)(null),[k,A]=(0,y.useState)(!1),[j,M]=(0,y.useState)(!1),N=(0,y.useRef)(null),P=(0,y.useRef)(null),F=.35;(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&i()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[i]),(0,y.useEffect)(()=>{if(h(!0),l){let e=(r||``).toLowerCase(),t=e===`3mf`||e===`gcode.3mf`,n=t||e===`stl`,i=t||e===`gcode`;p({has_model:n,has_gcode:i,has_source:!1,build_volume:{x:256,y:256,z:256},filament_colors:[]}),d(n?`3d`:i?`gcode`:null),h(!1);return}if(!e){p(null),d(null),h(!1);return}Q.getArchiveCapabilities(e).then(e=>{p(e),e.has_model?d(`3d`):e.has_gcode&&d(`gcode`),h(!1)}).catch(()=>{p({has_model:!0,has_gcode:!1,has_source:!1,build_volume:{x:256,y:256,z:256},filament_colors:[]}),d(`3d`),h(!1)})},[e,r,l]),(0,y.useEffect)(()=>{if(b(!0),S(null),w(0),l){let e=(r||``).toLowerCase();if(!t||!(e===`3mf`||e===`gcode.3mf`)){_(null),b(!1);return}Q.getLibraryFilePlates(t).then(e=>_(e)).catch(()=>_(null)).finally(()=>b(!1));return}if(!e){_(null),b(!1);return}Q.getArchivePlates(e).then(e=>_(e)).catch(()=>_(null)).finally(()=>b(!1))},[e,r,l,t]);let I=(0,y.useMemo)(()=>g?.plates??[],[g]),L=(g?.is_multi_plate??!1)&&I.length>1,R=T&&L,z=x==null?null:I.find(e=>e.index===x)??null,B=e=>e.object_count??e.objects?.length??0,V=I.reduce((e,t)=>e+B(t),0),ee=z?B(z):V,te=z?o(`modelViewer.plateNumber`,{number:z.index}):o(`modelViewer.allPlates`),ne=I.length>0,re=(0,y.useRef)(null),ie=(0,y.useRef)(null),[H,ae]=(0,y.useState)(10),[oe,U]=(0,y.useState)(3),se=I.length>H,ce=Math.max(1,Math.ceil(I.length/H)),le=se?I.slice(C*H,(C+1)*H):I;(0,y.useEffect)(()=>{if(!R){ae(10),U(3);return}let e=re.current,t=ie.current;if(!e||!t)return;let n=0,r=()=>{let n=t.clientWidth,r=Math.floor(n/210),i=Math.max(3,Math.min(5,r||3));U(e=>e===i?e:i);let a=window.getComputedStyle(e),o=Number.parseFloat(a.rowGap||`0`),s=e.querySelector(`button`)?.getBoundingClientRect().height??44,c=t.clientHeight,l=Math.max(1,Math.floor((c+o)/(s+o)))*i,u=Math.max(1,l-1);ae(e=>e===u?e:u)},i=()=>{n&&cancelAnimationFrame(n),n=requestAnimationFrame(r)};i();let a=new ResizeObserver(i);return a.observe(t),a.observe(e),()=>{n&&cancelAnimationFrame(n),a.disconnect()}},[R,I.length]),(0,y.useEffect)(()=>{if(!se){w(0);return}w(e=>Math.min(e,ce-1))},[I.length,se,ce]),(0,y.useEffect)(()=>{if(!se||x==null)return;let e=I.findIndex(e=>e.index===x);if(e<0)return;let t=Math.floor(e/H);w(e=>e===t?e:t)},[I,H,x,se]),(0,y.useEffect)(()=>{if(!R){O(null),M(!1);return}if(j)return;let e=N.current,t=P.current;if(!e||!t)return;let n=e.clientHeight;if(!n)return;let r=Math.max(240,n*F),i=Math.max(160,n-10-r),a=Math.min(t.scrollHeight,i);O(Math.max(160,a))},[R,j,I.length,C,10,160,240,F]),(0,y.useEffect)(()=>{if(!k)return;let e=e=>{let t=N.current;if(!t)return;let n=t.getBoundingClientRect(),r=n.height;if(!r)return;let i=Math.max(240,r*F),a=Math.max(160,r-10-i);O(Math.min(a,Math.max(160,e.clientY-n.top)))},t=()=>{A(!1),M(!0)};return document.addEventListener(`mousemove`,e),document.addEventListener(`mouseup`,t),document.body.style.cursor=`row-resize`,document.body.style.userSelect=`none`,()=>{document.removeEventListener(`mousemove`,e),document.removeEventListener(`mouseup`,t),document.body.style.cursor=``,document.body.style.userSelect=``}},[k,10,160,240,F]);let ue=l?(r||``).toLowerCase()===`3mf`:!0,de=(()=>{let e=(r||``).toLowerCase();return e===`3mf`||e===`stl`||e===`step`||e===`stp`})(),fe=!!(l&&s?.use_slicer_api&&a&&de);return(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 ${T?`p-0`:`p-8`}`,onClick:i,children:(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary w-full flex flex-col ${T?`h-full max-w-none rounded-none`:`h-[80vh] max-w-4xl rounded-xl`}`,onClick:e=>e.stopPropagation(),children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0 flex-1 mr-4`,children:[(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white truncate`,children:n}),ne&&(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray bg-bambu-dark-tertiary/70 px-2 py-1 rounded whitespace-nowrap`,children:[te,`: `,o(`modelViewer.objectCount`,{count:ee})]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[fe?(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:a,children:[(0,K.jsx)(Ms,{className:`w-4 h-4`}),o(`slice.action`)]}):(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:async()=>{if(!ue)return;let r=n||`model`;try{if(l){let{token:e}=await Q.createLibrarySlicerToken(t),n=Q.getLibrarySlicerDownloadUrl(t,e,r);qW(`${window.location.origin}${n}`,c)}else{let{token:t}=await Q.createArchiveSlicerToken(e),n=Q.getArchiveSlicerDownloadUrl(e,t,r);qW(`${window.location.origin}${n}`,c)}}catch{qW(l?`${window.location.origin}${Q.getLibraryFileDownloadUrl(t)}`:`${window.location.origin}${Q.getArchiveForSlicer(e,r)}`,c)}},disabled:!ue,children:[(0,K.jsx)(Zs,{className:`w-4 h-4`}),o(`modelViewer.openInSlicer`)]}),(0,K.jsx)($,{variant:`secondary`,size:`sm`,onClick:()=>E(e=>!e),title:T?`Exit fullscreen`:`Enter fullscreen`,children:T?(0,K.jsx)(ol,{className:`w-4 h-4`}):(0,K.jsx)(nl,{className:`w-4 h-4`})}),(0,K.jsx)($,{variant:`ghost`,size:`sm`,onClick:i,children:(0,K.jsx)(qu,{className:`w-5 h-5`})})]})]}),f&&(0,K.jsxs)(`div`,{className:`flex border-b border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`button`,{onClick:()=>f.has_model&&d(`3d`),disabled:!f.has_model,className:`flex items-center gap-2 px-6 py-3 text-sm font-medium transition-colors ${u===`3d`?`text-bambu-green border-b-2 border-bambu-green`:f.has_model?`text-bambu-gray hover:text-white`:`text-bambu-gray/30 cursor-not-allowed`}`,children:[(0,K.jsx)(qo,{className:`w-4 h-4`}),o(`modelViewer.tabs.model`),!f.has_model&&(0,K.jsxs)(`span`,{className:`text-xs`,children:[`(`,o(`modelViewer.notAvailable`),`)`]})]}),(0,K.jsxs)(`button`,{onClick:()=>f.has_gcode&&d(`gcode`),disabled:!f.has_gcode,className:`flex items-center gap-2 px-6 py-3 text-sm font-medium transition-colors ${u===`gcode`?`text-bambu-green border-b-2 border-bambu-green`:f.has_gcode?`text-bambu-gray hover:text-white`:`text-bambu-gray/30 cursor-not-allowed`}`,children:[(0,K.jsx)(Os,{className:`w-4 h-4`}),o(`modelViewer.tabs.gcode`),!f.has_gcode&&(0,K.jsxs)(`span`,{className:`text-xs`,children:[`(`,o(`modelViewer.notSliced`),`)`]})]})]}),(0,K.jsx)(`div`,{className:`flex-1 overflow-hidden p-4`,children:m?(0,K.jsx)(`div`,{className:`w-full h-full flex items-center justify-center`,children:(0,K.jsx)(X,{className:`w-8 h-8 animate-spin text-bambu-green`})}):u===`3d`&&f?(0,K.jsxs)(`div`,{ref:N,className:`w-full h-full flex flex-col ${R?`gap-0 min-h-0`:`gap-3`}`,children:[L&&(0,K.jsxs)(`div`,{ref:P,style:R&&D!=null?{height:D}:void 0,className:`rounded-lg border border-bambu-dark-tertiary bg-bambu-dark p-3 ${R?`flex flex-col shrink-0`:``}`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-bambu-gray mb-2`,children:[(0,K.jsx)(Vc,{className:`w-4 h-4`}),o(`modelViewer.plates`),v&&(0,K.jsx)(X,{className:`w-3 h-3 animate-spin`})]}),(0,K.jsxs)(`div`,{className:R?`flex flex-col min-h-0 flex-1`:void 0,children:[(0,K.jsx)(`div`,{ref:ie,className:R?`min-h-0 overflow-hidden pr-1 flex-1`:void 0,children:(0,K.jsxs)(`div`,{ref:re,className:R?`grid gap-2`:`grid grid-cols-2 md:grid-cols-3 gap-2`,style:R?{gridTemplateColumns:`repeat(${oe}, minmax(0, 1fr))`}:void 0,children:[(0,K.jsxs)(`button`,{type:`button`,onClick:()=>S(null),className:`flex items-center rounded-lg border text-left transition-colors ${R?`gap-1.5 p-1.5 w-full`:`gap-2 p-2`} ${x==null?`border-bambu-green bg-bambu-green/10`:`border-bambu-dark-tertiary bg-bambu-dark-secondary hover:border-bambu-gray`}`,children:[(0,K.jsx)(`div`,{className:`rounded bg-bambu-dark-tertiary flex items-center justify-center ${R?`w-8 h-8`:`w-10 h-10`}`,children:(0,K.jsx)(Vc,{className:`${R?`w-4 h-4`:`w-5 h-5`} text-bambu-gray`})}),(0,K.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,K.jsx)(`p`,{className:`${R?`text-xs`:`text-sm`} text-white font-medium truncate`,children:o(`modelViewer.allPlates`)}),(0,K.jsx)(`p`,{className:`${R?`text-[10px]`:`text-xs`} text-bambu-gray truncate`,children:o(`modelViewer.plateCount`,{count:I.length})})]}),x==null&&(0,K.jsx)(as,{className:`${R?`w-3.5 h-3.5`:`w-4 h-4`} text-bambu-green flex-shrink-0`})]}),le.map(e=>(0,K.jsxs)(`button`,{type:`button`,onClick:()=>S(e.index),className:`flex items-center rounded-lg border text-left transition-colors ${R?`gap-1.5 p-1.5 w-full`:`gap-2 p-2`} ${x===e.index?`border-bambu-green bg-bambu-green/10`:`border-bambu-dark-tertiary bg-bambu-dark-secondary hover:border-bambu-gray`}`,children:[e.has_thumbnail&&e.thumbnail_url?(0,K.jsx)(`img`,{src:e.thumbnail_url,alt:`Plate ${e.index}`,className:`${R?`w-8 h-8`:`w-10 h-10`} rounded object-cover bg-bambu-dark-tertiary`}):(0,K.jsx)(`div`,{className:`rounded bg-bambu-dark-tertiary flex items-center justify-center ${R?`w-8 h-8`:`w-10 h-10`}`,children:(0,K.jsx)(Vc,{className:`${R?`w-4 h-4`:`w-5 h-5`} text-bambu-gray`})}),(0,K.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,K.jsx)(`p`,{className:`${R?`text-xs`:`text-sm`} text-white font-medium truncate`,children:e.name||o(`modelViewer.plateNumber`,{number:e.index})}),(0,K.jsx)(`p`,{className:`${R?`text-[10px]`:`text-xs`} text-bambu-gray truncate`,children:o(`modelViewer.objectCount`,{count:e.object_count??e.objects?.length??0})})]}),x===e.index&&(0,K.jsx)(as,{className:`${R?`w-3.5 h-3.5`:`w-4 h-4`} text-bambu-green flex-shrink-0`})]},e.index))]})}),(z||se)&&(0,K.jsxs)(`div`,{className:`mt-auto pt-3 flex items-center gap-4 text-xs text-bambu-gray overflow-x-auto`,children:[z&&(0,K.jsxs)(`div`,{className:`flex items-center gap-3 whitespace-nowrap`,children:[(0,K.jsx)(`span`,{children:o(`modelViewer.plateNumber`,{number:z.index})}),z.print_time_seconds!=null&&(0,K.jsx)(`span`,{children:o(`modelViewer.eta`,{minutes:Math.round(z.print_time_seconds/60)})}),z.filament_used_grams!=null&&(0,K.jsxs)(`span`,{children:[z.filament_used_grams.toFixed(1),` g`]}),z.filaments.length>0&&(0,K.jsx)(`span`,{children:o(`modelViewer.filamentCount`,{count:z.filaments.length})})]}),se&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2 whitespace-nowrap ${z?`ml-auto`:``}`,children:[(0,K.jsx)(`span`,{children:o(`modelViewer.pagination.pageOf`,{current:C+1,total:ce})}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(`button`,{type:`button`,onClick:()=>w(e=>Math.max(e-1,0)),disabled:C===0,className:`px-2 py-1 rounded border text-xs ${C===0?`border-bambu-dark-tertiary text-bambu-gray/40 cursor-not-allowed`:`border-bambu-dark-tertiary text-bambu-gray hover:text-white hover:border-bambu-gray`}`,children:o(`modelViewer.pagination.prev`)}),(()=>{let e=Math.max(0,C-2),t=Math.min(ce,e+5);t-e<5&&(e=Math.max(0,t-5));let n=Array.from({length:t-e},(t,n)=>e+n);return(0,K.jsxs)(K.Fragment,{children:[e>0&&(0,K.jsx)(`button`,{type:`button`,onClick:()=>w(0),className:`px-2 py-1 rounded border text-xs ${C===0?`border-bambu-green text-bambu-green`:`border-bambu-dark-tertiary text-bambu-gray hover:text-white hover:border-bambu-gray`}`,children:`1`}),e>1&&(0,K.jsx)(`span`,{className:`px-1`,children:`…`}),n.map(e=>(0,K.jsx)(`button`,{type:`button`,onClick:()=>w(e),className:`px-2 py-1 rounded border text-xs ${C===e?`border-bambu-green text-bambu-green`:`border-bambu-dark-tertiary text-bambu-gray hover:text-white hover:border-bambu-gray`}`,children:e+1},e)),tw(ce-1),className:`px-2 py-1 rounded border text-xs ${C===ce-1?`border-bambu-green text-bambu-green`:`border-bambu-dark-tertiary text-bambu-gray hover:text-white hover:border-bambu-gray`}`,children:ce})]})})(),(0,K.jsx)(`button`,{type:`button`,onClick:()=>w(e=>Math.min(e+1,ce-1)),disabled:C>=ce-1,className:`px-2 py-1 rounded border text-xs ${C>=ce-1?`border-bambu-dark-tertiary text-bambu-gray/40 cursor-not-allowed`:`border-bambu-dark-tertiary text-bambu-gray hover:text-white hover:border-bambu-gray`}`,children:o(`modelViewer.pagination.next`)})]})]})]})]})]}),R&&(0,K.jsx)(`div`,{role:`separator`,"aria-orientation":`horizontal`,onMouseDown:e=>{e.preventDefault(),A(!0),M(!0)},className:`h-2 cursor-row-resize flex items-center justify-center ${k?`bg-bambu-dark-tertiary`:`bg-bambu-dark-secondary/60 hover:bg-bambu-dark-tertiary`}`,children:(0,K.jsx)(`div`,{className:`w-12 h-1 rounded-full bg-bambu-gray/50`})}),(0,K.jsx)(`div`,{className:`flex-1 ${R?`min-h-0`:``}`,children:(0,K.jsx)(_y,{url:l?Q.getLibraryFileDownloadUrl(t):f.has_source?Q.getSource3mfDownloadUrl(e):Q.getArchiveDownload(e),fileType:r,buildVolume:f.build_volume,filamentColors:f.filament_colors,selectedPlateId:x,className:`w-full h-full`})})]}):u===`gcode`&&f?(0,K.jsx)(dT,{gcodeUrl:l?Q.getLibraryFileGcodeUrl(t):Q.getArchiveGcode(e),filamentColors:f.filament_colors,className:`w-full h-full`}):(0,K.jsx)(`div`,{className:`w-full h-full flex items-center justify-center text-bambu-gray`,children:o(`modelViewer.noPreview`)})})]})})}var K6=[`library-tags`];function TWe({open:e,fileIds:t,onClose:n}){let{t:r}=W(),i=oo(),{showToast:a}=Pd(),[o,s]=(0,y.useState)(`add`),[c,l]=(0,y.useState)(new Set),[u,d]=(0,y.useState)(``),[f,p]=(0,y.useState)(``);(0,y.useEffect)(()=>{e||(s(`add`),l(new Set),d(``),p(``))},[e]);let{data:m=[],isLoading:h}=q({queryKey:K6,queryFn:Q.getLibraryTags,enabled:e}),g=(0,y.useMemo)(()=>{let e=u.trim().toLowerCase();return e?m.filter(t=>t.name.toLowerCase().includes(e)):m},[m,u]),_=e=>{l(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},v=J({mutationFn:e=>Q.createLibraryTag(e),onSuccess:e=>{l(t=>new Set(t).add(e.id)),p(``),i.invalidateQueries({queryKey:K6})},onError:e=>{a(e.message||r(`fileManager.tags.saveFailed`),`error`)}}),b=J({mutationFn:()=>Q.bulkAssignLibraryTags(t,Array.from(c),o),onSuccess:e=>{a(o===`add`?r(`fileManager.tags.applyAddSuccess`,{count:e.associations_added,files:e.files_updated}):r(`fileManager.tags.applyRemoveSuccess`,{count:e.associations_removed,files:e.files_updated}),`success`),i.invalidateQueries({queryKey:[`library-files`]}),i.invalidateQueries({queryKey:K6}),n()},onError:e=>{a(e.message||r(`fileManager.tags.applyFailed`),`error`)}});if((0,y.useEffect)(()=>{if(!e)return;let t=e=>{e.key===`Escape`&&!b.isPending&&!v.isPending&&n()};return document.addEventListener(`keydown`,t),()=>document.removeEventListener(`keydown`,t)},[e,n,b.isPending,v.isPending]),!e)return null;let x=!f.trim()||v.isPending||m.some(e=>e.name.toLowerCase()===f.trim().toLowerCase()),S=`bulk-tags-picker-title`;return(0,K.jsxs)(`div`,{className:`fixed inset-0 z-[60] flex items-center justify-center`,children:[(0,K.jsx)(`div`,{className:`absolute inset-0 bg-black/60`,onClick:()=>!b.isPending&&n()}),(0,K.jsxs)(`div`,{className:`relative w-full max-w-md mx-4 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl shadow-2xl max-h-[90vh] flex flex-col`,role:`dialog`,"aria-modal":`true`,"aria-labelledby":S,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between gap-4 px-5 py-4 border-b border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`h3`,{id:S,className:`text-base font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(vu,{className:`w-4 h-4 text-bambu-green`}),r(`fileManager.tags.bulkTitle`,{count:t.length})]}),(0,K.jsx)(`button`,{type:`button`,className:`p-1.5 text-bambu-gray hover:text-white rounded`,onClick:n,"aria-label":r(`common.close`),children:(0,K.jsx)(qu,{className:`w-5 h-5`})})]}),(0,K.jsxs)(`div`,{className:`px-5 py-3 border-b border-bambu-dark-tertiary flex gap-4 text-sm`,children:[(0,K.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`radio`,name:`bulk-action`,checked:o===`add`,onChange:()=>s(`add`),className:`accent-bambu-green`}),(0,K.jsx)(`span`,{className:`text-white`,children:r(`fileManager.tags.actionAdd`)})]}),(0,K.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`radio`,name:`bulk-action`,checked:o===`remove`,onChange:()=>s(`remove`),className:`accent-bambu-green`}),(0,K.jsx)(`span`,{className:`text-white`,children:r(`fileManager.tags.actionRemove`)})]})]}),(0,K.jsx)(`div`,{className:`px-5 py-3 border-b border-bambu-dark-tertiary`,children:(0,K.jsx)(`input`,{type:`text`,value:u,onChange:e=>d(e.target.value),placeholder:r(`fileManager.tags.searchPlaceholder`),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`})}),(0,K.jsx)(`div`,{className:`overflow-y-auto flex-1 min-h-[8rem] max-h-[24rem]`,children:h?(0,K.jsxs)(`div`,{className:`flex items-center justify-center py-12 text-bambu-gray`,children:[(0,K.jsx)(X,{className:`w-5 h-5 animate-spin mr-2`}),r(`common.loading`)]}):g.length===0?(0,K.jsx)(`div`,{className:`py-12 text-center text-bambu-gray text-sm`,children:m.length===0?r(`fileManager.tags.empty`):r(`fileManager.tags.noMatches`)}):(0,K.jsx)(`ul`,{className:`divide-y divide-bambu-dark-tertiary/40`,children:g.map(e=>(0,K.jsx)(`li`,{children:(0,K.jsxs)(`label`,{className:`flex items-center gap-3 px-5 py-2 hover:bg-bambu-dark-tertiary/30 cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:c.has(e.id),onChange:()=>_(e.id),className:`accent-bambu-green`}),(0,K.jsx)(`span`,{className:`text-sm text-white truncate flex-1`,children:e.name}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:e.file_count})]})},e.id))})}),o===`add`&&(0,K.jsxs)(`div`,{className:`px-5 py-3 border-t border-bambu-dark-tertiary flex gap-2`,children:[(0,K.jsx)(`input`,{type:`text`,value:f,onChange:e=>p(e.target.value),placeholder:r(`fileManager.tags.createPlaceholder`),maxLength:64,className:`flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,onKeyDown:e=>{e.key===`Enter`&&!x&&(e.preventDefault(),v.mutate(f.trim()))}}),(0,K.jsxs)($,{type:`button`,variant:`secondary`,onClick:()=>v.mutate(f.trim()),disabled:x,children:[v.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(Ol,{className:`w-4 h-4`}),r(`fileManager.tags.createButton`)]})]}),(0,K.jsxs)(`div`,{className:`px-5 py-4 border-t border-bambu-dark-tertiary flex justify-end gap-2`,children:[(0,K.jsx)($,{type:`button`,variant:`secondary`,onClick:n,disabled:b.isPending,children:r(`common.cancel`)}),(0,K.jsxs)($,{type:`button`,onClick:()=>b.mutate(),disabled:c.size===0||b.isPending||t.length===0,children:[b.isPending&&(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),r(o===`add`?`fileManager.tags.applyAdd`:`fileManager.tags.applyRemove`)]})]})]})]})}function EWe(e,t){let n=t||{};return(e[e.length-1]===``?[...e,``]:e).join((n.padRight?` `:``)+`,`+(n.padLeft===!1?``:` `)).trim()}var DWe=/^[$_\p{ID_Start}][$_\u{200C}\u{200D}\p{ID_Continue}]*$/u,OWe=/^[$_\p{ID_Start}][-$_\u{200C}\u{200D}\p{ID_Continue}]*$/u,kWe={};function q6(e,t){return((t||kWe).jsx?OWe:DWe).test(e)}var AWe=/[ \t\n\f\r]/g;function jWe(e){return typeof e==`object`?e.type===`text`?J6(e.value):!1:J6(e)}function J6(e){return e.replace(AWe,``)===``}var Y6=class{constructor(e,t,n){this.normal=t,this.property=e,n&&(this.space=n)}};Y6.prototype.normal={},Y6.prototype.property={},Y6.prototype.space=void 0;function X6(e,t){let n={},r={};for(let t of e)Object.assign(n,t.property),Object.assign(r,t.normal);return new Y6(n,r,t)}function Z6(e){return e.toLowerCase()}var Q6=class{constructor(e,t){this.attribute=t,this.property=e}};Q6.prototype.attribute=``,Q6.prototype.booleanish=!1,Q6.prototype.boolean=!1,Q6.prototype.commaOrSpaceSeparated=!1,Q6.prototype.commaSeparated=!1,Q6.prototype.defined=!1,Q6.prototype.mustUseProperty=!1,Q6.prototype.number=!1,Q6.prototype.overloadedBoolean=!1,Q6.prototype.property=``,Q6.prototype.spaceSeparated=!1,Q6.prototype.space=void 0;var $6=s({boolean:()=>e8,booleanish:()=>t8,commaOrSpaceSeparated:()=>o8,commaSeparated:()=>a8,number:()=>r8,overloadedBoolean:()=>n8,spaceSeparated:()=>i8}),MWe=0,e8=s8(),t8=s8(),n8=s8(),r8=s8(),i8=s8(),a8=s8(),o8=s8();function s8(){return 2**++MWe}var c8=Object.keys($6),l8=class extends Q6{constructor(e,t,n,r){let i=-1;if(super(e,t),u8(this,`space`,r),typeof n==`number`)for(;++i4&&n.slice(0,4)===`data`&&LWe.test(t)){if(t.charAt(4)===`-`){let e=t.slice(5).replace(v8,BWe);r=`data`+e.charAt(0).toUpperCase()+e.slice(1)}else{let e=t.slice(4);if(!v8.test(e)){let n=e.replace(IWe,zWe);n.charAt(0)!==`-`&&(n=`-`+n),t=`data`+n}}i=l8}return new i(r,t)}function zWe(e){return`-`+e.toLowerCase()}function BWe(e){return e.charAt(1).toUpperCase()}var VWe=X6([f8,NWe,h8,g8,_8],`html`),y8=X6([f8,PWe,h8,g8,_8],`svg`);function HWe(e){return e.join(` `).trim()}var UWe=o(((e,t)=>{var n=/\/\*[^*]*\*+([^/*][^*]*\*+)*\//g,r=/\n/g,i=/^\s*/,a=/^(\*?[-#/*\\\w]+(\[[0-9a-z_-]+\])?)\s*/,o=/^:\s*/,s=/^((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|\([^)]*?\)|[^};])+)/,c=/^[;\s]*/,l=/^\s+|\s+$/g,u=` +`+n+`}`}return String(e)}function aWe({setting:e,onClose:t,onDeleted:n,onDuplicate:r,onEdit:i,hasPermission:a,t:o}){let{showToast:s}=Pd(),c=oo(),[l,u]=(0,y.useState)(!1),{data:d,isLoading:f}=q({queryKey:[`cloudSettingDetail`,e.setting_id],queryFn:()=>Q.getCloudSettingDetail(e.setting_id)}),p=J({mutationFn:()=>Q.deleteCloudSetting(e.setting_id),onSuccess:()=>{s(o(`profiles.presets.toast.deleted`)),c.invalidateQueries({queryKey:[`cloudSettings`]}),n()},onError:e=>s(e.message,`error`)}),m=j6(e.setting_id),h=A6(e.name,d?.setting?.inherits);return(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,children:(0,K.jsx)(Ed,{className:`w-full max-w-3xl max-h-[90vh] flex flex-col overflow-hidden`,children:(0,K.jsxs)(Od,{className:`p-0 flex flex-col min-h-0 flex-1`,children:[(0,K.jsxs)(`div`,{className:`flex-shrink-0 flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`h2`,{className:`text-xl font-semibold text-white truncate`,children:e.name}),m&&(0,K.jsx)(`span`,{className:`px-2 py-0.5 text-xs font-medium bg-bambu-green/20 text-bambu-green rounded-full`,children:o(`profiles.presets.editable`)})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mt-1 text-sm text-bambu-gray`,children:[(0,K.jsx)(`span`,{className:`capitalize`,children:o(`profiles.presets.types.${e.type}`)}),h.printer&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`span`,{children:`•`}),(0,K.jsx)(`span`,{children:h.printer})]})]})]}),(0,K.jsx)(`button`,{onClick:t,className:`p-2 text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary rounded-lg transition-colors`,children:(0,K.jsx)(qu,{className:`w-5 h-5`})})]}),(0,K.jsx)(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-4`,children:f?(0,K.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,K.jsx)(X,{className:`w-8 h-8 text-bambu-green animate-spin`})}):d?(0,K.jsx)(`pre`,{className:`text-xs text-bambu-gray font-mono whitespace-pre-wrap break-all bg-bambu-dark p-4 rounded-lg border border-bambu-dark-tertiary overflow-x-auto max-w-full`,children:P6(d)}):(0,K.jsx)(`div`,{className:`text-center py-16 text-bambu-gray`,children:o(`profiles.presets.failedToLoadDetails`)})}),l?(0,K.jsxs)(`div`,{className:`flex-shrink-0 p-4 border-t border-bambu-dark-tertiary bg-red-500/5`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-3 text-red-700 dark:text-red-400`,children:[(0,K.jsx)(ku,{className:`w-5 h-5`}),(0,K.jsx)(`span`,{className:`font-medium`,children:o(`profiles.presets.deleteConfirm`)})]}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mb-4`,children:o(`profiles.presets.deleteWarning`,{name:e.name})}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)($,{variant:`secondary`,onClick:()=>u(!1),disabled:p.isPending,className:`flex-1`,children:o(`common.cancel`)}),(0,K.jsxs)($,{variant:`danger`,onClick:()=>p.mutate(),disabled:p.isPending,className:`flex-1`,children:[p.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(Eu,{className:`w-4 h-4`}),o(`common.delete`)]})]})]}):(0,K.jsx)(`div`,{className:`flex-shrink-0 p-4 border-t border-bambu-dark-tertiary`,children:(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)($,{variant:`secondary`,onClick:t,className:`flex-1`,children:o(`common.close`)}),(0,K.jsxs)($,{variant:`secondary`,onClick:r,disabled:!a(`cloud:auth`),title:a(`cloud:auth`)?void 0:o(`profiles.presets.noDuplicatePermission`),children:[(0,K.jsx)(Fs,{className:`w-4 h-4`}),o(`profiles.presets.duplicate`)]}),m&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)($,{variant:`secondary`,onClick:i,disabled:f||!d||!a(`cloud:auth`),title:a(`cloud:auth`)?void 0:o(`profiles.presets.noEditPermission`),children:[(0,K.jsx)(wl,{className:`w-4 h-4`}),o(`common.edit`)]}),(0,K.jsx)($,{variant:`danger`,onClick:()=>u(!0),disabled:!a(`cloud:auth`),title:a(`cloud:auth`)?void 0:o(`profiles.presets.noDeletePermission`),children:(0,K.jsx)(Eu,{className:`w-4 h-4`})})]})]})})]})})})}function F6(){try{let e=localStorage.getItem(`bambusy_preset_templates`);return e?JSON.parse(e):[]}catch{return[]}}function I6(e){localStorage.setItem(`bambusy_preset_templates`,JSON.stringify(e))}function oWe({onClose:e,onApply:t,t:n}){let{showToast:r}=Pd(),[i,a]=(0,y.useState)(F6),[o,s]=(0,y.useState)(`all`),[c,l]=(0,y.useState)(null),[u,d]=(0,y.useState)(``),[f,p]=(0,y.useState)(``),[m,h]=(0,y.useState)(`{}`),[g,_]=(0,y.useState)(null),[v,b]=(0,y.useState)(null),x=o===`all`?i:i.filter(e=>e.type===o),S=e=>{a(e),I6(e)},C=e=>{S(i.filter(t=>t.id!==e)),b(null),r(n(`profiles.templates.toast.deleted`))},w=e=>{l(e.id),d(e.name),p(e.description),h(JSON.stringify(e.settings,null,2)),_(null)},T=()=>{if(!(!c||!u.trim()))try{let e=JSON.parse(m);S(i.map(t=>t.id===c?{...t,name:u.trim(),description:f.trim(),settings:e}:t)),l(null),r(n(`profiles.templates.toast.updated`))}catch(e){_(e.message)}},E=()=>{l(null),d(``),p(``),h(`{}`),_(null)},D=e=>{S(i.map(t=>t.id===e?{...t,showInModal:!t.showInModal}:t))},O={filament:{label:n(`profiles.presets.types.filament`),icon:Gs,color:`text-amber-600 dark:text-amber-400`},print:{label:n(`profiles.presets.types.process`),icon:Jl,color:`text-blue-600 dark:text-blue-400`},printer:{label:n(`profiles.presets.types.printer`),icon:jl,color:`text-purple-600 dark:text-purple-400`}},k=v?i.find(e=>e.id===v):null;return(0,y.useEffect)(()=>{let t=t=>{t.key===`Escape`&&(v?b(null):c?E():e())};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[v,c,e]),(0,K.jsxs)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:[k&&(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-60`,children:(0,K.jsx)(Ed,{className:`w-full max-w-md`,children:(0,K.jsxs)(Od,{className:`p-6`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3 mb-4`,children:[(0,K.jsx)(`div`,{className:`p-2 bg-red-500/20 rounded-lg`,children:(0,K.jsx)(ku,{className:`w-6 h-6 text-red-600 dark:text-red-400`})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h3`,{className:`text-lg font-semibold text-white`,children:n(`profiles.templates.deleteTitle`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`profiles.templates.deleteWarning`)})]})]}),(0,K.jsx)(`p`,{className:`text-white mb-6`,children:n(`profiles.templates.deleteConfirm`,{name:k.name})}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)($,{variant:`secondary`,onClick:()=>b(null),className:`flex-1`,children:n(`common.cancel`)}),(0,K.jsxs)($,{onClick:()=>C(v),className:`flex-1 bg-red-500 hover:bg-red-600`,children:[(0,K.jsx)(Eu,{className:`w-4 h-4`}),n(`common.delete`)]})]})]})})}),(0,K.jsx)(Ed,{className:`w-full max-w-2xl max-h-[80vh] flex flex-col`,children:(0,K.jsxs)(Od,{className:`p-0 flex flex-col h-full`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(lu,{className:`w-5 h-5 text-amber-600 dark:text-amber-400`}),n(`profiles.templates.title`)]}),(0,K.jsx)(`button`,{onClick:e,className:`text-bambu-gray hover:text-white`,children:(0,K.jsx)(qu,{className:`w-5 h-5`})})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 p-4 border-b border-bambu-dark-tertiary`,children:[(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:n(`profiles.templates.typeFilter`)}),[`all`,`filament`,`print`,`printer`].map(e=>(0,K.jsx)(`button`,{onClick:()=>s(e),className:`px-3 py-1 text-sm rounded-lg transition-colors ${o===e?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white`}`,children:e===`all`?n(`common.all`):O[e].label},e))]}),(0,K.jsx)(`div`,{className:`flex-1 overflow-y-auto p-4`,children:x.length===0?(0,K.jsxs)(`div`,{className:`text-center py-12 text-bambu-gray`,children:[(0,K.jsx)(lu,{className:`w-12 h-12 mx-auto mb-4 opacity-30`}),(0,K.jsx)(`p`,{children:n(`profiles.templates.noTemplates`)}),(0,K.jsx)(`p`,{className:`text-sm mt-1`,children:n(`profiles.templates.createFirst`)})]}):(0,K.jsx)(`div`,{className:`space-y-2`,children:x.map(e=>{let r=O[e.type],i=r.icon;return c===e.id?(0,K.jsxs)(`div`,{className:`p-4 bg-bambu-dark rounded-lg border border-bambu-green`,children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-3 mb-3`,children:[(0,K.jsx)(`input`,{type:`text`,value:u,onChange:e=>d(e.target.value),placeholder:n(`profiles.templates.namePlaceholder`),className:`px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`,autoFocus:!0}),(0,K.jsx)(`input`,{type:`text`,value:f,onChange:e=>p(e.target.value),placeholder:n(`profiles.templates.descriptionPlaceholder`),className:`px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`})]}),(0,K.jsxs)(`div`,{className:`mb-3`,children:[(0,K.jsx)(`label`,{className:`text-xs text-bambu-gray mb-1 block`,children:n(`profiles.templates.settingsJson`)}),(0,K.jsx)(`textarea`,{value:m,onChange:e=>{h(e.target.value),_(null)},rows:6,className:`w-full px-3 py-2 bg-bambu-dark-secondary border rounded text-white text-sm font-mono focus:outline-none ${g?`border-red-500`:`border-bambu-dark-tertiary focus:border-bambu-green`}`}),g&&(0,K.jsx)(`p`,{className:`text-xs text-red-700 dark:text-red-400 mt-1`,children:g})]}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsxs)($,{size:`sm`,onClick:T,disabled:!u.trim(),children:[(0,K.jsx)(zl,{className:`w-4 h-4`}),`Save`]}),(0,K.jsx)($,{size:`sm`,variant:`secondary`,onClick:E,children:`Cancel`})]})]},e.id):(0,K.jsxs)(`div`,{className:`flex items-center gap-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary hover:border-bambu-gray-dark transition-colors`,children:[(0,K.jsx)(i,{className:`w-5 h-5 ${r.color} flex-shrink-0`}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsx)(`p`,{className:`text-sm font-medium text-white`,children:e.name}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray truncate`,children:e.description})]}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray-dark px-2 py-1 bg-bambu-dark-secondary rounded`,children:n(`profiles.templates.fieldsCount`,{count:Object.keys(e.settings).length})}),(0,K.jsx)(`button`,{onClick:()=>D(e.id),className:`p-1 transition-colors ${e.showInModal?`text-bambu-green hover:text-bambu-green/70`:`text-bambu-gray hover:text-white`}`,title:e.showInModal?n(`profiles.templates.shownInModals`):n(`profiles.templates.hiddenInModals`),children:e.showInModal?(0,K.jsx)($s,{className:`w-4 h-4`}):(0,K.jsx)(Qs,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>t(e),className:`px-3 py-1 text-xs bg-bambu-green/20 text-bambu-green rounded hover:bg-bambu-green/30 transition-colors`,children:n(`profiles.templates.apply`)}),(0,K.jsx)(`button`,{onClick:()=>w(e),className:`p-1 text-bambu-gray hover:text-white`,title:n(`common.edit`),children:(0,K.jsx)(wl,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>b(e.id),className:`p-1 text-bambu-gray hover:text-red-600 dark:hover:text-red-400`,title:n(`common.delete`),children:(0,K.jsx)(Eu,{className:`w-4 h-4`})})]},e.id)})})})]})})]})}function L6({onClose:e,leftPreset:t,rightPreset:n,leftLabel:r,rightLabel:i,t:a}){let[o,s]=(0,y.useState)(`changes`),[c,l]=(0,y.useState)(``),u=(0,y.useMemo)(()=>{let e=new Set([...Object.keys(t),...Object.keys(n)]),r=[];for(let i of e){if(i===`inherits`||i===`version`)continue;let e=t[i],a=n[i],o=i in t,s=i in n,c;c=!o&&s?`added`:o&&!s?`removed`:JSON.stringify(e)===JSON.stringify(a)?`same`:`changed`,r.push({key:i,left:e,right:a,status:c})}return r.sort((e,t)=>{let n={changed:0,added:1,removed:2,same:3};return n[e.status]===n[t.status]?e.key.localeCompare(t.key):n[e.status]-n[t.status]})},[t,n]),d=(0,y.useMemo)(()=>{let e=[...u];if(o===`changes`&&(e=e.filter(e=>e.status!==`same`)),c){let t=c.toLowerCase();e=e.filter(e=>e.key.toLowerCase().includes(t)||String(e.left).toLowerCase().includes(t)||String(e.right).toLowerCase().includes(t))}return e},[u,o,c]),f=(0,y.useMemo)(()=>({added:u.filter(e=>e.status===`added`).length,removed:u.filter(e=>e.status===`removed`).length,changed:u.filter(e=>e.status===`changed`).length,same:u.filter(e=>e.status===`same`).length}),[u]),p=e=>{if(e===void 0)return`—`;if(e===null)return`null`;if(Array.isArray(e))return e.length===0?`[]`:e.length===1?String(e[0]):e.join(`, `);if(typeof e==`object`)return JSON.stringify(e);let t=String(e);if(t.includes(`\\n`)||t.length>100){let e=t.split(`\\n`).length;if(e>1)return`[${e} lines of G-code/script]`;if(t.length>100)return t.substring(0,100)+`…`}return t};return(0,y.useEffect)(()=>{let t=t=>{t.key===`Escape`&&e()};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e]),(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:(0,K.jsx)(Ed,{className:`w-full max-w-4xl max-h-[85vh] flex flex-col overflow-hidden`,children:(0,K.jsxs)(Od,{className:`p-0 flex flex-col min-h-0 flex-1`,children:[(0,K.jsxs)(`div`,{className:`flex-shrink-0 flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(xc,{className:`w-5 h-5 text-blue-600 dark:text-blue-400`}),a(`profiles.diff.title`)]}),(0,K.jsx)(`button`,{onClick:e,className:`text-bambu-gray hover:text-white`,children:(0,K.jsx)(qu,{className:`w-5 h-5`})})]}),(0,K.jsxs)(`div`,{className:`flex-shrink-0 grid grid-cols-2 gap-4 p-4 border-b border-bambu-dark-tertiary bg-bambu-dark`,children:[(0,K.jsxs)(`div`,{className:`text-center`,children:[(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:a(`profiles.diff.left`)}),(0,K.jsx)(`p`,{className:`text-white font-medium truncate`,children:r})]}),(0,K.jsxs)(`div`,{className:`text-center`,children:[(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:a(`profiles.diff.right`)}),(0,K.jsx)(`p`,{className:`text-white font-medium truncate`,children:i})]})]}),(0,K.jsxs)(`div`,{className:`flex-shrink-0 flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-4 text-sm`,children:[(0,K.jsxs)(`span`,{className:`flex items-center gap-1 text-green-700 dark:text-green-400`,children:[(0,K.jsx)(Ol,{className:`w-3.5 h-3.5`}),f.added,` `,a(`profiles.diff.added`)]}),(0,K.jsxs)(`span`,{className:`flex items-center gap-1 text-red-700 dark:text-red-400`,children:[(0,K.jsx)(cl,{className:`w-3.5 h-3.5`}),f.removed,` `,a(`profiles.diff.removed`)]}),(0,K.jsxs)(`span`,{className:`flex items-center gap-1 text-amber-700 dark:text-amber-400`,children:[(0,K.jsx)(Io,{className:`w-3.5 h-3.5`}),f.changed,` `,a(`profiles.diff.changed`)]}),(0,K.jsxs)(`span`,{className:`flex items-center gap-1 text-bambu-gray`,children:[(0,K.jsx)(Ys,{className:`w-3.5 h-3.5`}),f.same,` `,a(`profiles.diff.same`)]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(Wl,{className:`absolute left-2 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,K.jsx)(`input`,{type:`text`,value:c,onChange:e=>l(e.target.value),placeholder:a(`profiles.diff.searchFields`),className:`pl-8 pr-3 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none w-48`})]}),f.same>0&&(0,K.jsxs)(`div`,{className:`flex rounded overflow-hidden border border-bambu-dark-tertiary`,children:[(0,K.jsx)(`button`,{onClick:()=>s(`changes`),className:`px-3 py-1.5 text-sm transition-colors ${o===`changes`?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white`}`,children:a(`profiles.diff.changes`)}),(0,K.jsx)(`button`,{onClick:()=>s(`all`),className:`px-3 py-1.5 text-sm transition-colors ${o===`all`?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white`}`,children:a(`common.all`)})]})]})]}),(0,K.jsx)(`div`,{className:`flex-1 min-h-0 overflow-y-auto`,children:d.length===0?(0,K.jsxs)(`div`,{className:`text-center py-12 text-bambu-gray`,children:[(0,K.jsx)(Ys,{className:`w-12 h-12 mx-auto mb-4 opacity-30`}),(0,K.jsx)(`p`,{children:a(o===`changes`?`profiles.diff.noDifferences`:`profiles.diff.noFieldsMatch`)})]}):(0,K.jsxs)(`table`,{className:`w-full`,children:[(0,K.jsx)(`thead`,{className:`sticky top-0 bg-bambu-dark-secondary`,children:(0,K.jsxs)(`tr`,{className:`text-sm text-bambu-gray border-b border-bambu-dark-tertiary`,children:[(0,K.jsx)(`th`,{className:`text-left p-3 w-1/3`,children:a(`profiles.diff.field`)}),(0,K.jsx)(`th`,{className:`text-left p-3 w-1/3`,children:r}),(0,K.jsx)(`th`,{className:`text-left p-3 w-1/3`,children:i})]})}),(0,K.jsx)(`tbody`,{children:d.map(e=>{let t={added:`bg-green-500/10`,removed:`bg-red-500/10`,changed:`bg-amber-500/10`,same:``}[e.status],n={added:(0,K.jsx)(Ol,{className:`w-3.5 h-3.5 text-green-600 dark:text-green-400`}),removed:(0,K.jsx)(cl,{className:`w-3.5 h-3.5 text-red-600 dark:text-red-400`}),changed:(0,K.jsx)(Io,{className:`w-3.5 h-3.5 text-amber-600 dark:text-amber-400`}),same:(0,K.jsx)(Ys,{className:`w-3.5 h-3.5 text-bambu-gray-dark`})}[e.status];return(0,K.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary ${t}`,children:[(0,K.jsx)(`td`,{className:`p-3`,children:(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[n,(0,K.jsx)(`span`,{className:`text-sm text-white font-mono`,children:e.key})]})}),(0,K.jsx)(`td`,{className:`p-3`,children:(0,K.jsx)(`span`,{className:`text-sm font-mono break-all ${e.status===`removed`?`text-red-700 dark:text-red-300`:e.status===`changed`?`text-white`:`text-bambu-gray`}`,children:p(e.left)})}),(0,K.jsx)(`td`,{className:`p-3`,children:(0,K.jsx)(`span`,{className:`text-sm font-mono break-all ${e.status===`added`?`text-green-700 dark:text-green-300`:e.status===`changed`?`text-white`:`text-bambu-gray`}`,children:p(e.right)})})]},e.key)})})]})})]})})})}function sWe({onClose:e,initialData:t,allPresets:n,t:r}){let{showToast:i}=Pd(),a=oo(),o=!!t?.setting_id,[s,c]=(0,y.useState)(`common`),[l,u]=(0,y.useState)(t?.type||`filament`),[d,f]=(0,y.useState)(t?.name?o?t.name:`${t.name} (Copy)`:``),[p,m]=(0,y.useState)(t?.base_id||``),[h,g]=(0,y.useState)(``),[_,v]=(0,y.useState)(t?.setting||{inherits:``}),[b,x]=(0,y.useState)(JSON.stringify(t?.setting||{inherits:``},null,2)),[S,C]=(0,y.useState)(null),[w,T]=(0,y.useState)(``),[E,D]=(0,y.useState)(!1),[O,k]=(0,y.useState)(``),[A,j]=(0,y.useState)(!1),[M,N]=(0,y.useState)(F6),[P,F]=(0,y.useState)(!1),[I,L]=(0,y.useState)(``),[R,z]=(0,y.useState)(``),[B,V]=(0,y.useState)(!0),[ee,te]=(0,y.useState)(null),[ne,re]=(0,y.useState)(!1),ie=(0,y.useMemo)(()=>({filament:n.filament,print:n.process,printer:n.printer})[l]||[],[n,l]),H=(0,y.useMemo)(()=>ie.filter(e=>j6(e.setting_id)),[ie]),{data:ae}=q({queryKey:[`cloudFields`,l],queryFn:()=>Q.getCloudFields(l===`print`?`process`:l),staleTime:1e3*60*60}),{data:oe}=q({queryKey:[`allPresetDetails`,l,H.map(e=>e.setting_id).join(`,`)],queryFn:async()=>{let e={};for(let t=0;t{try{let t=await Q.getCloudSettingDetail(e.setting_id);return{id:e.setting_id,detail:t}}catch{return null}}))).forEach(t=>{t&&(e[t.id]=t.detail)})}return e},enabled:H.length>0,staleTime:1e3*60*10}),{data:U,isLoading:se}=q({queryKey:[`cloudSettingDetail`,p],queryFn:()=>Q.getCloudSettingDetail(p),enabled:!!p});(0,y.useEffect)(()=>{s!==`json`&&x(JSON.stringify(_,null,2))},[_,s]);let ce=(0,y.useMemo)(()=>({filament:n.filament,print:n.process,printer:n.printer}[l]||[]).filter(e=>!j6(e.setting_id)).sort((e,t)=>e.name.localeCompare(t.name)),[n,l]);(0,y.useEffect)(()=>{if(!p)return;let e=ce.find(e=>e.setting_id===p);e&&(g(e.name),o||(v({inherits:e.name}),x(JSON.stringify({inherits:e.name},null,2))))},[p,ce,o]);let le=(0,y.useMemo)(()=>{let e=ae?.fields||[],t=new Set(e.map(e=>e.key)),n=new Set,i=new Set([`inherits`,`updated_time`,`compatible_printers`,`compatible_prints`]);oe&&Object.values(oe).forEach(e=>{e?.setting&&Object.keys(e.setting).forEach(e=>{!t.has(e)&&!i.has(e)&&n.add(e)})}),Object.keys(_).forEach(e=>{!t.has(e)&&!i.has(e)&&n.add(e)});let a=Array.from(n).sort().map(e=>({key:e,label:e.replace(/_/g,` `).replace(/\b\w/g,e=>e.toUpperCase()),type:`text`,category:`discovered`,description:r(`profiles.presets.discoveredFromPresets`)}));return[...e,...a]},[ae,oe,_,r]),ue=le.filter(e=>e.label.toLowerCase().includes(w.toLowerCase())||e.key.toLowerCase().includes(w.toLowerCase())),de=()=>{if(O.trim()){let e=O.trim().toLowerCase().replace(/\s+/g,`_`);fe(e,``),k(``),j(!1),i(r(`profiles.presets.toast.fieldAdded`,{key:e}))}},fe=(e,t)=>{v(n=>{let r={...n};return t===``||t===void 0?delete r[e]:r[e]=t,r})},pe=e=>{v(t=>({...t,...e.settings})),te(e.name),i(r(`profiles.templates.toast.applied`))},me=()=>{if(!I.trim())return;let e={..._};if(delete e.inherits,Object.keys(e).length===0){i(r(`profiles.presets.noOverridesToSave`),`error`);return}let t={id:Date.now().toString(),name:I.trim(),description:R.trim()||r(`profiles.presets.customTemplate`),type:l,settings:e,showInModal:B},n=[...M,t];N(n),I6(n),F(!1),L(``),z(``),V(!0),i(r(`profiles.templates.toast.created`))},he=(0,y.useMemo)(()=>M.filter(e=>e.type===l&&e.showInModal),[l,M]),ge=e=>{x(e);try{v(JSON.parse(e)),C(null)}catch(e){C(e.message)}},_e=e=>{e.preventDefault(),D(!1);let t=e.dataTransfer.files[0];if(t&&t.name.endsWith(`.json`)){let e=new FileReader;e.onload=e=>{try{let t=e.target?.result,n=JSON.parse(t),a=n.setting||n;v(e=>({...e,...a})),x(JSON.stringify({..._,...a},null,2)),i(r(`profiles.presets.fileImported`))}catch{i(r(`profiles.presets.invalidJsonFile`),`error`)}},e.readAsText(t)}},ve=J({mutationFn:()=>{let e={..._},t=l===`filament`?`filament_settings_id`:l===`print`?`print_settings_id`:`printer_settings_id`;e[t]=`"${d}"`;let n={type:l,name:d,base_id:p,setting:e};return Q.createCloudSetting(n)},onSuccess:async()=>{i(r(`profiles.presets.toast.created`)),await a.refetchQueries({queryKey:[`cloudSettings`]}),e()},onError:e=>i(e.message,`error`)}),ye=J({mutationFn:()=>{if(!t?.setting_id)throw Error(r(`profiles.presets.noSettingId`));return Q.updateCloudSetting(t.setting_id,{name:d,setting:_})},onSuccess:async()=>{i(r(`profiles.presets.toast.updated`)),a.removeQueries({queryKey:[`cloudSettingDetail`]}),await a.refetchQueries({queryKey:[`cloudSettings`]}),e()},onError:e=>i(e.message,`error`)}),be=o?ye:ve,xe=U?.setting?.inherits,Se=xe?ce.find(e=>e.name===xe):void 0,{data:Ce}=q({queryKey:[`cloudSettingDetail`,Se?.setting_id],queryFn:()=>Q.getCloudSettingDetail(Se.setting_id),enabled:!!Se?.setting_id}),we=(0,y.useMemo)(()=>{let e=Ce?.setting||{},t=U?.setting||{},n=p&&oe?.[p]?.setting?oe[p].setting:{};return{...e,...t,...n}},[p,U,Ce,oe]),Te=e=>{if(e==null)return``;if(Array.isArray(e)){let t=[...new Set(e.map(e=>String(e)))];return t.length===1?t[0]:e.join(`, `)}return String(e)},Ee=e=>{let t=_[e.key],n=we[e.key],i=Te(n),a=se?r(`common.loading`):i||``,o=`w-full px-3 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`;if(e.type===`boolean`){let r=t===`1`||t===void 0&&n===`1`;return(0,K.jsx)(`button`,{type:`button`,onClick:()=>fe(e.key,t===`1`?`0`:`1`),className:`w-8 h-5 rounded-full transition-colors ${r?`bg-bambu-green`:`bg-bambu-dark-tertiary`}`,children:(0,K.jsx)(`div`,{className:`w-4 h-4 rounded-full bg-white shadow transition-transform ${r?`translate-x-3.5`:`translate-x-0.5`}`})})}return e.type===`select`?(0,K.jsxs)(`select`,{value:t||``,onChange:t=>fe(e.key,t.target.value),className:o,children:[(0,K.jsx)(`option`,{value:``,children:a}),e.options?.map(e=>(0,K.jsx)(`option`,{value:e.value,children:e.label},e.value))]}):(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`input`,{type:e.type===`number`?`number`:`text`,value:t===void 0?``:String(t),onChange:t=>fe(e.key,t.target.value),step:e.step,min:e.min,max:e.max,placeholder:a,className:o}),e.unit&&(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray whitespace-nowrap`,children:e.unit})]})},De=(0,y.useMemo)(()=>U?.setting?U.setting:{},[U]);return(0,K.jsxs)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,onDragOver:e=>{e.preventDefault(),D(!0)},onDragLeave:()=>D(!1),onDrop:_e,children:[ne&&p&&(0,K.jsx)(L6,{onClose:()=>re(!1),leftPreset:De,rightPreset:_,leftLabel:r(`profiles.presets.baseLabel`,{name:h||p}),rightLabel:r(`profiles.presets.currentLabel`,{name:d||r(`profiles.presets.newPreset`)}),t:r}),(0,K.jsx)(Ed,{className:`w-full max-w-6xl max-h-[90vh] flex flex-col overflow-y-auto`,children:(0,K.jsxs)(Od,{className:`p-0 flex flex-col h-full`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h2`,{className:`text-xl font-semibold text-white`,children:r(o?`profiles.presets.editPreset`:t?`profiles.presets.duplicatePreset`:`profiles.presets.createNewPreset`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:r(`profiles.presets.customizeSettings`)})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[p&&(0,K.jsxs)(`button`,{onClick:()=>re(!0),className:`flex items-center gap-2 px-3 py-2 text-sm text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary rounded-lg transition-colors`,title:r(`profiles.presets.compareWithBase`),children:[(0,K.jsx)(xc,{className:`w-4 h-4`}),r(`profiles.presets.compare`)]}),(0,K.jsx)(`button`,{onClick:e,className:`p-2 text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary rounded-lg transition-colors`,children:(0,K.jsx)(qu,{className:`w-5 h-5`})})]})]}),E&&(0,K.jsx)(`div`,{className:`absolute inset-0 bg-bambu-green/10 border-2 border-dashed border-bambu-green rounded-lg flex items-center justify-center z-10`,children:(0,K.jsxs)(`div`,{className:`text-center`,children:[(0,K.jsx)(Nu,{className:`w-12 h-12 text-bambu-green mx-auto mb-2`}),(0,K.jsx)(`p`,{className:`text-bambu-green font-medium`,children:r(`profiles.presets.dropJsonToImport`)})]})}),(0,K.jsxs)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary space-y-3`,children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-3 gap-4 max-[640px]:grid-cols-1`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`common.type`)}),(0,K.jsxs)(`select`,{value:l,onChange:e=>{u(e.target.value),m(``)},className:`w-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:[(0,K.jsx)(`option`,{value:`filament`,children:r(`profiles.presets.types.filament`)}),(0,K.jsx)(`option`,{value:`print`,children:r(`profiles.presets.types.process`)}),(0,K.jsx)(`option`,{value:`printer`,children:r(`profiles.presets.types.printer`)})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`profiles.presets.basePreset`)}),(0,K.jsxs)(`select`,{value:p,onChange:e=>m(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,children:[(0,K.jsx)(`option`,{value:``,children:r(`profiles.presets.selectBasePreset`)}),ce.map(e=>(0,K.jsx)(`option`,{value:e.setting_id,children:e.name},e.setting_id))]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`profiles.presets.presetName`)}),(0,K.jsx)(`input`,{type:`text`,value:d,onChange:e=>f(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,placeholder:r(`profiles.presets.myCustomPreset`)})]})]}),h&&(0,K.jsx)(`div`,{className:`text-xs text-bambu-gray`,children:(0,K.jsxs)(`p`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(as,{className:`w-3 h-3 text-bambu-green`}),r(`profiles.presets.inheritsFrom`),` `,(0,K.jsx)(`span`,{className:`text-white`,children:h}),se&&(0,K.jsx)(X,{className:`w-3 h-3 animate-spin ml-1`})]})})]}),(0,K.jsxs)(`div`,{className:`flex border-b border-bambu-dark-tertiary max-[640px]:flex-wrap max-[640px]:items-center`,children:[(0,K.jsxs)(`button`,{onClick:()=>c(`common`),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${s===`common`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-white border-transparent`}`,children:[(0,K.jsx)(au,{className:`w-4 h-4`}),r(`profiles.presets.tabs.common`)]}),(0,K.jsxs)(`button`,{onClick:()=>c(`fields`),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${s===`fields`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-white border-transparent`}`,children:[(0,K.jsx)(Jc,{className:`w-4 h-4`}),r(`profiles.presets.tabs.allFields`)]}),(0,K.jsxs)(`button`,{onClick:()=>c(`json`),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${s===`json`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-white border-transparent`}`,children:[(0,K.jsx)(ks,{className:`w-4 h-4`}),`JSON`,S&&(0,K.jsx)(ps,{className:`w-3 h-3 text-red-600 dark:text-red-400`})]}),(0,K.jsx)(`div`,{className:`flex-1 max-[640px]:hidden`}),(0,K.jsxs)(`button`,{onClick:()=>{let e=new Blob([JSON.stringify({name:d,type:l,base_id:p,setting:_},null,2)],{type:`application/json`}),t=URL.createObjectURL(e),n=document.createElement(`a`);n.href=t,n.download=`${d||`preset`}.json`,document.body.appendChild(n),n.click(),document.body.removeChild(n),URL.revokeObjectURL(t),i(r(`profiles.presets.toast.exported`))},className:`flex items-center gap-2 px-4 py-3 text-sm text-bambu-gray hover:text-white transition-colors`,title:r(`profiles.presets.exportToJson`),children:[(0,K.jsx)(Ws,{className:`w-4 h-4`}),r(`common.download`)]}),(0,K.jsxs)(`button`,{onClick:()=>document.getElementById(`file-import`)?.click(),className:`flex items-center gap-2 px-4 py-3 text-sm text-bambu-gray hover:text-white transition-colors`,title:r(`profiles.presets.importFromJson`),children:[(0,K.jsx)(Nu,{className:`w-4 h-4`}),r(`common.upload`)]}),(0,K.jsx)(`input`,{id:`file-import`,type:`file`,accept:`.json`,className:`hidden`,onChange:e=>{let t=e.target.files?.[0];if(t){let e=new FileReader;e.onload=e=>{try{let t=JSON.parse(e.target?.result),n=t.setting||t;v(e=>({...e,...n})),i(r(`profiles.presets.fileImported`))}catch{i(r(`profiles.presets.invalidJson`),`error`)}},e.readAsText(t)}}})]}),(0,K.jsxs)(`div`,{className:`flex-1 p-4`,children:[s===`common`&&(0,K.jsxs)(`div`,{className:`space-y-6`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,K.jsxs)(`h3`,{className:`text-sm font-medium text-white flex items-center gap-2`,children:[(0,K.jsx)(lu,{className:`w-4 h-4 text-amber-600 dark:text-amber-400`}),r(`profiles.templates.title`)]}),Object.keys(_).filter(e=>e!==`inherits`).length>0&&(0,K.jsxs)(`button`,{onClick:()=>F(!P),className:`text-xs text-bambu-gray hover:text-white flex items-center gap-1 transition-colors`,children:[(0,K.jsx)(zl,{className:`w-3 h-3`}),r(`profiles.presets.saveAsTemplate`)]})]}),P&&(0,K.jsxs)(`div`,{className:`mb-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-2 mb-2`,children:[(0,K.jsx)(`input`,{type:`text`,value:I,onChange:e=>L(e.target.value),placeholder:r(`profiles.templates.namePlaceholder`),className:`px-3 py-1.5 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`,autoFocus:!0}),(0,K.jsx)(`input`,{type:`text`,value:R,onChange:e=>z(e.target.value),placeholder:r(`profiles.templates.descriptionPlaceholder`),className:`px-3 py-1.5 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsxs)($,{size:`sm`,onClick:me,disabled:!I.trim(),children:[(0,K.jsx)(zl,{className:`w-3 h-3`}),r(`common.save`)]}),(0,K.jsx)($,{size:`sm`,variant:`secondary`,onClick:()=>F(!1),children:r(`common.cancel`)})]}),(0,K.jsxs)(`button`,{onClick:()=>V(!B),className:`flex items-center gap-1.5 text-xs transition-colors ${B?`text-bambu-green`:`text-bambu-gray hover:text-white`}`,children:[B?(0,K.jsx)($s,{className:`w-3.5 h-3.5`}):(0,K.jsx)(Qs,{className:`w-3.5 h-3.5`}),r(B?`profiles.templates.shownInModals`:`profiles.templates.hiddenInModals`)]})]})]}),ee&&(0,K.jsxs)(`div`,{className:`mb-3 px-3 py-2 bg-bambu-green/10 border border-bambu-green/30 rounded-lg flex items-center gap-2`,children:[(0,K.jsx)(as,{className:`w-4 h-4 text-bambu-green`}),(0,K.jsxs)(`span`,{className:`text-sm text-bambu-green`,children:[r(`profiles.presets.templateApplied`),` `,(0,K.jsx)(`span`,{className:`font-medium`,children:ee})]}),(0,K.jsx)(`button`,{onClick:()=>te(null),className:`ml-auto text-bambu-green/70 hover:text-bambu-green`,children:(0,K.jsx)(qu,{className:`w-4 h-4`})})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-3 gap-2`,children:[he.map(e=>(0,K.jsxs)(`button`,{onClick:()=>pe(e),className:`p-3 text-left bg-bambu-dark border border-bambu-dark-tertiary rounded-lg hover:border-bambu-gray-dark transition-colors`,children:[(0,K.jsx)(`p`,{className:`text-sm font-medium text-white`,children:e.name}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e.description})]},e.id)),he.length===0&&(0,K.jsx)(`p`,{className:`col-span-3 text-center text-bambu-gray text-sm py-4`,children:r(`profiles.presets.noTemplatesSelected`)})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray-dark mt-2 text-center`,children:r(`profiles.presets.manageTemplatesHint`)})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h3`,{className:`text-sm font-medium text-white mb-3`,children:r(`profiles.presets.commonSettings`)}),(0,K.jsx)(`div`,{className:`grid grid-cols-2 gap-x-6 gap-y-3`,children:le.slice(0,10).map(e=>(0,K.jsxs)(`div`,{className:`flex items-center justify-between gap-4 max-[640px]:flex-col max-[640px]:items-start`,children:[(0,K.jsx)(`label`,{className:`text-sm text-bambu-gray flex-shrink-0`,children:e.label}),(0,K.jsx)(`div`,{className:`w-48 max-[640px]:w-full`,children:Ee(e)})]},e.key))})]}),Object.keys(_).length>1&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h3`,{className:`text-sm font-medium text-white mb-3`,children:r(`profiles.presets.currentOverrides`)}),(0,K.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:Object.entries(_).filter(([e])=>e!==`inherits`).map(([e,t])=>(0,K.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-2 py-1 bg-bambu-green/10 text-bambu-green text-xs rounded`,children:[e,`: `,String(t).slice(0,20),(0,K.jsx)(`button`,{onClick:()=>fe(e,void 0),className:`hover:text-white`,children:(0,K.jsx)(qu,{className:`w-3 h-3`})})]},e))})]})]}),s===`fields`&&(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-6`,style:{height:`400px`},children:[(0,K.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-3 flex-shrink-0`,children:[(0,K.jsx)(`h3`,{className:`text-sm font-medium text-white`,children:r(`profiles.presets.availableFields`)}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:oe?r(`profiles.templates.fieldsCount`,{count:le.length}):r(`common.loading`)})]}),(0,K.jsxs)(`div`,{className:`relative mb-3 flex-shrink-0`,children:[(0,K.jsx)(Wl,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,K.jsx)(`input`,{type:`text`,value:w,onChange:e=>T(e.target.value),placeholder:r(`profiles.presets.searchFieldsPlaceholder`),className:`w-full pl-10 pr-4 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none`})]}),(0,K.jsxs)(`div`,{className:`flex-1 overflow-y-auto space-y-1 pr-2 min-h-0`,children:[ue.filter(e=>!(e.key in _)).map(e=>{let t=we[e.key],n=Te(t);return(0,K.jsxs)(`div`,{onClick:()=>{v(t=>({...t,[e.key]:n||``}))},className:`flex items-center justify-between gap-2 p-2 rounded-lg hover:bg-bambu-dark-tertiary transition-colors cursor-pointer group`,children:[(0,K.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,K.jsx)(`p`,{className:`text-sm text-white truncate`,children:e.label}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray-dark truncate`,children:e.key})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 flex-shrink-0`,children:[n&&(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray bg-bambu-dark px-2 py-0.5 rounded max-w-32 truncate`,title:n,children:[n.slice(0,20),n.length>20?`...`:``]}),(0,K.jsx)(`div`,{className:`w-6 h-6 flex items-center justify-center rounded bg-bambu-dark-tertiary group-hover:bg-bambu-green/20 transition-colors`,children:(0,K.jsx)(Ol,{className:`w-4 h-4 text-bambu-gray group-hover:text-bambu-green transition-colors`})})]})]},e.key)}),ue.filter(e=>!(e.key in _)).length===0&&(0,K.jsx)(`p`,{className:`text-center text-bambu-gray py-4 text-sm`,children:r(w?`profiles.presets.noMatchingFields`:`profiles.presets.allFieldsAdded`)})]}),(0,K.jsx)(`div`,{className:`pt-3 mt-3 border-t border-bambu-dark-tertiary flex-shrink-0`,children:A?(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)(`input`,{type:`text`,value:O,onChange:e=>k(e.target.value),onKeyDown:e=>e.key===`Enter`&&de(),placeholder:`custom_field_name`,className:`flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white font-mono text-sm placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none`,autoFocus:!0}),(0,K.jsx)($,{size:`sm`,onClick:de,disabled:!O.trim(),children:(0,K.jsx)(Ol,{className:`w-4 h-4`})}),(0,K.jsx)($,{size:`sm`,variant:`secondary`,onClick:()=>{j(!1),k(``)},children:(0,K.jsx)(qu,{className:`w-4 h-4`})})]}):(0,K.jsxs)(`button`,{onClick:()=>j(!0),className:`w-full flex items-center justify-center gap-2 p-2 text-sm text-bambu-gray hover:text-white border border-dashed border-bambu-dark-tertiary hover:border-bambu-gray-dark rounded-lg transition-colors`,children:[(0,K.jsx)(Ol,{className:`w-4 h-4`}),r(`profiles.presets.addCustomField`)]})})]}),(0,K.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-3 flex-shrink-0`,children:[(0,K.jsx)(`h3`,{className:`text-sm font-medium text-white`,children:r(`profiles.presets.yourOverrides`)}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:r(`profiles.templates.fieldsCount`,{count:Object.keys(_).filter(e=>e!==`inherits`).length})})]}),(0,K.jsxs)(`div`,{className:`flex-1 overflow-y-auto space-y-2 pr-2 min-h-0`,children:[Object.entries(_).filter(([e])=>e!==`inherits`).map(([e,t])=>{let n=le.find(t=>t.key===e);return(0,K.jsxs)(`div`,{className:`p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-sm font-medium text-white`,children:n?.label||e}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray-dark`,children:e})]}),(0,K.jsx)(`button`,{onClick:()=>fe(e,void 0),className:`p-1 text-bambu-gray hover:text-red-600 dark:hover:text-red-400 transition-colors`,children:(0,K.jsx)(qu,{className:`w-4 h-4`})})]}),n?Ee(n):(0,K.jsx)(`input`,{type:`text`,value:String(t),onChange:t=>fe(e,t.target.value),className:`w-full px-3 py-1.5 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`})]},e)}),Object.keys(_).filter(e=>e!==`inherits`).length===0&&(0,K.jsxs)(`div`,{className:`text-center py-8 text-bambu-gray`,children:[(0,K.jsx)(au,{className:`w-8 h-8 mx-auto mb-2 opacity-50`}),(0,K.jsx)(`p`,{className:`text-sm`,children:r(`profiles.presets.noOverridesYet`)}),(0,K.jsx)(`p`,{className:`text-xs mt-1`,children:r(`profiles.presets.clickFieldsToAdd`)})]})]}),Object.keys(_).filter(e=>e!==`inherits`).length>0&&(0,K.jsx)(`div`,{className:`pt-3 mt-3 border-t border-bambu-dark-tertiary flex-shrink-0`,children:(0,K.jsxs)(`button`,{onClick:()=>{F(!0),c(`common`)},className:`w-full flex items-center justify-center gap-2 p-2 text-sm text-bambu-gray hover:text-white border border-dashed border-bambu-dark-tertiary hover:border-bambu-gray-dark rounded-lg transition-colors`,children:[(0,K.jsx)(zl,{className:`w-4 h-4`}),r(`profiles.presets.saveAsTemplate`)]})})]})]}),s===`json`&&(0,K.jsxs)(`div`,{className:`space-y-2`,children:[S&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-red-700 dark:text-red-400 text-sm`,children:[(0,K.jsx)(ps,{className:`w-4 h-4`}),S]}),(0,K.jsx)(`textarea`,{value:b,onChange:e=>ge(e.target.value),className:`w-full h-80 px-3 py-2 bg-bambu-dark border rounded-lg text-white text-xs font-mono focus:outline-none resize-none ${S?`border-red-500 focus:border-red-500`:`border-bambu-dark-tertiary focus:border-bambu-green`}`,spellCheck:!1}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:r(`profiles.presets.jsonTip`)})]})]}),(0,K.jsxs)(`div`,{className:`p-4 border-t border-bambu-dark-tertiary flex gap-2`,children:[(0,K.jsx)($,{variant:`secondary`,onClick:e,className:`flex-1`,children:r(`common.cancel`)}),(0,K.jsxs)($,{onClick:()=>be.mutate(),disabled:be.isPending||!d.trim()||!o&&!p||!!S,className:`flex-1`,children:[be.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):o?(0,K.jsx)(zl,{className:`w-4 h-4`}):(0,K.jsx)(Ol,{className:`w-4 h-4`}),r(o?`common.save`:t?`common.duplicate`:`common.create`)]})]})]})})]})}function cWe({settings:e,lastSyncTime:t,onRefresh:n,isRefreshing:r,printers:i,hasPermission:a,t:o}){let[s,c]=(0,y.useState)(``),[l,u]=(0,y.useState)(`all`),[d,f]=(0,y.useState)(`all`),[p,m]=(0,y.useState)(`all`),[h,g]=(0,y.useState)(`all`),[_,v]=(0,y.useState)(`all`),[b,x]=(0,y.useState)(`all`),[S,C]=(0,y.useState)(null),[w,T]=(0,y.useState)(!1),[E,D]=(0,y.useState)(!1),[O,k]=(0,y.useState)(null),[A,j]=(0,y.useState)(null),[M,N]=(0,y.useState)(null),[P,F]=(0,y.useState)(!1),[I,L]=(0,y.useState)([null,null]),[R,z]=(0,y.useState)(!1),[B,V]=(0,y.useState)(null),ee=oo(),te=(0,y.useMemo)(()=>[...e.filament.map(e=>({...e,type:`filament`})),...e.printer.map(e=>({...e,type:`printer`})),...e.process.map(e=>({...e,type:`process`}))].map(e=>({...e,meta:A6(e.name)})),[e]),ne=(0,y.useMemo)(()=>{let e=new Set,t=new Set,n=new Set;return te.forEach(r=>{r.meta.nozzle&&e.add(r.meta.nozzle),r.meta.filamentType&&t.add(r.meta.filamentType),r.meta.layerHeight&&n.add(r.meta.layerHeight)}),{printers:i.map(e=>({id:e.id.toString(),name:e.name})),nozzles:Array.from(e).sort((e,t)=>parseFloat(e)-parseFloat(t)),filaments:Array.from(t).sort(),layerHeights:Array.from(n).sort((e,t)=>parseFloat(e)-parseFloat(t))}},[te,i]),re=(0,y.useMemo)(()=>p===`all`?null:i.find(e=>e.id.toString()===p)?.model||null,[p,i]),ie=(0,y.useMemo)(()=>te.filter(e=>l===`all`||e.type===l).filter(e=>{if(d===`all`)return!0;let t=j6(e.setting_id);return d===`custom`?t:!t}).filter(e=>{if(p===`all`||!re)return!0;let t=e.meta.printer?.toLowerCase()||``,n=re.toLowerCase();return t.includes(n)||n.includes(t)}).filter(e=>h===`all`||e.meta.nozzle===h).filter(e=>_===`all`||e.meta.filamentType===_).filter(e=>b===`all`||e.meta.layerHeight===b).filter(e=>s===``||e.name.toLowerCase().includes(s.toLowerCase())).sort((e,t)=>e.name.localeCompare(t.name)),[te,l,d,p,re,h,_,b,s]),H=e=>{if(P){let t=I[0]?.setting_id===e.setting_id,n=I[1]?.setting_id===e.setting_id;if(t)L([I[1],null]);else if(n)L([I[0],null]);else if(!I[0])L([e,null]);else if(I[1]){if(I[0].type!==e.type)return;L([I[0],e])}else{if(I[0].type!==e.type)return;L([I[0],e])}}else C(e)},ae=e=>{if(I[0]?.setting_id===e.setting_id)return 0;if(I[1]?.setting_id===e.setting_id)return 1},oe=async e=>{try{let t=await Q.getCloudSettingDetail(e.setting_id);k({type:e.type===`process`?`print`:e.type,name:e.name,base_id:t.base_id||`GFSA00`,setting:t.setting||{}}),C(null)}catch(e){console.error(`Failed to fetch preset details for duplication:`,e)}},U=async e=>{try{ee.removeQueries({queryKey:[`cloudSettingDetail`,e.setting_id]});let t=await Q.getCloudSettingDetail(e.setting_id);j({type:e.type===`process`?`print`:e.type,name:e.name,base_id:t.base_id||`GFSA00`,setting:t.setting||{},setting_id:e.setting_id}),C(null)}catch(e){console.error(`Failed to fetch preset details for editing:`,e)}},se=()=>{u(`all`),f(`all`),m(`all`),g(`all`),v(`all`),x(`all`),c(``)},ce=l!==`all`||d!==`all`||p!==`all`||h!==`all`||_!==`all`||b!==`all`||s!==``,le=e.filament.length+e.printer.length+e.process.length;return(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`space-y-4 mb-6`,children:[(0,K.jsxs)(`div`,{className:`flex flex-col sm:flex-row gap-3`,children:[(0,K.jsxs)(`div`,{className:`relative flex-1`,children:[(0,K.jsx)(Wl,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,K.jsx)(`input`,{type:`text`,value:s,onChange:e=>c(e.target.value),placeholder:o(`profiles.cloudView.searchPlaceholder`),className:`w-full pl-10 pr-4 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none`})]}),(0,K.jsxs)(`div`,{className:`flex gap-2 max-[550px]:flex-wrap max-[550px]:items-center`,children:[(0,K.jsxs)($,{variant:P?`primary`:`secondary`,onClick:()=>{P?(F(!1),L([null,null])):F(!0)},children:[(0,K.jsx)(xc,{className:`w-4 h-4`}),o(P?`common.cancel`:`profiles.presets.compare`)]}),(0,K.jsxs)($,{variant:`secondary`,onClick:()=>D(!0),disabled:!a(`cloud:auth`),title:a(`cloud:auth`)?void 0:o(`profiles.cloudView.noTemplatesPermission`),children:[(0,K.jsx)(lu,{className:`w-4 h-4`}),o(`profiles.cloudView.templates`)]}),(0,K.jsxs)($,{variant:`secondary`,onClick:n,disabled:r||!a(`cloud:auth`),title:a(`cloud:auth`)?void 0:o(`profiles.cloudView.noRefreshPermission`),children:[(0,K.jsx)(Pl,{className:`w-4 h-4 ${r?`animate-spin`:``}`}),o(`profiles.cloudView.refresh`)]}),(0,K.jsxs)($,{onClick:()=>T(!0),disabled:!a(`cloud:auth`),title:a(`cloud:auth`)?void 0:o(`profiles.cloudView.noCreatePermission`),children:[(0,K.jsx)(Ol,{className:`w-4 h-4`}),o(`profiles.cloudView.newPreset`)]})]})]}),(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,K.jsx)(_c,{className:`w-4 h-4 text-bambu-gray`}),(0,K.jsx)(M6,{label:o(`profiles.cloudView.filters.type`),value:l,options:[{value:`all`,label:o(`profiles.cloudView.filters.all`),count:le},{value:`filament`,label:o(`profiles.cloudView.filters.filament`),count:e.filament.length},{value:`printer`,label:o(`profiles.cloudView.filters.printer`),count:e.printer.length},{value:`process`,label:o(`profiles.cloudView.filters.process`),count:e.process.length}],onChange:e=>u(e)}),(0,K.jsx)(M6,{label:o(`profiles.cloudView.filters.owner`),value:d,options:[{value:`all`,label:o(`profiles.cloudView.filters.all`)},{value:`custom`,label:o(`profiles.cloudView.filters.myPresets`)},{value:`builtin`,label:o(`profiles.cloudView.filters.builtIn`)}],onChange:e=>f(e)}),ne.printers.length>0&&(0,K.jsx)(M6,{label:o(`profiles.cloudView.filters.printer`),value:p,options:[{value:`all`,label:o(`profiles.cloudView.filters.all`)},...ne.printers.map(e=>({value:e.id,label:e.name}))],onChange:m}),ne.nozzles.length>0&&(0,K.jsx)(M6,{label:o(`profiles.cloudView.filters.nozzle`),value:h,options:[{value:`all`,label:o(`profiles.cloudView.filters.all`)},...ne.nozzles.map(e=>({value:e,label:e}))],onChange:g}),ne.filaments.length>0&&(l===`all`||l===`filament`)&&(0,K.jsx)(M6,{label:o(`profiles.cloudView.filters.filament`),value:_,options:[{value:`all`,label:o(`profiles.cloudView.filters.all`)},...ne.filaments.map(e=>({value:e,label:e}))],onChange:v}),ne.layerHeights.length>0&&(l===`all`||l===`process`)&&(0,K.jsx)(M6,{label:o(`profiles.cloudView.filters.layer`),value:b,options:[{value:`all`,label:o(`profiles.cloudView.filters.all`)},...ne.layerHeights.map(e=>({value:e,label:e}))],onChange:x}),ce&&(0,K.jsx)(`button`,{onClick:se,className:`px-3 py-2 text-sm text-bambu-gray hover:text-white transition-colors`,children:o(`profiles.cloudView.clearFilters`)})]})]}),P&&(0,K.jsx)(`div`,{className:`mb-4 p-3 bg-blue-500/10 border border-blue-500/30 rounded-lg`,children:(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,K.jsx)(xc,{className:`w-5 h-5 text-blue-600 dark:text-blue-400`}),(0,K.jsx)(`span`,{className:`text-white font-medium`,children:o(`profiles.cloudView.compareMode`)}),(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:I[0]?o(`profiles.cloudView.selectAnotherPreset`,{type:I[0].type}):o(`profiles.cloudView.clickTwoPresets`)})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`px-2 py-1 text-sm rounded truncate max-w-[200px] ${I[0]?`bg-blue-500/30 text-blue-700 dark:text-blue-300`:`bg-bambu-dark text-bambu-gray`}`,children:I[0]?I[0].name:o(`profiles.cloudView.selectFirst`)}),(0,K.jsx)(Io,{className:`w-4 h-4 text-bambu-gray`}),(0,K.jsx)(`span`,{className:`px-2 py-1 text-sm rounded truncate max-w-[200px] ${I[1]?`bg-blue-500/30 text-blue-700 dark:text-blue-300`:`bg-bambu-dark text-bambu-gray`}`,children:I[1]?I[1].name:o(`profiles.cloudView.selectSecond`)})]}),I[0]&&I[1]&&(0,K.jsxs)($,{size:`sm`,onClick:async()=>{try{let[e,t]=await Promise.all([Q.getCloudSettingDetail(I[0].setting_id),Q.getCloudSettingDetail(I[1].setting_id)]);V([e.setting||{},t.setting||{}]),z(!0)}catch{}},children:[(0,K.jsx)(xc,{className:`w-4 h-4`}),o(`profiles.cloudView.compareNow`)]})]})]})}),(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center gap-4 mb-4 text-sm text-bambu-gray`,children:[t&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(ws,{className:`w-3 h-3`}),o(`profiles.cloudView.lastSynced`),` `,Lf(t.toISOString(),`system`,o)]}),(0,K.jsx)(`span`,{children:o(`profiles.cloudView.showingCount`,{showing:ie.length,total:le})}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-bambu-green`}),(0,K.jsxs)(`span`,{children:[`= `,o(`profiles.presets.myPreset`)]})]})]}),ie.length===0?(0,K.jsxs)(`div`,{className:`text-center py-16`,children:[(0,K.jsx)(Vc,{className:`w-12 h-12 text-bambu-gray-dark mx-auto mb-4`}),(0,K.jsx)(`p`,{className:`text-bambu-gray`,children:o(`profiles.cloudView.noPresetsFound`)}),ce&&(0,K.jsx)(`button`,{onClick:se,className:`mt-2 text-sm text-bambu-green hover:text-bambu-green-light`,children:o(`profiles.cloudView.clearFilters`)})]}):(0,K.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-6`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-3 px-1`,children:[(0,K.jsx)(Gs,{className:`w-4 h-4 text-amber-600 dark:text-amber-400`}),(0,K.jsx)(`h3`,{className:`text-sm font-medium text-bambu-gray`,children:o(`profiles.cloudView.columns.filament`)}),(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray-dark`,children:[`(`,ie.filter(e=>e.type===`filament`).length,`)`]})]}),(0,K.jsxs)(`div`,{className:`space-y-1 max-h-[calc(100vh-320px)] overflow-y-auto pr-1`,children:[ie.filter(e=>e.type===`filament`).map(e=>(0,K.jsx)(N6,{setting:e,onClick:()=>H(e),onDuplicate:()=>oe(e),compareMode:P,isCompareSelected:ae(e)!==void 0,compareIndex:ae(e),compareDisabled:P&&!!I[0]&&I[0].type!==e.type,t:o},e.setting_id)),ie.filter(e=>e.type===`filament`).length===0&&(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray-dark px-3 py-2`,children:o(`profiles.cloudView.noFilamentPresets`)})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-3 px-1`,children:[(0,K.jsx)(Jl,{className:`w-4 h-4 text-blue-600 dark:text-blue-400`}),(0,K.jsx)(`h3`,{className:`text-sm font-medium text-bambu-gray`,children:o(`profiles.cloudView.columns.process`)}),(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray-dark`,children:[`(`,ie.filter(e=>e.type===`process`).length,`)`]})]}),(0,K.jsxs)(`div`,{className:`space-y-1 max-h-[calc(100vh-320px)] overflow-y-auto pr-1`,children:[ie.filter(e=>e.type===`process`).map(e=>(0,K.jsx)(N6,{setting:e,onClick:()=>H(e),onDuplicate:()=>oe(e),compareMode:P,isCompareSelected:ae(e)!==void 0,compareIndex:ae(e),compareDisabled:P&&!!I[0]&&I[0].type!==e.type,t:o},e.setting_id)),ie.filter(e=>e.type===`process`).length===0&&(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray-dark px-3 py-2`,children:o(`profiles.cloudView.noProcessPresets`)})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-3 px-1`,children:[(0,K.jsx)(jl,{className:`w-4 h-4 text-purple-600 dark:text-purple-400`}),(0,K.jsx)(`h3`,{className:`text-sm font-medium text-bambu-gray`,children:o(`profiles.cloudView.columns.printer`)}),(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray-dark`,children:[`(`,ie.filter(e=>e.type===`printer`).length,`)`]})]}),(0,K.jsxs)(`div`,{className:`space-y-1 max-h-[calc(100vh-320px)] overflow-y-auto pr-1`,children:[ie.filter(e=>e.type===`printer`).map(e=>(0,K.jsx)(N6,{setting:e,onClick:()=>H(e),onDuplicate:()=>oe(e),compareMode:P,isCompareSelected:ae(e)!==void 0,compareIndex:ae(e),compareDisabled:P&&!!I[0]&&I[0].type!==e.type,t:o},e.setting_id)),ie.filter(e=>e.type===`printer`).length===0&&(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray-dark px-3 py-2`,children:o(`profiles.cloudView.noPrinterPresets`)})]})]})]}),S&&(0,K.jsx)(aWe,{setting:S,onClose:()=>C(null),onDeleted:()=>C(null),onDuplicate:()=>oe(S),onEdit:()=>U(S),hasPermission:a,t:o}),(w||O||A||M)&&(0,K.jsx)(sWe,{onClose:()=>{T(!1),k(null),j(null),N(null)},initialData:A||O||(M?{type:M.type,name:``,base_id:``,setting:M.setting}:void 0),allPresets:e,t:o}),E&&(0,K.jsx)(oWe,{onClose:()=>D(!1),onApply:e=>{N({type:e.type,setting:e.settings}),D(!1)},t:o}),R&&B&&I[0]&&I[1]&&(0,K.jsx)(L6,{onClose:()=>{z(!1),V(null)},leftPreset:B[0],rightPreset:B[1],leftLabel:I[0].name,rightLabel:I[1].name,t:o})]})}function lWe(){let{t:e}=W(),t=oo(),{showToast:n}=Pd(),{hasPermission:r}=bd(),[i,a]=(0,y.useState)(`cloud`),[o,s]=(0,y.useState)(),{data:c,isLoading:l}=q({queryKey:[`cloudStatus`],queryFn:Q.getCloudStatus}),{data:u=[]}=q({queryKey:[`printers`],queryFn:Q.getPrinters}),{data:d,isLoading:f,refetch:p,dataUpdatedAt:m}=q({queryKey:[`cloudSettings`],queryFn:()=>Q.getCloudSettings(),enabled:!!c?.is_authenticated,retry:!1,staleTime:1e3*60*5});(0,y.useEffect)(()=>{m&&s(new Date(m))},[m]);let h=J({mutationFn:Q.cloudLogout,onSuccess:()=>{t.invalidateQueries({queryKey:[`cloudStatus`]}),t.removeQueries({queryKey:[`cloudSettings`]}),n(e(`profiles.toast.loggedOut`))}});return l?(0,K.jsx)(`div`,{className:`p-4 md:p-8 flex items-center justify-center min-h-[400px]`,children:(0,K.jsx)(X,{className:`w-8 h-8 text-bambu-green animate-spin`})}):(0,K.jsxs)(`div`,{className:`p-4 md:p-8`,children:[(0,K.jsxs)(`div`,{className:`mb-6`,children:[(0,K.jsxs)(`h1`,{className:`text-2xl font-bold text-white flex items-center gap-3`,children:[(0,K.jsx)(Ds,{className:`w-7 h-7 text-bambu-green`}),e(`profiles.title`)]}),(0,K.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:e(`profiles.subtitle`)})]}),(0,K.jsxs)(`div`,{className:`flex border-b border-bambu-dark-tertiary mb-6`,children:[(0,K.jsxs)(`button`,{onClick:()=>a(`cloud`),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${i===`cloud`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-white border-transparent`}`,children:[(0,K.jsx)(Ds,{className:`w-4 h-4`}),e(`profiles.tabs.bambuCloud`)]}),(0,K.jsxs)(`button`,{onClick:()=>a(`orca_cloud`),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${i===`orca_cloud`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-white border-transparent`}`,children:[(0,K.jsx)(Ds,{className:`w-4 h-4`}),e(`profiles.tabs.orcaCloud`)]}),(0,K.jsxs)(`button`,{onClick:()=>a(`local`),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${i===`local`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-white border-transparent`}`,children:[(0,K.jsx)(Dc,{className:`w-4 h-4`}),e(`profiles.tabs.local`)]}),(0,K.jsxs)(`button`,{onClick:()=>a(`kprofiles`),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${i===`kprofiles`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-white border-transparent`}`,children:[(0,K.jsx)(vc,{className:`w-4 h-4`}),e(`profiles.tabs.kprofiles`)]})]}),i===`cloud`&&(0,K.jsxs)(K.Fragment,{children:[c?.is_authenticated&&(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-3 mb-6 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`w-2 h-2 rounded-full bg-bambu-green animate-pulse`}),(0,K.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[e(`profiles.connectedAs`),` `,(0,K.jsx)(`span`,{className:`text-white`,children:c.email}),c.region&&(0,K.jsx)(`span`,{className:`ml-2 px-2 py-0.5 text-xs rounded bg-bambu-dark-tertiary text-bambu-gray`,children:c.region===`china`?e(`profiles.login.regionChina`):e(`profiles.login.regionGlobal`)})]})]}),(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:()=>h.mutate(),disabled:h.isPending||!r(`cloud:auth`),title:r(`cloud:auth`)?void 0:e(`profiles.noLogoutPermission`),children:[(0,K.jsx)(Qc,{className:`w-4 h-4`}),e(`profiles.logout`)]})]}),c?.sign_in_expired&&(0,K.jsxs)(`div`,{className:`flex items-start gap-3 p-3 mb-6 rounded-lg border border-yellow-500/40 bg-yellow-500/10`,children:[(0,K.jsx)(ku,{className:`w-5 h-5 shrink-0 text-yellow-400 mt-0.5`}),(0,K.jsxs)(`div`,{className:`text-sm`,children:[(0,K.jsx)(`p`,{className:`text-white font-medium`,children:e(`profiles.signInExpiredTitle`)}),(0,K.jsx)(`p`,{className:`text-bambu-gray`,children:e(`profiles.signInExpiredBody`)})]})]}),c?.is_authenticated?f?(0,K.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,K.jsx)(X,{className:`w-8 h-8 text-bambu-green animate-spin`})}):d?(0,K.jsx)(cWe,{settings:d,lastSyncTime:o,onRefresh:()=>p(),isRefreshing:f,printers:u,hasPermission:r,t:e}):(0,K.jsxs)(`div`,{className:`text-center py-16`,children:[(0,K.jsx)(`p`,{className:`text-bambu-gray mb-4`,children:e(`profiles.failedToLoad`)}),(0,K.jsx)($,{onClick:()=>p(),children:e(`profiles.retry`)})]}):(0,K.jsx)(rWe,{onSuccess:()=>{t.invalidateQueries({queryKey:[`cloudStatus`]})},t:e})]}),i===`orca_cloud`&&(0,K.jsx)(tWe,{}),i===`local`&&(0,K.jsx)(XUe,{}),i===`kprofiles`&&(0,K.jsx)(KUe,{}),(0,K.jsx)(iWe,{})]})}function uWe(e,t){let n=(t||``).toUpperCase().replace(/[- ]/g,``),r=n.includes(`X1`),i=n.includes(`P1`),a=n.includes(`A1MINI`),o=n.includes(`A1`)&&!a,s=n.includes(`H2D`),c=n.includes(`H2C`),l=n.includes(`H2S`),u=s||c||l,d=n.includes(`P2S`),f=n.includes(`X2D`),p=d||f;switch(e){case`Lubricate Steel Rods`:return p?`https://wiki.bambulab.com/en/p2s/maintenance/lubricate-x-y-z-axis`:null;case`Clean Steel Rods`:return p?`https://wiki.bambulab.com/en/p2s/maintenance/lubricate-x-y-z-axis`:null;case`Lubricate Linear Rails`:return a?`https://wiki.bambulab.com/en/a1-mini/maintenance/lubricate-y-axis`:o?`https://wiki.bambulab.com/en/a1/maintenance/lubricate-y-axis`:u?`https://wiki.bambulab.com/en/h2/maintenance/x-axis-lubrication`:null;case`Clean Nozzle/Hotend`:return r||i?`https://wiki.bambulab.com/en/x1/troubleshooting/nozzle-clog`:a||o?`https://wiki.bambulab.com/en/a1-mini/troubleshooting/nozzle-clog`:u?`https://wiki.bambulab.com/en/h2/maintenance/nozzl-cold-pull-maintenance-and-cleaning`:p?`https://wiki.bambulab.com/en/p2s/maintenance/cold-pull-maintenance-hotend`:`https://wiki.bambulab.com/en/x1/troubleshooting/nozzle-clog`;case`Check Belt Tension`:return r?`https://wiki.bambulab.com/en/x1/maintenance/belt-tension`:i?`https://wiki.bambulab.com/en/p1/maintenance/p1p-maintenance`:a?`https://wiki.bambulab.com/en/a1-mini/maintenance/belt_tension`:o?`https://wiki.bambulab.com/en/a1/maintenance/belt_tension`:s?`https://wiki.bambulab.com/en/h2/maintenance/belt-tension`:c?`https://wiki.bambulab.com/en/h2c/maintenance/belt-tension`:l?`https://wiki.bambulab.com/en/h2s/maintenance/belt-tension`:p?`https://wiki.bambulab.com/en/p2s/maintenance/belt-tension`:`https://wiki.bambulab.com/en/x1/maintenance/belt-tension`;case`Clean Carbon Rods`:return r||i?`https://wiki.bambulab.com/en/general/carbon-rods-clearance`:null;case`Clean Linear Rails`:return a?`https://wiki.bambulab.com/en/a1-mini/maintenance/lubricate-y-axis`:o?`https://wiki.bambulab.com/en/a1/maintenance/lubricate-y-axis`:u?`https://wiki.bambulab.com/en/h2/maintenance/x-axis-lubrication`:null;case`Clean Build Plate`:return`https://wiki.bambulab.com/en/filament-acc/acc/pei-plate-clean-guide`;case`Check PTFE Tube`:return r||i?`https://wiki.bambulab.com/en/x1/maintenance/replace-ptfe-tube`:a||o?`https://wiki.bambulab.com/en/a1-mini/maintenance/ptfe-tube`:s?`https://wiki.bambulab.com/en/h2/maintenance/replace-ptfe-tube-on-h2d-printer`:l?`https://wiki.bambulab.com/en/h2s/maintenance/replace-ptfe-tube-on-h2s-printer`:c?`https://wiki.bambulab.com/en/h2/maintenance/replace-ptfe-tube-on-h2d-printer`:`https://wiki.bambulab.com/en/x1/maintenance/replace-ptfe-tube`;case`Replace HEPA Filter`:case`HEPA Filter`:case`Replace Carbon Filter`:case`Carbon Filter`:return u?`https://wiki.bambulab.com/en/h2/maintenance/replace-smoke-purifier-air-filte`:`https://wiki.bambulab.com/en/x1/maintenance/replace-carbon-filter`;case`Lubricate Left Nozzle Rail`:case`Left Nozzle Rail`:return u?`https://wiki.bambulab.com/en/h2/maintenance/x-axis-lubrication`:null;default:return null}}var R6={Droplet:Gs,Flame:cc,Ruler:Rl,Sparkles:lu,Square:fu,Cable:Xo,Wrench:Ku,Calendar:$o,Timer:Tu,Cog:Ms,Fan:ec,Zap:Yu,Wind:Wu,Thermometer:wu,Layers:Vc,Box:qo,Target:yu,RefreshCw:Pl,Settings:Yl,Filter:_c,CircleDot:_s};function z6(e){return e&&R6[e]||Ku}function B6(e,t,n){if(t===`days`){if(e<1)return n?n(`common.today`):`Today`;if(e===1)return n?n(`maintenance.day`):`1 day`;if(e<7){let t=Math.round(e);return n?n(`maintenance.days`,{count:t}):`${t} days`}if(e<180){let t=Math.round(e/7);return t===1?n?n(`maintenance.week`):`1 week`:n?n(`maintenance.weeks`,{count:t}):`${t} weeks`}let t=Math.round(e/30);return t===1?n?n(`maintenance.month`):`1 month`:n?n(`maintenance.months`,{count:t}):`${t} months`}else{if(e<1)return`${Math.round(e*60)}m`;if(e<24)return`${e<10?e.toFixed(1):Math.round(e)}h`;let t=e/24;if(t<7)return`${t<2?t.toFixed(1):Math.round(t)}d`;let n=t/7;return n<12?`${n<2?n.toFixed(1):Math.round(n)}w`:`${Math.round(n/4)}mo`}}function V6(e,t,n){return t===`days`?e===1?n?n(`maintenance.day`):`1 day`:e===7?n?n(`maintenance.week`):`1 week`:e===14?n?n(`maintenance.weeks`,{count:2}):`2 weeks`:e===30?n?n(`maintenance.month`):`1 month`:e===60?n?n(`maintenance.months`,{count:2}):`2 months`:e===90?n?n(`maintenance.months`,{count:3}):`3 months`:e===180?n?n(`maintenance.months`,{count:6}):`6 months`:e===365?n?n(`maintenance.year`):`1 year`:n?n(`maintenance.days`,{count:e}):`${e} days`:`${e}h`}function dWe({item:e,onPerform:t,onToggle:n,hasPermission:r,t:i}){let a=z6(e.maintenance_type_icon),o=e.interval_type||`hours`,s=(()=>{if(o===`days`){let t=e.days_since_maintenance??0;return Math.max(0,Math.min(100,t/e.interval_hours*100))}return Math.max(0,Math.min(100,(e.interval_hours-e.hours_until_due)/e.interval_hours*100))})(),c=()=>e.enabled?e.is_due?`text-red-700 dark:text-red-400`:e.is_warning?`text-amber-700 dark:text-amber-400`:`text-bambu-green`:`text-bambu-gray`;return(0,K.jsx)(`div`,{className:`rounded-xl border p-4 transition-all ${e.enabled?e.is_due?`bg-red-500/5 border-red-500/20`:e.is_warning?`bg-amber-500/5 border-amber-500/20`:`bg-bambu-dark-secondary border-bambu-dark-tertiary`:`bg-bambu-dark-secondary/50`}`,children:(0,K.jsxs)(`div`,{className:`flex items-start gap-3 max-[550px]:flex-wrap`,children:[(0,K.jsxs)(`div`,{className:`relative p-2.5 rounded-lg shrink-0 ${e.is_due?`bg-red-500/20`:e.is_warning?`bg-amber-500/20`:e.enabled?`bg-bambu-dark`:`bg-bambu-dark/50`}`,children:[(0,K.jsx)(a,{className:`w-5 h-5 ${c()}`}),e.enabled&&(e.is_due||e.is_warning)&&(0,K.jsx)(`span`,{className:`absolute -top-1 -right-1 w-2.5 h-2.5 rounded-full ${e.is_due?`bg-red-500`:`bg-amber-500`} animate-pulse`})]}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`h3`,{className:`font-medium truncate ${e.enabled?`text-white`:`text-bambu-gray`}`,children:e.maintenance_type_name}),o===`days`&&(0,K.jsx)(`span`,{title:i(`maintenance.timeBasedInterval`),children:(0,K.jsx)($o,{className:`w-3.5 h-3.5 text-bambu-gray shrink-0`})}),(()=>{let t=e.maintenance_type_wiki_url||uWe(e.maintenance_type_name,e.printer_model);return t?(0,K.jsx)(`a`,{href:t,target:`_blank`,rel:`noopener noreferrer`,className:`text-bambu-gray hover:text-bambu-green transition-colors shrink-0`,title:i(`maintenance.viewDocumentation`),onClick:e=>e.stopPropagation(),children:(0,K.jsx)(Zs,{className:`w-3.5 h-3.5`})}):null})()]}),(0,K.jsx)(`div`,{className:`mt-2 mb-1.5`,children:(0,K.jsx)(`div`,{className:`w-full h-1.5 bg-bambu-dark rounded-full overflow-hidden`,children:(0,K.jsx)(`div`,{className:`h-full rounded-full transition-all duration-500 ${e.enabled?e.is_due?`bg-red-500`:e.is_warning?`bg-amber-500`:`bg-bambu-green`:`bg-bambu-gray/30`}`,style:{width:`${s}%`}})})}),(0,K.jsxs)(`div`,{className:`text-xs flex items-center gap-1 ${c()}`,children:[e.is_due&&(0,K.jsx)(ku,{className:`w-3 h-3`}),e.is_warning&&!e.is_due&&(0,K.jsx)(ws,{className:`w-3 h-3`}),!e.is_due&&!e.is_warning&&e.enabled&&(0,K.jsx)(as,{className:`w-3 h-3`}),(()=>{if(!e.enabled)return i(`common.disabled`);if(o===`days`){let t=e.days_until_due??0;return e.is_due?i(`maintenance.overdueBy`,{duration:B6(Math.abs(t),`days`,i)}):e.is_warning?i(`maintenance.dueIn`,{duration:B6(t,`days`,i)}):i(`maintenance.timeLeft`,{duration:B6(t,`days`,i)})}else return e.is_due?i(`maintenance.overdueBy`,{duration:B6(Math.abs(e.hours_until_due),`hours`,i)}):e.is_warning?i(`maintenance.dueIn`,{duration:B6(e.hours_until_due,`hours`,i)}):i(`maintenance.timeLeft`,{duration:B6(e.hours_until_due,`hours`,i)})})()]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0 max-[550px]:w-full max-[550px]:justify-end max-[550px]:mt-1`,children:[(0,K.jsx)(`span`,{title:r(`maintenance:update`)?void 0:i(`maintenance.noPermissionUpdate`),children:(0,K.jsx)(cU,{checked:e.enabled,onChange:t=>n(e.id,t),disabled:!r(`maintenance:update`)})}),(0,K.jsxs)($,{size:`sm`,variant:e.is_due?`primary`:`secondary`,onClick:()=>t(e.id),disabled:!e.enabled||!r(`maintenance:update`),title:r(`maintenance:update`)?void 0:i(`maintenance.noPermissionPerform`),className:`!px-3`,children:[(0,K.jsx)(Il,{className:`w-3.5 h-3.5`}),i(`common.reset`)]})]})]})})}function fWe({overview:e,onPerform:t,onToggle:n,onSetHours:r,hasPermission:i,t:a}){let[o,s]=(0,y.useState)(!1),[c,l]=(0,y.useState)(!1),[u,d]=(0,y.useState)(e.total_print_hours.toFixed(1)),f=[...e.maintenance_items].sort((e,t)=>e.is_due&&!t.is_due?-1:!e.is_due&&t.is_due?1:e.is_warning&&!t.is_warning?-1:!e.is_warning&&t.is_warning?1:e.maintenance_type_id-t.maintenance_type_id),p=f.find(e=>e.enabled&&(e.is_due||e.is_warning)),m=()=>{let t=parseFloat(u);!isNaN(t)&&t>=0&&(r(e.printer_id,t),l(!1))};return(0,K.jsxs)(Ed,{className:`overflow-hidden`,children:[(0,K.jsxs)(`div`,{className:`p-5`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,K.jsx)(`h2`,{className:`text-xl font-semibold text-white`,children:e.printer_name}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e.due_count>0&&(0,K.jsxs)(`span`,{className:`px-2.5 py-1 bg-red-100 text-red-700 dark:bg-red-500/20 dark:text-red-400 text-xs font-medium rounded-full flex items-center gap-1.5`,children:[(0,K.jsx)(ku,{className:`w-3 h-3`}),a(`maintenance.overdueCount`,{count:e.due_count})]}),e.warning_count>0&&(0,K.jsxs)(`span`,{className:`px-2.5 py-1 bg-amber-100 text-amber-700 dark:bg-amber-500/20 dark:text-amber-400 text-xs font-medium rounded-full flex items-center gap-1.5`,children:[(0,K.jsx)(ws,{className:`w-3 h-3`}),a(`maintenance.dueSoonCount`,{count:e.warning_count})]}),e.due_count===0&&e.warning_count===0&&(0,K.jsxs)(`span`,{className:`px-2.5 py-1 bg-bambu-green/20 text-bambu-green text-xs font-medium rounded-full flex items-center gap-1.5`,children:[(0,K.jsx)(as,{className:`w-3 h-3`}),a(`maintenance.allGood`)]})]})]}),(0,K.jsxs)(`button`,{onClick:()=>s(!o),className:`flex items-center gap-1.5 px-3 py-1.5 text-sm text-bambu-gray hover:text-white hover:bg-bambu-dark rounded-lg transition-colors`,children:[o?(0,K.jsx)(us,{className:`w-4 h-4`}):(0,K.jsx)(ss,{className:`w-4 h-4`}),a(o?`common.collapse`:`common.expand`)]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-6 mt-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`p-2 bg-bambu-dark/50 rounded-lg`,children:(0,K.jsx)(Tu,{className:`w-4 h-4 text-bambu-gray`})}),c?(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`input`,{type:`number`,value:u,onChange:e=>d(e.target.value),onKeyDown:e=>{e.key===`Enter`&&m(),e.key===`Escape`&&l(!1)},className:`w-24 px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm`,min:`0`,step:`1`,autoFocus:!0}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:a(`common.hours`)}),(0,K.jsx)($,{size:`sm`,onClick:m,children:a(`common.save`)}),(0,K.jsx)($,{size:`sm`,variant:`secondary`,onClick:()=>l(!1),children:a(`common.cancel`)})]}):(0,K.jsxs)(`button`,{onClick:()=>{i(`maintenance:update`)&&(d(Math.round(e.total_print_hours).toString()),l(!0))},className:`group ${i(`maintenance:update`)?``:`cursor-not-allowed opacity-60`}`,title:i(`maintenance:update`)?void 0:a(`maintenance.noPermissionEditHours`),children:[(0,K.jsxs)(`div`,{className:`text-sm font-medium text-white ${i(`maintenance:update`)?`group-hover:text-bambu-green`:``} transition-colors flex items-center gap-1`,children:[Math.round(e.total_print_hours),` `,a(`common.hours`),(0,K.jsx)(Sl,{className:`w-3 h-3 text-bambu-gray ${i(`maintenance:update`)?`group-hover:text-bambu-green`:``}`})]}),(0,K.jsx)(`div`,{className:`text-xs text-bambu-gray`,children:a(`maintenance.totalPrintTime`)})]})]}),(0,K.jsx)(`div`,{className:`w-px h-10 bg-bambu-dark-tertiary`}),p&&(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`p-2 rounded-lg ${p.is_due?`bg-red-500/20`:`bg-amber-500/20`}`,children:(0,K.jsx)(z6(p.maintenance_type_icon),{className:`w-4 h-4 ${p.is_due?`text-red-600 dark:text-red-400`:`text-amber-600 dark:text-amber-400`}`})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`div`,{className:`text-sm font-medium ${p.is_due?`text-red-700 dark:text-red-400`:`text-amber-700 dark:text-amber-400`}`,children:p.maintenance_type_name}),(0,K.jsx)(`div`,{className:`text-xs ${p.is_due?`text-red-700/80 dark:text-red-400/70`:`text-amber-700/80 dark:text-amber-400/70`}`,children:p.is_due?a(`common.overdue`):a(`maintenance.dueSoon`)})]})]})]})]}),o&&(0,K.jsx)(Od,{className:`pt-0 border-t border-bambu-dark-tertiary`,children:(0,K.jsx)(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 gap-3 pt-4`,children:f.map(e=>(0,K.jsx)(dWe,{item:e,onPerform:t,onToggle:n,hasPermission:i,t:a},e.id))})})]})}function pWe({overview:e,types:t,onUpdateInterval:n,onAddType:r,onUpdateType:i,onDeleteType:a,onRestoreDefaults:o,isRestoringDefaults:s,onAssignType:c,onRemoveItem:l,hasPermission:u,t:d}){let[f,p]=(0,y.useState)(null),[m,h]=(0,y.useState)(``),[g,_]=(0,y.useState)(`hours`),[v,b]=(0,y.useState)(!1),[x,S]=(0,y.useState)(``),[C,w]=(0,y.useState)(`100`),[T,E]=(0,y.useState)(`hours`),[D,O]=(0,y.useState)(`Wrench`),[k,A]=(0,y.useState)(``),[j,M]=(0,y.useState)(new Set),[N,P]=(0,y.useState)(null),[F,I]=(0,y.useState)(null),L=(0,y.useMemo)(()=>e?e.map(e=>({id:e.printer_id,name:e.printer_name})):[],[e]),R=t=>e?e.filter(e=>e.maintenance_items.some(e=>e.maintenance_type_id===t)).map(e=>({printerId:e.printer_id,printerName:e.printer_name,itemId:e.maintenance_items.find(e=>e.maintenance_type_id===t)?.id})):[],z=t=>{if(!e)return[];let n=new Set(R(t).map(e=>e.printerId));return L.filter(e=>!n.has(e.id))},[B,V]=(0,y.useState)(null),[ee,te]=(0,y.useState)(``),[ne,re]=(0,y.useState)(``),[ie,H]=(0,y.useState)(`hours`),[ae,oe]=(0,y.useState)(`Wrench`),[U,se]=(0,y.useState)(``),ce=e=>{V(e),te(e.name),re(e.default_interval_hours.toString()),H(e.interval_type||`hours`),oe(e.icon||`Wrench`),se(e.wiki_url||``)},le=()=>{B&&ee.trim()&&parseFloat(ne)>0&&(i(B.id,{name:ee.trim(),default_interval_hours:parseFloat(ne),interval_type:ie,icon:ae,wiki_url:U.trim()||null}),V(null))},ue=(e,t,r)=>{let i=parseFloat(m);!isNaN(i)&&i>0&&n(e,{custom_interval_hours:Math.abs(i-t)<.01?null:i,custom_interval_type:g===r?null:g}),p(null)},de=e=>{e.preventDefault(),x.trim()&&parseFloat(C)>0&&j.size>0&&(r({name:x.trim(),default_interval_hours:parseFloat(C),interval_type:T,icon:D,wiki_url:k.trim()||null},Array.from(j)),S(``),w(`100`),E(`hours`),A(``),M(new Set),b(!1))},fe=e=>{M(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},pe=e?.map(e=>({printerId:e.printer_id,printerName:e.printer_name,items:e.maintenance_items.sort((e,t)=>e.maintenance_type_id-t.maintenance_type_id)})).sort((e,t)=>e.printerName.localeCompare(t.printerName))||[],me=t.filter(e=>e.is_system),he=t.filter(e=>!e.is_system);return(0,K.jsxs)(`div`,{className:`space-y-8`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-4`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:d(`maintenance.maintenanceTypes`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:d(`maintenance.maintenanceTypesDescription`)})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)($,{variant:`secondary`,onClick:o,disabled:!u(`maintenance:delete`)||s,title:u(`maintenance:delete`)?void 0:d(`maintenance.noPermissionDeleteTypes`),children:d(`maintenance.restoreDefaults`)}),(0,K.jsxs)($,{onClick:()=>b(!v),disabled:!u(`maintenance:create`),title:u(`maintenance:create`)?void 0:d(`maintenance.noPermissionEditTypes`),children:[(0,K.jsx)(Ol,{className:`w-4 h-4`}),d(`maintenance.addCustomType`)]})]})]}),v&&(0,K.jsx)(Ed,{className:`mb-6`,children:(0,K.jsx)(Od,{className:`py-4`,children:(0,K.jsxs)(`form`,{onSubmit:de,children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4`,children:[(0,K.jsxs)(`div`,{className:`lg:col-span-2`,children:[(0,K.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1.5`,children:d(`common.name`)}),(0,K.jsx)(`input`,{type:`text`,value:x,onChange:e=>S(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,placeholder:d(`maintenance.exampleName`),autoFocus:!0})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1.5`,children:d(`maintenance.intervalType`)}),(0,K.jsxs)(`select`,{value:T,onChange:e=>{E(e.target.value),e.target.value===`days`?w(`30`):w(`100`)},className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,children:[(0,K.jsx)(`option`,{value:`hours`,children:d(`maintenance.printHours`)}),(0,K.jsx)(`option`,{value:`days`,children:d(`maintenance.calendarDays`)})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1.5`,children:d(`maintenance.intervalValue`,{type:T===`days`?d(`maintenance.calendarDays`).toLowerCase():d(`common.hours`)})}),(0,K.jsx)(`input`,{type:`number`,value:C,onChange:e=>w(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,min:`1`})]})]}),(0,K.jsx)(`div`,{className:`mt-4 flex items-end justify-between`,children:(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1.5`,children:d(`maintenance.icon`)}),(0,K.jsx)(`div`,{className:`flex gap-1`,children:Object.keys(R6).map(e=>{let t=R6[e];return(0,K.jsx)(`button`,{type:`button`,onClick:()=>O(e),className:`p-2 rounded-lg transition-colors ${D===e?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary`}`,children:(0,K.jsx)(t,{className:`w-4 h-4`})},e)})})]})}),(0,K.jsxs)(`div`,{className:`mt-4`,children:[(0,K.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1.5`,children:d(`maintenance.documentationLink`)}),(0,K.jsx)(`input`,{type:`url`,value:k,onChange:e=>A(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,placeholder:`https://wiki.bambulab.com/...`})]}),(0,K.jsxs)(`div`,{className:`mt-4`,children:[(0,K.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1.5`,children:d(`maintenance.assignToPrinters`)}),(0,K.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:L.map(e=>(0,K.jsx)(`button`,{type:`button`,onClick:()=>fe(e.id),className:`px-3 py-1.5 rounded-lg text-sm transition-colors ${j.has(e.id)?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary`}`,children:e.name},e.id))}),j.size===0&&(0,K.jsx)(`p`,{className:`text-xs text-orange-700 dark:text-orange-400 mt-1`,children:d(`maintenance.selectAtLeastOnePrinter`)})]}),(0,K.jsxs)(`div`,{className:`mt-4 flex justify-end gap-2`,children:[(0,K.jsx)($,{type:`button`,variant:`secondary`,onClick:()=>{b(!1),M(new Set)},children:d(`common.cancel`)}),(0,K.jsx)($,{type:`submit`,disabled:!x.trim()||j.size===0,children:d(`maintenance.addType`)})]})]})})}),(0,K.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-3`,children:[me.map(e=>{let t=z6(e.icon),n=e.interval_type||`hours`;return(0,K.jsx)(`div`,{className:`bg-bambu-dark-secondary rounded-xl p-4 border border-bambu-dark-tertiary`,children:(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`p-2.5 bg-bambu-dark rounded-lg`,children:(0,K.jsx)(t,{className:`w-5 h-5 text-bambu-gray`})}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsx)(`div`,{className:`text-sm font-medium text-white truncate`,children:e.name}),(0,K.jsxs)(`div`,{className:`text-xs text-bambu-gray mt-0.5 flex items-center gap-1`,children:[n===`days`?(0,K.jsx)($o,{className:`w-3 h-3`}):(0,K.jsx)(Tu,{className:`w-3 h-3`}),V6(e.default_interval_hours,n,d)]})]}),(0,K.jsx)(`button`,{onClick:()=>{u(`maintenance:delete`)&&I(e)},disabled:!u(`maintenance:delete`),title:u(`maintenance:delete`)?void 0:d(`maintenance.noPermissionDeleteTypes`),className:`p-2 rounded-lg hover:bg-bambu-dark text-bambu-gray hover:text-red-600 dark:hover:text-red-400 transition-colors ${u(`maintenance:delete`)?``:`opacity-50 cursor-not-allowed`}`,children:(0,K.jsx)(Eu,{className:`w-4 h-4`})})]})},e.id)}),he.map(e=>{let t=z6(e.icon),n=e.interval_type||`hours`;if(B?.id===e.id)return(0,K.jsx)(`div`,{className:`bg-bambu-dark-secondary rounded-xl p-4 border border-bambu-green`,children:(0,K.jsxs)(`div`,{className:`space-y-3`,children:[(0,K.jsx)(`input`,{type:`text`,value:ee,onChange:e=>te(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,placeholder:d(`common.name`),autoFocus:!0}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsxs)(`select`,{value:ie,onChange:e=>H(e.target.value),className:`flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,children:[(0,K.jsx)(`option`,{value:`hours`,children:d(`maintenance.printHours`)}),(0,K.jsx)(`option`,{value:`days`,children:d(`maintenance.calendarDays`)})]}),(0,K.jsx)(`input`,{type:`number`,value:ne,onChange:e=>re(e.target.value),className:`w-24 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,min:`1`})]}),(0,K.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:Object.keys(R6).map(e=>{let t=R6[e];return(0,K.jsx)(`button`,{type:`button`,onClick:()=>oe(e),className:`p-1.5 rounded transition-colors ${ae===e?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white`}`,children:(0,K.jsx)(t,{className:`w-3.5 h-3.5`})},e)})}),(0,K.jsx)(`input`,{type:`url`,value:U,onChange:e=>se(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,placeholder:d(`maintenance.documentationLink`)}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)($,{size:`sm`,onClick:le,disabled:!ee.trim(),children:d(`common.save`)}),(0,K.jsx)($,{size:`sm`,variant:`secondary`,onClick:()=>V(null),children:d(`common.cancel`)})]})]})},e.id);let r=R(e.id),i=z(e.id),o=N===e.id;return(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl p-4 border border-bambu-green/30`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`p-2.5 bg-bambu-green/20 rounded-lg`,children:(0,K.jsx)(t,{className:`w-5 h-5 text-bambu-green`})}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`text-sm font-medium text-white truncate`,children:e.name}),(0,K.jsx)(`span`,{className:`px-1.5 py-0.5 bg-bambu-green/20 text-bambu-green text-[10px] font-medium rounded`,children:d(`maintenance.custom`)})]}),(0,K.jsxs)(`div`,{className:`text-xs text-bambu-gray mt-0.5 flex items-center gap-1`,children:[n===`days`?(0,K.jsx)($o,{className:`w-3 h-3`}):(0,K.jsx)(Tu,{className:`w-3 h-3`}),V6(e.default_interval_hours,n,d)]})]}),(0,K.jsxs)(`button`,{onClick:()=>P(o?null:e.id),className:`px-2 py-1 rounded-lg border transition-colors flex items-center gap-1 ${r.length>0?`border-bambu-green/50 bg-bambu-green/10 text-bambu-green hover:bg-bambu-green/20`:`border-orange-300 bg-orange-50 text-orange-700 hover:bg-orange-100 dark:border-orange-400/50 dark:bg-orange-400/10 dark:text-orange-400 dark:hover:bg-orange-400/20`}`,title:d(`maintenance.printersAssignedClick`,{count:r.length}),children:[(0,K.jsx)(jl,{className:`w-3 h-3`}),(0,K.jsx)(`span`,{className:`text-xs font-medium`,children:r.length}),(0,K.jsx)(ss,{className:`w-3 h-3 transition-transform ${o?`rotate-180`:``}`})]}),(0,K.jsx)(`button`,{onClick:()=>ce(e),disabled:!u(`maintenance:update`),title:u(`maintenance:update`)?void 0:d(`maintenance.noPermissionEditTypes`),className:`p-2 rounded-lg hover:bg-bambu-dark text-bambu-gray hover:text-white transition-colors ${u(`maintenance:update`)?``:`opacity-50 cursor-not-allowed`}`,children:(0,K.jsx)(Sl,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>{confirm(d(`maintenance.deleteTypeConfirm`,{name:e.name}))&&a(e.id)},disabled:!u(`maintenance:delete`),title:u(`maintenance:delete`)?void 0:d(`maintenance.noPermissionDeleteTypes`),className:`p-2 rounded-lg hover:bg-bambu-dark text-bambu-gray hover:text-red-600 dark:hover:text-red-400 transition-colors ${u(`maintenance:delete`)?``:`opacity-50 cursor-not-allowed`}`,children:(0,K.jsx)(Eu,{className:`w-4 h-4`})})]}),o&&(0,K.jsxs)(`div`,{className:`mt-3 pt-3 border-t border-bambu-dark-tertiary`,children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:d(`maintenance.assignedToPrinters`)}),r.length===0?(0,K.jsx)(`p`,{className:`text-xs text-orange-700 dark:text-orange-400`,children:d(`maintenance.noPrintersAssigned`)}):(0,K.jsx)(`div`,{className:`flex flex-wrap gap-1 mb-2`,children:r.map(e=>(0,K.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-2 py-1 bg-bambu-dark rounded text-xs text-white`,children:[e.printerName,(0,K.jsx)(`button`,{onClick:()=>e.itemId&&l(e.itemId),disabled:!u(`maintenance:delete`),title:u(`maintenance:delete`)?d(`maintenance.removeFromPrinter`):d(`maintenance.noPermissionRemovePrinter`),className:`ml-1 ${u(`maintenance:delete`)?`hover:text-red-600 dark:hover:text-red-400`:`opacity-50 cursor-not-allowed`}`,children:`×`})]},e.printerId))}),i.length>0&&(0,K.jsxs)(`div`,{className:`flex flex-wrap gap-1`,children:[(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray mr-1`,children:d(`maintenance.addPrinterShort`)}),i.map(t=>(0,K.jsxs)(`button`,{onClick:()=>c(t.id,e.id),disabled:!u(`maintenance:create`),title:u(`maintenance:create`)?void 0:d(`maintenance.noPermissionAssignPrinter`),className:`px-2 py-1 bg-bambu-dark rounded text-xs transition-colors ${u(`maintenance:create`)?`hover:bg-bambu-green/20 text-bambu-gray hover:text-bambu-green`:`opacity-50 cursor-not-allowed text-bambu-gray`}`,children:[`+ `,t.name]},t.id))]})]})]},e.id)})]})]}),pe.length>0&&(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`mb-4`,children:[(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:d(`maintenance.intervalOverrides`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:d(`maintenance.intervalOverridesDescription`)})]}),(0,K.jsx)(`div`,{className:`space-y-4`,children:pe.map(e=>(0,K.jsx)(Ed,{children:(0,K.jsxs)(Od,{className:`py-4`,children:[(0,K.jsx)(`h3`,{className:`text-sm font-medium text-white mb-3`,children:e.printerName}),(0,K.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-2`,children:e.items.map(e=>{let n=z6(e.maintenance_type_icon),r=t.find(t=>t.id===e.maintenance_type_id),i=r?.default_interval_hours||e.interval_hours,a=r?.interval_type||`hours`,o=e.interval_type||`hours`,s=f===e.id;return(0,K.jsxs)(`div`,{className:`flex items-center gap-2 p-2.5 bg-bambu-dark rounded-lg`,children:[(0,K.jsx)(n,{className:`w-4 h-4 text-bambu-gray shrink-0`}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray flex-1 truncate`,children:e.maintenance_type_name}),s?(0,K.jsxs)(`div`,{className:`flex items-center gap-1`,children:[g===`days`?(0,K.jsx)($o,{className:`w-3.5 h-3.5 text-bambu-gray shrink-0`}):(0,K.jsx)(Tu,{className:`w-3.5 h-3.5 text-bambu-gray shrink-0`}),(0,K.jsxs)(`select`,{value:g,onChange:e=>_(e.target.value),className:`px-1.5 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-xs`,children:[(0,K.jsx)(`option`,{value:`hours`,children:d(`maintenance.printHours`)}),(0,K.jsx)(`option`,{value:`days`,children:d(`maintenance.calendarDays`)})]}),(0,K.jsx)(`input`,{type:`number`,value:m,onChange:e=>h(e.target.value),onKeyDown:t=>{t.key===`Enter`&&ue(e.id,i,a),t.key===`Escape`&&p(null)},className:`w-16 px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-xs`,min:`1`}),(0,K.jsx)($,{size:`sm`,onClick:()=>ue(e.id,i,a),children:`OK`})]}):(0,K.jsxs)(`button`,{onClick:()=>{u(`maintenance:update`)&&(p(e.id),h(e.interval_hours.toString()),_(o))},disabled:!u(`maintenance:update`),title:u(`maintenance:update`)?void 0:d(`maintenance.noPermissionEditIntervals`),className:`px-2 py-1 bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded text-xs font-medium text-white transition-colors flex items-center gap-1 ${u(`maintenance:update`)?`hover:bg-bambu-dark-secondary hover:border-bambu-green`:`opacity-50 cursor-not-allowed`}`,children:[o===`days`?(0,K.jsx)($o,{className:`w-3 h-3`}):(0,K.jsx)(Tu,{className:`w-3 h-3`}),V6(e.interval_hours,o,d),(0,K.jsx)(Sl,{className:`w-3 h-3 text-bambu-gray`})]})]},e.id)})})]})},e.printerId))})]}),pe.length===0&&(0,K.jsx)(Ed,{children:(0,K.jsxs)(Od,{className:`text-center py-12`,children:[(0,K.jsx)(ws,{className:`w-12 h-12 mx-auto mb-4 text-bambu-gray/30`}),(0,K.jsx)(`p`,{className:`text-bambu-gray`,children:d(`common.noPrinters`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray/70 mt-1`,children:d(`maintenance.intervalOverridesDescription`)})]})}),F&&(0,K.jsx)(Vd,{title:d(`maintenance.deleteSystemTypeTitle`),message:d(`maintenance.deleteSystemTypeMessage`,{name:F.name}),confirmText:d(`common.delete`),cancelText:d(`common.cancel`),variant:`danger`,cancelVariant:`primary`,cardClassName:`bg-red-950/70 border border-red-800/70`,onConfirm:()=>{a(F.id),I(null)},onCancel:()=>I(null)})]})}function mWe(){let{t:e}=W(),t=oo(),{showToast:n}=Pd(),{hasPermission:r}=bd(),[i,a]=(0,y.useState)(`status`),{data:o,isLoading:s}=q({queryKey:[`maintenanceOverview`],queryFn:Q.getMaintenanceOverview}),{data:c}=q({queryKey:[`maintenanceTypes`],queryFn:Q.getMaintenanceTypes}),l=J({mutationFn:({id:e,notes:t})=>Q.performMaintenance(e,t),onSuccess:()=>{t.invalidateQueries({queryKey:[`maintenanceOverview`]}),t.invalidateQueries({queryKey:[`maintenanceSummary`]}),n(e(`maintenance.maintenanceComplete`))},onError:e=>{n(e.message,`error`)}}),u=J({mutationFn:({id:e,data:t})=>Q.updateMaintenanceItem(e,t),onSuccess:()=>{t.invalidateQueries({queryKey:[`maintenanceOverview`]})},onError:e=>{n(e.message,`error`)}}),d=J({mutationFn:({id:e,data:t})=>Q.updateMaintenanceType(e,t),onSuccess:()=>{t.invalidateQueries({queryKey:[`maintenanceTypes`]}),t.invalidateQueries({queryKey:[`maintenanceOverview`]}),n(e(`maintenance.typeUpdated`))},onError:e=>{n(e.message,`error`)}}),f=J({mutationFn:Q.deleteMaintenanceType,onSuccess:()=>{t.invalidateQueries({queryKey:[`maintenanceTypes`]}),t.invalidateQueries({queryKey:[`maintenanceOverview`]}),n(e(`maintenance.typeDeleted`))},onError:e=>{n(e.message,`error`)}}),p=J({mutationFn:Q.restoreDefaultMaintenanceTypes,onSuccess:r=>{t.invalidateQueries({queryKey:[`maintenanceTypes`]}),t.invalidateQueries({queryKey:[`maintenanceOverview`]}),n(e(`maintenance.defaultsRestored`,{count:r.restored}))},onError:e=>{n(e.message,`error`)}}),m=J({mutationFn:({printerId:e,hours:t})=>Q.setPrinterHours(e,t),onSuccess:()=>{t.invalidateQueries({queryKey:[`maintenanceOverview`]}),t.invalidateQueries({queryKey:[`maintenanceSummary`]}),n(e(`maintenance.printHoursUpdated`))},onError:e=>{n(e.message,`error`)}}),h=J({mutationFn:({printerId:e,typeId:t})=>Q.assignMaintenanceType(e,t),onSuccess:()=>{t.invalidateQueries({queryKey:[`maintenanceOverview`]}),n(e(`maintenance.printerAssigned`))},onError:e=>{n(e.message,`error`)}}),g=J({mutationFn:Q.removeMaintenanceItem,onSuccess:()=>{t.invalidateQueries({queryKey:[`maintenanceOverview`]}),n(e(`maintenance.printerRemoved`))},onError:e=>{n(e.message,`error`)}}),_=e=>{l.mutate({id:e})},v=(e,t)=>{u.mutate({id:e,data:{enabled:t}})},b=(e,t)=>{m.mutate({printerId:e,hours:t})};if(s)return(0,K.jsx)(`div`,{className:`p-4 md:p-8 flex justify-center`,children:(0,K.jsx)(X,{className:`w-8 h-8 text-bambu-green animate-spin`})});let x=o?.reduce((e,t)=>e+t.due_count,0)||0,S=o?.reduce((e,t)=>e+t.warning_count,0)||0;return(0,K.jsxs)(`div`,{className:`p-4 md:p-8`,children:[(0,K.jsxs)(`div`,{className:`mb-6`,children:[(0,K.jsxs)(`h1`,{className:`text-2xl font-bold text-white flex items-center gap-3`,children:[(0,K.jsx)(Ku,{className:`w-7 h-7 text-bambu-green`}),e(`maintenance.title`)]}),(0,K.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:i===`status`?(0,K.jsxs)(K.Fragment,{children:[x>0&&(0,K.jsx)(`span`,{className:`text-red-700 dark:text-red-400`,children:e(`maintenance.dueCount`,{count:x})}),x>0&&S>0&&` · `,S>0&&(0,K.jsx)(`span`,{className:`text-amber-700 dark:text-amber-400`,children:e(`maintenance.warningCount`,{count:S})}),x===0&&S===0&&(0,K.jsx)(`span`,{className:`text-bambu-green`,children:e(`maintenance.allOk`)})]}):e(`maintenance.configureSettings`)})]}),(0,K.jsxs)(`div`,{className:`flex gap-1 mb-6 border-b border-bambu-dark-tertiary`,children:[(0,K.jsx)(`button`,{onClick:()=>a(`status`),className:`px-4 py-2 text-sm font-medium border-b-2 -mb-px transition-colors ${i===`status`?`text-bambu-green border-bambu-green`:`text-bambu-gray border-transparent hover:text-white`}`,children:e(`maintenance.statusTab`)}),(0,K.jsx)(`button`,{onClick:()=>a(`settings`),className:`px-4 py-2 text-sm font-medium border-b-2 -mb-px transition-colors ${i===`settings`?`text-bambu-green border-bambu-green`:`text-bambu-gray border-transparent hover:text-white`}`,children:e(`maintenance.settingsTab`)})]}),i===`status`?(0,K.jsx)(`div`,{className:`space-y-6`,children:o&&o.length>0?[...o].sort((e,t)=>{let n=e.due_count*10+e.warning_count,r=t.due_count*10+t.warning_count;return n===r?e.printer_name.localeCompare(t.printer_name):r-n}).map(t=>(0,K.jsx)(fWe,{overview:t,onPerform:_,onToggle:v,onSetHours:b,hasPermission:r,t:e},t.printer_id)):(0,K.jsx)(Ed,{children:(0,K.jsxs)(Od,{className:`text-center py-16`,children:[(0,K.jsx)(Ku,{className:`w-16 h-16 mx-auto mb-4 text-bambu-gray/30`}),(0,K.jsx)(`p`,{className:`text-lg font-medium text-white mb-2`,children:e(`common.noPrinters`)}),(0,K.jsx)(`p`,{className:`text-bambu-gray`,children:e(`maintenance.configureSettings`)})]})})}):(0,K.jsx)(pWe,{overview:o,types:c||[],onUpdateInterval:(e,t)=>u.mutate({id:e,data:t}),onAddType:async(r,i)=>{let a=await Q.createMaintenanceType(r);for(let e of i)await Q.assignMaintenanceType(e,a.id);t.invalidateQueries({queryKey:[`maintenanceTypes`]}),t.invalidateQueries({queryKey:[`maintenanceOverview`]}),n(e(`maintenance.typeUpdated`))},onUpdateType:(e,t)=>d.mutate({id:e,data:t}),onDeleteType:e=>f.mutate(e),onRestoreDefaults:()=>p.mutate(),isRestoringDefaults:p.isPending,onAssignType:(e,t)=>h.mutate({printerId:e,typeId:t}),onRemoveItem:e=>g.mutate(e),hasPermission:r,t:e})]})}var H6=[`#ef4444`,`#f97316`,`#eab308`,`#22c55e`,`#06b6d4`,`#3b82f6`,`#8b5cf6`,`#ec4899`,`#6b7280`];function U6({project:e,onClose:t,onSave:n,isLoading:r,currencySymbol:i,t:a}){let[o,s]=(0,y.useState)(e?.name||``),[c,l]=(0,y.useState)(e?.description||``),[u,d]=(0,y.useState)(e?.color||H6[0]),[f,p]=(0,y.useState)(e?.target_count?.toString()||``),[m,h]=(0,y.useState)(e?.target_parts_count?.toString()||``),[g,_]=(0,y.useState)(e?.status||`active`),[v,b]=(0,y.useState)(e?.tags||``),[x,S]=(0,y.useState)(e?.due_date?.split(`T`)[0]||``),[C,w]=(0,y.useState)(e?.priority||`normal`),[T,E]=(0,y.useState)(e?.budget?.toString()||``),[D,O]=(0,y.useState)(e?.url||``),[k,A]=(0,y.useState)(null),j=oo(),[M,N]=(0,y.useState)(e?.cover_image_filename||null),P=(0,y.useRef)(null),[F,I]=(0,y.useState)(!1),[L,R]=(0,y.useState)(0);return(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg w-full max-w-md border border-bambu-dark-tertiary flex flex-col max-h-[calc(100vh-2rem)]`,children:[(0,K.jsx)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary flex-shrink-0`,children:(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:a(e?`projects.editProject`:`projects.newProject`)})}),(0,K.jsxs)(`form`,{onSubmit:t=>{t.preventDefault();let r=D.trim();if(r&&!/^https?:\/\//i.test(r)){A(a(`projects.urlInvalid`));return}A(null),n({name:o.trim(),description:c.trim()||void 0,color:u,target_count:f?parseInt(f,10):void 0,target_parts_count:m?parseInt(m,10):void 0,tags:e?v.trim()||null:v.trim()||void 0,due_date:e?x||null:x||void 0,priority:C,budget:T.trim()?parseFloat(T):null,url:e?r||null:r||void 0,...e&&{status:g}})},className:`flex flex-col flex-1 min-h-0`,children:[(0,K.jsxs)(`div`,{className:`p-4 space-y-4 overflow-y-auto flex-1`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`common.name`)}),(0,K.jsx)(`input`,{type:`text`,value:o,onChange:e=>s(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:a(`projects.namePlaceholder`),required:!0})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`common.description`)}),(0,K.jsx)(`textarea`,{value:c,onChange:e=>l(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green resize-none`,placeholder:a(`projects.descriptionPlaceholder`),rows:2})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`projects.urlLabel`)}),(0,K.jsx)(`input`,{type:`url`,value:D,onChange:e=>{O(e.target.value),k&&A(null)},className:`w-full bg-bambu-dark border rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none ${k?`border-red-500 focus:border-red-500`:`border-bambu-dark-tertiary focus:border-bambu-green`}`,placeholder:a(`projects.urlPlaceholder`),maxLength:2048}),k&&(0,K.jsx)(`p`,{className:`text-xs text-red-600 dark:text-red-400 mt-1`,children:k})]}),e&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`projects.coverImageLabel`)}),(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`w-20 h-20 rounded bg-bambu-dark border border-bambu-dark-tertiary overflow-hidden flex items-center justify-center flex-shrink-0`,children:M?(0,K.jsx)(`img`,{src:`${Q.getProjectCoverImageUrl(e.id)}?v=${L}`,alt:a(`projects.coverImageAlt`),className:`w-full h-full object-cover`}):(0,K.jsx)(Fc,{className:`w-6 h-6 text-bambu-gray`})}),(0,K.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,K.jsx)(`input`,{ref:P,type:`file`,accept:`image/jpeg,image/png,image/gif,image/webp`,onChange:async t=>{let n=t.target.files?.[0];if(!(!n||!e)){I(!0);try{N((await Q.uploadProjectCoverImage(e.id,n)).filename),R(e=>e+1),j.invalidateQueries({queryKey:[`projects`]})}catch{}finally{I(!1),P.current&&(P.current.value=``)}}},className:`hidden`}),(0,K.jsxs)($,{type:`button`,variant:`secondary`,onClick:()=>P.current?.click(),disabled:F,children:[F?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(Nu,{className:`w-4 h-4 mr-1`}),a(M?`projects.coverImageReplace`:`projects.coverImageUpload`)]}),M&&(0,K.jsxs)($,{type:`button`,variant:`secondary`,onClick:async()=>{if(e){I(!0);try{await Q.deleteProjectCoverImage(e.id),N(null),R(e=>e+1),j.invalidateQueries({queryKey:[`projects`]})}finally{I(!1)}}},disabled:F,children:[(0,K.jsx)(qu,{className:`w-4 h-4 mr-1`}),a(`projects.coverImageRemove`)]})]})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`projects.color`)}),(0,K.jsx)(`div`,{className:`flex gap-2 flex-wrap`,children:H6.map(e=>(0,K.jsx)(`button`,{type:`button`,onClick:()=>d(e),className:`w-8 h-8 rounded-full transition-transform ${u===e?`ring-2 ring-white ring-offset-2 ring-offset-bambu-dark-secondary scale-110`:``}`,style:{backgroundColor:e}},e))})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`projects.targetPlates`)}),(0,K.jsx)(`input`,{type:`number`,value:f,onChange:e=>p(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:a(`projects.targetPlatesPlaceholder`),min:`1`}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:a(`projects.targetPlatesHelp`)})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`projects.targetParts`)}),(0,K.jsx)(`input`,{type:`number`,value:m,onChange:e=>h(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:a(`projects.targetPartsPlaceholder`),min:`1`}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:a(`projects.targetPartsHelp`)})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`projects.tagsLabel`)}),(0,K.jsx)(`input`,{type:`text`,value:v,onChange:e=>b(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:a(`projects.tagsPlaceholder`)})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`projects.dueDate`)}),(0,K.jsx)(`input`,{type:`date`,value:x,onChange:e=>S(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white focus:outline-none focus:border-bambu-green`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`projects.priority`)}),(0,K.jsxs)(`select`,{value:C,onChange:e=>w(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white focus:outline-none focus:border-bambu-green`,children:[(0,K.jsx)(`option`,{value:`low`,children:a(`projects.priorityLow`)}),(0,K.jsx)(`option`,{value:`normal`,children:a(`projects.priorityNormal`)}),(0,K.jsx)(`option`,{value:`high`,children:a(`projects.priorityHigh`)}),(0,K.jsx)(`option`,{value:`urgent`,children:a(`projects.priorityUrgent`)})]})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`projectDetail.cost.budget`)}),(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(`span`,{className:`absolute left-3 top-1/2 -translate-y-1/2 text-bambu-gray pointer-events-none`,children:i}),(0,K.jsx)(`input`,{type:`number`,step:`0.01`,min:`0`,value:T,onChange:e=>E(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded pl-8 pr-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:`0.00`})]})]}),e&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`common.status`)}),(0,K.jsxs)(`select`,{value:g,onChange:e=>_(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white focus:outline-none focus:border-bambu-green`,children:[(0,K.jsx)(`option`,{value:`active`,children:a(`projects.statusActive`)}),(0,K.jsx)(`option`,{value:`completed`,children:a(`projects.statusCompleted`)}),(0,K.jsx)(`option`,{value:`archived`,children:a(`projects.statusArchived`)})]})]})]}),(0,K.jsxs)(`div`,{className:`flex justify-end gap-2 p-4 border-t border-bambu-dark-tertiary flex-shrink-0`,children:[(0,K.jsx)($,{type:`button`,variant:`secondary`,onClick:t,children:a(`common.cancel`)}),(0,K.jsx)($,{type:`submit`,disabled:!o.trim()||r,children:r?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):a(e?`common.save`:`projects.create`)})]})]})]})})}function hWe({projectId:e,altText:t}){let n=(0,y.useRef)(null),[r,i]=(0,y.useState)(!1),[a,o]=(0,y.useState)(null);return(0,K.jsxs)(`div`,{ref:n,className:`relative flex-shrink-0`,onMouseEnter:()=>{if(!n.current)return;let e=n.current.getBoundingClientRect(),t=window.innerWidth,r=window.innerHeight,a=e.right+8;a+384>t-8&&(a=e.left-384-8);let s=e.top;s+384>r-8&&(s=r-384-8),s<8&&(s=8),o({left:a,top:s}),i(!0)},onMouseLeave:()=>i(!1),onClick:e=>e.stopPropagation(),children:[(0,K.jsx)(`div`,{className:`w-10 h-10 rounded-lg overflow-hidden bg-bambu-dark border border-bambu-dark-tertiary`,children:(0,K.jsx)(`img`,{src:Q.getProjectCoverImageUrl(e),alt:t,className:`w-full h-full object-cover`,loading:`lazy`})}),r&&a&&(0,Bp.createPortal)((0,K.jsx)(`div`,{className:`fixed z-[100] w-96 h-96 rounded-lg overflow-hidden border border-bambu-dark-tertiary shadow-2xl bg-bambu-dark pointer-events-none`,style:{left:a.left,top:a.top},"aria-hidden":`true`,children:(0,K.jsx)(`img`,{src:Q.getProjectCoverImageUrl(e),alt:``,className:`w-full h-full object-contain`,loading:`lazy`})}),document.body)]})}function gWe({project:e,onClick:t,onEdit:n,onDelete:r,hasPermission:i,t:a}){let o=e.target_count?Math.round(e.archive_count/e.target_count*100):0,s=e.target_parts_count?Math.round(e.completed_count/e.target_parts_count*100):0,c=e.status===`completed`,l=e.status===`archived`,[u,d]=(0,y.useState)(!1),f=c?{icon:gs,color:`text-bambu-green`,bg:`bg-bambu-green/10`}:l?{icon:jo,color:`text-bambu-gray`,bg:`bg-bambu-gray/10`}:e.queue_count>0?{icon:ws,color:`text-blue-600 dark:text-blue-400`,bg:`bg-blue-50 dark:bg-blue-400/10`}:{icon:uc,color:`text-bambu-gray`,bg:`bg-bambu-gray/10`};return(0,K.jsxs)(`div`,{className:`group relative bg-gradient-to-br from-bambu-card to-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary hover:border-bambu-green/50 hover:shadow-lg hover:shadow-bambu-green/5 transition-all duration-300 cursor-pointer overflow-hidden`,onClick:t,children:[(0,K.jsx)(`div`,{className:`absolute top-0 left-0 w-1.5 h-full`,style:{backgroundColor:e.color||`#6b7280`,boxShadow:`0 0 12px ${e.color||`#6b7280`}40`}}),(0,K.jsxs)(`div`,{className:`p-5 pl-6`,children:[(0,K.jsxs)(`div`,{className:`flex items-start justify-between mb-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0 flex-1`,children:[e.cover_image_filename?(0,K.jsx)(hWe,{projectId:e.id,altText:a(`projects.coverImageAlt`)}):(0,K.jsx)(`div`,{className:`p-2 rounded-lg ${f.bg} flex-shrink-0`,children:(0,K.jsx)(f.icon,{className:`w-5 h-5 ${f.color}`})}),(0,K.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,K.jsx)(`h3`,{className:`font-semibold text-white truncate`,children:e.name}),e.url&&(0,K.jsx)(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,onClick:e=>e.stopPropagation(),title:e.url,"aria-label":a(`projects.openExternalUrl`),className:`inline-flex items-center justify-center w-6 h-6 rounded bg-bambu-dark border border-bambu-dark-tertiary text-bambu-green hover:bg-bambu-green/10 hover:border-bambu-green transition-colors flex-shrink-0`,children:(0,K.jsx)(Zs,{className:`w-3.5 h-3.5`})}),e.target_parts_count?(0,K.jsxs)(`span`,{className:`text-xs px-2 py-0.5 rounded-full whitespace-nowrap font-medium ${s>=100?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark text-bambu-gray`}`,children:[e.completed_count,`/`,e.target_parts_count,` `,a(`projects.parts`)]}):e.target_count?(0,K.jsxs)(`span`,{className:`text-xs px-2 py-0.5 rounded-full whitespace-nowrap font-medium ${o>=100?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark text-bambu-gray`}`,children:[e.archive_count,`/`,e.target_count,` `,a(`projects.plates`)]}):e.completed_count>0?(0,K.jsxs)(`span`,{className:`text-xs px-2 py-0.5 rounded-full whitespace-nowrap font-medium bg-bambu-dark text-bambu-gray`,children:[e.completed_count,` `,a(`projects.parts`)]}):null,c&&(0,K.jsx)(`span`,{className:`text-xs bg-bambu-green/20 text-bambu-green px-2 py-0.5 rounded-full whitespace-nowrap`,children:a(`projects.done`)}),l&&(0,K.jsx)(`span`,{className:`text-xs bg-bambu-gray/20 text-bambu-gray px-2 py-0.5 rounded-full whitespace-nowrap`,children:a(`projects.statusArchived`)})]}),e.description&&(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray/70 mt-1 line-clamp-1`,children:e.description}),e.archives&&e.archives.length>0&&(()=>{let t=e.archives.map(e=>e.filament_type).filter(Boolean).flatMap(e=>e.split(`,`).map(e=>e.trim())).filter(Boolean),n=[...new Set(t)],r=e.archives.map(e=>e.filament_color).filter(Boolean).flatMap(e=>e.split(`,`).map(e=>e.trim())).filter(e=>e.startsWith(`#`)||/^[0-9A-Fa-f]{6}$/.test(e)),i=[...new Set(r)];return n.length===0&&i.length===0?null:(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mt-1.5`,children:[n.slice(0,3).map(e=>(0,K.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 bg-bambu-dark text-bambu-gray rounded`,children:e},e)),i.length>0&&(0,K.jsxs)(`div`,{className:`flex items-center gap-0.5`,children:[i.slice(0,5).map(e=>(0,K.jsx)(`div`,{className:`w-3 h-3 rounded-full border border-black/20`,style:{backgroundColor:e.startsWith(`#`)?e:`#${e}`},title:e},e)),i.length>5&&(0,K.jsxs)(`span`,{className:`text-[10px] text-bambu-gray ml-0.5`,children:[`+`,i.length-5]})]})]})})()]})]}),(0,K.jsxs)(`div`,{className:`relative`,onClick:e=>e.stopPropagation(),children:[(0,K.jsx)(`button`,{className:`p-1.5 rounded-lg hover:bg-bambu-dark text-bambu-gray hover:text-white transition-colors opacity-0 group-hover:opacity-100`,onClick:()=>d(!u),children:(0,K.jsx)(qs,{className:`w-4 h-4`})}),u&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`fixed inset-0 z-10`,onClick:()=>d(!1)}),(0,K.jsxs)(`div`,{className:`absolute right-0 top-8 z-20 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl py-1 min-w-[120px]`,children:[(0,K.jsxs)(`button`,{className:`w-full px-3 py-2 text-left text-sm flex items-center gap-2 ${i(`projects:update`)?`text-white hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{i(`projects:update`)&&(n(),d(!1))},disabled:!i(`projects:update`),title:i(`projects:update`)?void 0:a(`projects.noEditPermission`),children:[(0,K.jsx)(Sl,{className:`w-4 h-4`}),a(`common.edit`)]}),(0,K.jsxs)(`button`,{className:`w-full px-3 py-2 text-left text-sm flex items-center gap-2 ${i(`projects:delete`)?`text-red-600 dark:text-red-400 hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{i(`projects:delete`)&&(r(),d(!1))},disabled:!i(`projects:delete`),title:i(`projects:delete`)?void 0:a(`projects.noDeletePermission`),children:[(0,K.jsx)(Eu,{className:`w-4 h-4`}),a(`common.delete`)]})]})]})]})]}),(0,K.jsx)(`div`,{className:`mb-4`,children:e.target_count||e.target_parts_count?(0,K.jsxs)(`div`,{className:`space-y-3`,children:[e.target_count&&(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between text-xs mb-1`,children:[(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:a(`projects.plates`)}),(0,K.jsxs)(`span`,{className:o>=100?`text-bambu-green font-medium`:`text-white`,children:[e.archive_count,` / `,e.target_count]})]}),(0,K.jsx)(`div`,{className:`h-2 bg-bambu-dark/80 rounded-full overflow-hidden backdrop-blur-sm`,children:(0,K.jsx)(`div`,{className:`h-full transition-all duration-500 ease-out rounded-full relative`,style:{width:`${Math.min(o,100)}%`,background:o>=100?`linear-gradient(90deg, #22c55e, #4ade80)`:`linear-gradient(90deg, ${e.color||`#6b7280`}, ${e.color||`#6b7280`}cc)`,boxShadow:`0 0 8px ${o>=100?`#22c55e`:e.color||`#6b7280`}60`}})})]}),e.target_parts_count&&(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between text-xs mb-1`,children:[(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:a(`projects.parts`)}),(0,K.jsxs)(`span`,{className:s>=100?`text-bambu-green font-medium`:`text-white`,children:[e.completed_count,` / `,e.target_parts_count]})]}),(0,K.jsx)(`div`,{className:`h-2 bg-bambu-dark/80 rounded-full overflow-hidden backdrop-blur-sm`,children:(0,K.jsx)(`div`,{className:`h-full transition-all duration-500 ease-out rounded-full relative`,style:{width:`${Math.min(s,100)}%`,background:s>=100?`linear-gradient(90deg, #22c55e, #4ade80)`:`linear-gradient(90deg, ${e.color||`#6b7280`}, ${e.color||`#6b7280`}cc)`,boxShadow:`0 0 8px ${s>=100?`#22c55e`:e.color||`#6b7280`}60`}})})]}),e.failed_count>0&&(0,K.jsxs)(`div`,{className:`text-xs text-red-600 dark:text-red-400`,children:[e.failed_count,` `,a(`projects.failed`)]})]}):e.completed_count>0||e.failed_count>0?(0,K.jsxs)(`div`,{className:`flex items-center gap-4 text-xs`,children:[e.completed_count>0&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 text-bambu-gray`,children:[(0,K.jsx)(jo,{className:`w-3.5 h-3.5`}),(0,K.jsxs)(`span`,{children:[e.completed_count,` `,a(`projects.completed`)]})]}),e.failed_count>0&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 text-red-600 dark:text-red-400`,children:[(0,K.jsx)(ku,{className:`w-3.5 h-3.5`}),(0,K.jsxs)(`span`,{children:[e.failed_count,` `,a(`projects.failed`)]})]}),e.queue_count>0&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 text-blue-600 dark:text-blue-400`,children:[(0,K.jsx)(ws,{className:`w-3.5 h-3.5`}),(0,K.jsxs)(`span`,{children:[e.queue_count,` `,a(`projects.inQueue`)]})]})]}):(0,K.jsx)(`div`,{className:`text-xs text-bambu-gray/60 italic`,children:a(`projects.noPrintsYet`)})}),e.archives&&e.archives.length>0&&(0,K.jsxs)(`div`,{className:`mb-4`,children:[(0,K.jsx)(`div`,{className:`grid grid-cols-4 gap-1.5`,children:e.archives.slice(0,4).map(e=>(0,K.jsxs)(`div`,{className:`relative aspect-square rounded-lg bg-bambu-dark overflow-hidden border border-bambu-dark-tertiary`,title:e.print_name||`Unknown`,children:[e.thumbnail_path?(0,K.jsx)(`img`,{src:Q.getArchiveThumbnail(e.id),alt:e.print_name||``,className:`w-full h-full object-cover`}):(0,K.jsx)(`div`,{className:`w-full h-full flex items-center justify-center text-bambu-gray/50`,children:(0,K.jsx)(_l,{className:`w-6 h-6`})}),e.status===`failed`&&(0,K.jsx)(`div`,{className:`absolute inset-0 bg-red-500/40 flex items-center justify-center`,children:(0,K.jsx)(ku,{className:`w-4 h-4 text-white`})})]},e.id))}),e.archive_count>4&&(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1.5 text-center`,children:a(`common.more`,{count:e.archive_count-4})})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between pt-3 border-t border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-4 text-xs text-bambu-gray`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5`,title:a(`projects.printJobs`),children:[(0,K.jsx)(Vc,{className:`w-3.5 h-3.5 text-blue-600 dark:text-blue-400`}),(0,K.jsxs)(`span`,{children:[e.archive_count,` `,a(`projects.plates`)]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5`,title:a(`projects.partsPrinted`),children:[(0,K.jsx)(_l,{className:`w-3.5 h-3.5 text-bambu-green`}),(0,K.jsxs)(`span`,{children:[e.completed_count,` `,a(`projects.parts`)]})]}),e.failed_count>0&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 text-red-600 dark:text-red-400`,title:a(`projects.failedParts`),children:[(0,K.jsx)(ku,{className:`w-3.5 h-3.5`}),(0,K.jsx)(`span`,{children:e.failed_count})]}),e.queue_count>0&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 text-yellow-600 dark:text-yellow-400`,title:a(`projects.inQueue`),children:[(0,K.jsx)(qc,{className:`w-3.5 h-3.5`}),(0,K.jsx)(`span`,{children:e.queue_count})]})]}),(0,K.jsx)(cs,{className:`w-4 h-4 text-bambu-gray/50 group-hover:text-bambu-gray transition-colors`})]})]})]})}function _We(){let{t:e}=W(),t=ir(),n=oo(),{showToast:r}=Pd(),{hasPermission:i}=bd(),[a,o]=(0,y.useState)(!1),[s,c]=(0,y.useState)(),[l,u]=(0,y.useState)(`active`),[d,f]=(0,y.useState)(null),{data:p}=q({queryKey:[`settings`],queryFn:Q.getSettings}),m=df(p?.currency||`USD`),{data:h,isLoading:g}=q({queryKey:[`projects`,l===`all`?void 0:l],queryFn:()=>Q.getProjects(l===`all`?void 0:l)}),_=J({mutationFn:e=>Q.createProject(e),onSuccess:()=>{n.invalidateQueries({queryKey:[`projects`]}),o(!1),r(e(`projects.toast.created`),`success`)},onError:e=>{r(e.message,`error`)}}),v=J({mutationFn:({id:e,data:t})=>Q.updateProject(e,t),onSuccess:()=>{n.invalidateQueries({queryKey:[`projects`]}),o(!1),c(void 0),r(e(`projects.toast.updated`),`success`)},onError:e=>{r(e.message,`error`)}}),b=J({mutationFn:e=>Q.deleteProject(e),onSuccess:()=>{f(null),r(e(`projects.toast.deleted`),`success`),setTimeout(()=>window.location.reload(),100)},onError:e=>{f(null),r(e.message,`error`)}}),x=J({mutationFn:e=>Q.importProject(e),onSuccess:()=>{n.invalidateQueries({queryKey:[`projects`]}),r(e(`projects.toast.imported`),`success`)},onError:e=>{r(e.message,`error`)}}),S=(0,y.useRef)(null),C=async()=>{try{let t=await Q.getProjects(),n=await Promise.all(t.map(async e=>await Q.exportProjectJson(e.id))),i=new Blob([JSON.stringify(n,null,2)],{type:`application/json`}),a=URL.createObjectURL(i),o=document.createElement(`a`);o.href=a,o.download=`bambuddy_projects_${new Date().toISOString().split(`T`)[0]}.json`,o.click(),URL.revokeObjectURL(a),r(e(`projects.toast.exported`),`success`)}catch(e){r(e.message,`error`)}},w=()=>{S.current?.click()},T=async t=>{let i=t.target.files?.[0];if(i){try{if(i.name.toLowerCase().endsWith(`.zip`))await Q.importProjectFile(i),n.invalidateQueries({queryKey:[`projects`]}),r(e(`projects.toast.imported`),`success`);else{let t=await i.text(),n=JSON.parse(t),a=Array.isArray(n)?n:[n];for(let e of a)await x.mutateAsync(e);a.length>1&&r(e(`projects.toast.multipleImported`,{count:a.length}),`success`)}}catch(t){r(`${e(`projects.toast.importFailed`)}: ${t.message}`,`error`)}t.target.value=``}},E=e=>{s?v.mutate({id:s.id,data:e}):_.mutate(e)},D=e=>{c(e),o(!0)},O=e=>{t(`/projects/${e.id}`)},k=e=>{f(e)},A=()=>{d!==null&&b.mutate(d)},j=h?.reduce((e,t)=>(e[t.status]=(e[t.status]||0)+1,e.all=(e.all||0)+1,e),{})||{};return(0,K.jsxs)(`div`,{className:`p-4 md:p-8 space-y-8`,children:[(0,K.jsx)(`input`,{ref:S,type:`file`,accept:`.json,.zip`,onChange:T,className:`hidden`}),(0,K.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center justify-between gap-4`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`h1`,{className:`text-2xl font-bold text-white flex items-center gap-3`,children:[(0,K.jsx)(uc,{className:`w-7 h-7 text-bambu-green`}),e(`projects.title`)]}),(0,K.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:e(`projects.subtitle`)})]}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsxs)($,{variant:`secondary`,onClick:w,disabled:!i(`projects:create`),title:i(`projects:create`)?e(`projects.importProject`):e(`projects.noImportPermission`),children:[(0,K.jsx)(Nu,{className:`w-4 h-4 mr-2`}),e(`projects.import`)]}),(0,K.jsxs)($,{variant:`secondary`,onClick:C,disabled:!i(`projects:read`),title:i(`projects:read`)?e(`projects.exportAll`):e(`projects.noExportPermission`),children:[(0,K.jsx)(Ws,{className:`w-4 h-4 mr-2`}),e(`projects.export`)]}),(0,K.jsxs)($,{onClick:()=>o(!0),className:`sm:w-auto w-full`,disabled:!i(`projects:create`),title:i(`projects:create`)?void 0:e(`projects.noCreatePermission`),children:[(0,K.jsx)(Ol,{className:`w-4 h-4 mr-2`}),e(`projects.newProject`)]})]})]}),(0,K.jsx)(`div`,{className:`flex gap-1 p-1 bg-bambu-dark rounded-xl w-fit`,children:[{key:`active`,label:e(`projects.statusActive`),icon:ws},{key:`completed`,label:e(`projects.statusCompleted`),icon:gs},{key:`archived`,label:e(`projects.statusArchived`),icon:jo},{key:`all`,label:e(`common.all`),icon:uc}].map(({key:e,label:t,icon:n})=>(0,K.jsxs)(`button`,{onClick:()=>u(e),className:`flex items-center gap-2 px-4 py-2 text-sm rounded-lg transition-all ${l===e?`bg-bambu-card text-white shadow-sm`:`text-bambu-gray hover:text-white`}`,children:[(0,K.jsx)(n,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{children:t}),j[e]>0&&(0,K.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded-full ${l===e?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark-tertiary`}`,children:j[e]})]},e))}),g?(0,K.jsx)(`div`,{className:`flex items-center justify-center py-20`,children:(0,K.jsxs)(`div`,{className:`flex flex-col items-center gap-3`,children:[(0,K.jsx)(X,{className:`w-8 h-8 animate-spin text-bambu-green`}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`projects.loading`)})]})}):h?.length===0?(0,K.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-20 px-4`,children:[(0,K.jsx)(`div`,{className:`p-4 bg-bambu-dark rounded-2xl mb-4`,children:(0,K.jsx)(uc,{className:`w-12 h-12 text-bambu-gray/50`})}),(0,K.jsx)(`h3`,{className:`text-lg font-medium text-white mb-2`,children:l===`all`?e(`projects.noProjects`):e(`projects.noProjectsFiltered`,{status:l})}),(0,K.jsx)(`p`,{className:`text-bambu-gray text-center max-w-md mb-6`,children:l===`all`?e(`projects.createFirst`):e(`projects.noProjectsFilteredHelp`,{status:l})}),l===`all`&&(0,K.jsxs)($,{onClick:()=>o(!0),disabled:!i(`projects:create`),title:i(`projects:create`)?void 0:e(`projects.noCreatePermission`),children:[(0,K.jsx)(Ol,{className:`w-4 h-4 mr-2`}),e(`projects.createFirstButton`)]})]}):(0,K.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-8`,children:h?.map(t=>(0,K.jsx)(gWe,{project:t,onClick:()=>O(t),onEdit:()=>D(t),onDelete:()=>k(t.id),hasPermission:i,t:e},t.id))}),d!==null&&(0,K.jsx)(Vd,{title:e(`projects.deleteProject`),message:e(`projects.deleteConfirm`),confirmText:e(`projects.deleteProject`),variant:`danger`,onConfirm:A,onCancel:()=>f(null)}),a&&(0,K.jsx)(U6,{project:s,onClose:()=>{o(!1),c(void 0)},onSave:E,isLoading:_.isPending||v.isPending,currencySymbol:m,t:e})]})}function vWe(e){let t=e.toLowerCase();return t.endsWith(`.gcode`)||t.endsWith(`.gcode.3mf`)}function yWe(e){return e>=1e3?`${(e/1e3).toFixed(2)}kg`:`${Math.round(e)}g`}function bWe({status:e,t}){let n={active:`bg-bambu-green/20 text-bambu-green`,completed:`bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400`,archived:`bg-bambu-gray/20 text-bambu-gray`},r=n[e]||n.active,i={active:t(`projectDetail.status.active`),completed:t(`projectDetail.status.completed`),archived:t(`projectDetail.status.archived`)};return(0,K.jsx)(`span`,{className:`px-2 py-1 rounded text-sm font-medium ${r}`,children:i[e]||e.charAt(0).toUpperCase()+e.slice(1)})}function W6({icon:e,label:t,value:n,subValue:r,hint:i,color:a=`text-bambu-gray`}){return(0,K.jsx)(Ed,{children:(0,K.jsx)(Od,{className:`p-4`,children:(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,title:i,children:[(0,K.jsx)(`div`,{className:`p-2 rounded-lg bg-bambu-dark ${a}`,children:(0,K.jsx)(e,{className:`w-5 h-5`})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:t}),(0,K.jsx)(`p`,{className:`text-xl font-semibold text-white`,children:n}),r&&(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray/70`,children:r})]})]})})})}function xWe({archives:e,t}){return e.length===0?(0,K.jsxs)(`div`,{className:`text-center py-8 text-bambu-gray`,children:[(0,K.jsx)(_l,{className:`w-12 h-12 mx-auto mb-2 opacity-50`}),(0,K.jsx)(`p`,{children:t(`projectDetail.noPrints`)})]}):(0,K.jsx)(`div`,{className:`grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 xl:grid-cols-6 gap-3`,children:e.map(e=>(0,K.jsxs)(Oi,{to:`/archives?search=${encodeURIComponent(e.print_name||``)}`,className:`group relative aspect-square rounded-lg bg-bambu-dark border border-bambu-dark-tertiary overflow-hidden hover:border-bambu-green transition-colors`,children:[e.thumbnail_path?(0,K.jsx)(`img`,{src:Q.getArchiveThumbnail(e.id),alt:e.print_name||`Print`,className:`w-full h-full object-cover`}):(0,K.jsx)(`div`,{className:`w-full h-full flex items-center justify-center text-bambu-gray`,children:(0,K.jsx)(_l,{className:`w-8 h-8`})}),e.status===`failed`&&(0,K.jsx)(`div`,{className:`absolute inset-0 bg-red-500/30 flex items-center justify-center`,children:(0,K.jsx)(xs,{className:`w-8 h-8 text-white`})}),e.status===`completed`&&(0,K.jsx)(`div`,{className:`absolute top-1 right-1`,children:(0,K.jsx)(hs,{className:`w-4 h-4 text-bambu-green`})}),(0,K.jsx)(`div`,{className:`absolute inset-x-0 bottom-0 bg-gradient-to-t from-black/80 to-transparent p-2 opacity-0 group-hover:opacity-100 transition-opacity`,children:(0,K.jsx)(`p`,{className:`text-xs text-white truncate`,children:e.print_name||`Unknown`})})]},e.id))})}function SWe({priority:e,t}){let n={low:{color:`bg-gray-500/20 text-gray-400`,label:t(`projectDetail.priority.low`)},normal:{color:`bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400`,label:t(`projectDetail.priority.normal`)},high:{color:`bg-orange-100 dark:bg-orange-500/20 text-orange-700 dark:text-orange-400`,label:t(`projectDetail.priority.high`)},urgent:{color:`bg-red-100 dark:bg-red-500/20 text-red-700 dark:text-red-400`,label:t(`projectDetail.priority.urgent`)}},{color:r,label:i}=n[e]||n.normal;return(0,K.jsxs)(`span`,{className:`px-2 py-1 rounded text-xs font-medium flex items-center gap-1 ${r}`,children:[e===`urgent`&&(0,K.jsx)(ku,{className:`w-3 h-3`}),i]})}function G6(e,t){if(!e)return null;let n=jf(e);if(!n)return null;let r=new Date,i=Math.ceil((n.getTime()-r.getTime())/(1e3*60*60*24));return i<0?{color:`text-red-700 dark:text-red-400`,label:t(`projectDetail.dueDate.overdue`)}:i===0?{color:`text-orange-700 dark:text-orange-400`,label:t(`projectDetail.dueDate.today`)}:i<=3?{color:`text-yellow-700 dark:text-yellow-400`,label:t(`projectDetail.dueDate.daysLeft`,{count:i})}:{color:`text-bambu-gray`,label:t(`projectDetail.dueDate.daysLeft`,{count:i})}}function CWe(){let{id:e}=lr(),t=ir(),{t:n}=W(),r=oo(),{showToast:i}=Pd(),{hasPermission:a}=bd(),[o,s]=(0,y.useState)(!1),[c,l]=(0,y.useState)(!1),[u,d]=(0,y.useState)(``),[f,p]=(0,y.useState)(null),m=parseInt(e||`0`,10),{data:h,isLoading:g,error:_}=q({queryKey:[`project`,m],queryFn:()=>Q.getProject(m),enabled:m>0}),{data:v,isLoading:b}=q({queryKey:[`project-archives`,m],queryFn:()=>Q.getProjectArchives(m),enabled:m>0}),{data:x,isLoading:S}=q({queryKey:[`project-bom`,m],queryFn:()=>Q.getProjectBOM(m),enabled:m>0}),{data:C,isLoading:w}=q({queryKey:[`project-timeline`,m],queryFn:()=>Q.getProjectTimeline(m,20),enabled:m>0}),{data:T}=q({queryKey:[`settings`],queryFn:Q.getSettings}),{data:E}=q({queryKey:[`project-folders`,m],queryFn:()=>Q.getLibraryFoldersByProject(m),enabled:m>0}),{data:D,isLoading:O}=q({queryKey:[`project-files`,m],queryFn:()=>Q.getLibraryFiles(null,!1,m),enabled:m>0}),k=(0,y.useMemo)(()=>{let e=new Map;for(let t of D??[])if(t.folder_id!=null){let n=e.get(t.folder_id)??[];n.push(t),e.set(t.folder_id,n)}return e},[D]),A=df(T?.currency||`USD`),j=T?.time_format||`system`,M=J({mutationFn:e=>Q.updateProject(m,e),onSuccess:()=>{r.invalidateQueries({queryKey:[`project`,m]}),r.invalidateQueries({queryKey:[`projects`]}),s(!1),l(!1),i(n(`projectDetail.toast.projectUpdated`),`success`)},onError:e=>{i(e.message,`error`)}}),N=()=>{d(h?.notes||``),l(!0)},P=()=>{M.mutate({notes:u})},F=()=>{l(!1),d(``)},[I,L]=(0,y.useState)(``),[R,z]=(0,y.useState)(1),[B,V]=(0,y.useState)(``),[ee,te]=(0,y.useState)(``),[ne,re]=(0,y.useState)(``),[ie,H]=(0,y.useState)(!1),[ae,oe]=(0,y.useState)(!1),[U,se]=(0,y.useState)(null),[ce,le]=(0,y.useState)(``),[ue,de]=(0,y.useState)(1),[fe,pe]=(0,y.useState)(``),[me,he]=(0,y.useState)(``),[ge,_e]=(0,y.useState)(``),[ve,ye]=(0,y.useState)({isOpen:!1,title:``,message:``,onConfirm:()=>{}}),be=J({mutationFn:e=>Q.createBOMItem(m,e),onSuccess:()=>{r.invalidateQueries({queryKey:[`project-bom`,m]}),r.invalidateQueries({queryKey:[`project`,m]}),L(``),z(1),V(``),te(``),re(``),H(!1),i(n(`projectDetail.toast.partAdded`),`success`)},onError:e=>i(e.message,`error`)}),xe=J({mutationFn:({itemId:e,data:t})=>Q.updateBOMItem(m,e,t),onSuccess:()=>{r.invalidateQueries({queryKey:[`project-bom`,m]}),r.invalidateQueries({queryKey:[`project`,m]}),se(null)},onError:e=>i(e.message,`error`)}),Se=J({mutationFn:e=>Q.deleteBOMItem(m,e),onSuccess:()=>{r.invalidateQueries({queryKey:[`project-bom`,m]}),r.invalidateQueries({queryKey:[`project`,m]}),i(n(`projectDetail.toast.partRemoved`),`success`)},onError:e=>i(e.message,`error`)}),Ce=e=>{e.preventDefault(),I.trim()&&be.mutate({name:I.trim(),quantity_needed:R,unit_price:B?parseFloat(B):void 0,sourcing_url:ee.trim()||void 0,remarks:ne.trim()||void 0})},we=e=>{let t=e.is_complete?0:e.quantity_needed;xe.mutate({itemId:e.id,data:{quantity_acquired:t}})},Te=(e,t)=>{ye({isOpen:!0,title:n(`projectDetail.bom.deletePart`),message:n(`projectDetail.bom.deleteConfirm`,{name:t}),onConfirm:()=>{ye(e=>({...e,isOpen:!1})),Se.mutate(e)}})},Ee=e=>{se(e),le(e.name),de(e.quantity_needed),pe(e.unit_price?.toString()||``),he(e.sourcing_url||``),_e(e.remarks||``)},De=e=>{e.preventDefault(),!(!U||!ce.trim())&&xe.mutate({itemId:U.id,data:{name:ce.trim(),quantity_needed:ue,unit_price:fe?parseFloat(fe):void 0,sourcing_url:me.trim()||void 0,remarks:ge.trim()||void 0}})},Oe=()=>{se(null)},ke=async()=>{try{let{blob:e,filename:t}=await Q.exportProjectZip(Number(m)),r=URL.createObjectURL(e),a=document.createElement(`a`);a.href=r,a.download=t||`${h?.name||`project`}_${new Date().toISOString().split(`T`)[0]}.zip`,a.click(),URL.revokeObjectURL(r),i(n(`projectDetail.toast.projectExported`),`success`)}catch(e){i(e.message,`error`)}},Ae=J({mutationFn:()=>Q.createTemplateFromProject(m),onSuccess:()=>{r.invalidateQueries({queryKey:[`projects`]}),i(n(`projectDetail.toast.templateCreated`),`success`)},onError:e=>i(e.message,`error`)}),je=e=>Nf(e,j,{month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`});if(g)return(0,K.jsx)(`div`,{className:`flex items-center justify-center py-24`,children:(0,K.jsx)(X,{className:`w-8 h-8 animate-spin text-bambu-green`})});if(_||!h)return(0,K.jsxs)(`div`,{className:`text-center py-24`,children:[(0,K.jsx)(`p`,{className:`text-bambu-gray`,children:_?`${n(`common.error`)}: ${_.message}`:n(`projectDetail.notFound`)}),(0,K.jsx)($,{variant:`secondary`,className:`mt-4`,onClick:()=>t(`/projects`),children:n(`projectDetail.backToProjects`)})]});let Me=h.stats,Ne=Me?.progress_percent??0,Pe=Me?.parts_progress_percent??0;return(0,K.jsxs)(`div`,{className:`p-4 md:p-8 space-y-8`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-bambu-gray`,children:[(0,K.jsx)(Oi,{to:`/projects`,className:`hover:text-white transition-colors`,children:n(`nav.projects`)}),(0,K.jsx)(cs,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{className:`text-white`,children:h.name})]}),(0,K.jsxs)(`div`,{className:`flex items-start justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,K.jsx)(`button`,{onClick:()=>t(`/projects`),className:`p-2 rounded-lg bg-bambu-card hover:bg-bambu-dark-tertiary transition-colors`,children:(0,K.jsx)(Po,{className:`w-5 h-5 text-bambu-gray`})}),(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`w-4 h-4 rounded-full shrink-0`,style:{backgroundColor:h.color||`#6b7280`}}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h1`,{className:`text-2xl font-bold text-white`,children:h.name}),h.description&&(0,K.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:h.description})]})]}),(0,K.jsx)(bWe,{status:h.status,t:n})]}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsxs)($,{variant:`secondary`,onClick:ke,disabled:!a(`projects:read`),title:a(`projects:read`)?n(`projectDetail.exportProject`):n(`projectDetail.noExportPermission`),children:[(0,K.jsx)(Ws,{className:`w-4 h-4 mr-2`}),n(`projectDetail.export`)]}),(0,K.jsxs)($,{onClick:()=>s(!0),disabled:!a(`projects:update`),title:a(`projects:update`)?void 0:n(`projectDetail.noEditPermission`),children:[(0,K.jsx)(Sl,{className:`w-4 h-4 mr-2`}),n(`common.edit`)]})]})]}),(h.target_count||h.target_parts_count)&&(0,K.jsx)(Ed,{children:(0,K.jsxs)(Od,{className:`p-4 space-y-4`,children:[h.target_count&&(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:n(`projectDetail.progress.platesProgress`)}),(0,K.jsxs)(`span`,{className:`text-sm font-medium text-white`,children:[Me?.total_archives||0,` / `,h.target_count,` `,n(`projectDetail.progress.printJobs`)]})]}),(0,K.jsx)(`div`,{className:`h-3 bg-bambu-dark rounded-full overflow-hidden`,children:(0,K.jsx)(`div`,{className:`h-full transition-all duration-500`,style:{width:`${Math.min(Ne,100)}%`,backgroundColor:Ne>=100?`#22c55e`:h.color||`#6b7280`}})}),(0,K.jsxs)(`div`,{className:`flex justify-between mt-1`,children:[(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray/70`,children:n(`projectDetail.progress.percentComplete`,{percent:Ne.toFixed(0)})}),Me?.remaining_prints!=null&&Me.remaining_prints>0&&(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray/70`,children:n(`projectDetail.progress.remaining`,{count:Me.remaining_prints})})]})]}),h.target_parts_count&&(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:n(`projectDetail.progress.partsProgress`)}),(0,K.jsxs)(`span`,{className:`text-sm font-medium text-white`,children:[Me?.completed_prints||0,` / `,h.target_parts_count,` `,n(`projectDetail.progress.parts`)]})]}),(0,K.jsx)(`div`,{className:`h-3 bg-bambu-dark rounded-full overflow-hidden`,children:(0,K.jsx)(`div`,{className:`h-full transition-all duration-500`,style:{width:`${Math.min(Pe,100)}%`,backgroundColor:Pe>=100?`#22c55e`:h.color||`#6b7280`}})}),(0,K.jsxs)(`div`,{className:`flex justify-between mt-1`,children:[(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray/70`,children:n(`projectDetail.progress.percentComplete`,{percent:Pe.toFixed(0)})}),Me?.remaining_parts!=null&&Me.remaining_parts>0&&(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray/70`,children:n(`projectDetail.progress.remaining`,{count:Me.remaining_parts})})]})]})]})}),Me&&(0,K.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-4`,children:[(0,K.jsx)(Ed,{children:(0,K.jsx)(Od,{className:`p-4`,children:(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`p-2 rounded-lg bg-bambu-dark text-bambu-green`,children:(0,K.jsx)(_l,{className:`w-5 h-5`})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`projectDetail.stats.printJobs`)}),(0,K.jsxs)(`p`,{className:`text-xl font-semibold text-white`,children:[Me.total_archives,` `,(0,K.jsx)(`span`,{className:`text-sm font-normal text-bambu-gray`,children:n(`projectDetail.stats.total`)})]}),Me.failed_prints>0&&(0,K.jsx)(`p`,{className:`text-sm text-status-error`,children:n(`projectDetail.stats.failed`,{count:Me.failed_prints})}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`projectDetail.stats.partsPrinted`,{count:Me.completed_prints})})]})]})})}),(0,K.jsx)(W6,{icon:ws,label:n(`projectDetail.stats.printTime`),value:zf(Me.total_print_time_hours),color:`text-yellow-600 dark:text-yellow-400`}),(0,K.jsx)(W6,{icon:jl,label:n(`projectDetail.stats.filamentUsed`),value:yWe(Me.total_filament_grams),color:`text-purple-600 dark:text-purple-400`})]}),Me&&(()=>{let e=Me.estimated_cost+Me.total_energy_cost+Me.bom_cost;return Me.estimated_cost>0||e>0||h.budget!==null})()&&(0,K.jsx)(Ed,{children:(0,K.jsxs)(Od,{className:`p-4`,children:[(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white mb-3`,children:n(`projectDetail.cost.title`)}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-4`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.cost.filamentCost`)}),(0,K.jsxs)(`p`,{className:`text-lg font-semibold text-white`,children:[A,Me.estimated_cost.toFixed(2)]})]}),Me.total_energy_kwh>0&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.cost.energy`)}),(0,K.jsxs)(`p`,{className:`text-lg font-semibold text-white`,children:[Me.total_energy_kwh.toFixed(3),` kWh`,Me.total_energy_cost>0&&(0,K.jsxs)(`span`,{className:`text-sm text-bambu-gray ml-1`,children:[`(`,A,Me.total_energy_cost.toFixed(2),`)`]})]})]}),(()=>{let e=Me.estimated_cost+Me.total_energy_cost+Me.bom_cost;return e<=0?null:(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.cost.totalCost`)}),(0,K.jsxs)(`p`,{className:`text-lg font-semibold text-bambu-green`,children:[A,e.toFixed(2)]}),Me.bom_cost>0&&(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray/70`,children:n(`projectDetail.cost.includesBom`)})]})})(),h.budget!==null&&(()=>{let e=Me.estimated_cost+Me.total_energy_cost+Me.bom_cost,t=h.budget-e;return(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.cost.budget`)}),(0,K.jsxs)(`p`,{className:`text-sm text-bambu-gray`,children:[n(`projectDetail.cost.total`),`: `,(0,K.jsxs)(`span`,{className:`text-white font-semibold`,children:[A,h.budget.toFixed(2)]})]}),(0,K.jsxs)(`p`,{className:`text-sm ${t>=0?`text-bambu-green`:`text-red-700 dark:text-red-400`}`,children:[n(`projectDetail.cost.remaining`),`: `,(0,K.jsxs)(`span`,{className:`font-semibold`,children:[A,t.toFixed(2)]})]})]})})()]})]})}),h.children&&h.children.length>0&&(0,K.jsx)(Ed,{children:(0,K.jsxs)(Od,{className:`p-4`,children:[(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2 mb-3`,children:[(0,K.jsx)(mc,{className:`w-5 h-5`}),n(`projectDetail.subProjects.title`,{count:h.children.length})]}),(0,K.jsx)(`div`,{className:`space-y-2`,children:h.children.map(e=>(0,K.jsxs)(Oi,{to:`/projects/${e.id}`,className:`flex items-center justify-between p-3 bg-bambu-dark rounded-lg hover:bg-bambu-dark-tertiary transition-colors`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`w-3 h-3 rounded-full`,style:{backgroundColor:e.color||`#6b7280`}}),(0,K.jsx)(`span`,{className:`text-white`,children:e.name}),(0,K.jsx)(`span`,{className:`text-xs px-2 py-0.5 rounded ${e.status===`completed`?`bg-status-ok/20 text-status-ok`:e.status===`archived`?`bg-bambu-gray/20 text-bambu-gray`:`bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400`}`,children:e.status})]}),e.progress_percent!==null&&(0,K.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[e.progress_percent.toFixed(0),`%`]})]},e.id))})]})}),h.parent_id&&h.parent_name&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,K.jsx)(Vc,{className:`w-4 h-4 text-bambu-gray`}),(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:n(`projectDetail.partOf`)}),(0,K.jsx)(Oi,{to:`/projects/${h.parent_id}`,className:`text-bambu-green hover:underline`,children:h.parent_name})]}),(h.tags||h.due_date||h.priority!==`normal`)&&(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center gap-4`,children:[h.priority&&h.priority!==`normal`&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.priorityLabel`)}),(0,K.jsx)(SWe,{priority:h.priority,t:n})]}),h.due_date&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)($o,{className:`w-4 h-4 text-bambu-gray`}),(0,K.jsx)(`span`,{className:`text-sm text-white`,children:Mf(h.due_date,{year:`numeric`,month:`short`,day:`numeric`})}),G6(h.due_date,n)&&(0,K.jsxs)(`span`,{className:`text-xs ${G6(h.due_date,n).color}`,children:[`(`,G6(h.due_date,n).label,`)`]})]}),h.tags&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(vu,{className:`w-4 h-4 text-bambu-gray`}),(0,K.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:h.tags.split(`,`).map((e,t)=>(0,K.jsx)(`span`,{className:`px-2 py-0.5 bg-bambu-dark-tertiary text-bambu-gray text-xs rounded`,children:e.trim()},t))})]})]}),(0,K.jsx)(Ed,{children:(0,K.jsxs)(Od,{className:`p-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(ac,{className:`w-5 h-5`}),n(`projectDetail.notes.title`)]}),c?(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:F,disabled:M.isPending,children:[(0,K.jsx)(qu,{className:`w-4 h-4 mr-1`}),n(`common.cancel`)]}),(0,K.jsxs)($,{size:`sm`,onClick:P,disabled:M.isPending,children:[M.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin mr-1`}):(0,K.jsx)(zl,{className:`w-4 h-4 mr-1`}),n(`common.save`)]})]}):(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:N,disabled:!a(`projects:update`),title:a(`projects:update`)?void 0:n(`projectDetail.notes.noEditPermission`),children:[(0,K.jsx)(Sl,{className:`w-4 h-4 mr-1`}),n(`common.edit`)]})]}),c?(0,K.jsx)(r2,{content:u,onChange:d,placeholder:n(`projectDetail.notes.placeholder`)}):h.notes?(0,K.jsx)(`div`,{className:`prose prose-invert prose-sm max-w-none`,dangerouslySetInnerHTML:{__html:JG.sanitize(h.notes)}}):(0,K.jsx)(`p`,{className:`text-bambu-gray/70 text-sm italic`,children:n(`projectDetail.notes.empty`)})]})}),(0,K.jsx)(Ed,{children:(0,K.jsxs)(Od,{className:`p-4`,children:[(0,K.jsx)(`div`,{className:`flex items-center justify-between mb-3`,children:(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(dc,{className:`w-5 h-5`}),n(`projectDetail.files.title`)]})}),(0,K.jsxs)(`p`,{className:`text-xs text-bambu-gray mb-3`,children:[(0,K.jsx)(Oi,{to:`/files`,className:`text-bambu-green hover:underline`,children:n(`projectDetail.files.linkFolders`)}),` `,n(`projectDetail.files.forQuickAccess`)]}),E&&E.length>0?(0,K.jsx)(`div`,{className:`space-y-4`,children:E.map(e=>{let t=k.get(e.id)??[],r=O;return(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(Oi,{to:`/files?folder=${e.id}`,className:`flex items-center justify-between p-3 bg-bambu-dark rounded-lg hover:bg-bambu-dark-tertiary transition-colors mb-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0`,children:[(0,K.jsx)(dc,{className:`w-5 h-5 text-bambu-green shrink-0`}),(0,K.jsxs)(`div`,{className:`min-w-0`,children:[(0,K.jsx)(`p`,{className:`text-sm text-white truncate`,children:e.name}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`projectDetail.files.fileCount`,{count:e.file_count})})]})]}),(0,K.jsx)(cs,{className:`w-4 h-4 text-bambu-gray shrink-0`})]}),r?(0,K.jsx)(`div`,{className:`flex items-center gap-2 px-3 py-2 text-bambu-gray text-sm`,children:(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`})}):t.length===0?(0,K.jsx)(`p`,{className:`text-bambu-gray/60 text-xs italic px-3`,children:n(`projectDetail.files.noFiles`)}):(0,K.jsx)(`div`,{className:`space-y-1 pl-3`,children:t.map(e=>{let t=vWe(e.filename);return(0,K.jsxs)(`div`,{className:`flex items-center gap-3 p-2 rounded-lg hover:bg-bambu-dark-tertiary transition-colors`,children:[(0,K.jsx)(`div`,{className:`w-10 h-10 shrink-0 rounded bg-bambu-dark overflow-hidden flex items-center justify-center`,children:e.thumbnail_path?(0,K.jsx)(`img`,{src:Q.getLibraryFileThumbnailUrl(e.id),alt:e.print_name||e.filename,className:`w-full h-full object-cover`}):(0,K.jsx)(tc,{className:`w-5 h-5 text-bambu-gray/40`})}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsx)(`p`,{className:`text-sm text-white truncate`,title:e.print_name||e.filename,children:e.print_name||e.filename}),(0,K.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded font-medium ${e.file_type===`3mf`?`bg-bambu-green/20 text-bambu-green`:e.file_type===`gcode`||e.file_type===`gcode.3mf`?`bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400`:`bg-bambu-gray/20 text-bambu-gray`}`,children:e.file_type.toUpperCase()})]}),t&&(0,K.jsx)(`div`,{className:`flex items-center gap-1 shrink-0`,children:(0,K.jsx)(`button`,{onClick:()=>p(e),title:n(`common.print`),className:`p-1.5 rounded hover:bg-bambu-green/20 text-bambu-green transition-colors`,children:(0,K.jsx)(jl,{className:`w-4 h-4`})})})]},e.id)})})]},e.id)})}):(0,K.jsx)(`p`,{className:`text-bambu-gray/70 text-sm italic`,children:n(`projectDetail.files.empty`)})]})}),(0,K.jsx)(Ed,{children:(0,K.jsxs)(Od,{className:`p-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-4`,children:[(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(eu,{className:`w-5 h-5`}),n(`projectDetail.bom.title`),Me&&Me.bom_total_items>0&&(0,K.jsxs)(`span`,{className:`text-sm font-normal text-bambu-gray`,children:[`(`,n(`projectDetail.bom.acquired`,{completed:Me.bom_completed_items,total:Me.bom_total_items}),`)`]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[x&&x.some(e=>e.is_complete)&&(0,K.jsx)(`button`,{onClick:()=>oe(!ae),className:`text-xs px-2 py-1 rounded transition-colors ${ae?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark text-bambu-gray hover:text-white`}`,children:n(ae?`projectDetail.bom.showAll`:`projectDetail.bom.hideDone`)}),!ie&&(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:()=>H(!0),disabled:!a(`projects:update`),title:a(`projects:update`)?void 0:n(`projectDetail.bom.noAddPermission`),children:[(0,K.jsx)(Ol,{className:`w-4 h-4 mr-1`}),n(`projectDetail.bom.addPart`)]})]})]}),ie&&(0,K.jsxs)(`form`,{onSubmit:Ce,className:`bg-bambu-dark rounded-lg p-4 mb-4 space-y-3`,children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-3`,children:[(0,K.jsx)(`input`,{type:`text`,value:I,onChange:e=>L(e.target.value),className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:n(`projectDetail.bom.partNamePlaceholder`),autoFocus:!0}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)(`input`,{type:`number`,value:R,onChange:e=>z(parseInt(e.target.value)||1),className:`w-20 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white focus:outline-none focus:border-bambu-green`,min:`1`,placeholder:n(`projectDetail.bom.qty`)}),(0,K.jsx)(`input`,{type:`number`,step:`0.01`,value:B,onChange:e=>V(e.target.value),className:`flex-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:n(`projectDetail.bom.price`,{currency:A})})]})]}),(0,K.jsx)(`input`,{type:`url`,value:ee,onChange:e=>te(e.target.value),className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:n(`projectDetail.bom.sourcingUrlPlaceholder`)}),(0,K.jsx)(`input`,{type:`text`,value:ne,onChange:e=>re(e.target.value),className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:n(`projectDetail.bom.remarksPlaceholder`)}),(0,K.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,K.jsx)($,{type:`button`,variant:`secondary`,size:`sm`,onClick:()=>H(!1),children:n(`common.cancel`)}),(0,K.jsx)($,{type:`submit`,size:`sm`,disabled:!I.trim()||be.isPending,children:be.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):n(`projectDetail.bom.addPart`)})]})]}),S?(0,K.jsx)(`div`,{className:`flex items-center justify-center py-4`,children:(0,K.jsx)(X,{className:`w-6 h-6 animate-spin text-bambu-green`})}):x&&x.length>0?(0,K.jsxs)(`div`,{className:`space-y-2`,children:[x.filter(e=>!ae||!e.is_complete).map(e=>(0,K.jsx)(`div`,{className:`p-3 rounded-lg transition-colors ${e.is_complete?`bg-status-ok/10`:`bg-bambu-dark`}`,children:U?.id===e.id?(0,K.jsxs)(`form`,{onSubmit:De,className:`space-y-3`,children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-3`,children:[(0,K.jsx)(`input`,{type:`text`,value:ce,onChange:e=>le(e.target.value),className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:n(`projectDetail.bom.partName`),autoFocus:!0}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)(`input`,{type:`number`,value:ue,onChange:e=>de(parseInt(e.target.value)||1),className:`w-20 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white focus:outline-none focus:border-bambu-green`,min:`1`,placeholder:n(`projectDetail.bom.qty`)}),(0,K.jsx)(`input`,{type:`number`,step:`0.01`,value:fe,onChange:e=>pe(e.target.value),className:`flex-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:n(`projectDetail.bom.price`,{currency:A})})]})]}),(0,K.jsx)(`input`,{type:`url`,value:me,onChange:e=>he(e.target.value),className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:n(`projectDetail.bom.sourcingUrlPlaceholder`)}),(0,K.jsx)(`input`,{type:`text`,value:ge,onChange:e=>_e(e.target.value),className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:n(`projectDetail.bom.remarksPlaceholder`)}),(0,K.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,K.jsx)($,{type:`button`,variant:`secondary`,size:`sm`,onClick:Oe,children:n(`common.cancel`)}),(0,K.jsx)($,{type:`submit`,size:`sm`,disabled:!ce.trim()||xe.isPending,children:xe.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):n(`common.save`)})]})]}):(0,K.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,K.jsx)(`button`,{onClick:()=>a(`projects:update`)&&we(e),disabled:xe.isPending||!a(`projects:update`),title:a(`projects:update`)?void 0:n(`projectDetail.bom.noUpdatePermission`),className:`w-5 h-5 mt-0.5 rounded border-2 flex items-center justify-center transition-colors shrink-0 ${e.is_complete?`bg-status-ok border-status-ok text-white`:a(`projects:update`)?`border-bambu-gray hover:border-bambu-green`:`border-bambu-gray/50 cursor-not-allowed`}`,children:e.is_complete&&(0,K.jsx)(hs,{className:`w-3 h-3`})}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,K.jsxs)(`p`,{className:`text-sm font-medium ${e.is_complete?`text-bambu-gray line-through`:`text-white`}`,children:[e.name,(0,K.jsxs)(`span`,{className:`text-bambu-gray font-normal ml-2`,children:[`x`,e.quantity_needed]})]}),e.unit_price!==null&&(0,K.jsxs)(`span`,{className:`text-xs text-bambu-green whitespace-nowrap`,children:[A,(e.unit_price*e.quantity_needed).toFixed(2)]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(`button`,{onClick:()=>a(`projects:update`)&&Ee(e),disabled:!a(`projects:update`),className:`p-1 rounded transition-colors shrink-0 ${a(`projects:update`)?`hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white`:`text-bambu-gray/50 cursor-not-allowed`}`,title:a(`projects:update`)?n(`common.edit`):n(`projectDetail.bom.noEditPermission`),children:(0,K.jsx)(wl,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>a(`projects:update`)&&Te(e.id,e.name),disabled:!a(`projects:update`),className:`p-1 rounded transition-colors shrink-0 ${a(`projects:update`)?`hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-red-400`:`text-bambu-gray/50 cursor-not-allowed`}`,title:a(`projects:update`)?n(`common.delete`):n(`projectDetail.bom.noDeletePermission`),children:(0,K.jsx)(Eu,{className:`w-4 h-4`})})]})]}),e.sourcing_url&&(0,K.jsxs)(`a`,{href:e.sourcing_url,target:`_blank`,rel:`noopener noreferrer`,className:`flex items-center gap-1 mt-1 text-xs text-blue-700 dark:text-blue-400 hover:text-blue-900 dark:hover:text-blue-300 transition-colors`,onClick:e=>e.stopPropagation(),children:[(0,K.jsx)(Zs,{className:`w-3 h-3 shrink-0`}),(0,K.jsx)(`span`,{className:`truncate`,children:(()=>{try{return new URL(e.sourcing_url).hostname.replace(`www.`,``)}catch{return e.sourcing_url}})()})]}),e.remarks&&(0,K.jsx)(`p`,{className:`mt-1 text-xs text-bambu-gray/80 italic`,children:e.remarks})]})]})},e.id)),Me&&Me.bom_cost>0&&(0,K.jsxs)(`div`,{className:`pt-2 mt-2 border-t border-bambu-dark-tertiary flex justify-between text-sm`,children:[(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:n(`projectDetail.bom.totalCost`)}),(0,K.jsxs)(`span`,{className:`text-white font-medium`,children:[A,Me.bom_cost.toFixed(2)]})]})]}):(0,K.jsx)(`p`,{className:`text-bambu-gray/70 text-sm italic`,children:n(`projectDetail.bom.empty`)})]})}),(0,K.jsx)(Ed,{children:(0,K.jsxs)(Od,{className:`p-4`,children:[(0,K.jsx)(`div`,{className:`flex items-center justify-between mb-3`,children:(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(Mc,{className:`w-5 h-5`}),n(`projectDetail.timeline.title`)]})}),w?(0,K.jsx)(`div`,{className:`flex items-center justify-center py-4`,children:(0,K.jsx)(X,{className:`w-6 h-6 animate-spin text-bambu-green`})}):C&&C.length>0?(0,K.jsx)(`div`,{className:`space-y-3`,children:C.slice(0,10).map((e,t)=>(0,K.jsxs)(`div`,{className:`flex gap-3`,children:[(0,K.jsxs)(`div`,{className:`w-8 h-8 rounded-full flex items-center justify-center shrink-0 ${e.event_type===`print_completed`?`bg-status-ok/20 text-status-ok`:e.event_type===`print_failed`?`bg-status-error/20 text-status-error`:e.event_type===`print_started`?`bg-yellow-100 dark:bg-yellow-500/20 text-yellow-700 dark:text-yellow-400`:`bg-bambu-dark-tertiary text-bambu-gray`}`,children:[e.event_type===`print_completed`&&(0,K.jsx)(hs,{className:`w-4 h-4`}),e.event_type===`print_failed`&&(0,K.jsx)(xs,{className:`w-4 h-4`}),e.event_type===`print_started`&&(0,K.jsx)(jl,{className:`w-4 h-4`}),e.event_type===`queued`&&(0,K.jsx)(qc,{className:`w-4 h-4`}),e.event_type===`project_created`&&(0,K.jsx)(Ol,{className:`w-4 h-4`})]}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsx)(`p`,{className:`text-sm text-white`,children:e.title}),e.description&&(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray truncate`,children:e.description}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray/70`,children:je(e.timestamp)})]})]},t))}):(0,K.jsx)(`p`,{className:`text-bambu-gray/70 text-sm italic`,children:n(`projectDetail.timeline.empty`)})]})}),!h.is_template&&(0,K.jsx)(`div`,{className:`flex justify-end`,children:(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:()=>Ae.mutate(),disabled:Ae.isPending||!a(`projects:create`),title:a(`projects:create`)?void 0:n(`projectDetail.template.noCreatePermission`),children:[Ae.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin mr-2`}):(0,K.jsx)(Fs,{className:`w-4 h-4 mr-2`}),n(`projectDetail.template.saveAsTemplate`)]})}),Me&&(Me.queued_prints>0||Me.in_progress_prints>0)&&(0,K.jsx)(Ed,{children:(0,K.jsxs)(Od,{className:`p-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(qc,{className:`w-5 h-5`}),n(`projectDetail.queue.title`)]}),(0,K.jsx)(Oi,{to:`/queue?project=${m}`,className:`text-sm text-bambu-green hover:underline`,children:n(`projectDetail.queue.viewAll`)})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-4 text-sm`,children:[Me.in_progress_prints>0&&(0,K.jsx)(`span`,{className:`text-yellow-700 dark:text-yellow-400`,children:n(`projectDetail.queue.printing`,{count:Me.in_progress_prints})}),Me.queued_prints>0&&(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:n(`projectDetail.queue.queued`,{count:Me.queued_prints})})]})]})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`div`,{className:`flex items-center justify-between mb-4`,children:(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(_l,{className:`w-5 h-5`}),n(`projectDetail.prints.title`,{count:v?.length||0})]})}),b?(0,K.jsx)(`div`,{className:`flex items-center justify-center py-8`,children:(0,K.jsx)(X,{className:`w-6 h-6 animate-spin text-bambu-green`})}):(0,K.jsx)(xWe,{archives:v||[],t:n})]}),o&&(0,K.jsx)(U6,{t:n,currencySymbol:A,project:{...h,archive_count:Me?.total_archives||0,total_items:Me?.total_items||0,completed_count:Me?.completed_prints||0,failed_count:Me?.failed_prints||0,queue_count:Me?.queued_prints||0,progress_percent:Me?.progress_percent||null,archives:[]},onClose:()=>s(!1),onSave:e=>M.mutate(e),isLoading:M.isPending}),ve.isOpen&&(0,K.jsx)(Vd,{title:ve.title,message:ve.message,confirmText:n(`common.delete`),variant:`danger`,onConfirm:ve.onConfirm,onCancel:()=>ye(e=>({...e,isOpen:!1}))}),f&&(0,K.jsx)(uW,{mode:`create`,libraryFileId:f.id,archiveName:f.print_name||f.filename,projectId:m,onClose:()=>p(null),onSuccess:()=>{p(null),r.invalidateQueries({queryKey:[`archives`]}),r.invalidateQueries({queryKey:[`queue`]})}})]})}function wWe({archiveId:e,libraryFileId:t,title:n,fileType:r,onClose:i,onSliceWithBambuddy:a}){let{t:o}=W(),{data:s}=q({queryKey:[`settings`],queryFn:Q.getSettings}),c=s?.open_in_slicer||s?.preferred_slicer||`bambu_studio`,l=t!=null,[u,d]=(0,y.useState)(null),[f,p]=(0,y.useState)(null),[m,h]=(0,y.useState)(!0),[g,_]=(0,y.useState)(null),[v,b]=(0,y.useState)(!1),[x,S]=(0,y.useState)(null),[C,w]=(0,y.useState)(0),[T,E]=(0,y.useState)(!1),[D,O]=(0,y.useState)(null),[k,A]=(0,y.useState)(!1),[j,M]=(0,y.useState)(!1),N=(0,y.useRef)(null),P=(0,y.useRef)(null),F=.35;(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&i()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[i]),(0,y.useEffect)(()=>{if(h(!0),l){let e=(r||``).toLowerCase(),t=e===`3mf`||e===`gcode.3mf`,n=t||e===`stl`,i=t||e===`gcode`;p({has_model:n,has_gcode:i,has_source:!1,build_volume:{x:256,y:256,z:256},filament_colors:[]}),d(n?`3d`:i?`gcode`:null),h(!1);return}if(!e){p(null),d(null),h(!1);return}Q.getArchiveCapabilities(e).then(e=>{p(e),e.has_model?d(`3d`):e.has_gcode&&d(`gcode`),h(!1)}).catch(()=>{p({has_model:!0,has_gcode:!1,has_source:!1,build_volume:{x:256,y:256,z:256},filament_colors:[]}),d(`3d`),h(!1)})},[e,r,l]),(0,y.useEffect)(()=>{if(b(!0),S(null),w(0),l){let e=(r||``).toLowerCase();if(!t||!(e===`3mf`||e===`gcode.3mf`)){_(null),b(!1);return}Q.getLibraryFilePlates(t).then(e=>_(e)).catch(()=>_(null)).finally(()=>b(!1));return}if(!e){_(null),b(!1);return}Q.getArchivePlates(e).then(e=>_(e)).catch(()=>_(null)).finally(()=>b(!1))},[e,r,l,t]);let I=(0,y.useMemo)(()=>g?.plates??[],[g]),L=(g?.is_multi_plate??!1)&&I.length>1,R=T&&L,z=x==null?null:I.find(e=>e.index===x)??null,B=e=>e.object_count??e.objects?.length??0,V=I.reduce((e,t)=>e+B(t),0),ee=z?B(z):V,te=z?o(`modelViewer.plateNumber`,{number:z.index}):o(`modelViewer.allPlates`),ne=I.length>0,re=(0,y.useRef)(null),ie=(0,y.useRef)(null),[H,ae]=(0,y.useState)(10),[oe,U]=(0,y.useState)(3),se=I.length>H,ce=Math.max(1,Math.ceil(I.length/H)),le=se?I.slice(C*H,(C+1)*H):I;(0,y.useEffect)(()=>{if(!R){ae(10),U(3);return}let e=re.current,t=ie.current;if(!e||!t)return;let n=0,r=()=>{let n=t.clientWidth,r=Math.floor(n/210),i=Math.max(3,Math.min(5,r||3));U(e=>e===i?e:i);let a=window.getComputedStyle(e),o=Number.parseFloat(a.rowGap||`0`),s=e.querySelector(`button`)?.getBoundingClientRect().height??44,c=t.clientHeight,l=Math.max(1,Math.floor((c+o)/(s+o)))*i,u=Math.max(1,l-1);ae(e=>e===u?e:u)},i=()=>{n&&cancelAnimationFrame(n),n=requestAnimationFrame(r)};i();let a=new ResizeObserver(i);return a.observe(t),a.observe(e),()=>{n&&cancelAnimationFrame(n),a.disconnect()}},[R,I.length]),(0,y.useEffect)(()=>{if(!se){w(0);return}w(e=>Math.min(e,ce-1))},[I.length,se,ce]),(0,y.useEffect)(()=>{if(!se||x==null)return;let e=I.findIndex(e=>e.index===x);if(e<0)return;let t=Math.floor(e/H);w(e=>e===t?e:t)},[I,H,x,se]),(0,y.useEffect)(()=>{if(!R){O(null),M(!1);return}if(j)return;let e=N.current,t=P.current;if(!e||!t)return;let n=e.clientHeight;if(!n)return;let r=Math.max(240,n*F),i=Math.max(160,n-10-r),a=Math.min(t.scrollHeight,i);O(Math.max(160,a))},[R,j,I.length,C,10,160,240,F]),(0,y.useEffect)(()=>{if(!k)return;let e=e=>{let t=N.current;if(!t)return;let n=t.getBoundingClientRect(),r=n.height;if(!r)return;let i=Math.max(240,r*F),a=Math.max(160,r-10-i);O(Math.min(a,Math.max(160,e.clientY-n.top)))},t=()=>{A(!1),M(!0)};return document.addEventListener(`mousemove`,e),document.addEventListener(`mouseup`,t),document.body.style.cursor=`row-resize`,document.body.style.userSelect=`none`,()=>{document.removeEventListener(`mousemove`,e),document.removeEventListener(`mouseup`,t),document.body.style.cursor=``,document.body.style.userSelect=``}},[k,10,160,240,F]);let ue=l?(r||``).toLowerCase()===`3mf`:!0,de=(()=>{let e=(r||``).toLowerCase();return e===`3mf`||e===`stl`||e===`step`||e===`stp`})(),fe=!!(l&&s?.use_slicer_api&&a&&de);return(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 ${T?`p-0`:`p-8`}`,onClick:i,children:(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary w-full flex flex-col ${T?`h-full max-w-none rounded-none`:`h-[80vh] max-w-4xl rounded-xl`}`,onClick:e=>e.stopPropagation(),children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0 flex-1 mr-4`,children:[(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white truncate`,children:n}),ne&&(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray bg-bambu-dark-tertiary/70 px-2 py-1 rounded whitespace-nowrap`,children:[te,`: `,o(`modelViewer.objectCount`,{count:ee})]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[fe?(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:a,children:[(0,K.jsx)(Ms,{className:`w-4 h-4`}),o(`slice.action`)]}):(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:async()=>{if(!ue)return;let r=n||`model`;try{if(l){let{token:e}=await Q.createLibrarySlicerToken(t),n=Q.getLibrarySlicerDownloadUrl(t,e,r);qW(`${window.location.origin}${n}`,c)}else{let{token:t}=await Q.createArchiveSlicerToken(e),n=Q.getArchiveSlicerDownloadUrl(e,t,r);qW(`${window.location.origin}${n}`,c)}}catch{qW(l?`${window.location.origin}${Q.getLibraryFileDownloadUrl(t)}`:`${window.location.origin}${Q.getArchiveForSlicer(e,r)}`,c)}},disabled:!ue,children:[(0,K.jsx)(Zs,{className:`w-4 h-4`}),o(`modelViewer.openInSlicer`)]}),(0,K.jsx)($,{variant:`secondary`,size:`sm`,onClick:()=>E(e=>!e),title:T?`Exit fullscreen`:`Enter fullscreen`,children:T?(0,K.jsx)(ol,{className:`w-4 h-4`}):(0,K.jsx)(nl,{className:`w-4 h-4`})}),(0,K.jsx)($,{variant:`ghost`,size:`sm`,onClick:i,children:(0,K.jsx)(qu,{className:`w-5 h-5`})})]})]}),f&&(0,K.jsxs)(`div`,{className:`flex border-b border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`button`,{onClick:()=>f.has_model&&d(`3d`),disabled:!f.has_model,className:`flex items-center gap-2 px-6 py-3 text-sm font-medium transition-colors ${u===`3d`?`text-bambu-green border-b-2 border-bambu-green`:f.has_model?`text-bambu-gray hover:text-white`:`text-bambu-gray/30 cursor-not-allowed`}`,children:[(0,K.jsx)(qo,{className:`w-4 h-4`}),o(`modelViewer.tabs.model`),!f.has_model&&(0,K.jsxs)(`span`,{className:`text-xs`,children:[`(`,o(`modelViewer.notAvailable`),`)`]})]}),(0,K.jsxs)(`button`,{onClick:()=>f.has_gcode&&d(`gcode`),disabled:!f.has_gcode,className:`flex items-center gap-2 px-6 py-3 text-sm font-medium transition-colors ${u===`gcode`?`text-bambu-green border-b-2 border-bambu-green`:f.has_gcode?`text-bambu-gray hover:text-white`:`text-bambu-gray/30 cursor-not-allowed`}`,children:[(0,K.jsx)(Os,{className:`w-4 h-4`}),o(`modelViewer.tabs.gcode`),!f.has_gcode&&(0,K.jsxs)(`span`,{className:`text-xs`,children:[`(`,o(`modelViewer.notSliced`),`)`]})]})]}),(0,K.jsx)(`div`,{className:`flex-1 overflow-hidden p-4`,children:m?(0,K.jsx)(`div`,{className:`w-full h-full flex items-center justify-center`,children:(0,K.jsx)(X,{className:`w-8 h-8 animate-spin text-bambu-green`})}):u===`3d`&&f?(0,K.jsxs)(`div`,{ref:N,className:`w-full h-full flex flex-col ${R?`gap-0 min-h-0`:`gap-3`}`,children:[L&&(0,K.jsxs)(`div`,{ref:P,style:R&&D!=null?{height:D}:void 0,className:`rounded-lg border border-bambu-dark-tertiary bg-bambu-dark p-3 ${R?`flex flex-col shrink-0`:``}`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-bambu-gray mb-2`,children:[(0,K.jsx)(Vc,{className:`w-4 h-4`}),o(`modelViewer.plates`),v&&(0,K.jsx)(X,{className:`w-3 h-3 animate-spin`})]}),(0,K.jsxs)(`div`,{className:R?`flex flex-col min-h-0 flex-1`:void 0,children:[(0,K.jsx)(`div`,{ref:ie,className:R?`min-h-0 overflow-hidden pr-1 flex-1`:void 0,children:(0,K.jsxs)(`div`,{ref:re,className:R?`grid gap-2`:`grid grid-cols-2 md:grid-cols-3 gap-2`,style:R?{gridTemplateColumns:`repeat(${oe}, minmax(0, 1fr))`}:void 0,children:[(0,K.jsxs)(`button`,{type:`button`,onClick:()=>S(null),className:`flex items-center rounded-lg border text-left transition-colors ${R?`gap-1.5 p-1.5 w-full`:`gap-2 p-2`} ${x==null?`border-bambu-green bg-bambu-green/10`:`border-bambu-dark-tertiary bg-bambu-dark-secondary hover:border-bambu-gray`}`,children:[(0,K.jsx)(`div`,{className:`rounded bg-bambu-dark-tertiary flex items-center justify-center ${R?`w-8 h-8`:`w-10 h-10`}`,children:(0,K.jsx)(Vc,{className:`${R?`w-4 h-4`:`w-5 h-5`} text-bambu-gray`})}),(0,K.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,K.jsx)(`p`,{className:`${R?`text-xs`:`text-sm`} text-white font-medium truncate`,children:o(`modelViewer.allPlates`)}),(0,K.jsx)(`p`,{className:`${R?`text-[10px]`:`text-xs`} text-bambu-gray truncate`,children:o(`modelViewer.plateCount`,{count:I.length})})]}),x==null&&(0,K.jsx)(as,{className:`${R?`w-3.5 h-3.5`:`w-4 h-4`} text-bambu-green flex-shrink-0`})]}),le.map(e=>(0,K.jsxs)(`button`,{type:`button`,onClick:()=>S(e.index),className:`flex items-center rounded-lg border text-left transition-colors ${R?`gap-1.5 p-1.5 w-full`:`gap-2 p-2`} ${x===e.index?`border-bambu-green bg-bambu-green/10`:`border-bambu-dark-tertiary bg-bambu-dark-secondary hover:border-bambu-gray`}`,children:[e.has_thumbnail&&e.thumbnail_url?(0,K.jsx)(`img`,{src:ad(e.thumbnail_url),alt:`Plate ${e.index}`,className:`${R?`w-8 h-8`:`w-10 h-10`} rounded object-cover bg-bambu-dark-tertiary`}):(0,K.jsx)(`div`,{className:`rounded bg-bambu-dark-tertiary flex items-center justify-center ${R?`w-8 h-8`:`w-10 h-10`}`,children:(0,K.jsx)(Vc,{className:`${R?`w-4 h-4`:`w-5 h-5`} text-bambu-gray`})}),(0,K.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,K.jsx)(`p`,{className:`${R?`text-xs`:`text-sm`} text-white font-medium truncate`,children:e.name||o(`modelViewer.plateNumber`,{number:e.index})}),(0,K.jsx)(`p`,{className:`${R?`text-[10px]`:`text-xs`} text-bambu-gray truncate`,children:o(`modelViewer.objectCount`,{count:e.object_count??e.objects?.length??0})})]}),x===e.index&&(0,K.jsx)(as,{className:`${R?`w-3.5 h-3.5`:`w-4 h-4`} text-bambu-green flex-shrink-0`})]},e.index))]})}),(z||se)&&(0,K.jsxs)(`div`,{className:`mt-auto pt-3 flex items-center gap-4 text-xs text-bambu-gray overflow-x-auto`,children:[z&&(0,K.jsxs)(`div`,{className:`flex items-center gap-3 whitespace-nowrap`,children:[(0,K.jsx)(`span`,{children:o(`modelViewer.plateNumber`,{number:z.index})}),z.print_time_seconds!=null&&(0,K.jsx)(`span`,{children:o(`modelViewer.eta`,{minutes:Math.round(z.print_time_seconds/60)})}),z.filament_used_grams!=null&&(0,K.jsxs)(`span`,{children:[z.filament_used_grams.toFixed(1),` g`]}),z.filaments.length>0&&(0,K.jsx)(`span`,{children:o(`modelViewer.filamentCount`,{count:z.filaments.length})})]}),se&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2 whitespace-nowrap ${z?`ml-auto`:``}`,children:[(0,K.jsx)(`span`,{children:o(`modelViewer.pagination.pageOf`,{current:C+1,total:ce})}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(`button`,{type:`button`,onClick:()=>w(e=>Math.max(e-1,0)),disabled:C===0,className:`px-2 py-1 rounded border text-xs ${C===0?`border-bambu-dark-tertiary text-bambu-gray/40 cursor-not-allowed`:`border-bambu-dark-tertiary text-bambu-gray hover:text-white hover:border-bambu-gray`}`,children:o(`modelViewer.pagination.prev`)}),(()=>{let e=Math.max(0,C-2),t=Math.min(ce,e+5);t-e<5&&(e=Math.max(0,t-5));let n=Array.from({length:t-e},(t,n)=>e+n);return(0,K.jsxs)(K.Fragment,{children:[e>0&&(0,K.jsx)(`button`,{type:`button`,onClick:()=>w(0),className:`px-2 py-1 rounded border text-xs ${C===0?`border-bambu-green text-bambu-green`:`border-bambu-dark-tertiary text-bambu-gray hover:text-white hover:border-bambu-gray`}`,children:`1`}),e>1&&(0,K.jsx)(`span`,{className:`px-1`,children:`…`}),n.map(e=>(0,K.jsx)(`button`,{type:`button`,onClick:()=>w(e),className:`px-2 py-1 rounded border text-xs ${C===e?`border-bambu-green text-bambu-green`:`border-bambu-dark-tertiary text-bambu-gray hover:text-white hover:border-bambu-gray`}`,children:e+1},e)),tw(ce-1),className:`px-2 py-1 rounded border text-xs ${C===ce-1?`border-bambu-green text-bambu-green`:`border-bambu-dark-tertiary text-bambu-gray hover:text-white hover:border-bambu-gray`}`,children:ce})]})})(),(0,K.jsx)(`button`,{type:`button`,onClick:()=>w(e=>Math.min(e+1,ce-1)),disabled:C>=ce-1,className:`px-2 py-1 rounded border text-xs ${C>=ce-1?`border-bambu-dark-tertiary text-bambu-gray/40 cursor-not-allowed`:`border-bambu-dark-tertiary text-bambu-gray hover:text-white hover:border-bambu-gray`}`,children:o(`modelViewer.pagination.next`)})]})]})]})]})]}),R&&(0,K.jsx)(`div`,{role:`separator`,"aria-orientation":`horizontal`,onMouseDown:e=>{e.preventDefault(),A(!0),M(!0)},className:`h-2 cursor-row-resize flex items-center justify-center ${k?`bg-bambu-dark-tertiary`:`bg-bambu-dark-secondary/60 hover:bg-bambu-dark-tertiary`}`,children:(0,K.jsx)(`div`,{className:`w-12 h-1 rounded-full bg-bambu-gray/50`})}),(0,K.jsx)(`div`,{className:`flex-1 ${R?`min-h-0`:``}`,children:(0,K.jsx)(_y,{url:l?Q.getLibraryFileDownloadUrl(t):f.has_source?Q.getSource3mfDownloadUrl(e):Q.getArchiveDownload(e),fileType:r,buildVolume:f.build_volume,filamentColors:f.filament_colors,selectedPlateId:x,className:`w-full h-full`})})]}):u===`gcode`&&f?(0,K.jsx)(dT,{gcodeUrl:l?Q.getLibraryFileGcodeUrl(t):Q.getArchiveGcode(e),filamentColors:f.filament_colors,className:`w-full h-full`}):(0,K.jsx)(`div`,{className:`w-full h-full flex items-center justify-center text-bambu-gray`,children:o(`modelViewer.noPreview`)})})]})})}var K6=[`library-tags`];function TWe({open:e,fileIds:t,onClose:n}){let{t:r}=W(),i=oo(),{showToast:a}=Pd(),[o,s]=(0,y.useState)(`add`),[c,l]=(0,y.useState)(new Set),[u,d]=(0,y.useState)(``),[f,p]=(0,y.useState)(``);(0,y.useEffect)(()=>{e||(s(`add`),l(new Set),d(``),p(``))},[e]);let{data:m=[],isLoading:h}=q({queryKey:K6,queryFn:Q.getLibraryTags,enabled:e}),g=(0,y.useMemo)(()=>{let e=u.trim().toLowerCase();return e?m.filter(t=>t.name.toLowerCase().includes(e)):m},[m,u]),_=e=>{l(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},v=J({mutationFn:e=>Q.createLibraryTag(e),onSuccess:e=>{l(t=>new Set(t).add(e.id)),p(``),i.invalidateQueries({queryKey:K6})},onError:e=>{a(e.message||r(`fileManager.tags.saveFailed`),`error`)}}),b=J({mutationFn:()=>Q.bulkAssignLibraryTags(t,Array.from(c),o),onSuccess:e=>{a(o===`add`?r(`fileManager.tags.applyAddSuccess`,{count:e.associations_added,files:e.files_updated}):r(`fileManager.tags.applyRemoveSuccess`,{count:e.associations_removed,files:e.files_updated}),`success`),i.invalidateQueries({queryKey:[`library-files`]}),i.invalidateQueries({queryKey:K6}),n()},onError:e=>{a(e.message||r(`fileManager.tags.applyFailed`),`error`)}});if((0,y.useEffect)(()=>{if(!e)return;let t=e=>{e.key===`Escape`&&!b.isPending&&!v.isPending&&n()};return document.addEventListener(`keydown`,t),()=>document.removeEventListener(`keydown`,t)},[e,n,b.isPending,v.isPending]),!e)return null;let x=!f.trim()||v.isPending||m.some(e=>e.name.toLowerCase()===f.trim().toLowerCase()),S=`bulk-tags-picker-title`;return(0,K.jsxs)(`div`,{className:`fixed inset-0 z-[60] flex items-center justify-center`,children:[(0,K.jsx)(`div`,{className:`absolute inset-0 bg-black/60`,onClick:()=>!b.isPending&&n()}),(0,K.jsxs)(`div`,{className:`relative w-full max-w-md mx-4 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl shadow-2xl max-h-[90vh] flex flex-col`,role:`dialog`,"aria-modal":`true`,"aria-labelledby":S,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between gap-4 px-5 py-4 border-b border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`h3`,{id:S,className:`text-base font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(vu,{className:`w-4 h-4 text-bambu-green`}),r(`fileManager.tags.bulkTitle`,{count:t.length})]}),(0,K.jsx)(`button`,{type:`button`,className:`p-1.5 text-bambu-gray hover:text-white rounded`,onClick:n,"aria-label":r(`common.close`),children:(0,K.jsx)(qu,{className:`w-5 h-5`})})]}),(0,K.jsxs)(`div`,{className:`px-5 py-3 border-b border-bambu-dark-tertiary flex gap-4 text-sm`,children:[(0,K.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`radio`,name:`bulk-action`,checked:o===`add`,onChange:()=>s(`add`),className:`accent-bambu-green`}),(0,K.jsx)(`span`,{className:`text-white`,children:r(`fileManager.tags.actionAdd`)})]}),(0,K.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`radio`,name:`bulk-action`,checked:o===`remove`,onChange:()=>s(`remove`),className:`accent-bambu-green`}),(0,K.jsx)(`span`,{className:`text-white`,children:r(`fileManager.tags.actionRemove`)})]})]}),(0,K.jsx)(`div`,{className:`px-5 py-3 border-b border-bambu-dark-tertiary`,children:(0,K.jsx)(`input`,{type:`text`,value:u,onChange:e=>d(e.target.value),placeholder:r(`fileManager.tags.searchPlaceholder`),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`})}),(0,K.jsx)(`div`,{className:`overflow-y-auto flex-1 min-h-[8rem] max-h-[24rem]`,children:h?(0,K.jsxs)(`div`,{className:`flex items-center justify-center py-12 text-bambu-gray`,children:[(0,K.jsx)(X,{className:`w-5 h-5 animate-spin mr-2`}),r(`common.loading`)]}):g.length===0?(0,K.jsx)(`div`,{className:`py-12 text-center text-bambu-gray text-sm`,children:m.length===0?r(`fileManager.tags.empty`):r(`fileManager.tags.noMatches`)}):(0,K.jsx)(`ul`,{className:`divide-y divide-bambu-dark-tertiary/40`,children:g.map(e=>(0,K.jsx)(`li`,{children:(0,K.jsxs)(`label`,{className:`flex items-center gap-3 px-5 py-2 hover:bg-bambu-dark-tertiary/30 cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:c.has(e.id),onChange:()=>_(e.id),className:`accent-bambu-green`}),(0,K.jsx)(`span`,{className:`text-sm text-white truncate flex-1`,children:e.name}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:e.file_count})]})},e.id))})}),o===`add`&&(0,K.jsxs)(`div`,{className:`px-5 py-3 border-t border-bambu-dark-tertiary flex gap-2`,children:[(0,K.jsx)(`input`,{type:`text`,value:f,onChange:e=>p(e.target.value),placeholder:r(`fileManager.tags.createPlaceholder`),maxLength:64,className:`flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,onKeyDown:e=>{e.key===`Enter`&&!x&&(e.preventDefault(),v.mutate(f.trim()))}}),(0,K.jsxs)($,{type:`button`,variant:`secondary`,onClick:()=>v.mutate(f.trim()),disabled:x,children:[v.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(Ol,{className:`w-4 h-4`}),r(`fileManager.tags.createButton`)]})]}),(0,K.jsxs)(`div`,{className:`px-5 py-4 border-t border-bambu-dark-tertiary flex justify-end gap-2`,children:[(0,K.jsx)($,{type:`button`,variant:`secondary`,onClick:n,disabled:b.isPending,children:r(`common.cancel`)}),(0,K.jsxs)($,{type:`button`,onClick:()=>b.mutate(),disabled:c.size===0||b.isPending||t.length===0,children:[b.isPending&&(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),r(o===`add`?`fileManager.tags.applyAdd`:`fileManager.tags.applyRemove`)]})]})]})]})}function EWe(e,t){let n=t||{};return(e[e.length-1]===``?[...e,``]:e).join((n.padRight?` `:``)+`,`+(n.padLeft===!1?``:` `)).trim()}var DWe=/^[$_\p{ID_Start}][$_\u{200C}\u{200D}\p{ID_Continue}]*$/u,OWe=/^[$_\p{ID_Start}][-$_\u{200C}\u{200D}\p{ID_Continue}]*$/u,kWe={};function q6(e,t){return((t||kWe).jsx?OWe:DWe).test(e)}var AWe=/[ \t\n\f\r]/g;function jWe(e){return typeof e==`object`?e.type===`text`?J6(e.value):!1:J6(e)}function J6(e){return e.replace(AWe,``)===``}var Y6=class{constructor(e,t,n){this.normal=t,this.property=e,n&&(this.space=n)}};Y6.prototype.normal={},Y6.prototype.property={},Y6.prototype.space=void 0;function X6(e,t){let n={},r={};for(let t of e)Object.assign(n,t.property),Object.assign(r,t.normal);return new Y6(n,r,t)}function Z6(e){return e.toLowerCase()}var Q6=class{constructor(e,t){this.attribute=t,this.property=e}};Q6.prototype.attribute=``,Q6.prototype.booleanish=!1,Q6.prototype.boolean=!1,Q6.prototype.commaOrSpaceSeparated=!1,Q6.prototype.commaSeparated=!1,Q6.prototype.defined=!1,Q6.prototype.mustUseProperty=!1,Q6.prototype.number=!1,Q6.prototype.overloadedBoolean=!1,Q6.prototype.property=``,Q6.prototype.spaceSeparated=!1,Q6.prototype.space=void 0;var $6=s({boolean:()=>e8,booleanish:()=>t8,commaOrSpaceSeparated:()=>o8,commaSeparated:()=>a8,number:()=>r8,overloadedBoolean:()=>n8,spaceSeparated:()=>i8}),MWe=0,e8=s8(),t8=s8(),n8=s8(),r8=s8(),i8=s8(),a8=s8(),o8=s8();function s8(){return 2**++MWe}var c8=Object.keys($6),l8=class extends Q6{constructor(e,t,n,r){let i=-1;if(super(e,t),u8(this,`space`,r),typeof n==`number`)for(;++i4&&n.slice(0,4)===`data`&&LWe.test(t)){if(t.charAt(4)===`-`){let e=t.slice(5).replace(v8,BWe);r=`data`+e.charAt(0).toUpperCase()+e.slice(1)}else{let e=t.slice(4);if(!v8.test(e)){let n=e.replace(IWe,zWe);n.charAt(0)!==`-`&&(n=`-`+n),t=`data`+n}}i=l8}return new i(r,t)}function zWe(e){return`-`+e.toLowerCase()}function BWe(e){return e.charAt(1).toUpperCase()}var VWe=X6([f8,NWe,h8,g8,_8],`html`),y8=X6([f8,PWe,h8,g8,_8],`svg`);function HWe(e){return e.join(` `).trim()}var UWe=o(((e,t)=>{var n=/\/\*[^*]*\*+([^/*][^*]*\*+)*\//g,r=/\n/g,i=/^\s*/,a=/^(\*?[-#/*\\\w]+(\[[0-9a-z_-]+\])?)\s*/,o=/^:\s*/,s=/^((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|\([^)]*?\)|[^};])+)/,c=/^[;\s]*/,l=/^\s+|\s+$/g,u=` `,d=`/`,f=`*`,p=``,m=`comment`,h=`declaration`;function g(e,t){if(typeof e!=`string`)throw TypeError(`First argument must be a string`);if(!e)return[];t||={};var l=1,g=1;function v(e){var t=e.match(r);t&&(l+=t.length);var n=e.lastIndexOf(u);g=~n?e.length-n:g+e.length}function y(){var e={line:l,column:g};return function(t){return t.position=new b(e),C(),t}}function b(e){this.start=e,this.end={line:l,column:g},this.source=t.source}b.prototype.content=e;function x(n){var r=Error(t.source+`:`+l+`:`+g+`: `+n);if(r.reason=n,r.filename=t.source,r.line=l,r.column=g,r.source=e,!t.silent)throw r}function S(t){var n=t.exec(e);if(n){var r=n[0];return v(r),e=e.slice(r.length),n}}function C(){S(i)}function w(e){var t;for(e||=[];t=T();)t!==!1&&e.push(t);return e}function T(){var t=y();if(!(d!=e.charAt(0)||f!=e.charAt(1))){for(var n=2;p!=e.charAt(n)&&(f!=e.charAt(n)||d!=e.charAt(n+1));)++n;if(n+=2,p===e.charAt(n-1))return x(`End of comment missing`);var r=e.slice(2,n-2);return g+=2,v(r),e=e.slice(n),g+=2,t({type:m,comment:r})}}function E(){var e=y(),t=S(a);if(t){if(T(),!S(o))return x(`property missing ':'`);var r=S(s),i=e({type:h,property:_(t[0].replace(n,p)),value:r?_(r[0].replace(n,p)):p});return S(c),i}}function D(){var e=[];w(e);for(var t;t=E();)t!==!1&&(e.push(t),w(e));return e}return C(),D()}function _(e){return e?e.replace(l,p):p}t.exports=g})),WWe=o((e=>{var t=e&&e.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(e,"__esModule",{value:!0}),e.default=r;var n=t(UWe());function r(e,t){let r=null;if(!e||typeof e!=`string`)return r;let i=(0,n.default)(e),a=typeof t==`function`;return i.forEach(e=>{if(e.type!==`declaration`)return;let{property:n,value:i}=e;a?t(n,i,e):i&&(r||={},r[n]=i)}),r}})),GWe=o((e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.camelCase=void 0;var t=/^--[a-zA-Z0-9_-]+$/,n=/-([a-z])/g,r=/^[^-]+$/,i=/^-(webkit|moz|ms|o|khtml)-/,a=/^-(ms)-/,o=function(e){return!e||r.test(e)||t.test(e)},s=function(e,t){return t.toUpperCase()},c=function(e,t){return`${t}-`};e.camelCase=function(e,t){return t===void 0&&(t={}),o(e)?e:(e=e.toLowerCase(),e=t.reactCompat?e.replace(a,c):e.replace(i,c),e.replace(n,s))}})),KWe=o(((e,t)=>{var n=(e&&e.__importDefault||function(e){return e&&e.__esModule?e:{default:e}})(WWe()),r=GWe();function i(e,t){var i={};return!e||typeof e!=`string`||(0,n.default)(e,function(e,n){e&&n&&(i[(0,r.camelCase)(e,t)]=n)}),i}i.default=i,t.exports=i})),b8=S8(`end`),x8=S8(`start`);function S8(e){return t;function t(t){let n=t&&t.position&&t.position[e]||{};if(typeof n.line==`number`&&n.line>0&&typeof n.column==`number`&&n.column>0)return{line:n.line,column:n.column,offset:typeof n.offset==`number`&&n.offset>-1?n.offset:void 0}}}function qWe(e){let t=x8(e),n=b8(e);if(t&&n)return{start:t,end:n}}function C8(e){return!e||typeof e!=`object`?``:`position`in e||`type`in e?T8(e.position):`start`in e||`end`in e?T8(e):`line`in e||`column`in e?w8(e):``}function w8(e){return E8(e&&e.line)+`:`+E8(e&&e.column)}function T8(e){return w8(e&&e.start)+`-`+w8(e&&e.end)}function E8(e){return e&&typeof e==`number`?e:1}var D8=class extends Error{constructor(e,t,n){super(),typeof t==`string`&&(n=t,t=void 0);let r=``,i={},a=!1;if(t&&(i=`line`in t&&`column`in t||`start`in t&&`end`in t?{place:t}:`type`in t?{ancestors:[t],place:t.position}:{...t}),typeof e==`string`?r=e:!i.cause&&e&&(a=!0,r=e.message,i.cause=e),!i.ruleId&&!i.source&&typeof n==`string`){let e=n.indexOf(`:`);e===-1?i.ruleId=n:(i.source=n.slice(0,e),i.ruleId=n.slice(e+1))}if(!i.place&&i.ancestors&&i.ancestors){let e=i.ancestors[i.ancestors.length-1];e&&(i.place=e.position)}let o=i.place&&`start`in i.place?i.place.start:i.place;this.ancestors=i.ancestors||void 0,this.cause=i.cause||void 0,this.column=o?o.column:void 0,this.fatal=void 0,this.file=``,this.message=r,this.line=o?o.line:void 0,this.name=C8(i.place)||`1:1`,this.place=i.place||void 0,this.reason=this.message,this.ruleId=i.ruleId||void 0,this.source=i.source||void 0,this.stack=a&&i.cause&&typeof i.cause.stack==`string`?i.cause.stack:``,this.actual=void 0,this.expected=void 0,this.note=void 0,this.url=void 0}};D8.prototype.file=``,D8.prototype.name=``,D8.prototype.reason=``,D8.prototype.message=``,D8.prototype.stack=``,D8.prototype.column=void 0,D8.prototype.line=void 0,D8.prototype.ancestors=void 0,D8.prototype.cause=void 0,D8.prototype.fatal=void 0,D8.prototype.place=void 0,D8.prototype.ruleId=void 0,D8.prototype.source=void 0;var JWe=l(KWe(),1),O8={}.hasOwnProperty,YWe=new Map,XWe=/[A-Z]/g,ZWe=new Set([`table`,`tbody`,`thead`,`tfoot`,`tr`]),QWe=new Set([`td`,`th`]);function $We(e,t){if(!t||t.Fragment===void 0)throw TypeError("Expected `Fragment` in options");let n=t.filePath||void 0,r;if(t.development){if(typeof t.jsxDEV!=`function`)throw TypeError("Expected `jsxDEV` in options when `development: true`");r=sGe(n,t.jsxDEV)}else{if(typeof t.jsx!=`function`)throw TypeError("Expected `jsx` in production options");if(typeof t.jsxs!=`function`)throw TypeError("Expected `jsxs` in production options");r=oGe(n,t.jsx,t.jsxs)}let i={Fragment:t.Fragment,ancestors:[],components:t.components||{},create:r,elementAttributeNameCase:t.elementAttributeNameCase||`react`,evaluater:t.createEvaluater?t.createEvaluater():void 0,filePath:n,ignoreInvalidStyle:t.ignoreInvalidStyle||!1,passKeys:t.passKeys!==!1,passNode:t.passNode||!1,schema:t.space===`svg`?y8:VWe,stylePropertyNameCase:t.stylePropertyNameCase||`dom`,tableCellAlignToStyle:t.tableCellAlignToStyle!==!1},a=k8(i,e,void 0);return a&&typeof a!=`string`?a:i.create(e,i.Fragment,{children:a||void 0},void 0)}function k8(e,t,n){if(t.type===`element`)return eGe(e,t,n);if(t.type===`mdxFlowExpression`||t.type===`mdxTextExpression`)return tGe(e,t);if(t.type===`mdxJsxFlowElement`||t.type===`mdxJsxTextElement`)return rGe(e,t,n);if(t.type===`mdxjsEsm`)return nGe(e,t);if(t.type===`root`)return iGe(e,t,n);if(t.type===`text`)return aGe(e,t)}function eGe(e,t,n){let r=e.schema,i=r;t.tagName.toLowerCase()===`svg`&&r.space===`html`&&(i=y8,e.schema=i),e.ancestors.push(t);let a=N8(e,t.tagName,!1),o=cGe(e,t),s=M8(e,t);return ZWe.has(t.tagName)&&(s=s.filter(function(e){return typeof e==`string`?!jWe(e):!0})),A8(e,o,a,t),j8(o,s),e.ancestors.pop(),e.schema=r,e.create(t,a,o,n)}function tGe(e,t){if(t.data&&t.data.estree&&e.evaluater){let n=t.data.estree.body[0];return n.type,e.evaluater.evaluateExpression(n.expression)}P8(e,t.position)}function nGe(e,t){if(t.data&&t.data.estree&&e.evaluater)return e.evaluater.evaluateProgram(t.data.estree);P8(e,t.position)}function rGe(e,t,n){let r=e.schema,i=r;t.name===`svg`&&r.space===`html`&&(i=y8,e.schema=i),e.ancestors.push(t);let a=t.name===null?e.Fragment:N8(e,t.name,!0),o=lGe(e,t),s=M8(e,t);return A8(e,o,a,t),j8(o,s),e.ancestors.pop(),e.schema=r,e.create(t,a,o,n)}function iGe(e,t,n){let r={};return j8(r,M8(e,t)),e.create(t,e.Fragment,r,n)}function aGe(e,t){return t.value}function A8(e,t,n,r){typeof n!=`string`&&n!==e.Fragment&&e.passNode&&(t.node=r)}function j8(e,t){if(t.length>0){let n=t.length>1?t:t[0];n&&(e.children=n)}}function oGe(e,t,n){return r;function r(e,r,i,a){let o=Array.isArray(i.children)?n:t;return a?o(r,i,a):o(r,i)}}function sGe(e,t){return n;function n(n,r,i,a){let o=Array.isArray(i.children),s=x8(n);return t(r,i,a,o,{columnNumber:s?s.column-1:void 0,fileName:e,lineNumber:s?s.line:void 0},void 0)}}function cGe(e,t){let n={},r,i;for(i in t.properties)if(i!==`children`&&O8.call(t.properties,i)){let a=uGe(e,i,t.properties[i]);if(a){let[i,o]=a;e.tableCellAlignToStyle&&i===`align`&&typeof o==`string`&&QWe.has(t.tagName)?r=o:n[i]=o}}if(r){let t=n.style||={};t[e.stylePropertyNameCase===`css`?`text-align`:`textAlign`]=r}return n}function lGe(e,t){let n={};for(let r of t.attributes)if(r.type===`mdxJsxExpressionAttribute`)if(r.data&&r.data.estree&&e.evaluater){let t=r.data.estree.body[0];t.type;let i=t.expression;i.type;let a=i.properties[0];a.type,Object.assign(n,e.evaluater.evaluateExpression(a.argument))}else P8(e,t.position);else{let i=r.name,a;if(r.value&&typeof r.value==`object`)if(r.value.data&&r.value.data.estree&&e.evaluater){let t=r.value.data.estree.body[0];t.type,a=e.evaluater.evaluateExpression(t.expression)}else P8(e,t.position);else a=r.value===null?!0:r.value;n[i]=a}return n}function M8(e,t){let n=[],r=-1,i=e.passKeys?new Map:YWe;for(;++ri?0:i+t:t>i?i:t,n=n>0?n:0,r.length<1e4)o=Array.from(r),o.unshift(t,n),e.splice(...o);else for(n&&e.splice(t,n);a0?(V8(e,e.length,0,t),e):t}var U8={}.hasOwnProperty;function W8(e){let t={},n=-1;for(;++n13&&n<32||n>126&&n<160||n>55295&&n<57344||n>64975&&n<65008||(n&65535)==65535||(n&65535)==65534||n>1114111?`�`:String.fromCodePoint(n)}function K8(e){return e.replace(/[\t\n\r ]+/g,` `).replace(/^ | $/g,``).toLowerCase().toUpperCase()}var q8=n5(/[A-Za-z]/),J8=n5(/[\dA-Za-z]/),yGe=n5(/[#-'*+\--9=?A-Z^-~]/);function Y8(e){return e!==null&&(e<32||e===127)}var X8=n5(/\d/),bGe=n5(/[\dA-Fa-f]/),xGe=n5(/[!-/:-@[-`{-~]/);function Z8(e){return e!==null&&e<-2}function Q8(e){return e!==null&&(e<0||e===32)}function $8(e){return e===-2||e===-1||e===32}var e5=n5(/\p{P}|\p{S}/u),t5=n5(/\s/);function n5(e){return t;function t(t){return t!==null&&t>-1&&e.test(String.fromCharCode(t))}}function r5(e){let t=[],n=-1,r=0,i=0;for(;++n55295&&a<57344){let t=e.charCodeAt(n+1);a<56320&&t>56319&&t<57344?(o=String.fromCharCode(a,t),i=1):o=`�`}else o=String.fromCharCode(a);o&&=(t.push(e.slice(r,n),encodeURIComponent(o)),r=n+i+1,``),i&&=(n+=i,0)}return t.join(``)+e.slice(r)}function i5(e,t,n,r){let i=r?r-1:1/0,a=0;return o;function o(r){return $8(r)?(e.enter(n),s(r)):t(r)}function s(r){return $8(r)&&a++o))return;let n=t.events.length,a=n,s,c;for(;a--;)if(t.events[a][0]===`exit`&&t.events[a][1].type===`chunkFlow`){if(s){c=t.events[a][1].end;break}s=!0}for(_(r),e=n;er;){let r=n[i];t.containerState=r[1],r[0].exit.call(t,e)}n.length=r}function v(){i.write([null]),a=void 0,i=void 0,t.containerState._closeFlow=void 0}}function EGe(e,t,n){return i5(e,e.attempt(this.parser.constructs.document,t,n),`linePrefix`,this.parser.constructs.disable.null.includes(`codeIndented`)?void 0:4)}function o5(e){if(e===null||Q8(e)||t5(e))return 1;if(e5(e))return 2}function s5(e,t,n){let r=[],i=-1;for(;++i1&&e[n][1].end.offset-e[n][1].start.offset>1?2:1;let d={...e[r][1].end},f={...e[n][1].start};l5(d,-c),l5(f,c),o={type:c>1?`strongSequence`:`emphasisSequence`,start:d,end:{...e[r][1].end}},s={type:c>1?`strongSequence`:`emphasisSequence`,start:{...e[n][1].start},end:f},a={type:c>1?`strongText`:`emphasisText`,start:{...e[r][1].end},end:{...e[n][1].start}},i={type:c>1?`strong`:`emphasis`,start:{...o.start},end:{...s.end}},e[r][1].end={...o.start},e[n][1].start={...s.end},l=[],e[r][1].end.offset-e[r][1].start.offset&&(l=H8(l,[[`enter`,e[r][1],t],[`exit`,e[r][1],t]])),l=H8(l,[[`enter`,i,t],[`enter`,o,t],[`exit`,o,t],[`enter`,a,t]]),l=H8(l,s5(t.parser.constructs.insideSpan.null,e.slice(r+1,n),t)),l=H8(l,[[`exit`,a,t],[`enter`,s,t],[`exit`,s,t],[`exit`,i,t]]),e[n][1].end.offset-e[n][1].start.offset?(u=2,l=H8(l,[[`enter`,e[n][1],t],[`exit`,e[n][1],t]])):u=0,V8(e,r-1,n-r+3,l),n=r+l.length-u-2;break}}for(n=-1;++n0&&$8(t)?i5(e,v,`linePrefix`,a+1)(t):v(t)}function v(t){return t===null||Z8(t)?e.check(m5,h,b)(t):(e.enter(`codeFlowValue`),y(t))}function y(t){return t===null||Z8(t)?(e.exit(`codeFlowValue`),v(t)):(e.consume(t),y)}function b(n){return e.exit(`codeFenced`),t(n)}function x(e,t,n){let i=0;return a;function a(t){return e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),c}function c(t){return e.enter(`codeFencedFence`),$8(t)?i5(e,l,`linePrefix`,r.parser.constructs.disable.null.includes(`codeIndented`)?void 0:4)(t):l(t)}function l(t){return t===s?(e.enter(`codeFencedFenceSequence`),u(t)):n(t)}function u(t){return t===s?(i++,e.consume(t),u):i>=o?(e.exit(`codeFencedFenceSequence`),$8(t)?i5(e,d,`whitespace`)(t):d(t)):n(t)}function d(r){return r===null||Z8(r)?(e.exit(`codeFencedFence`),t(r)):n(r)}}}function RGe(e,t,n){let r=this;return i;function i(t){return t===null?n(t):(e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),a)}function a(e){return r.parser.lazy[r.now().line]?n(e):t(e)}}var g5={name:`codeIndented`,tokenize:BGe},zGe={partial:!0,tokenize:VGe};function BGe(e,t,n){let r=this;return i;function i(t){return e.enter(`codeIndented`),i5(e,a,`linePrefix`,5)(t)}function a(e){let t=r.events[r.events.length-1];return t&&t[1].type===`linePrefix`&&t[2].sliceSerialize(t[1],!0).length>=4?o(e):n(e)}function o(t){return t===null?c(t):Z8(t)?e.attempt(zGe,o,c)(t):(e.enter(`codeFlowValue`),s(t))}function s(t){return t===null||Z8(t)?(e.exit(`codeFlowValue`),o(t)):(e.consume(t),s)}function c(n){return e.exit(`codeIndented`),t(n)}}function VGe(e,t,n){let r=this;return i;function i(t){return r.parser.lazy[r.now().line]?n(t):Z8(t)?(e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),i):i5(e,a,`linePrefix`,5)(t)}function a(e){let a=r.events[r.events.length-1];return a&&a[1].type===`linePrefix`&&a[2].sliceSerialize(a[1],!0).length>=4?t(e):Z8(e)?i(e):n(e)}}var HGe={name:`codeText`,previous:WGe,resolve:UGe,tokenize:GGe};function UGe(e){let t=e.length-4,n=3,r,i;if((e[n][1].type===`lineEnding`||e[n][1].type===`space`)&&(e[t][1].type===`lineEnding`||e[t][1].type===`space`)){for(r=n;++r=this.left.length+this.right.length)throw RangeError("Cannot access index `"+e+"` in a splice buffer of size `"+(this.left.length+this.right.length)+"`");return ethis.left.length?this.right.slice(this.right.length-n+this.left.length,this.right.length-e+this.left.length).reverse():this.left.slice(e).concat(this.right.slice(this.right.length-n+this.left.length).reverse())}splice(e,t,n){let r=t||0;this.setCursor(Math.trunc(e));let i=this.right.splice(this.right.length-r,1/0);return n&&_5(this.left,n),i.reverse()}pop(){return this.setCursor(1/0),this.left.pop()}push(e){this.setCursor(1/0),this.left.push(e)}pushMany(e){this.setCursor(1/0),_5(this.left,e)}unshift(e){this.setCursor(0),this.right.push(e)}unshiftMany(e){this.setCursor(0),_5(this.right,e.reverse())}setCursor(e){if(!(e===this.left.length||e>this.left.length&&this.right.length===0||e<0&&this.left.length===0))if(e=4?t(i):e.interrupt(r.parser.constructs.flow,n,t)(i)}}function y5(e,t,n,r,i,a,o,s,c){let l=c||1/0,u=0;return d;function d(t){return t===60?(e.enter(r),e.enter(i),e.enter(a),e.consume(t),e.exit(a),f):t===null||t===32||t===41||Y8(t)?n(t):(e.enter(r),e.enter(o),e.enter(s),e.enter(`chunkString`,{contentType:`string`}),h(t))}function f(n){return n===62?(e.enter(a),e.consume(n),e.exit(a),e.exit(i),e.exit(r),t):(e.enter(s),e.enter(`chunkString`,{contentType:`string`}),p(n))}function p(t){return t===62?(e.exit(`chunkString`),e.exit(s),f(t)):t===null||t===60||Z8(t)?n(t):(e.consume(t),t===92?m:p)}function m(t){return t===60||t===62||t===92?(e.consume(t),p):p(t)}function h(i){return!u&&(i===null||i===41||Q8(i))?(e.exit(`chunkString`),e.exit(s),e.exit(o),e.exit(r),t(i)):u999||l===null||l===91||l===93&&!c||l===94&&!s&&`_hiddenFootnoteSupport`in o.parser.constructs?n(l):l===93?(e.exit(a),e.enter(i),e.consume(l),e.exit(i),e.exit(r),t):Z8(l)?(e.enter(`lineEnding`),e.consume(l),e.exit(`lineEnding`),u):(e.enter(`chunkString`,{contentType:`string`}),d(l))}function d(t){return t===null||t===91||t===93||Z8(t)||s++>999?(e.exit(`chunkString`),u(t)):(e.consume(t),c||=!$8(t),t===92?f:d)}function f(t){return t===91||t===92||t===93?(e.consume(t),s++,d):d(t)}}function x5(e,t,n,r,i,a){let o;return s;function s(t){return t===34||t===39||t===40?(e.enter(r),e.enter(i),e.consume(t),e.exit(i),o=t===40?41:t,c):n(t)}function c(n){return n===o?(e.enter(i),e.consume(n),e.exit(i),e.exit(r),t):(e.enter(a),l(n))}function l(t){return t===o?(e.exit(a),c(o)):t===null?n(t):Z8(t)?(e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),i5(e,l,`linePrefix`)):(e.enter(`chunkString`,{contentType:`string`}),u(t))}function u(t){return t===o||t===null||Z8(t)?(e.exit(`chunkString`),l(t)):(e.consume(t),t===92?d:u)}function d(t){return t===o||t===92?(e.consume(t),u):u(t)}}function S5(e,t){let n;return r;function r(i){return Z8(i)?(e.enter(`lineEnding`),e.consume(i),e.exit(`lineEnding`),n=!0,r):$8(i)?i5(e,r,n?`linePrefix`:`lineSuffix`)(i):t(i)}}var $Ge={name:`definition`,tokenize:tKe},eKe={partial:!0,tokenize:nKe};function tKe(e,t,n){let r=this,i;return a;function a(t){return e.enter(`definition`),o(t)}function o(t){return b5.call(r,e,s,n,`definitionLabel`,`definitionLabelMarker`,`definitionLabelString`)(t)}function s(t){return i=K8(r.sliceSerialize(r.events[r.events.length-1][1]).slice(1,-1)),t===58?(e.enter(`definitionMarker`),e.consume(t),e.exit(`definitionMarker`),c):n(t)}function c(t){return Q8(t)?S5(e,l)(t):l(t)}function l(t){return y5(e,u,n,`definitionDestination`,`definitionDestinationLiteral`,`definitionDestinationLiteralMarker`,`definitionDestinationRaw`,`definitionDestinationString`)(t)}function u(t){return e.attempt(eKe,d,d)(t)}function d(t){return $8(t)?i5(e,f,`whitespace`)(t):f(t)}function f(a){return a===null||Z8(a)?(e.exit(`definition`),r.parser.defined.push(i),t(a)):n(a)}}function nKe(e,t,n){return r;function r(t){return Q8(t)?S5(e,i)(t):n(t)}function i(t){return x5(e,a,n,`definitionTitle`,`definitionTitleMarker`,`definitionTitleString`)(t)}function a(t){return $8(t)?i5(e,o,`whitespace`)(t):o(t)}function o(e){return e===null||Z8(e)?t(e):n(e)}}var rKe={name:`hardBreakEscape`,tokenize:iKe};function iKe(e,t,n){return r;function r(t){return e.enter(`hardBreakEscape`),e.consume(t),i}function i(r){return Z8(r)?(e.exit(`hardBreakEscape`),t(r)):n(r)}}var aKe={name:`headingAtx`,resolve:oKe,tokenize:sKe};function oKe(e,t){let n=e.length-2,r=3,i,a;return e[r][1].type===`whitespace`&&(r+=2),n-2>r&&e[n][1].type===`whitespace`&&(n-=2),e[n][1].type===`atxHeadingSequence`&&(r===n-1||n-4>r&&e[n-2][1].type===`whitespace`)&&(n-=r+1===n?2:4),n>r&&(i={type:`atxHeadingText`,start:e[r][1].start,end:e[n][1].end},a={type:`chunkText`,start:e[r][1].start,end:e[n][1].end,contentType:`text`},V8(e,r,n-r+1,[[`enter`,i,t],[`enter`,a,t],[`exit`,a,t],[`exit`,i,t]])),e}function sKe(e,t,n){let r=0;return i;function i(t){return e.enter(`atxHeading`),a(t)}function a(t){return e.enter(`atxHeadingSequence`),o(t)}function o(t){return t===35&&r++<6?(e.consume(t),o):t===null||Q8(t)?(e.exit(`atxHeadingSequence`),s(t)):n(t)}function s(n){return n===35?(e.enter(`atxHeadingSequence`),c(n)):n===null||Z8(n)?(e.exit(`atxHeading`),t(n)):$8(n)?i5(e,s,`whitespace`)(n):(e.enter(`atxHeadingText`),l(n))}function c(t){return t===35?(e.consume(t),c):(e.exit(`atxHeadingSequence`),s(t))}function l(t){return t===null||t===35||Q8(t)?(e.exit(`atxHeadingText`),s(t)):(e.consume(t),l)}}var cKe=`address.article.aside.base.basefont.blockquote.body.caption.center.col.colgroup.dd.details.dialog.dir.div.dl.dt.fieldset.figcaption.figure.footer.form.frame.frameset.h1.h2.h3.h4.h5.h6.head.header.hr.html.iframe.legend.li.link.main.menu.menuitem.nav.noframes.ol.optgroup.option.p.param.search.section.summary.table.tbody.td.tfoot.th.thead.title.tr.track.ul`.split(`.`),C5=[`pre`,`script`,`style`,`textarea`],lKe={concrete:!0,name:`htmlFlow`,resolveTo:fKe,tokenize:pKe},uKe={partial:!0,tokenize:hKe},dKe={partial:!0,tokenize:mKe};function fKe(e){let t=e.length;for(;t--&&!(e[t][0]===`enter`&&e[t][1].type===`htmlFlow`););return t>1&&e[t-2][1].type===`linePrefix`&&(e[t][1].start=e[t-2][1].start,e[t+1][1].start=e[t-2][1].start,e.splice(t-2,2)),e}function pKe(e,t,n){let r=this,i,a,o,s,c;return l;function l(e){return u(e)}function u(t){return e.enter(`htmlFlow`),e.enter(`htmlFlowData`),e.consume(t),d}function d(s){return s===33?(e.consume(s),f):s===47?(e.consume(s),a=!0,h):s===63?(e.consume(s),i=3,r.interrupt?t:I):q8(s)?(e.consume(s),o=String.fromCharCode(s),g):n(s)}function f(a){return a===45?(e.consume(a),i=2,p):a===91?(e.consume(a),i=5,s=0,m):q8(a)?(e.consume(a),i=4,r.interrupt?t:I):n(a)}function p(i){return i===45?(e.consume(i),r.interrupt?t:I):n(i)}function m(i){return i===`CDATA[`.charCodeAt(s++)?(e.consume(i),s===6?r.interrupt?t:O:m):n(i)}function h(t){return q8(t)?(e.consume(t),o=String.fromCharCode(t),g):n(t)}function g(s){if(s===null||s===47||s===62||Q8(s)){let c=s===47,l=o.toLowerCase();return!c&&!a&&C5.includes(l)?(i=1,r.interrupt?t(s):O(s)):cKe.includes(o.toLowerCase())?(i=6,c?(e.consume(s),_):r.interrupt?t(s):O(s)):(i=7,r.interrupt&&!r.parser.lazy[r.now().line]?n(s):a?v(s):y(s))}return s===45||J8(s)?(e.consume(s),o+=String.fromCharCode(s),g):n(s)}function _(i){return i===62?(e.consume(i),r.interrupt?t:O):n(i)}function v(t){return $8(t)?(e.consume(t),v):E(t)}function y(t){return t===47?(e.consume(t),E):t===58||t===95||q8(t)?(e.consume(t),b):$8(t)?(e.consume(t),y):E(t)}function b(t){return t===45||t===46||t===58||t===95||J8(t)?(e.consume(t),b):x(t)}function x(t){return t===61?(e.consume(t),S):$8(t)?(e.consume(t),x):y(t)}function S(t){return t===null||t===60||t===61||t===62||t===96?n(t):t===34||t===39?(e.consume(t),c=t,C):$8(t)?(e.consume(t),S):w(t)}function C(t){return t===c?(e.consume(t),c=null,T):t===null||Z8(t)?n(t):(e.consume(t),C)}function w(t){return t===null||t===34||t===39||t===47||t===60||t===61||t===62||t===96||Q8(t)?x(t):(e.consume(t),w)}function T(e){return e===47||e===62||$8(e)?y(e):n(e)}function E(t){return t===62?(e.consume(t),D):n(t)}function D(t){return t===null||Z8(t)?O(t):$8(t)?(e.consume(t),D):n(t)}function O(t){return t===45&&i===2?(e.consume(t),M):t===60&&i===1?(e.consume(t),N):t===62&&i===4?(e.consume(t),L):t===63&&i===3?(e.consume(t),I):t===93&&i===5?(e.consume(t),F):Z8(t)&&(i===6||i===7)?(e.exit(`htmlFlowData`),e.check(uKe,R,k)(t)):t===null||Z8(t)?(e.exit(`htmlFlowData`),k(t)):(e.consume(t),O)}function k(t){return e.check(dKe,A,R)(t)}function A(t){return e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),j}function j(t){return t===null||Z8(t)?k(t):(e.enter(`htmlFlowData`),O(t))}function M(t){return t===45?(e.consume(t),I):O(t)}function N(t){return t===47?(e.consume(t),o=``,P):O(t)}function P(t){if(t===62){let n=o.toLowerCase();return C5.includes(n)?(e.consume(t),L):O(t)}return q8(t)&&o.length<8?(e.consume(t),o+=String.fromCharCode(t),P):O(t)}function F(t){return t===93?(e.consume(t),I):O(t)}function I(t){return t===62?(e.consume(t),L):t===45&&i===2?(e.consume(t),I):O(t)}function L(t){return t===null||Z8(t)?(e.exit(`htmlFlowData`),R(t)):(e.consume(t),L)}function R(n){return e.exit(`htmlFlow`),t(n)}}function mKe(e,t,n){let r=this;return i;function i(t){return Z8(t)?(e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),a):n(t)}function a(e){return r.parser.lazy[r.now().line]?n(e):t(e)}}function hKe(e,t,n){return r;function r(r){return e.enter(`lineEnding`),e.consume(r),e.exit(`lineEnding`),e.attempt(u5,t,n)}}var gKe={name:`htmlText`,tokenize:_Ke};function _Ke(e,t,n){let r=this,i,a,o;return s;function s(t){return e.enter(`htmlText`),e.enter(`htmlTextData`),e.consume(t),c}function c(t){return t===33?(e.consume(t),l):t===47?(e.consume(t),x):t===63?(e.consume(t),y):q8(t)?(e.consume(t),w):n(t)}function l(t){return t===45?(e.consume(t),u):t===91?(e.consume(t),a=0,m):q8(t)?(e.consume(t),v):n(t)}function u(t){return t===45?(e.consume(t),p):n(t)}function d(t){return t===null?n(t):t===45?(e.consume(t),f):Z8(t)?(o=d,N(t)):(e.consume(t),d)}function f(t){return t===45?(e.consume(t),p):d(t)}function p(e){return e===62?M(e):e===45?f(e):d(e)}function m(t){return t===`CDATA[`.charCodeAt(a++)?(e.consume(t),a===6?h:m):n(t)}function h(t){return t===null?n(t):t===93?(e.consume(t),g):Z8(t)?(o=h,N(t)):(e.consume(t),h)}function g(t){return t===93?(e.consume(t),_):h(t)}function _(t){return t===62?M(t):t===93?(e.consume(t),_):h(t)}function v(t){return t===null||t===62?M(t):Z8(t)?(o=v,N(t)):(e.consume(t),v)}function y(t){return t===null?n(t):t===63?(e.consume(t),b):Z8(t)?(o=y,N(t)):(e.consume(t),y)}function b(e){return e===62?M(e):y(e)}function x(t){return q8(t)?(e.consume(t),S):n(t)}function S(t){return t===45||J8(t)?(e.consume(t),S):C(t)}function C(t){return Z8(t)?(o=C,N(t)):$8(t)?(e.consume(t),C):M(t)}function w(t){return t===45||J8(t)?(e.consume(t),w):t===47||t===62||Q8(t)?T(t):n(t)}function T(t){return t===47?(e.consume(t),M):t===58||t===95||q8(t)?(e.consume(t),E):Z8(t)?(o=T,N(t)):$8(t)?(e.consume(t),T):M(t)}function E(t){return t===45||t===46||t===58||t===95||J8(t)?(e.consume(t),E):D(t)}function D(t){return t===61?(e.consume(t),O):Z8(t)?(o=D,N(t)):$8(t)?(e.consume(t),D):T(t)}function O(t){return t===null||t===60||t===61||t===62||t===96?n(t):t===34||t===39?(e.consume(t),i=t,k):Z8(t)?(o=O,N(t)):$8(t)?(e.consume(t),O):(e.consume(t),A)}function k(t){return t===i?(e.consume(t),i=void 0,j):t===null?n(t):Z8(t)?(o=k,N(t)):(e.consume(t),k)}function A(t){return t===null||t===34||t===39||t===60||t===61||t===96?n(t):t===47||t===62||Q8(t)?T(t):(e.consume(t),A)}function j(e){return e===47||e===62||Q8(e)?T(e):n(e)}function M(r){return r===62?(e.consume(r),e.exit(`htmlTextData`),e.exit(`htmlText`),t):n(r)}function N(t){return e.exit(`htmlTextData`),e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),P}function P(t){return $8(t)?i5(e,F,`linePrefix`,r.parser.constructs.disable.null.includes(`codeIndented`)?void 0:4)(t):F(t)}function F(t){return e.enter(`htmlTextData`),o(t)}}var w5={name:`labelEnd`,resolveAll:xKe,resolveTo:SKe,tokenize:CKe},vKe={tokenize:wKe},yKe={tokenize:TKe},bKe={tokenize:EKe};function xKe(e){let t=-1,n=[];for(;++t=3&&(a===null||Z8(a))?(e.exit(`thematicBreak`),t(a)):n(a)}function c(t){return t===i?(e.consume(t),r++,c):(e.exit(`thematicBreakSequence`),$8(t)?i5(e,s,`whitespace`)(t):s(t))}}var D5={continuation:{tokenize:IKe},exit:RKe,name:`list`,tokenize:FKe},NKe={partial:!0,tokenize:zKe},PKe={partial:!0,tokenize:LKe};function FKe(e,t,n){let r=this,i=r.events[r.events.length-1],a=i&&i[1].type===`linePrefix`?i[2].sliceSerialize(i[1],!0).length:0,o=0;return s;function s(t){let i=r.containerState.type||(t===42||t===43||t===45?`listUnordered`:`listOrdered`);if(i===`listUnordered`?!r.containerState.marker||t===r.containerState.marker:X8(t)){if(r.containerState.type||(r.containerState.type=i,e.enter(i,{_container:!0})),i===`listUnordered`)return e.enter(`listItemPrefix`),t===42||t===45?e.check(E5,n,l)(t):l(t);if(!r.interrupt||t===49)return e.enter(`listItemPrefix`),e.enter(`listItemValue`),c(t)}return n(t)}function c(t){return X8(t)&&++o<10?(e.consume(t),c):(!r.interrupt||o<2)&&(r.containerState.marker?t===r.containerState.marker:t===41||t===46)?(e.exit(`listItemValue`),l(t)):n(t)}function l(t){return e.enter(`listItemMarker`),e.consume(t),e.exit(`listItemMarker`),r.containerState.marker=r.containerState.marker||t,e.check(u5,r.interrupt?n:u,e.attempt(NKe,f,d))}function u(e){return r.containerState.initialBlankLine=!0,a++,f(e)}function d(t){return $8(t)?(e.enter(`listItemPrefixWhitespace`),e.consume(t),e.exit(`listItemPrefixWhitespace`),f):n(t)}function f(n){return r.containerState.size=a+r.sliceSerialize(e.exit(`listItemPrefix`),!0).length,t(n)}}function IKe(e,t,n){let r=this;return r.containerState._closeFlow=void 0,e.check(u5,i,a);function i(n){return r.containerState.furtherBlankLines=r.containerState.furtherBlankLines||r.containerState.initialBlankLine,i5(e,t,`listItemIndent`,r.containerState.size+1)(n)}function a(n){return r.containerState.furtherBlankLines||!$8(n)?(r.containerState.furtherBlankLines=void 0,r.containerState.initialBlankLine=void 0,o(n)):(r.containerState.furtherBlankLines=void 0,r.containerState.initialBlankLine=void 0,e.attempt(PKe,t,o)(n))}function o(i){return r.containerState._closeFlow=!0,r.interrupt=void 0,i5(e,e.attempt(D5,t,n),`linePrefix`,r.parser.constructs.disable.null.includes(`codeIndented`)?void 0:4)(i)}}function LKe(e,t,n){let r=this;return i5(e,i,`listItemIndent`,r.containerState.size+1);function i(e){let i=r.events[r.events.length-1];return i&&i[1].type===`listItemIndent`&&i[2].sliceSerialize(i[1],!0).length===r.containerState.size?t(e):n(e)}}function RKe(e){e.exit(this.containerState.type)}function zKe(e,t,n){let r=this;return i5(e,i,`listItemPrefixWhitespace`,r.parser.constructs.disable.null.includes(`codeIndented`)?void 0:5);function i(e){let i=r.events[r.events.length-1];return!$8(e)&&i&&i[1].type===`listItemPrefixWhitespace`?t(e):n(e)}}var O5={name:`setextUnderline`,resolveTo:BKe,tokenize:VKe};function BKe(e,t){let n=e.length,r,i,a;for(;n--;)if(e[n][0]===`enter`){if(e[n][1].type===`content`){r=n;break}e[n][1].type===`paragraph`&&(i=n)}else e[n][1].type===`content`&&e.splice(n,1),!a&&e[n][1].type===`definition`&&(a=n);let o={type:`setextHeading`,start:{...e[r][1].start},end:{...e[e.length-1][1].end}};return e[i][1].type=`setextHeadingText`,a?(e.splice(i,0,[`enter`,o,t]),e.splice(a+1,0,[`exit`,e[r][1],t]),e[r][1].end={...e[a][1].end}):e[r][1]=o,e.push([`exit`,o,t]),e}function VKe(e,t,n){let r=this,i;return a;function a(t){let a=r.events.length,s;for(;a--;)if(r.events[a][1].type!==`lineEnding`&&r.events[a][1].type!==`linePrefix`&&r.events[a][1].type!==`content`){s=r.events[a][1].type===`paragraph`;break}return!r.parser.lazy[r.now().line]&&(r.interrupt||s)?(e.enter(`setextHeadingLine`),i=t,o(t)):n(t)}function o(t){return e.enter(`setextHeadingLineSequence`),s(t)}function s(t){return t===i?(e.consume(t),s):(e.exit(`setextHeadingLineSequence`),$8(t)?i5(e,c,`lineSuffix`)(t):c(t))}function c(r){return r===null||Z8(r)?(e.exit(`setextHeadingLine`),t(r)):n(r)}}var HKe={tokenize:UKe};function UKe(e){let t=this,n=e.attempt(u5,r,e.attempt(this.parser.constructs.flowInitial,i,i5(e,e.attempt(this.parser.constructs.flow,i,e.attempt(JGe,i)),`linePrefix`)));return n;function r(r){if(r===null){e.consume(r);return}return e.enter(`lineEndingBlank`),e.consume(r),e.exit(`lineEndingBlank`),t.currentConstruct=void 0,n}function i(r){if(r===null){e.consume(r);return}return e.enter(`lineEnding`),e.consume(r),e.exit(`lineEnding`),t.currentConstruct=void 0,n}}var WKe={resolveAll:A5()},GKe=k5(`string`),KKe=k5(`text`);function k5(e){return{resolveAll:A5(e===`text`?qKe:void 0),tokenize:t};function t(t){let n=this,r=this.parser.constructs[e],i=t.attempt(r,a,o);return a;function a(e){return c(e)?i(e):o(e)}function o(e){if(e===null){t.consume(e);return}return t.enter(`data`),t.consume(e),s}function s(e){return c(e)?(t.exit(`data`),i(e)):(t.consume(e),s)}function c(e){if(e===null)return!0;let t=r[e],i=-1;if(t)for(;++inqe,contentInitial:()=>XKe,disable:()=>rqe,document:()=>YKe,flow:()=>QKe,flowInitial:()=>ZKe,insideSpan:()=>tqe,string:()=>$Ke,text:()=>eqe}),YKe={42:D5,43:D5,45:D5,48:D5,49:D5,50:D5,51:D5,52:D5,53:D5,54:D5,55:D5,56:D5,57:D5,62:d5},XKe={91:$Ge},ZKe={[-2]:g5,[-1]:g5,32:g5},QKe={35:aKe,42:E5,45:[O5,E5],60:lKe,61:O5,95:E5,96:h5,126:h5},$Ke={38:p5,92:f5},eqe={[-5]:T5,[-4]:T5,[-3]:T5,33:DKe,38:p5,42:c5,60:[kGe,gKe],91:kKe,92:[rKe,f5],93:w5,95:c5,96:HGe},tqe={null:[c5,WKe]},nqe={null:[42,95]},rqe={null:[]};function iqe(e,t,n){let r={_bufferIndex:-1,_index:0,line:n&&n.line||1,column:n&&n.column||1,offset:n&&n.offset||0},i={},a=[],o=[],s=[],c={attempt:C(x),check:C(S),consume:v,enter:y,exit:b,interrupt:C(S,{interrupt:!0})},l={code:null,containerState:{},defineSkip:h,events:[],now:m,parser:e,previous:null,sliceSerialize:f,sliceStream:p,write:d},u=t.tokenize.call(l,c);return t.resolveAll&&a.push(t),l;function d(e){return o=H8(o,e),g(),o[o.length-1]===null?(w(t,0),l.events=s5(a,l.events,l),l.events):[]}function f(e,t){return oqe(p(e),t)}function p(e){return aqe(o,e)}function m(){let{_bufferIndex:e,_index:t,line:n,column:i,offset:a}=r;return{_bufferIndex:e,_index:t,line:n,column:i,offset:a}}function h(e){i[e.line]=e.column,E()}function g(){let e;for(;r._index-1){let e=o[0];typeof e==`string`?o[0]=e.slice(r):o.shift()}a>0&&o.push(e[i].slice(0,a))}return o}function oqe(e,t){let n=-1,r=[],i;for(;++n0){let e=a.tokenStack[a.tokenStack.length-1];(e[1]||F5).call(a,void 0,e[0])}for(r.position={start:N5(e.length>0?e[0][1].start:{line:1,column:1,offset:0}),end:N5(e.length>0?e[e.length-2][1].end:{line:1,column:1,offset:0})},d=-1;++d - +